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: ColorPicker implement showText
API
#42865
Conversation
Pull reviewers statsStats of the last 30 days for ant-design:
|
size-limit report 📦
|
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## feature #42865 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 650 650
Lines 10956 10974 +18
Branches 2971 2979 +8
=========================================
+ Hits 10956 10974 +18
☔ View full report in Codecov by Sentry. |
| disabled | 禁用颜色选择器 | boolean | - | | | ||
| placement | 弹出窗口的位置 | `top` \| `topLeft` \| `topRight` \| `bottom` \| `bottomLeft` \| `bottomRight` | `bottomLeft` | | | ||
| arrow | 配置弹出的箭头 | `boolean \| { pointAtCenter: boolean }` | true | | | ||
| showValue | 是否显示选定的颜色 | `boolean` | - | 5.7.0 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 showValue 直观上看不出来是啥意思,是不是类似 DatePicker 一样给个 format 函数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还能解决自定义的问题。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前只是简单的根据 format
生成对应的颜色字符串,如果需要深度定制 format
格式确实需要一个函数,意下如何? cc @MadCcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数吧,一步到位。
@@ -39,6 +39,7 @@ export interface ColorPickerProps | |||
allowClear?: boolean; | |||
presets?: PresetsItem[]; | |||
arrow?: boolean | { pointAtCenter: boolean }; | |||
showValue?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我意思是不需要 showValue 这个属性了,这个命名不好,不容易理解。
直接用 format 取代掉。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format
已经有对应属性了,换一个?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实,<ColorPicker inputRender={} />
好了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputRender:( formatStr:string ) => string
or
inputRender:( formatStr:string, color:Color) => string
? @afc163
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputRender: (color: Color) => React.ReactNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color
是对象还是字符串
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对象
Co-authored-by: MadCcc <1075746765@qq.com>
bb68bbd
to
32483ae
Compare
textRender
API
@@ -40,6 +42,9 @@ const ColorTrigger = forwardRef<HTMLDivElement, colorTriggerProps>((props, ref) | |||
{...rest} | |||
> | |||
{containerNode} | |||
{typeof textRender === 'function' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个在 ts 中已经约束了函数,这里不需要判断类型了吧
{typeof textRender === 'function' && ( | |
{textRender && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
兜底也可以,可以保证 js 不会报错
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的想法是这种情况反而不需要兜底,如果用户传了不是函数,就让 js 把报错抛出去,兜底的话用户反而看不到错误,不知道为啥这里不显示 dom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果值隐式转换成boolean
,可能会多一个空节点。
Co-authored-by: MadCcc <1075746765@qq.com>
alignItems: 'center', | ||
justifyContent: 'center', | ||
transition: `all ${motionDurationMid}`, | ||
background: colorBgElevated, | ||
padding: paddingXXS - 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 可以写成 lineWidth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好
@@ -142,6 +146,12 @@ const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => { | |||
borderColor: colorBgTextActive, | |||
}, | |||
}, | |||
[`${componentCls}-trigger-text`]: { | |||
marginInlineStart: marginXS, | |||
marginInlineEnd: marginXS - 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量不要留魔法数字
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里改成 lineWidth * 2 ?
@@ -142,6 +146,12 @@ const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => { | |||
borderColor: colorBgTextActive, | |||
}, | |||
}, | |||
[`${componentCls}-trigger-text`]: { | |||
marginInlineStart: marginXS, | |||
marginInlineEnd: marginXS - lineWidth * 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 lineWidth*2
没什么道理,如果是两边对称应该是减去原有的 padding
@@ -40,6 +42,9 @@ const ColorTrigger = forwardRef<HTMLDivElement, colorTriggerProps>((props, ref) | |||
{...rest} | |||
> | |||
{containerNode} | |||
{typeof textRender === 'function' && ( | |||
<div className={`${colorTriggerPrefixCls}-text`}>{textRender(color)}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉还是加个默认的 showText 好点,textRender 还是要写代码
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showText
跟之前 showValue
是一个意思?
textRender
APIshowText
API
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
Light:
Dark:
📝 Changelog
ColorPicker
implementshowText
API颜色选择器
实现showText
API☑️ Self-Check before Merge
🚀 Summary
🤖 Generated by Copilot at 2babb91
This pull request adds a new feature to the
ColorPicker
component that allows showing the selected color as a text value in different formats. It updates the component logic, style, documentation, and tests to support this feature. It also adds a new demo fileshowValue.tsx
and its corresponding markdown fileshowValue.md
to showcase the feature.🔍 Walkthrough
🤖 Generated by Copilot at 2babb91
showValue
to theColorPicker
component, which controls whether to show the selected color as a string in the trigger component (link, link, link, link, link).