Drawer 抽屉
定义/Definition
属于次级导航分类,结合手势操作,从屏幕边缘唤出抽屉栏。
可用做侧边菜单、右边抽屉。
规则 / Rule
侧边抽屉导航最好不要设计在顶部或者底部,防止和系统的操作冲突。
代码演示
基本
遮罩层模式
// 此处用作demo展示,不要用在生产环境
this.customNavFlag = true;
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>
<List.Body>
{[1, 2, 3, 4, 5, 6].map((i, index) => {
if (index === 0) {
return (<List.Item key={index}
thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
}
return (<List.Item key={index}
thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
})}
</List.Body>
</List>);
const drawerProps = {
open: this.state.open,
position: this.state.position,
onOpenChange: this.onOpenChange,
};
return (<div>
<NavBar iconName="ellipsis" onLeftClick={this.onOpenChange}>
基本
</NavBar>
<div className="drawer-container">
<Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps}>
请点击左上角
</Drawer>
</div>
</div>);
},
});
ReactDOM.render(<App1 />, mountNode);
嵌入文档模式
嵌入到文档流中
// 此处用作demo展示,不要用在生产环境
this.customNavFlag = true;
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>
<List.Body>
{[1, 2, 3, 4, 5, 6].map((i, index) => {
if (index === 0) {
return (<List.Item key={index}
thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
}
return (<List.Item key={index}
thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
})}
</List.Body>
</List>);
const drawerProps = {
docked: this.state.docked,
open: false,
position: 'left',
};
return (<div>
<NavBar iconName="ellipsis" onLeftClick={() => this.onDock('docked')}>嵌入文档</NavBar>
<div className="drawer-container">
<Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps}>
请点击左上角
</Drawer>
</div>
</div>);
},
});
ReactDOM.render(<App />, mountNode);
右出
嵌入到文档流中
// 此处用作demo展示,不要用在生产环境
this.customNavFlag = true;
import { Drawer, List, NavBar } from 'antd-mobile';
const App = React.createClass({
getInitialState() {
return {
docked1: false,
};
},
onDock(d) {
this.setState({
[d]: !this.state[d],
});
},
render() {
const sidebar = (<List>
<List.Body>
{[1, 2, 3, 4, 5, 6].map((i, index) => {
if (index === 0) {
return (<List.Item key={index}
thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
}
return (<List.Item key={index}
thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
line={2}
><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
})}
</List.Body>
</List>);
const drawerProps1 = {
docked: this.state.docked1,
open: false,
position: 'right',
};
return (<div>
<NavBar iconName={false}
rightContent={<span onClick={() => this.onDock('docked1')}>点击</span>}
>
嵌入文档
</NavBar>
<div className="drawer-container">
<Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps1}>
请点击右上角
</Drawer>
</div>
</div>);
},
});
ReactDOM.render(<App />, mountNode);
API
成员 | 说明 | 类型 | 默认值 |
---|
sidebarStyle(web) | - | Object | {} |
contentStyle(web) | - | Object | {} |
overlayStyle(web) | - | Object | {} |
dragHandleStyle(web) | - | Object | {} |
touch(web) | 是否开启触摸手势 | Boolean | true |
transitions(web) | 是否开启动画 | Boolean | true |
docked(web) | 是否嵌入到正常文档流里 | Boolean | false |
dragToggleDistance(web) | 打开关闭抽屉时距sidebar的拖动距离 | Number | 30 |
open(web) | 开关状态 | Boolean | false |
children | 主要内容 | any | n/a |
sidebar | 抽屉里的内容 | any | n/a |
onOpenChange | open 状态切换时调用 | Function | n/a |
position | 抽屉所在位置 | String | 'left', enum{'left', 'right', 'top'(web), 'bottom'(web)} |
drawerWidth(ios/android) | 抽屉宽度 | Number | 300 |
drawerBackgroundColor(ios/android) | 指定抽屉背景色 | String | - |
openDrawer(ios/android) | 打开drawer | Function | n/a |
closeDrawer(ios/android) | 关闭drawer | Function | n/a |