Drawer 抽屉
从左侧滑出的模态,包含各种导航分类。
规则
- 是 Android 推荐的导航方式,常见于该平台应用。
代码演示
基本
遮罩层模式
import { Drawer, List, NavBar } from 'antd-mobile';
const App1 = React.createClass({
getInitialState() {
return {
open: false,
position: 'left',
};
},
onOpenChange(isOpen) {
console.log(isOpen, arguments);
this.setState({ open: !this.state.open });
},
render() {
const sidebar = (<List>
{[...Array(20).keys()].map((i, index) => {
if (index === 0) {
return (<List.Item key={index}
thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
multipleLine
>分类</List.Item>);
}
return (<List.Item key={index}
thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
>分类{index}</List.Item>);
})}
</List>);
const drawerProps = {
open: this.state.open,
position: this.state.position,
onOpenChange: this.onOpenChange,
};
return (<div style={{ height: '100%' }}>
<NavBar iconName="ellipsis" onLeftClick={this.onOpenChange}>基本</NavBar>
<Drawer
className="my-drawer"
sidebar={sidebar}
dragHandleStyle={{ display: 'none' }}
contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
{...drawerProps}
>
请点击左上角图标
</Drawer>
</div>);
},
});
ReactDOM.render(<App1 />, mountNode);
.my-drawer {
position: relative;
height: 100%;
overflow: auto;
}
.my-drawer .am-drawer-sidebar {
max-width: 4.6rem;
background-color: #fff;
overflow: auto;
}
.my-drawer .am-drawer-sidebar .am-list {
padding: 0;
}
嵌入文档模式
嵌入到文档流中
import { Drawer, List, NavBar } from 'antd-mobile';
const App = React.createClass({
getInitialState() {
return {
docked: false,
};
},
onDock(d) {
this.setState({
[d]: !this.state[d],
});
},
render() {
const sidebar = (<List>
{[...Array(20).keys()].map((i, index) => {
if (index === 0) {
return (<List.Item key={index}
thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
multipleLine
>分类</List.Item>);
}
return (<List.Item key={index}
thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
>分类{index}</List.Item>);
})}
</List>);
const drawerProps = {
docked: this.state.docked,
open: false,
position: 'left',
};
return (<div style={{ height: '100%' }}>
<NavBar iconName="ellipsis" onLeftClick={() => this.onDock('docked')}>嵌入文档</NavBar>
<Drawer
className="my-drawer"
sidebar={sidebar}
dragHandleStyle={{ display: 'none' }}
sidebarStyle={{ border: '1px solid #ddd' }}
contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
{...drawerProps}
>
请点击左上角图标
</Drawer>
</div>);
},
});
ReactDOM.render(<App />, mountNode);
.my-drawer {
position: relative;
height: 100%;
overflow: auto;
}
.my-drawer .am-drawer-sidebar {
max-width: 4.6rem;
background-color: #fff;
overflow: auto;
}
.my-drawer .am-drawer-sidebar .am-list {
padding: 0;
}
API ( 适用平台:WEB、React-Native )
成员 | 说明 | 类型 | 默认值 |
---|
children | 主要内容 | any | - |
sidebar | 抽屉里的内容 | any | - |
onOpenChange | open 状态切换时调用 | (open: bool): void | - |
position | 抽屉所在位置 | String | 'left', enum{'left', 'right', 'top'(web only ), 'bottom'(web only )} |
sidebarStyle (web only ) | - | Object | {} |
contentStyle (web only ) | - | Object | {} |
overlayStyle(web only ) | - | Object | {} |
dragHandleStyle(web only ) | - | Object | {} |
touch(web only ) | 是否开启触摸手势 | Boolean | true |
transitions(web only ) | 是否开启动画 | Boolean | true |
docked(web only ) | 是否嵌入到正常文档流里 | Boolean | false |
dragToggleDistance(web only ) | 打开关闭抽屉时距 sidebar 的拖动距离 | Number | 30 |
open(web only ) | 开关状态 | Boolean | false |
drawerWidth (rn only ) | 抽屉宽度 | Number | 300 |
drawerBackgroundColor (rn only ) | 指定抽屉背景色 | String | - |
openDrawer (rn only ) | 打开函数 | (): void | - |
closeDrawer (rn only ) | 关闭函数 | (): void | - |