mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-01 06:49:32 +08:00
2cdf586291
* chore: fix lint * chore: fix lint * test: fix 16 * fix: lint
75 lines
1.6 KiB
TypeScript
75 lines
1.6 KiB
TypeScript
import { MailOutlined } from '@ant-design/icons';
|
|
import React, { useState } from 'react';
|
|
import type { MenuProps, MenuTheme } from 'antd';
|
|
import { Menu, Switch } from 'antd';
|
|
|
|
type MenuItem = Required<MenuProps>['items'][number];
|
|
|
|
function getItem(
|
|
label: React.ReactNode,
|
|
key?: React.Key | null,
|
|
icon?: React.ReactNode,
|
|
children?: MenuItem[],
|
|
theme?: 'light' | 'dark',
|
|
): MenuItem {
|
|
return {
|
|
key,
|
|
icon,
|
|
children,
|
|
label,
|
|
theme,
|
|
} as MenuItem;
|
|
}
|
|
|
|
const App: React.FC = () => {
|
|
const [theme, setTheme] = useState<MenuTheme>('light');
|
|
const [current, setCurrent] = useState('1');
|
|
|
|
const changeTheme = (value: boolean) => {
|
|
setTheme(value ? 'dark' : 'light');
|
|
};
|
|
|
|
const onClick: MenuProps['onClick'] = (e) => {
|
|
setCurrent(e.key);
|
|
};
|
|
|
|
const items: MenuItem[] = [
|
|
getItem(
|
|
'Navigation One',
|
|
'sub1',
|
|
<MailOutlined />,
|
|
[getItem('Option 1', '1'), getItem('Option 2', '2'), getItem('Option 3', '3')],
|
|
theme,
|
|
),
|
|
getItem('Option 5', '5'),
|
|
getItem('Option 6', '6'),
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<Switch
|
|
checked={theme === 'dark'}
|
|
onChange={changeTheme}
|
|
checkedChildren="Dark"
|
|
unCheckedChildren="Light"
|
|
/>
|
|
<br />
|
|
<br />
|
|
<Menu
|
|
onClick={onClick}
|
|
style={{ width: 256 }}
|
|
openKeys={['sub1']}
|
|
selectedKeys={[current]}
|
|
mode="vertical"
|
|
theme="dark"
|
|
items={items}
|
|
getPopupContainer={function test(node) {
|
|
return node.parentNode as HTMLElement;
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|