ant-design/components/menu/demo/menu-v4.tsx
afc163 d90c1c62c0
fix: upgrade @ant-design/icons to 5.1.0 (#42443)
* Update package.json

* Update package.json

* chore: update snapshot

* style: #1890ff => #1677ff

* style: fix Upload icon color

* style: fix Upload icon color

* revert menu v4 demo
2023-05-18 09:40:09 +08:00

92 lines
2.2 KiB
TypeScript

import {
AppstoreOutlined,
CalendarOutlined,
LinkOutlined,
MailOutlined,
SettingOutlined,
} from '@ant-design/icons';
import { ConfigProvider, Menu, Switch } from 'antd';
import type { MenuProps } from 'antd/es/menu';
import React, { useState } from 'react';
type MenuItem = Required<MenuProps>['items'][number];
function getItem(
label: React.ReactNode,
key?: React.Key | null,
icon?: React.ReactNode,
children?: MenuItem[],
): MenuItem {
return {
key,
icon,
children,
label,
} as MenuItem;
}
const items: MenuItem[] = [
getItem('Navigation One', '1', <MailOutlined />),
getItem('Navigation Two', '2', <CalendarOutlined />),
getItem('Navigation Two', 'sub1', <AppstoreOutlined />, [
getItem('Option 3', '3'),
getItem('Option 4', '4'),
getItem('Submenu', 'sub1-2', null, [getItem('Option 5', '5'), getItem('Option 6', '6')]),
]),
getItem('Navigation Three', 'sub2', <SettingOutlined />, [
getItem('Option 7', '7'),
getItem('Option 8', '8'),
getItem('Option 9', '9'),
getItem('Option 10', '10'),
]),
getItem(
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
Ant Design
</a>,
'link',
<LinkOutlined />,
),
];
const App: React.FC = () => {
const [mode, setMode] = useState<'vertical' | 'inline'>('inline');
const changeMode = (value: boolean) => {
setMode(value ? 'vertical' : 'inline');
};
return (
<>
<Switch onChange={changeMode} /> Change Mode
<br />
<br />
<ConfigProvider
theme={{
components: {
Menu: {
radiusItem: 0,
radiusSubMenuItem: 0,
colorItemTextHover: '#1890ff',
colorItemTextSelected: '#1890ff',
colorItemBgSelected: '#e6f7ff',
colorActiveBarWidth: 3,
itemMarginInline: 0,
colorItemBgHover: 'transparent',
},
},
}}
>
<Menu
style={{ width: 256 }}
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
mode={mode}
items={items}
/>
</ConfigProvider>
</>
);
};
export default App;