mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
2cdf586291
* chore: fix lint * chore: fix lint * test: fix 16 * fix: lint
28 lines
686 B
TypeScript
28 lines
686 B
TypeScript
import React, { useMemo, useState } from 'react';
|
|
import { Button, ColorPicker, theme } from 'antd';
|
|
import type { Color } from 'antd/es/color-picker';
|
|
|
|
const Demo: React.FC = () => {
|
|
const { token } = theme.useToken();
|
|
const [color, setColor] = useState<Color | string>(token.colorPrimary);
|
|
|
|
const bgColor = useMemo<string>(
|
|
() => (typeof color === 'string' ? color : color.toHexString()),
|
|
[color],
|
|
);
|
|
|
|
const btnStyle: React.CSSProperties = {
|
|
backgroundColor: bgColor,
|
|
};
|
|
|
|
return (
|
|
<ColorPicker value={color} onChange={setColor}>
|
|
<Button type="primary" style={btnStyle}>
|
|
open
|
|
</Button>
|
|
</ColorPicker>
|
|
);
|
|
};
|
|
|
|
export default Demo;
|