Collapse折叠面板 - 图1

Collapse 折叠面板

基本用法

  1. import { Cell, Switch, Collapse, Checkbox } from 'zarm';
  2. class Demo extends React.Component {
  3. state = {
  4. animated: false,
  5. multiple: false,
  6. activeKey: '1',
  7. }
  8. onChange = (activeKey) => {
  9. console.log(activeKey);
  10. this.setState({ activeKey })
  11. }
  12. render() {
  13. const { animated, multiple, activeKey } = this.state;
  14. return (
  15. <>
  16. <Checkbox.Group block style={{ padding: '8px 16px 8px 16px' }}>
  17. <Checkbox value="animated" checked={animated} onChange={(e) => { this.setState({ animated: e.target.checked })}}>开启切换动画</Checkbox>
  18. <Checkbox value="multiple" checked={multiple} onChange={(e) => { this.setState({ multiple: e.target.checked, activeKey: e.target.checked ? [] : undefined })}}>允许展开多项</Checkbox>
  19. </Checkbox.Group>
  20. <Collapse disabled activeKey={activeKey} animated={animated} multiple={multiple} onChange={this.onChange}>
  21. <Collapse.Item key="1" title="Header of Item1">
  22. This is content of item1. This is content of item1. This is content of item1.
  23. </Collapse.Item>
  24. <Collapse.Item key="2" title="Header of Item2">
  25. This is content of item2. This is content of item2. This is content of item2.
  26. </Collapse.Item>
  27. <Collapse.Item key="3" title="Header of Item3">
  28. This is content of item3. This is content of item3. This is content of item3.
  29. </Collapse.Item>
  30. </Collapse>
  31. </>
  32. );
  33. }
  34. }
  35. ReactDOM.render(<Demo />, mountNode);

默认展开项

  1. import { Collapse } from 'zarm';
  2. ReactDOM.render(
  3. <Collapse multiple defaultActiveKey={['0', '1']}>
  4. <Collapse.Item key="0" title="Header of Item1">
  5. This is content of item1. This is content of item1. This is content of item1.
  6. </Collapse.Item>
  7. <Collapse.Item key="1" title="Header of Item2">
  8. This is content of item2. This is content of item2. This is content of item2.
  9. </Collapse.Item>
  10. <Collapse.Item key="2" title="Header of Item3">
  11. This is content of item3. This is content of item3. This is content of item3.
  12. </Collapse.Item>
  13. </Collapse>
  14. , mountNode);

禁用子项

  1. import { Collapse } from 'zarm';
  2. ReactDOM.render(
  3. <Collapse multiple defaultActiveKey={['test2']}>
  4. <Collapse.Item key="test1" title="Header of Item1">
  5. This is content of item1. This is content of item1. This is content of item1.
  6. </Collapse.Item>
  7. <Collapse.Item key="test2" title="Header of Item2" disabled>
  8. This is content of item2. This is content of item2. This is content of item2.
  9. </Collapse.Item>
  10. <Collapse.Item key="test3" title="Header of Item3" disabled>
  11. This is content of item3. This is content of item3. This is content of item3.
  12. </Collapse.Item>
  13. </Collapse>
  14. , mountNode);

API

Collapse

属性类型默认值说明
multiplebooleanfalse是否可以同时展开多项
animatedbooleanfalse是否添加展开动画
activeKeystring | number | string[] | number[][]动态更新展开项的索引数组或字符串或数字
defaultActiveKeystring | number | string[] | number[][]初始化默认展开项的索引数组或字符串或数字
onChange(activeKey?: string | number | string[] | number[]) => void-点击某一项的回调函数,返回选中的项

Collapse.Item

属性类型默认值说明
titleReactNode-每一项的名称
keystring | number-对应activeKey
disabledbooleanfalse是否禁用
onChange(active?: boolean) => void-点击某一项的回调函数