Drawer 抽屉

从左侧滑出的模态,包含各种导航分类。

规则

  • 是 Android 推荐的导航方式,常见于该平台应用。

代码演示

基本

遮罩层模式

  1. import { Drawer, List, NavBar } from 'antd-mobile';
  2. const App1 = React.createClass({
  3. getInitialState() {
  4. return {
  5. open: false,
  6. position: 'left',
  7. };
  8. },
  9. onOpenChange(isOpen) {
  10. console.log(isOpen, arguments);
  11. this.setState({ open: !this.state.open });
  12. },
  13. render() {
  14. const sidebar = (<List>
  15. <List.Body>
  16. {[...Array(20).keys()].map((i, index) => {
  17. if (index === 0) {
  18. return (<List.Item key={index}
  19. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  20. multipleLine
  21. >分类</List.Item>);
  22. }
  23. return (<List.Item key={index}
  24. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  25. >分类{index}</List.Item>);
  26. })}
  27. </List.Body>
  28. </List>);
  29. const drawerProps = {
  30. open: this.state.open,
  31. position: this.state.position,
  32. onOpenChange: this.onOpenChange,
  33. };
  34. return (<div style={{ height: '100%' }}>
  35. <NavBar iconName="ellipsis" onLeftClick={this.onOpenChange}>
  36. 基本
  37. </NavBar>
  38. <div className="drawer-container">
  39. <Drawer sidebar={sidebar}
  40. dragHandleStyle={{ display: 'none' }}
  41. contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
  42. {...drawerProps}
  43. >
  44. 请点击左上角
  45. </Drawer>
  46. </div>
  47. </div>);
  48. },
  49. });
  50. ReactDOM.render(<App1 />, mountNode);

嵌入文档模式

嵌入到文档流中

  1. import { Drawer, List, NavBar } from 'antd-mobile';
  2. const App = React.createClass({
  3. getInitialState() {
  4. return {
  5. docked: false,
  6. };
  7. },
  8. onDock(d) {
  9. this.setState({
  10. [d]: !this.state[d],
  11. });
  12. },
  13. render() {
  14. const sidebar = (<List>
  15. <List.Body>
  16. {[...Array(20).keys()].map((i, index) => {
  17. if (index === 0) {
  18. return (<List.Item key={index}
  19. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  20. multipleLine
  21. >分类</List.Item>);
  22. }
  23. return (<List.Item key={index}
  24. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  25. >分类{index}</List.Item>);
  26. })}
  27. </List.Body>
  28. </List>);
  29. const drawerProps = {
  30. docked: this.state.docked,
  31. open: false,
  32. position: 'left',
  33. };
  34. return (<div style={{ height: '100%' }}>
  35. <NavBar iconName="ellipsis" onLeftClick={() => this.onDock('docked')}>嵌入文档</NavBar>
  36. <div className="drawer-container">
  37. <Drawer sidebar={sidebar}
  38. dragHandleStyle={{ display: 'none' }}
  39. sidebarStyle={{ border: '1px solid #ddd' }}
  40. contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
  41. {...drawerProps}
  42. >
  43. 请点击左上角
  44. </Drawer>
  45. </div>
  46. </div>);
  47. },
  48. });
  49. 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