mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
6cfbace3cd
* chore: migrate to webpack@5
* Revert "feat: support popupBg and darkPopupBg (#45826)"
This reverts commit 496ac3326f
.
* chore: update
159 lines
3.4 KiB
TypeScript
159 lines
3.4 KiB
TypeScript
import {
|
|
AppstoreOutlined,
|
|
ContainerOutlined,
|
|
DesktopOutlined,
|
|
MailOutlined,
|
|
PieChartOutlined,
|
|
SettingOutlined,
|
|
} from '@ant-design/icons';
|
|
import React, { useState } from 'react';
|
|
import type { MenuProps } from 'antd';
|
|
import { ConfigProvider, Menu, Space } from 'antd';
|
|
|
|
type MenuItem = Required<MenuProps>['items'][number];
|
|
|
|
const items: MenuProps['items'] = [
|
|
{
|
|
label: 'Navigation One',
|
|
key: 'mail',
|
|
icon: <MailOutlined />,
|
|
},
|
|
{
|
|
label: 'Navigation Two',
|
|
key: 'app',
|
|
icon: <AppstoreOutlined />,
|
|
disabled: true,
|
|
},
|
|
{
|
|
label: 'Navigation Three - Submenu',
|
|
key: 'SubMenu',
|
|
icon: <SettingOutlined />,
|
|
children: [
|
|
{
|
|
type: 'group',
|
|
label: 'Item 1',
|
|
children: [
|
|
{
|
|
label: 'Option 1',
|
|
key: 'setting:1',
|
|
},
|
|
{
|
|
label: 'Option 2',
|
|
key: 'setting:2',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: 'group',
|
|
label: 'Item 2',
|
|
children: [
|
|
{
|
|
label: 'Option 3',
|
|
key: 'setting:3',
|
|
},
|
|
{
|
|
label: 'Option 4',
|
|
key: 'setting:4',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: (
|
|
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
|
|
Navigation Four - Link
|
|
</a>
|
|
),
|
|
key: 'alipay',
|
|
},
|
|
];
|
|
|
|
function getItem(
|
|
label: React.ReactNode,
|
|
key: React.Key,
|
|
icon?: React.ReactNode,
|
|
children?: MenuItem[],
|
|
type?: 'group',
|
|
): MenuItem {
|
|
return {
|
|
key,
|
|
icon,
|
|
children,
|
|
label,
|
|
type,
|
|
} as MenuItem;
|
|
}
|
|
|
|
const items2: MenuProps['items'] = [
|
|
getItem('Option 1', '1', <PieChartOutlined />),
|
|
getItem('Option 2', '2', <DesktopOutlined />),
|
|
getItem('Option 3', '3', <ContainerOutlined />),
|
|
|
|
getItem('Navigation One', 'sub1', <MailOutlined />, [
|
|
getItem('Option 5', '5'),
|
|
getItem('Option 6', '6'),
|
|
getItem('Option 7', '7'),
|
|
getItem('Option 8', '8'),
|
|
]),
|
|
|
|
getItem('Navigation Two', 'sub2', <AppstoreOutlined />, [
|
|
getItem('Option 9', '9'),
|
|
getItem('Option 10', '10'),
|
|
|
|
getItem('Submenu', 'sub3', null, [getItem('Option 11', '11'), getItem('Option 12', '12')]),
|
|
]),
|
|
];
|
|
|
|
const App: React.FC = () => {
|
|
const [current, setCurrent] = useState('mail');
|
|
|
|
const onClick: MenuProps['onClick'] = (e) => {
|
|
console.log('click ', e);
|
|
setCurrent(e.key);
|
|
};
|
|
|
|
return (
|
|
<Space direction="vertical">
|
|
<ConfigProvider
|
|
theme={{
|
|
components: {
|
|
Menu: {
|
|
horizontalItemBorderRadius: 6,
|
|
horizontalItemHoverBg: '#f5f5f5',
|
|
},
|
|
},
|
|
}}
|
|
>
|
|
<Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
|
|
</ConfigProvider>
|
|
<ConfigProvider
|
|
theme={{
|
|
components: {
|
|
Menu: {
|
|
darkItemColor: '#91daff',
|
|
darkItemBg: '#d48806',
|
|
darkSubMenuItemBg: '#faad14',
|
|
darkItemSelectedColor: '#ffccc7',
|
|
darkItemSelectedBg: '#52c41a',
|
|
},
|
|
},
|
|
}}
|
|
>
|
|
<Menu
|
|
defaultSelectedKeys={['1']}
|
|
defaultOpenKeys={['sub1']}
|
|
mode="inline"
|
|
theme="dark"
|
|
items={items2}
|
|
style={{
|
|
width: 256,
|
|
}}
|
|
/>
|
|
</ConfigProvider>
|
|
</Space>
|
|
);
|
|
};
|
|
|
|
export default App;
|