feat(color-picker): Support better customization with semantic classNames/styles as function#54962
feat(color-picker): Support better customization with semantic classNames/styles as function#54962zombieJ merged 6 commits intoant-design:nextfrom meet-student:color-picker
Conversation
|
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🧪 Early access (Sonnet 4.5): enabledWe are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience. Note:
Comment |
👁 Visual Regression Report for PR #54962 Failed ❌
Important There are 4 diffs found in this PR: 🔄
|
There was a problem hiding this comment.
Summary of Changes
Hello @meet-student, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the ColorPicker component by introducing the ability to define classNames and styles using functions. This allows for highly flexible and conditional styling based on the component's properties, providing developers with greater control over its appearance. The changes include updates to the core component logic, comprehensive documentation, new examples, and robust test coverage to support this new feature.
Highlights
- Enhanced Customization for ColorPicker: The ColorPicker component now supports
classNamesandstylesprops that can accept functions. These functions receive the component'spropsas an argument, enabling dynamic application of CSS classes and inline styles based on the component's current state (e.g.,disabled,size). - New Demo and Documentation: A new demo (
style-class.tsx) and corresponding documentation (style-class.md,index.en-US.md,index.zh-CN.md) have been added to illustrate this new customization capability, providing clear examples for developers. - Type Definition Updates and Test Coverage: The component's TypeScript interfaces (
interface.ts) have been updated to reflect the new function-basedclassNamesandstylestypes, ensuring type safety. New test cases have also been added inindex.test.tsxto validate the functionality of these new customization options.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature to the ColorPicker component, allowing classNames and styles to be provided as functions for dynamic customization. The implementation is well-done, with corresponding tests and documentation. My review focuses on improving the TypeScript definitions and documentation for these new capabilities to make them more accurate, intuitive, and less restrictive for developers. I've suggested changes to the type definitions in interface.ts to better reflect the intended API and allow for more flexible styling of nested components. I've also pointed out areas in the documentation that could be clarified to better explain the structure of the classNames and styles props.
| | allowClear | Allow clearing color selected | boolean | false | | | ||
| | arrow | Configuration for popup arrow | `boolean \| { pointAtCenter: boolean }` | true | | | ||
| | children | Trigger of ColorPicker | React.ReactNode | - | | | ||
| | classNames | Customize class names for each semantic structure inside the component. Supports object or function. | [Record<SemanticDOM, string> \| (info: { props })=> Record<SemanticDOM, string>](#semantic-dom) | - | 5.4.0 | |
There was a problem hiding this comment.
The documented type for classNames is a bit misleading as it doesn't fully reflect the nested structure of the prop (e.g., for popup). A more accurate representation, such as ({ root?: string, popup?: { root?: string } }) | (info) => ..., would be clearer for users and better align with the component's semantic DOM structure. The same applies to the styles prop.
| | allowClear | 允许清除选择的颜色 | boolean | false | | | ||
| | arrow | 配置弹出的箭头 | `boolean \| { pointAtCenter: boolean }` | true | | | ||
| | children | 颜色选择器的触发器 | React.ReactNode | - | | | ||
| | classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | [Record<SemanticDOM, string> \| (info: { props })=> Record<SemanticDOM, string>](#semantic-dom) | - | 5.4.0 | |
There was a problem hiding this comment.
The documented type for classNames is a bit misleading as it doesn't fully reflect the nested structure of the prop (e.g., for popup). A more accurate representation, such as ({ root?: string, popup?: { root?: string } }) | (info) => ..., would be clearer for users and better align with the component's semantic DOM structure. The same applies to the styles prop.
components/color-picker/interface.ts
Outdated
| classNames?: ColorPickerClassNamesType & { | ||
| popup?: Partial<Record<PopupSemantic, string>>; | ||
| }; | ||
| styles?: ColorPickerStylesType & { | ||
| popup?: Partial<Record<PopupSemantic, React.CSSProperties>>; | ||
| popupOverlayInner?: CSSProperties; | ||
| }; |
There was a problem hiding this comment.
The current type definitions for classNames and styles are a bit confusing and potentially incorrect. The use of an intersection (&) with a union type that includes a function can lead to a misleading type of function & object. This structure also seems to prevent providing popup classNames or styles from within the function, which limits the dynamic styling capabilities.
To improve clarity and flexibility, consider refactoring these types to represent a choice between a complete object structure (including popup) or a function that returns that complete structure. This would make the API more intuitive and fully support dynamic styling for all parts of the component.
More templates
commit: |
Bundle ReportChanges will increase total bundle size by 240 bytes (0.01%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: antd.min-array-pushAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #54962 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 798 798
Lines 14749 14750 +1
Branches 3896 3896
=========================================
+ Hits 14749 14750 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ames/styles as function
| const App: React.FC = () => { | ||
| const { styles: classNames } = useStyles(); | ||
|
|
||
| const stylesObject: ColorPickerProps['styles'] = { |
| if (info.props.size === 'large') { | ||
| return { | ||
| popup: { | ||
| root: { |
|
冲突看一下 |
|
skip 需调整语义化结构 |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the ColorPicker component to support better customization by allowing semantic classNames and styles props to accept functions in addition to objects. This enables dynamic styling based on component props.
Key changes:
- Refactor
classNamesandstylesprops to use generic semantic types that support both objects and functions - Add comprehensive testing for both object and function-based styling
- Include documentation and demo showing the new functionality
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
components/color-picker/interface.ts |
Define new type aliases for ColorPicker semantic styling that support functions |
components/color-picker/ColorPicker.tsx |
Update component to pass merged props to semantic styling system |
components/color-picker/demo/style-class.tsx |
Add demo showing both object and function-based styling |
components/color-picker/__tests__/semantic.test.tsx |
Add comprehensive tests for semantic styling functionality |
| Documentation files | Update API documentation to reflect new function support |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.










中文版模板 / Chinese template
🤔 This is a ...
🔗 Related Issues
💡 Background and Solution
📝 Change Log