Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support classnames and styles #289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thinkasany
Copy link

@thinkasany thinkasany commented Feb 25, 2025

Summary by CodeRabbit

  • 新功能
    • 组件现支持自定义弹窗样式,用户可通过设置特定样式及类名来自定义弹窗和文本区域的外观。
  • 测试
    • 新增测试用例,验证自定义样式和类名在弹窗及文本区域中的正确应用,确保功能如预期工作。

Copy link

coderabbitai bot commented Feb 25, 2025

Walkthrough

此次更改在两个组件中增加了自定义样式的支持。在 KeywordTrigger.tsx 中,为 KeywordTriggerProps 接口添加了可选的 popupStyle 属性,并将其传递给 Trigger 组件。在 Mentions.tsx 中,扩展了 MentionsProps 接口,为 classNamesstyles 分别增加了 textareapopup 属性,使得可对文本区域和弹出框进行更精细的样式定制。同时,新增的测试用例验证了这些样式与类名的正确应用。

Changes

文件路径 更改摘要
src/KeywordTrigger.tsx KeywordTriggerProps 接口新增 popupStyle?: React.CSSProperties 属性,并将其传递给 Trigger 组件。
src/Mentions.tsx 扩展 MentionsProps 接口,classNamesstyles 对象中分别添加 textareapopup 属性,更新了相应组件的属性传递。
tests/Mentions.spec.tsx 新增测试用例,验证 Mentions 组件中下拉菜单与文本区域的自定义类名和样式是否正常生效。

Sequence Diagram(s)

sequenceDiagram
    participant M as Mentions
    participant IM as InternalMentions
    participant TA as TextArea
    participant KT as KeywordTrigger
    participant T as Trigger

    M->>IM: 传递 classNames 与 styles (textarea, popup)
    IM->>TA: 应用textarea的classNames与styles
    IM->>KT: 应用popup的classNames与styles
    KT->>T: 传递popupStyle属性
Loading

Poem

森林中我蹦跳不停,
代码之花悄然绽放;
样式灵动如露珠晶莹,
弹窗轻舞讲述新风尚;
萌兔庆祝变更时,
萌心满满乐淘淘!
🥕🌙🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/KeywordTrigger.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

src/Mentions.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

tests/Mentions.spec.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 843d868 and 69436cc.

📒 Files selected for processing (3)
  • src/KeywordTrigger.tsx (3 hunks)
  • src/Mentions.tsx (6 hunks)
  • tests/Mentions.spec.tsx (1 hunks)
🔇 Additional comments (10)
src/KeywordTrigger.tsx (3)

54-54: 新增了 popupStyle 属性以支持自定义样式。

新增了 popupStyle 属性允许为弹出框指定自定义样式,这与 PR 目标一致。


66-66: 正确解构 popupStyle 属性。

从 props 中正确解构了 popupStyle 属性以便后续使用。


97-97: 将 popupStyle 属性传递给 Trigger 组件。

成功将 popupStyle 属性传递给 Trigger 组件,使样式生效。

tests/Mentions.spec.tsx (1)

270-292: 测试用例验证了自定义类名和样式功能。

新增的测试用例很好地验证了以下功能:

  1. 自定义弹出框类名 (test-popup) 能正确应用
  2. 自定义弹出框背景色 (red) 能正确应用
  3. 自定义文本区域类名 (test-textarea) 能正确应用
  4. 自定义文本区域背景色 (blue) 能正确应用

测试用例设计全面,覆盖了本次新增功能的核心特性。

src/Mentions.tsx (6)

74-80: 扩展 MentionsProps 接口以支持更细粒度的样式定制。

成功扩展了 MentionsProps 接口,为 classNamesstyles 添加了 textareapopup 属性,允许对文本区域和弹出框进行更精细的样式定制。这种设计与组件库的通用样式定制模式一致。


101-102: 重命名变量以避免命名冲突。

classNames 重命名为 mentionClassNames,并添加了 styles 属性的解构,避免了与内部变量的命名冲突,同时保持了代码清晰度。


484-485: 为 TextArea 组件添加样式支持。

正确地将 textarea 的类名和样式传递给了 TextArea 组件,确保自定义样式能够应用到文本区域。


519-524: 为 KeywordTrigger 组件添加样式支持。

成功地将 popup 的类名和样式传递给了 KeywordTrigger 组件,确保自定义样式能够应用到弹出框。使用 classNames 函数合并了传入的 dropdownClassNamementionClassNames?.popup,保持了向后兼容性。


547-548: 在外层组件中保持一致的命名模式。

与内部组件保持一致,将 classNames 重命名为 mentionsClassNames,并添加了 styles 属性的解构,保持了代码的一致性。


591-600: 正确传递样式和类名到子组件。

成功将样式和类名传递给 BaseInput 和 InternalMentions 组件,确保样式能够在整个组件层次结构中正确应用。

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant