import * as React from 'react'; import { TinyColor } from '@ctrl/tinycolor'; import { Drawer, Form, Input, Button, InputNumber, Checkbox, Space } from 'antd'; import { useIntl } from 'react-intl'; import { BugOutlined, EyeOutlined } from '@ant-design/icons'; import { DesignToken } from '../../../../../components/_util/theme'; import defaultTheme from '../../../../../components/_util/theme/default'; import Preview from './Preview'; export interface ThemeConfigProps { componentName: string; defaultToken: DesignToken; onChangeTheme: (theme: DesignToken) => void; } export default ({ onChangeTheme, defaultToken, componentName }: ThemeConfigProps) => { const { formatMessage } = useIntl(); const [visible, setVisible] = React.useState(false); const [previewVisible, setPreviewVisible] = React.useState(false); const [form] = Form.useForm(); const keys = Object.keys(defaultTheme); const onFinish = (nextToken: DesignToken) => { onChangeTheme(nextToken); }; return ( <>
setVisible(true)} > Dynamic Theme
{ setVisible(false); }} title={formatMessage({ id: 'app.theme.switch.dynamic' })} extra={ } destroyOnClose >
{keys.map((key: keyof typeof defaultToken) => { const originValue = defaultToken[key]; const originValueType = typeof originValue; let node: React.ReactElement; switch (originValueType) { case 'number': node = ; break; default: node = ; } const rules: any[] = [{ required: true }]; const originColor = new TinyColor(originValue); if (originValueType === 'string' && originColor.isValid) { rules.push({ validator: async (_: any, value: string) => { if (!new TinyColor(value).isValid) { throw new Error('Invalidate color type'); } }, }); } return ( {node} ); })} Bind Style on hash className
setPreviewVisible(false)} /> ); };