mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
2722850c0d
* fix: sync @rc-component/color-picker@1.1.0 * Update package.json Co-authored-by: afc163 <afc163@gmail.com> --------- Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import RcColorPicker from '@rc-component/color-picker';
|
|
import type { FC } from 'react';
|
|
import React from 'react';
|
|
import Divider from '../divider';
|
|
import type { Color } from './color';
|
|
import ColorClear from './components/ColorClear';
|
|
import ColorInput from './components/ColorInput';
|
|
import ColorPresets from './components/ColorPresets';
|
|
import type { ColorPickerBaseProps } from './interface';
|
|
|
|
interface ColorPickerPanelProps extends ColorPickerBaseProps {
|
|
onChange?: (value?: Color) => void;
|
|
onClear?: (clear?: boolean) => void;
|
|
}
|
|
|
|
const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|
const { prefixCls, allowClear, presets, onChange, onClear, color, ...injectProps } = props;
|
|
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
|
|
|
const extraPanelRender = (panel: React.ReactNode) => (
|
|
<div className={colorPickerPanelPrefixCls}>
|
|
{allowClear && (
|
|
<ColorClear
|
|
prefixCls={prefixCls}
|
|
value={color}
|
|
onChange={(clearColor) => {
|
|
onChange?.(clearColor);
|
|
onClear?.(true);
|
|
}}
|
|
{...injectProps}
|
|
/>
|
|
)}
|
|
{panel}
|
|
<ColorInput value={color} onChange={onChange} prefixCls={prefixCls} {...injectProps} />
|
|
{Array.isArray(presets) && (
|
|
<>
|
|
<Divider className={`${colorPickerPanelPrefixCls}-divider`} />
|
|
<ColorPresets value={color} presets={presets} prefixCls={prefixCls} onChange={onChange} />
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
return (
|
|
<RcColorPicker
|
|
prefixCls={prefixCls}
|
|
value={color?.toHsb()}
|
|
onChange={onChange}
|
|
panelRender={extraPanelRender}
|
|
/>
|
|
);
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
ColorPickerPanel.displayName = 'ColorPickerPanel';
|
|
}
|
|
|
|
export default ColorPickerPanel;
|