ant-design/docs/spec/layout/demo/aside-collapse.md

227 lines
5.3 KiB
Markdown
Raw Normal View History

2016-05-16 10:58:34 +08:00
---
order: 4
title:
zh-CN: 可收起展开的侧边导航
en-US: Collapsed aside
2016-05-16 10:58:34 +08:00
---
## zh-CN
2016-05-16 10:58:34 +08:00
页面横向空间有限时使用。侧边导航默认收起,点击底部按钮时展开。
## en-US
This pattern is used when the horizontal space is limited. Aside navigation is default to be collapsed, you can click the button at the bottom to expand it.
2017-01-19 15:19:03 +08:00
````__react
2016-05-16 10:58:34 +08:00
import { Menu, Breadcrumb, Icon } from 'antd';
import BrowserDemo from 'site/theme/template/BrowserDemo';
2016-05-16 10:58:34 +08:00
const SubMenu = Menu.SubMenu;
const AsideCollapse = React.createClass({
getInitialState() {
return {
collapse: true,
};
},
onCollapseChange() {
this.setState({
collapse: !this.state.collapse,
})
},
render() {
const collapse = this.state.collapse;
return (
2016-12-23 17:58:37 +08:00
<div className={collapse ? "layout-aside layout-aside-collapse" : "layout-aside"}>
<aside className="layout-sider">
<div className="layout-logo"></div>
2016-05-16 10:58:34 +08:00
<Menu mode="inline" theme="dark" defaultSelectedKeys={['user']}>
<Menu.Item key="user">
<Icon type="user" />
{!collapse && <span className="nav-text">Navigation 1</span>}
2016-05-16 10:58:34 +08:00
</Menu.Item>
<Menu.Item key="setting">
<Icon type="setting" />
{!collapse && <span className="nav-text">Navigation 2</span>}
2016-05-16 10:58:34 +08:00
</Menu.Item>
<Menu.Item key="laptop">
<Icon type="laptop" />
{!collapse && <span className="nav-text">Navigation 3</span>}
2016-05-16 10:58:34 +08:00
</Menu.Item>
<Menu.Item key="notification">
<Icon type="notification" />
{!collapse && <span className="nav-text">Navigation 4</span>}
2016-05-16 10:58:34 +08:00
</Menu.Item>
<Menu.Item key="folder">
<Icon type="folder" />
{!collapse && <span className="nav-text">Navigation 5</span>}
2016-05-16 10:58:34 +08:00
</Menu.Item>
</Menu>
2016-12-23 17:58:37 +08:00
<div className="aside-action" onClick={this.onCollapseChange}>
2016-05-16 10:58:34 +08:00
{collapse ? <Icon type="right" /> : <Icon type="left" />}
</div>
</aside>
2016-12-23 17:58:37 +08:00
<div className="layout-main">
<div className="layout-header"></div>
<div className="layout-container">
2016-05-16 10:58:34 +08:00
<Breadcrumb>
<Breadcrumb.Item>Home</Breadcrumb.Item>
<Breadcrumb.Item>App list</Breadcrumb.Item>
<Breadcrumb.Item>Any app</Breadcrumb.Item>
2016-05-16 10:58:34 +08:00
</Breadcrumb>
2016-12-23 17:58:37 +08:00
<div className="layout-content">
2016-05-16 10:58:34 +08:00
<div style={{ height: 220 }}>
Contents
2016-05-16 10:58:34 +08:00
</div>
</div>
</div>
2016-12-23 17:58:37 +08:00
<div className="layout-footer">
Ant Design all rights reserved © 2015 Created by Ant UED
2016-05-16 10:58:34 +08:00
</div>
</div>
</div>
);
},
});
2016-05-16 14:35:24 +08:00
2016-05-16 10:58:34 +08:00
ReactDOM.render(<BrowserDemo><AsideCollapse /></BrowserDemo>, mountNode);
````
````css
2016-12-23 17:58:37 +08:00
.layout-aside {
2016-05-16 10:58:34 +08:00
position: relative;
min-height: 100%;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-logo {
2016-05-16 10:58:34 +08:00
height: 32px;
background: #333;
2016-12-23 17:58:37 +08:00
border-radius: 4px;
margin: 16px 24px;
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-logo {
2016-05-16 10:58:34 +08:00
width: 32px;
margin: 16px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider {
2016-05-16 10:58:34 +08:00
width: 224px;
background: #404040;
position: absolute;
overflow: visible;
padding-bottom: 24px;
height: 100%;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider {
2016-05-16 10:58:34 +08:00
width: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu {
2016-05-16 10:58:34 +08:00
margin-bottom: 20px;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item {
2016-05-16 10:58:34 +08:00
margin: 16px 0;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item .nav-text {
2016-05-20 14:19:09 +08:00
vertical-align: baseline;
2016-05-18 11:43:40 +08:00
display: inline-block;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-sider > .menu > .menu-item > .anticon {
2016-05-18 11:43:40 +08:00
transition: font-size .3s;
2016-05-16 14:35:24 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item {
2016-05-16 10:58:34 +08:00
transition: all 0s ease;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item > .anticon {
2016-05-16 14:35:24 +08:00
font-size: 16px;
display: inline-block;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item .nav-text {
2016-05-16 10:58:34 +08:00
display: none;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item:hover {
2016-05-16 10:58:34 +08:00
background: #2db7f5;
color: #fff;
transition: all 0s ease;
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-sider > .menu > .menu-item:hover .nav-text {
2016-05-16 10:58:34 +08:00
display: inline-block;
2016-05-16 14:35:24 +08:00
vertical-align: top;
2016-05-16 10:58:34 +08:00
background: #2db7f5;
color: #fff;
padding-right: 16px;
border-radius: 0 5px 5px 0;
}
2016-05-16 14:35:24 +08:00
/* 实际使用中需要改成 position: fixed */
2016-12-23 17:58:37 +08:00
.layout-aside .aside-action {
2016-05-16 10:58:34 +08:00
height: 42px;
width: 224px;
position: absolute;
bottom: 0;
background: #656565;
color: #fff;
text-align: center;
line-height: 42px;
cursor: pointer;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .aside-action {
2016-05-16 10:58:34 +08:00
width: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-header {
2016-05-16 10:58:34 +08:00
background: #fff;
height: 64px;
border-bottom: 1px solid #e9e9e9;
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-main {
2016-05-16 10:58:34 +08:00
margin-left: 224px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside-collapse .layout-main {
2016-05-16 10:58:34 +08:00
margin-left: 64px;
2016-12-23 17:58:37 +08:00
transition: all .3s;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-container {
margin: 12px 16px 24px;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-content {
2016-05-16 10:58:34 +08:00
background: #fff;
padding: 24px;
2016-12-23 17:58:37 +08:00
margin-top: 12px;
border-radius: 4px;
2016-05-16 10:58:34 +08:00
}
2016-12-23 17:58:37 +08:00
.layout-aside .layout-footer {
2016-05-16 10:58:34 +08:00
height: 64px;
line-height: 64px;
text-align: center;
font-size: 12px;
color: #999;
background: #fff;
border-top: 1px solid #e9e9e9;
width: 100%;
}
````