Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions components/color-picker/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,8 @@ describe('ColorPicker', () => {
).toBeFalsy()

// className
expect(
underlineWrapper.find('.kd-color-picker-container .kd-color-picker-input').at(2).hasClass('my-color-picker'),
).toBeTruthy()
expect(
borderedWrapper.find('.kd-color-picker-container .kd-color-picker-input').at(2).hasClass('my-color-picker'),
).toBeTruthy()
expect(underlineWrapper.find('.kd-color-picker-container').hasClass('my-color-picker')).toBeTruthy()
expect(borderedWrapper.find('.kd-color-picker-container').hasClass('my-color-picker')).toBeTruthy()

// placeholder
expect(underlineWrapper.find('.kd-input-underline').prop('placeholder')).toEqual('#')
Expand All @@ -138,8 +134,8 @@ describe('ColorPicker', () => {
expect(underlineWrapper.find('.kd-input-wrapper-underline').prop('style')).toBeFalsy()
underlineWrapper.setProps({ style: { height: '40px' } })
underlineWrapper.update()
expect(underlineWrapper.find('.kd-input-wrapper-underline').prop('style')).toEqual({ height: '40px' })
expect(underlineWrapper.find('.kd-input-wrapper-underline')).toHaveStyle('height', '40px')
expect(underlineWrapper.find('.kd-color-picker-container').prop('style')).toEqual({ height: '40px' })
expect(underlineWrapper.find('.kd-color-picker-container')).toHaveStyle('height', '40px')

// default prefixIcon
expect(underlineWrapper.find('.kd-input-prefix').find('.kd-color-picker-icon')).toHaveClassName(
Expand Down Expand Up @@ -345,6 +341,11 @@ describe('ColorPicker', () => {
expect(defaultOpenWrapper.find('.kd-color-picker-panel-historical-color-box')).not.toExist()
expect(defaultOpenWrapper.find('.kd-color-picker-panel-color-box-title')).not.toExist()

// popperClassName
defaultOpenWrapper.setProps({ popperClassName: 'color-picker-test' })
defaultOpenWrapper.update()
expect(defaultOpenWrapper.find('.color-picker-test')).toExist()

// showColorTransfer
defaultOpenWrapper.setProps({ showColorTransfer: false })
defaultOpenWrapper.update()
Expand Down
13 changes: 7 additions & 6 deletions components/color-picker/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ const ColorPicker: FC<Partial<IColorPickerProps>> = (props) => {
defaultValue,
defaultOpen,
visible,
popperClassName,
suffixIcon,
prefixIcon,
onChange,
onVisibleChange,
...otherProps
} = colorPickerProps
const [inputColorValue, setInputColorValue] = useState<string>(defaultValue || '')
const [inputCorrectColorValue, setInputCorrectColorValue] = useState<string>('')
Expand All @@ -57,11 +59,11 @@ const ColorPicker: FC<Partial<IColorPickerProps>> = (props) => {
const [clickedHistoricalColorIndex, setClickedHistoricalColorIndex] = useState<number>()

const colorPickerPrefixCls = getPrefixCls!(prefixCls, 'color-picker')
const popUpLayer = getPrefixCls!(prefixCls, 'color-picker-pop')
const containerCls = classNames(`${colorPickerPrefixCls}-container`, {
const popUpLayer = classNames(getPrefixCls!(prefixCls, 'color-picker-pop'), popperClassName)
const containerCls = classNames(`${colorPickerPrefixCls}-container`, className, {
[`${colorPickerPrefixCls}-container-pure`]: pure,
})
const inputCls = classNames(`${colorPickerPrefixCls}-input`, className)
const inputCls = classNames(`${colorPickerPrefixCls}-input`)
const inputRef = useRef<HTMLInputElement>(null)
const showColorPickerPanel =
showColorTransfer ||
Expand Down Expand Up @@ -198,15 +200,14 @@ const ColorPicker: FC<Partial<IColorPickerProps>> = (props) => {
}, [borderType, colTypeArr, colorPickerPrefixCls, inputCorrectColorValue, value])

const colorInputEle = (
<div className={containerCls} ref={inputRef}>
<div className={containerCls} ref={inputRef} style={style}>
<Input
borderType={pure ? 'bordered' : borderType}
placeholder={placeholder}
value={value ?? inputColorValue}
className={inputCls}
onChange={handleChange}
onBlur={handleBlur}
style={style}
onClick={handleClick}
prefix={
<div onClick={handleClick} className={`${colorPickerPrefixCls}-icon-container`}>
Expand Down Expand Up @@ -273,7 +274,7 @@ const ColorPicker: FC<Partial<IColorPickerProps>> = (props) => {
)

const popperProps = {
...colorPickerProps,
...otherProps,
popperClassName: popUpLayer,
placement: 'bottomLeft',
defaultVisible: showPanel,
Expand Down
1 change: 1 addition & 0 deletions components/color-picker/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ subtitle: 颜色选择器
| historicalColor | 用户自定义的最近使用颜色,数组中支持十六进制、RGB 、HSB 、HSL 或者颜色英文名称,同时支持透明度,如:\['blue', '#0000FF', '#0000FFEE', 'RGB(0,0,255)', 'RGBA(0,0,200,0.5)', 'HSL(240,100%,50%)', 'HSLA(240,100%,50%,0.5)', 'HSB(240,100%,100%)', 'HSBA(240,100%,100%,0.5)'\] | string[] | - | 1.8.16 |
| panelFormatConfig | 配置颜色面板下拉颜色格式选项,**注意:default 的值必须是 show 中存在的值** | {show:('HEX' \| 'RGB' \| 'HSB' \| 'HSL')[], default:'HEX' \| 'RGB' \| 'HSB' \| 'HSL'} | { show: \['HEX', 'HSB', 'RGB', 'HSL'\], default: 'HEX' } | 1.8.16 |
| placeholder | 输入框内容为空时的输入提示 | string | # | 1.7.0 |
| popperClassName | 颜色选择面板的类名 | string | # | 1.8.21 |
| presetColor | 用户自定义的预设颜色,数组中支持十六进制、RGB 、HSB 、HSL 或者颜色英文名称,同时支持透明度,如:\['blue', '#0000FF', '#0000FFEE', 'RGB(0,0,255)', 'RGBA(0,0,200,0.5)', 'HSL(240,100%,50%)', 'HSLA(240,100%,50%,0.5)', 'HSB(240,100%,100%)', 'HSBA(240,100%,100%,0.5)'\] | string[] | - | 1.8.16 |
| pure | 纯色块模式 | boolean | false | 1.8.16 |
| switchName | 设置功能色开关的名称,**注意:如自定义的名称需支持国际化需要提供 internationalName** | { name: string; internationalName?: string } | { name: '跟随主题色'; internationalName:'followFunctionalColor' } | 1.7.0 |
Expand Down
9 changes: 5 additions & 4 deletions components/color-picker/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.@{color-picker-prefix-cls}-container {
position: relative;
width: @color-picker-input-sizing-width;
height: @color-picker-input-sizing-height;

&-pure {
width: 28px;
Expand All @@ -32,8 +33,8 @@
}

.@{color-picker-prefix-cls}-input {
width: @color-picker-input-sizing-width;
height: @color-picker-input-sizing-height;
height: 100%;
width: 100%;
padding: 0 8px;
border-bottom: 1px solid rgba(217, 217, 217, 1);
font-size: @color-picker-input-font-size;
Expand All @@ -58,7 +59,7 @@
width: @color-picker-input-prefix-line-sizing-width;
height: @color-picker-input-prefix-line-sizing-height;
background-color: #ff2e3d;
rotate: 45deg;
transform: rotate(45deg);
}
}
}
Expand Down Expand Up @@ -117,7 +118,7 @@
width: 1px;
height: 22.6px;
background-color: #ff2e3d;
rotate: 45deg;
transform: rotate(45deg);
}

.active {
Expand Down