-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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: new component ColorPicker #41990
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## feature #41990 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 619 638 +19
Lines 10570 10826 +256
Branches 2886 2943 +57
==========================================
+ Hits 10570 10826 +256
☔ View full report in Codecov by Sentry. |
components/affix/index.tsx
Outdated
@@ -2,9 +2,9 @@ import classNames from 'classnames'; | |||
import ResizeObserver from 'rc-resize-observer'; | |||
import omit from 'rc-util/lib/omit'; | |||
import React, { createRef, forwardRef, useContext } from 'react'; | |||
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame'; |
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.
这个文件需要回滚一下
<Select.Option value={ColorFormatEnum.hex}> | ||
{ColorFormatEnum.hex.toLocaleUpperCase()} | ||
</Select.Option> | ||
<Select.Option value={ColorFormatEnum.hsb}> | ||
{ColorFormatEnum.hsb.toLocaleUpperCase()} | ||
</Select.Option> | ||
<Select.Option value={ColorFormatEnum.rgb}> | ||
{ColorFormatEnum.rgb.toLocaleUpperCase()} | ||
</Select.Option> |
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.
用 options
components/color-picker/enum.ts
Outdated
@@ -0,0 +1,6 @@ | |||
/* eslint-disable import/prefer-default-export */ | |||
export enum ColorFormatEnum { |
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.
这个写个字面量放 interface 里就行
|
|
||
export interface ColorPickerProps | ||
extends Omit<RcColorPickerProps, 'onChange' | 'arrow' | 'value' | 'defaultValue' | 'children'> { | ||
value?: Color | string; |
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.
这个类型好多地方都有在用,是不是可以弄一个新类型聚合一下呢?
比如:type ColorVal = Color | string
,命名上可以再斟酌一下,不过感觉有个别名,在其他地方使用的时候会方便一点
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.
可以考虑加个通用类型
import React from 'react'; | ||
import ColorPicker from '../ColorPicker'; | ||
|
||
describe('ColorPicker', () => { |
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.
还没,还在UI走查阶段,有空我补一下
|
||
const ColorHexInput: FC<ColorHexInputProps> = ({ prefixCls, value, onChange }) => { | ||
const ColorHexInputPrefixCls = `${prefixCls}-hex-input`; | ||
const [hexValue, setHexValue] = useState(toHex(value?.toHexString() || '')); |
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.
如果 value 有可能为空的话,是不是可以单独定义一个变量处理兜底逻辑,这样就不用后面每次用 value 的时候都用可选链,担心太多可选链会增加包的体积,例如:
const val = useMemo(() => value ? value.toHexString() : '', [value])
这样后面直接用 val 就好了?
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.
可以优化一下,可选链多了确实不好
闲夕大佬这么晚还在推代码 |
辛苦了大佬🙏 |
看样子可以上 5.5 的车了🎉 |
argos 没有截图,还得看看 |
没问题了 |
用 es 目录。 |
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
💡 Background and solution
📝 Changelog
☑️ Self-Check before Merge
Copilot
🤖 Generated by Copilot at 45700f1
Summary
🎨🧪📝
This pull request adds a new ColorPicker component to the ant-design library, which allows users to select and edit colors in different formats. It includes the component implementation, tests, demos, and documentation files. The component uses the RcColorPicker component as a base, and extends it with some custom logic, styles, and subcomponents. The component also provides a hook to manage the color state, and exports some types for external use.
Walkthrough
ColorPicker
component and its documentation (link, link, link, link)ExPanel
component to extend theRcColorPicker
panel with aColorDataBar
component (link, link)Color
interface and theColorFactory
class to wrap theRcColor
class and provide custom methods and properties (link, link)ColorFormatEnum
type and theColorFormat
,PressetsItem
, andColorPickerBaseProps
types for the props and internal components of theColorPicker
component (link, link)ColorHexInput
,ColorPlaceholder
, andColorSteppers
components to render and edit the color values in different formats (link, link, link)ColorPicker
component and its markdown file (link, link)ColorPicker
component and its demos, using the testing library and image snapshots (link, link, link, link)ColorPicker
component and its subcomponents (link)