OffCanvas

OffCanvas 组件,侧边栏组件。

组件

OffCanvas

<OffCanvas> 组件,放置侧边栏内容。

Props

<OffCanvas> 属性通过触发器 <OffCanvasTrigger> 传递,暂无需要设置的属性。

OffCanvasTrigger

<OffCanvasTrigger> 组件,侧边栏触发器。

offCanvas
PropType: node

要触发的侧边栏,OffCanvas 组件实例,必需

placement
PropType: enum('left', 'right')

侧边栏位置,默认为 left

animation
PropType: enum('slide', 'push')

动画效果,默认为 slide

pageContainer
PropType: node

使用 push 动画效果时,侧边栏「推」的容器(一般为 SPA 的容器),可以传递容器 id 或者 容器 React 组件实例。

onOpen
PropType: func

侧边栏打开时的回调函数。

onClosed
PropType: func

侧边栏关闭以后的回调函数。

方法

调用方式见示例代码。

.open()

打开侧边栏。

.close()

关闭侧边栏。

示例

  1. import React from 'react';
  2. import {
  3. Link,
  4. } from 'react-router';
  5. import {
  6. Container,
  7. Group,
  8. Button,
  9. OffCanvas,
  10. OffCanvasTrigger,
  11. List,
  12. } from 'amazeui-touch';
  13. const OffCanvasExample = React.createClass({
  14. onDismiss(e) {
  15. // 从 OffCanvas 内部元素关闭 OffCanvas
  16. // 紧耦合,需要重构 OffCanvas
  17. this.refs.oct.close();
  18. },
  19. renderOC() {
  20. return (
  21. <OffCanvas>
  22. <div>
  23. <h3 className="margin">OffCanvas 内容</h3>
  24. <p className="margin-h"> OffCanvas 内放置 React Router Link 演示</p>
  25. <List>
  26. <List.Item
  27. linkComponent={Link}
  28. linkProps={{
  29. to: `/`,
  30. onClick: this.onDismiss,
  31. }}
  32. title="组件"
  33. />
  34. <List.Item
  35. linkComponent={Link}
  36. linkProps={{
  37. to: '/about',
  38. onClick: this.onDismiss,
  39. }}
  40. title="关于"
  41. />
  42. <List.Item
  43. href="https://github.com/amazeui/amazeui-touch"
  44. title="GitHub"
  45. target="_blank"
  46. onClick={this.onDismiss}
  47. />
  48. </List>
  49. </div>
  50. </OffCanvas>
  51. )
  52. },
  53. render() {
  54. return (
  55. <Container {...this.props}>
  56. <h2>Overlay</h2>
  57. <Group
  58. header="左侧显示 OffCanvas"
  59. >
  60. <OffCanvasTrigger
  61. ref="oct"
  62. offCanvas={this.renderOC()}
  63. >
  64. <Button amStyle="primary">显示左侧 Offcanvas</Button>
  65. </OffCanvasTrigger>
  66. </Group>
  67. <Group
  68. header="右侧显示 OffCanvas"
  69. >
  70. <OffCanvasTrigger
  71. placement="right"
  72. offCanvas={<OffCanvas><p>右侧边栏 OffCanvas 内容</p></OffCanvas>}
  73. >
  74. <Button amStyle="secondary">显示右侧 Offcanvas</Button>
  75. </OffCanvasTrigger>
  76. </Group>
  77. <h2>Push</h2>
  78. <Group
  79. header="右侧显示 OffCanvas"
  80. >
  81. <OffCanvasTrigger
  82. animation="push"
  83. pageContainer="#sk-root"
  84. offCanvas={<OffCanvas><p>OffCanvas 内容</p></OffCanvas>}
  85. >
  86. <Button amStyle="primary">显示左侧 Offcanvas</Button>
  87. </OffCanvasTrigger>
  88. </Group>
  89. <Group
  90. header="右侧显示 OffCanvas"
  91. >
  92. <OffCanvasTrigger
  93. animation="push"
  94. pageContainer="#sk-root"
  95. placement="right"
  96. offCanvas={<OffCanvas><p>右侧边栏 OffCanvas 内容</p></OffCanvas>}
  97. >
  98. <Button amStyle="secondary">显示右侧 Offcanvas</Button>
  99. </OffCanvasTrigger>
  100. </Group>
  101. </Container>
  102. );
  103. }
  104. });
  105. export default OffCanvasExample;

DemoCopy

Version: 1.0.0

原文: http://t.amazeui.org/#/docs/offcanvas