import { FloatButton } from 'antd'; import { CompactTheme, DarkTheme } from 'antd-token-previewer/lib/icons'; import { UnorderedListOutlined, LinkOutlined } from '@ant-design/icons'; import { FormattedMessage } from 'dumi'; import React from 'react'; import ThemeIcon from './ThemeIcon'; export type ThemeName = 'light' | 'dark' | 'compact' | 'hideSideBar' | 'hideAnchor'; export type ThemeSwitchProps = { value?: ThemeName[]; onChange: (value: ThemeName[]) => void; }; const ThemeSwitch: React.FC = (props: ThemeSwitchProps) => { const { value = ['light'], onChange } = props; return ( }> } type={value.includes('dark') ? 'primary' : 'default'} onClick={() => { const themeValue = value.includes('dark') ? 'light' : 'dark'; onChange([themeValue, ...value.filter((item) => ['dark', 'light'].indexOf(item) < 0)]); // compact 值必须放在靠后位置 }} tooltip={} /> } type={value.includes('compact') ? 'primary' : 'default'} onClick={() => { if (value.includes('compact')) { onChange(value.filter((item) => item !== 'compact')); } else { onChange([...value, 'compact']); } }} tooltip={} /> } type={value.includes('hideSideBar') ? 'primary' : 'default'} onClick={() => { if (value.includes('hideSideBar')) { onChange(value.filter((item) => item !== 'hideSideBar')); } else { onChange([...value, 'hideSideBar']); } }} tooltip={} /> } type={value.includes('hideAnchor') ? 'primary' : 'default'} onClick={() => { if (value.includes('hideAnchor')) { onChange(value.filter((item) => item !== 'hideAnchor')); } else { onChange([...value, 'hideAnchor']); } }} tooltip={} /> ); }; export default ThemeSwitch;