ant-design/components/color-picker/demo/presets.tsx
2023-12-16 00:35:27 +08:00

18 lines
633 B
TypeScript

import React from 'react';
import { generate, green, presetPalettes, red } from '@ant-design/colors';
import { ColorPicker, theme } from 'antd';
import type { ColorPickerProps } from 'antd';
type Presets = Required<ColorPickerProps>['presets'][number];
const genPresets = (presets = presetPalettes) =>
Object.entries(presets).map<Presets>(([label, colors]) => ({ label, colors }));
const Demo: React.FC = () => {
const { token } = theme.useToken();
const presets = genPresets({ primary: generate(token.colorPrimary), red, green });
return <ColorPicker presets={presets} defaultValue="#1677ff" />;
};
export default Demo;