2023-07-28 16:17:43 +08:00
|
|
|
import React, { useMemo, useState } from 'react';
|
2023-05-28 15:15:28 +08:00
|
|
|
import { Button, ColorPicker, theme } from 'antd';
|
2023-05-14 11:47:01 +08:00
|
|
|
import type { Color } from 'antd/es/color-picker';
|
2023-05-12 14:43:48 +08:00
|
|
|
|
2023-05-28 15:15:28 +08:00
|
|
|
const Demo: React.FC = () => {
|
2023-05-12 14:43:48 +08:00
|
|
|
const { token } = theme.useToken();
|
|
|
|
const [color, setColor] = useState<Color | string>(token.colorPrimary);
|
2023-05-14 11:47:01 +08:00
|
|
|
|
|
|
|
const bgColor = useMemo<string>(
|
2023-05-12 14:43:48 +08:00
|
|
|
() => (typeof color === 'string' ? color : color.toHexString()),
|
|
|
|
[color],
|
|
|
|
);
|
|
|
|
|
2023-05-28 15:15:28 +08:00
|
|
|
const btnStyle: React.CSSProperties = {
|
2023-05-16 13:49:59 +08:00
|
|
|
backgroundColor: bgColor,
|
|
|
|
};
|
|
|
|
|
2023-05-12 14:43:48 +08:00
|
|
|
return (
|
|
|
|
<ColorPicker value={color} onChange={setColor}>
|
2023-05-28 15:15:28 +08:00
|
|
|
<Button type="primary" style={btnStyle}>
|
|
|
|
open
|
|
|
|
</Button>
|
2023-05-12 14:43:48 +08:00
|
|
|
</ColorPicker>
|
|
|
|
);
|
|
|
|
};
|
2023-05-28 15:15:28 +08:00
|
|
|
|
|
|
|
export default Demo;
|