ant-design/components/color-picker/ColorPickerPanel.tsx
叶枫 14a1e6bd51
feat: tsconfig enable strict (#47998)
* feat: tsconfig enable strict

* feat: add no-explicit-any

* feat: strict

* feat: as THEME

* feat: 优化 keys 类型写法

* feat: demo remove any

* feat: as number

* feat: this any

* feat: add eslint

* feat: cascader

* feat: props any

* feat: remove any

* feat: remove any

* feat: any 提示错误

* feat: remove any

* feat: add eslint

* feat: 允许 T = any 存在

* feat: color funciton

* feat: 恢复 lint

* feat: merge master

* feat: as ReactElement

* feat: type
2024-04-01 15:49:45 +08:00

72 lines
2.0 KiB
TypeScript

import type { FC } from 'react';
import React from 'react';
import type { HsbaColorType } from '@rc-component/color-picker';
import Divider from '../divider';
import type { Color } from './color';
import PanelPicker from './components/PanelPicker';
import PanelPresets from './components/PanelPresets';
import { PanelPickerProvider, PanelPresetsProvider } from './context';
import type { ColorPickerBaseProps } from './interface';
export interface ColorPickerPanelProps extends ColorPickerBaseProps {
onChange?: (value?: Color, type?: HsbaColorType, pickColor?: boolean) => void;
onClear?: () => void;
}
const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
const { prefixCls, presets, panelRender, color, onChange, onClear, ...injectProps } = props;
const colorPickerPanelPrefixCls = `${prefixCls}-inner`;
// ==== Inject props ===
const panelPickerProps = {
prefixCls,
value: color,
onChange,
onClear,
...injectProps,
};
const panelPresetsProps = React.useMemo(
() => ({
prefixCls,
value: color,
presets,
onChange,
}),
[prefixCls, color, presets, onChange],
);
// ====================== Render ======================
const innerPanel = (
<div className={`${colorPickerPanelPrefixCls}-content`}>
<PanelPicker />
{Array.isArray(presets) && <Divider />}
<PanelPresets />
</div>
);
return (
<PanelPickerProvider value={panelPickerProps}>
<PanelPresetsProvider value={panelPresetsProps}>
<div className={colorPickerPanelPrefixCls}>
{typeof panelRender === 'function'
? panelRender(innerPanel, {
components: {
Picker: PanelPicker,
Presets: PanelPresets,
},
})
: innerPanel}
</div>
</PanelPresetsProvider>
</PanelPickerProvider>
);
};
if (process.env.NODE_ENV !== 'production') {
ColorPickerPanel.displayName = 'ColorPickerPanel';
}
export default ColorPickerPanel;