Drawer 抽屉

定义/Definition

属于次级导航分类,结合手势操作,从屏幕边缘唤出抽屉栏。 可用做侧边菜单、右边抽屉。

规则 / Rule

侧边抽屉导航最好不要设计在顶部或者底部,防止和系统的操作冲突。

代码演示

基本

遮罩层模式

  1. // 此处用作demo展示,不要用在生产环境
  2. this.customNavFlag = true;
  3. import { Drawer, List, NavBar } from 'antd-mobile';
  4. const App1 = React.createClass({
  5. getInitialState() {
  6. return {
  7. open: false,
  8. position: 'left',
  9. };
  10. },
  11. onOpenChange(isOpen) {
  12. console.log(isOpen, arguments);
  13. this.setState({ open: !this.state.open });
  14. },
  15. render() {
  16. const sidebar = (<List>
  17. <List.Body>
  18. {[1, 2, 3, 4, 5, 6].map((i, index) => {
  19. if (index === 0) {
  20. return (<List.Item key={index}
  21. thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
  22. line={2}
  23. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  24. }
  25. return (<List.Item key={index}
  26. thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
  27. line={2}
  28. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  29. })}
  30. </List.Body>
  31. </List>);
  32. const drawerProps = {
  33. open: this.state.open,
  34. position: this.state.position,
  35. onOpenChange: this.onOpenChange,
  36. };
  37. return (<div>
  38. <NavBar iconName="ellipsis" onLeftClick={this.onOpenChange}>
  39. 基本
  40. </NavBar>
  41. <div className="drawer-container">
  42. <Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps}>
  43. 请点击左上角
  44. </Drawer>
  45. </div>
  46. </div>);
  47. },
  48. });
  49. ReactDOM.render(<App1 />, mountNode);

嵌入文档模式

嵌入到文档流中

  1. // 此处用作demo展示,不要用在生产环境
  2. this.customNavFlag = true;
  3. import { Drawer, List, NavBar } from 'antd-mobile';
  4. const App = React.createClass({
  5. getInitialState() {
  6. return {
  7. docked: false,
  8. };
  9. },
  10. onDock(d) {
  11. this.setState({
  12. [d]: !this.state[d],
  13. });
  14. },
  15. render() {
  16. const sidebar = (<List>
  17. <List.Body>
  18. {[1, 2, 3, 4, 5, 6].map((i, index) => {
  19. if (index === 0) {
  20. return (<List.Item key={index}
  21. thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
  22. line={2}
  23. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  24. }
  25. return (<List.Item key={index}
  26. thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
  27. line={2}
  28. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  29. })}
  30. </List.Body>
  31. </List>);
  32. const drawerProps = {
  33. docked: this.state.docked,
  34. open: false,
  35. position: 'left',
  36. };
  37. return (<div>
  38. <NavBar iconName="ellipsis" onLeftClick={() => this.onDock('docked')}>嵌入文档</NavBar>
  39. <div className="drawer-container">
  40. <Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps}>
  41. 请点击左上角
  42. </Drawer>
  43. </div>
  44. </div>);
  45. },
  46. });
  47. ReactDOM.render(<App />, mountNode);

右出

嵌入到文档流中

  1. // 此处用作demo展示,不要用在生产环境
  2. this.customNavFlag = true;
  3. import { Drawer, List, NavBar } from 'antd-mobile';
  4. const App = React.createClass({
  5. getInitialState() {
  6. return {
  7. docked1: false,
  8. };
  9. },
  10. onDock(d) {
  11. this.setState({
  12. [d]: !this.state[d],
  13. });
  14. },
  15. render() {
  16. const sidebar = (<List>
  17. <List.Body>
  18. {[1, 2, 3, 4, 5, 6].map((i, index) => {
  19. if (index === 0) {
  20. return (<List.Item key={index}
  21. thumb="https://os.alipayobjects.com/rmsportal/mOoPurdIfmcuqtr.png"
  22. line={2}
  23. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  24. }
  25. return (<List.Item key={index}
  26. thumb="http://img0.bdstatic.com/img/image/daren/ximeng2.jpg"
  27. line={2}
  28. ><div className="am-list-title">收银员</div><div className="am-list-brief">仅可进行收款、退款及查账操作</div></List.Item>);
  29. })}
  30. </List.Body>
  31. </List>);
  32. const drawerProps1 = {
  33. docked: this.state.docked1,
  34. open: false,
  35. position: 'right',
  36. };
  37. return (<div>
  38. <NavBar iconName={false}
  39. rightContent={<span onClick={() => this.onDock('docked1')}>点击</span>}
  40. >
  41. 嵌入文档
  42. </NavBar>
  43. <div className="drawer-container">
  44. <Drawer sidebar={sidebar} dragHandleStyle={{ display: 'none' }} {...drawerProps1}>
  45. 请点击右上角
  46. </Drawer>
  47. </div>
  48. </div>);
  49. },
  50. });
  51. ReactDOM.render(<App />, mountNode);

Drawer抽屉 - 图1

API

成员说明类型默认值
sidebarStyle(web)-Object{}
contentStyle(web)-Object{}
overlayStyle(web)-Object{}
dragHandleStyle(web)-Object{}
touch(web)是否开启触摸手势Booleantrue
transitions(web)是否开启动画Booleantrue
docked(web)是否嵌入到正常文档流里Booleanfalse
dragToggleDistance(web)打开关闭抽屉时距sidebar的拖动距离Number30
open(web)开关状态Booleanfalse
children主要内容anyn/a
sidebar抽屉里的内容anyn/a
onOpenChangeopen 状态切换时调用Functionn/a
position抽屉所在位置String'left', enum{'left', 'right', 'top'(web), 'bottom'(web)}
drawerWidth(ios/android)抽屉宽度Number300
drawerBackgroundColor(ios/android)指定抽屉背景色String-
openDrawer(ios/android)打开drawerFunctionn/a
closeDrawer(ios/android)关闭drawerFunctionn/a