ant-design/components/color-picker/demo/panel-render.tsx
叶枫 502dac12aa
docs: format code (#48309)
* docs: fix code

* feat: lint

* feat: prettier

* feat: test

* feat: review

* feat: format html

* feat: format html
2024-04-08 14:04:08 +08:00

82 lines
1.8 KiB
TypeScript

import React from 'react';
import { cyan, generate, green, presetPalettes, red } from '@ant-design/colors';
import { Col, ColorPicker, Divider, Row, Space, 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 HorizontalLayoutDemo = () => {
const { token } = theme.useToken();
const presets = genPresets({
primary: generate(token.colorPrimary),
red,
green,
cyan,
});
const customPanelRender: ColorPickerProps['panelRender'] = (
_,
{ components: { Picker, Presets } },
) => (
<Row justify="space-between" wrap={false}>
<Col span={12}>
<Presets />
</Col>
<Divider type="vertical" style={{ height: 'auto' }} />
<Col flex="auto">
<Picker />
</Col>
</Row>
);
return (
<ColorPicker
defaultValue={token.colorPrimary}
styles={{ popupOverlayInner: { width: 480 } }}
presets={presets}
panelRender={customPanelRender}
/>
);
};
const BasicDemo = () => (
<ColorPicker
defaultValue="#1677ff"
panelRender={(panel) => (
<div className="custom-panel">
<div
style={{
fontSize: 12,
color: 'rgba(0, 0, 0, 0.88)',
lineHeight: '20px',
marginBottom: 8,
}}
>
Color Picker
</div>
{panel}
</div>
)}
/>
);
export default () => (
<Space direction="vertical">
<Space>
<span>Add title:</span>
<BasicDemo />
</Space>
<Space>
<span>Horizontal layout:</span>
<HorizontalLayoutDemo />
</Space>
</Space>
);