2023-07-28 17:15:04 +08:00
|
|
|
import React from 'react';
|
2023-07-27 11:31:38 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ColorPicker,
|
|
|
|
ConfigProvider,
|
|
|
|
Divider,
|
|
|
|
Form,
|
|
|
|
Input,
|
|
|
|
InputNumber,
|
|
|
|
Space,
|
|
|
|
Switch,
|
|
|
|
} from 'antd';
|
2024-01-11 15:55:58 +08:00
|
|
|
import type { ColorPickerProps, GetProp } from 'antd';
|
|
|
|
|
|
|
|
type Color = Exclude<GetProp<ColorPickerProps, 'value'>, string>;
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2022-11-18 17:23:21 +08:00
|
|
|
type ThemeData = {
|
|
|
|
borderRadius: number;
|
|
|
|
colorPrimary: string;
|
2023-07-27 11:31:38 +08:00
|
|
|
Button?: {
|
|
|
|
colorPrimary: string;
|
|
|
|
algorithm?: boolean;
|
|
|
|
};
|
2022-11-09 12:28:04 +08:00
|
|
|
};
|
|
|
|
|
2022-11-18 17:23:21 +08:00
|
|
|
const defaultData: ThemeData = {
|
|
|
|
borderRadius: 6,
|
|
|
|
colorPrimary: '#1677ff',
|
2023-07-27 11:31:38 +08:00
|
|
|
Button: {
|
|
|
|
colorPrimary: '#00B96B',
|
|
|
|
},
|
2022-11-09 12:28:04 +08:00
|
|
|
};
|
|
|
|
|
2022-11-18 17:23:21 +08:00
|
|
|
export default () => {
|
|
|
|
const [form] = Form.useForm();
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2022-11-18 17:23:21 +08:00
|
|
|
const [data, setData] = React.useState<ThemeData>(defaultData);
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
return (
|
2023-07-27 11:31:38 +08:00
|
|
|
<div>
|
|
|
|
<ConfigProvider
|
|
|
|
theme={{
|
|
|
|
token: {
|
|
|
|
colorPrimary: data.colorPrimary,
|
|
|
|
borderRadius: data.borderRadius,
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Button: {
|
|
|
|
colorPrimary: data.Button?.colorPrimary,
|
|
|
|
algorithm: data.Button?.algorithm,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Space>
|
|
|
|
<Input />
|
|
|
|
<Button type="primary">Button</Button>
|
|
|
|
</Space>
|
|
|
|
</ConfigProvider>
|
|
|
|
<Divider />
|
2022-11-18 17:23:21 +08:00
|
|
|
<Form
|
|
|
|
form={form}
|
2023-07-27 11:31:38 +08:00
|
|
|
onValuesChange={(_, allValues) => {
|
2022-12-01 16:06:22 +08:00
|
|
|
setData({
|
|
|
|
...allValues,
|
|
|
|
});
|
2022-11-18 17:23:21 +08:00
|
|
|
}}
|
|
|
|
name="theme"
|
|
|
|
initialValues={defaultData}
|
|
|
|
labelCol={{ span: 4 }}
|
|
|
|
wrapperCol={{ span: 20 }}
|
|
|
|
>
|
2023-07-27 11:31:38 +08:00
|
|
|
<Form.Item
|
|
|
|
name="colorPrimary"
|
|
|
|
label="Primary Color"
|
|
|
|
trigger="onChangeComplete"
|
|
|
|
getValueFromEvent={(color: Color) => color.toHexString()}
|
|
|
|
>
|
2023-05-15 15:11:05 +08:00
|
|
|
<ColorPicker />
|
2022-11-18 17:23:21 +08:00
|
|
|
</Form.Item>
|
|
|
|
<Form.Item name="borderRadius" label="Border Radius">
|
|
|
|
<InputNumber />
|
|
|
|
</Form.Item>
|
2023-07-27 11:31:38 +08:00
|
|
|
<Form.Item label="Button">
|
|
|
|
<Form.Item name={['Button', 'algorithm']} valuePropName="checked" label="algorithm">
|
|
|
|
<Switch />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name={['Button', 'colorPrimary']}
|
|
|
|
label="Primary Color"
|
|
|
|
trigger="onChangeComplete"
|
|
|
|
getValueFromEvent={(color: Color) => color.toHexString()}
|
|
|
|
>
|
|
|
|
<ColorPicker />
|
|
|
|
</Form.Item>
|
|
|
|
</Form.Item>
|
2022-11-18 17:23:21 +08:00
|
|
|
<Form.Item name="submit" wrapperCol={{ offset: 4, span: 20 }}>
|
|
|
|
<Button type="primary">Submit</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
2023-07-27 11:31:38 +08:00
|
|
|
</div>
|
2022-11-09 12:28:04 +08:00
|
|
|
);
|
|
|
|
};
|