2019-04-05 16:15:01 +08:00
|
|
|
---
|
|
|
|
order: 99
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义触发器 Debug
|
|
|
|
en-US: Custom trigger debug
|
|
|
|
debug: true
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
修改内容前,请尝试此 Demo 查看样式是否抖动。
|
|
|
|
|
2022-03-18 15:20:35 +08:00
|
|
|
```tsx
|
|
|
|
import { Layout, Menu, MenuProps } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import {
|
|
|
|
TeamOutlined,
|
|
|
|
UserOutlined,
|
|
|
|
FileOutlined,
|
|
|
|
DesktopOutlined,
|
|
|
|
PieChartOutlined,
|
|
|
|
MenuUnfoldOutlined,
|
|
|
|
MenuFoldOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2019-04-05 16:15:01 +08:00
|
|
|
|
|
|
|
const { Header, Sider, Content } = Layout;
|
2022-03-18 15:20:35 +08:00
|
|
|
|
|
|
|
const items: MenuProps['items'] = [
|
|
|
|
{
|
|
|
|
key: '1',
|
|
|
|
icon: <PieChartOutlined />,
|
|
|
|
label: 'Option 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '2',
|
|
|
|
icon: <DesktopOutlined />,
|
|
|
|
label: 'Option 2',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'sub1',
|
|
|
|
icon: <UserOutlined />,
|
|
|
|
label: 'User',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
key: '3',
|
|
|
|
label: 'Tom',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '4',
|
|
|
|
label: 'Bill',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '5',
|
|
|
|
label: 'Alex',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'sub2',
|
|
|
|
icon: <TeamOutlined />,
|
|
|
|
label: 'Team',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
key: '6',
|
|
|
|
label: 'Team 1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '7',
|
|
|
|
label: 'Team 2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '9',
|
|
|
|
icon: <FileOutlined />,
|
|
|
|
},
|
|
|
|
];
|
2019-04-05 16:15:01 +08:00
|
|
|
|
|
|
|
class SiderDemo extends React.Component {
|
|
|
|
state = {
|
|
|
|
collapsed: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
toggle = () => {
|
|
|
|
this.setState({
|
|
|
|
collapsed: !this.state.collapsed,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Sider trigger={null} collapsible collapsed={this.state.collapsed}>
|
|
|
|
<div className="logo" />
|
2022-03-18 15:20:35 +08:00
|
|
|
<Menu
|
|
|
|
theme="dark"
|
|
|
|
mode="inline"
|
|
|
|
defaultSelectedKeys={['3']}
|
|
|
|
defaultOpenKeys={['sub1']}
|
|
|
|
items={items}
|
|
|
|
/>
|
2019-04-05 16:15:01 +08:00
|
|
|
</Sider>
|
|
|
|
<Layout>
|
2019-12-26 12:21:08 +08:00
|
|
|
<Header className="site-layout-background" style={{ padding: 0 }}>
|
2019-11-28 12:34:33 +08:00
|
|
|
{React.createElement(this.state.collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
|
2019-08-13 14:07:17 +08:00
|
|
|
className: 'trigger',
|
|
|
|
onClick: this.toggle,
|
|
|
|
})}
|
2019-04-05 16:15:01 +08:00
|
|
|
</Header>
|
|
|
|
<Content
|
2019-12-26 12:21:08 +08:00
|
|
|
className="site-layout-background"
|
2019-04-05 16:15:01 +08:00
|
|
|
style={{
|
|
|
|
margin: '24px 16px',
|
|
|
|
padding: 24,
|
|
|
|
minHeight: 280,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Content
|
|
|
|
</Content>
|
|
|
|
</Layout>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<SiderDemo />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2019-04-05 16:15:01 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```css
|
2019-04-05 16:15:01 +08:00
|
|
|
#components-layout-demo-custom-trigger .trigger {
|
2021-01-30 19:39:02 +08:00
|
|
|
padding: 0 24px;
|
2019-04-05 16:15:01 +08:00
|
|
|
font-size: 18px;
|
|
|
|
line-height: 64px;
|
|
|
|
cursor: pointer;
|
2019-05-07 14:57:32 +08:00
|
|
|
transition: color 0.3s;
|
2019-04-05 16:15:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#components-layout-demo-custom-trigger .trigger:hover {
|
|
|
|
color: #1890ff;
|
|
|
|
}
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|