mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 08:56:43 +08:00
968200d11e
* feat: Menu support darkPopupBg token * fix lint * fix
184 lines
4.0 KiB
TypeScript
184 lines
4.0 KiB
TypeScript
import React, { useState } from 'react';
|
|
import {
|
|
AppstoreOutlined,
|
|
ContainerOutlined,
|
|
DesktopOutlined,
|
|
MailOutlined,
|
|
PieChartOutlined,
|
|
SettingOutlined,
|
|
} from '@ant-design/icons';
|
|
import type { MenuProps } from 'antd';
|
|
import { ConfigProvider, Menu, Space, theme } 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={{
|
|
algorithm: [theme.darkAlgorithm],
|
|
components: {
|
|
Menu: {
|
|
popupBg: 'yellow',
|
|
darkPopupBg: 'red',
|
|
},
|
|
},
|
|
}}
|
|
>
|
|
<Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} />
|
|
<Menu
|
|
defaultSelectedKeys={['1']}
|
|
defaultOpenKeys={['sub1']}
|
|
mode="inline"
|
|
theme="dark"
|
|
inlineCollapsed
|
|
items={items2}
|
|
style={{
|
|
width: 56,
|
|
}}
|
|
/>
|
|
</ConfigProvider>
|
|
<ConfigProvider
|
|
theme={{
|
|
components: {
|
|
Menu: {
|
|
horizontalItemBorderRadius: 6,
|
|
popupBg: 'red',
|
|
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;
|