2016-04-27 17:44:25 +08:00
|
|
|
---
|
|
|
|
order: 5
|
2016-08-26 14:42:41 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 切换菜单类型
|
|
|
|
en-US: Switch the menu type
|
2016-04-27 17:44:25 +08:00
|
|
|
---
|
2016-04-27 15:26:03 +08:00
|
|
|
|
2016-08-26 14:42:41 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-04-27 15:26:03 +08:00
|
|
|
展示动态切换模式。
|
|
|
|
|
2016-08-26 14:42:41 +08:00
|
|
|
## en-US
|
|
|
|
|
2020-10-12 12:00:00 +08:00
|
|
|
Show the dynamic switching mode (between `inline` and `vertical`).
|
2016-08-26 14:42:41 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2020-04-26 23:16:15 +08:00
|
|
|
import { Menu, Switch, Divider } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import {
|
|
|
|
MailOutlined,
|
|
|
|
CalendarOutlined,
|
|
|
|
AppstoreOutlined,
|
|
|
|
SettingOutlined,
|
2020-05-03 11:28:15 +08:00
|
|
|
LinkOutlined,
|
2019-11-28 12:34:33 +08:00
|
|
|
} from '@ant-design/icons';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-06-19 16:02:01 +08:00
|
|
|
const { SubMenu } = Menu;
|
2016-04-27 15:26:03 +08:00
|
|
|
|
2017-02-20 21:51:23 +08:00
|
|
|
class Sider extends React.Component {
|
|
|
|
state = {
|
|
|
|
mode: 'inline',
|
2017-06-19 16:02:01 +08:00
|
|
|
theme: 'light',
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
changeMode = value => {
|
2016-04-27 15:26:03 +08:00
|
|
|
this.setState({
|
|
|
|
mode: value ? 'vertical' : 'inline',
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
changeTheme = value => {
|
2017-06-19 16:02:01 +08:00
|
|
|
this.setState({
|
|
|
|
theme: value ? 'dark' : 'light',
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2016-04-27 15:26:03 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2020-04-26 23:16:15 +08:00
|
|
|
<>
|
2017-06-19 16:02:01 +08:00
|
|
|
<Switch onChange={this.changeMode} /> Change Mode
|
2020-04-26 23:16:15 +08:00
|
|
|
<Divider type="vertical" />
|
2020-01-03 19:00:01 +08:00
|
|
|
<Switch onChange={this.changeTheme} /> Change Style
|
2016-04-27 15:26:03 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<Menu
|
2017-11-06 21:28:51 +08:00
|
|
|
style={{ width: 256 }}
|
2017-06-19 16:02:01 +08:00
|
|
|
defaultSelectedKeys={['1']}
|
2016-04-27 15:26:03 +08:00
|
|
|
defaultOpenKeys={['sub1']}
|
2016-06-06 13:54:10 +08:00
|
|
|
mode={this.state.mode}
|
2017-06-19 16:02:01 +08:00
|
|
|
theme={this.state.theme}
|
2016-06-06 13:54:10 +08:00
|
|
|
>
|
2020-04-26 23:16:15 +08:00
|
|
|
<Menu.Item key="1" icon={<MailOutlined />}>
|
2017-06-19 16:02:01 +08:00
|
|
|
Navigation One
|
|
|
|
</Menu.Item>
|
2020-04-26 23:16:15 +08:00
|
|
|
<Menu.Item key="2" icon={<CalendarOutlined />}>
|
2017-06-19 16:02:01 +08:00
|
|
|
Navigation Two
|
|
|
|
</Menu.Item>
|
2020-04-26 23:16:15 +08:00
|
|
|
<SubMenu key="sub1" icon={<AppstoreOutlined />} title="Navigation Two">
|
2017-06-19 16:02:01 +08:00
|
|
|
<Menu.Item key="3">Option 3</Menu.Item>
|
|
|
|
<Menu.Item key="4">Option 4</Menu.Item>
|
2017-10-27 17:40:31 +08:00
|
|
|
<SubMenu key="sub1-2" title="Submenu">
|
2017-06-19 16:02:01 +08:00
|
|
|
<Menu.Item key="5">Option 5</Menu.Item>
|
|
|
|
<Menu.Item key="6">Option 6</Menu.Item>
|
2016-04-27 15:26:03 +08:00
|
|
|
</SubMenu>
|
|
|
|
</SubMenu>
|
2020-04-26 23:16:15 +08:00
|
|
|
<SubMenu key="sub2" icon={<SettingOutlined />} title="Navigation Three">
|
2017-06-19 16:02:01 +08:00
|
|
|
<Menu.Item key="7">Option 7</Menu.Item>
|
|
|
|
<Menu.Item key="8">Option 8</Menu.Item>
|
2016-09-23 09:38:57 +08:00
|
|
|
<Menu.Item key="9">Option 9</Menu.Item>
|
|
|
|
<Menu.Item key="10">Option 10</Menu.Item>
|
2016-04-27 15:26:03 +08:00
|
|
|
</SubMenu>
|
2020-05-03 11:28:15 +08:00
|
|
|
<Menu.Item key="link" icon={<LinkOutlined />}>
|
|
|
|
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
|
|
|
|
Ant Design
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
2016-04-27 15:26:03 +08:00
|
|
|
</Menu>
|
2020-04-26 23:16:15 +08:00
|
|
|
</>
|
2016-04-27 15:26:03 +08:00
|
|
|
);
|
2017-02-20 21:51:23 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-16 21:13:59 +08:00
|
|
|
|
2016-04-27 15:26:03 +08:00
|
|
|
ReactDOM.render(<Sider />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|