Tabs标签页 - 图1

Tabs 标签页

基本用法

  1. import { Tabs } from 'zarm';
  2. const { Panel } = Tabs;
  3. class Demo extends React.Component {
  4. state = {
  5. value: 0,
  6. }
  7. onChange = (index) => {
  8. console.log(index);
  9. this.setState({ value: index })
  10. }
  11. render() {
  12. return (
  13. <Tabs value={this.state.value} onChange={this.onChange}>
  14. <Panel title="选项卡1">
  15. <div className="content">选项卡1内容</div>
  16. </Panel>
  17. <Panel title="选项卡2">
  18. <div className="content">选项卡2内容</div>
  19. </Panel>
  20. </Tabs>
  21. );
  22. }
  23. }
  24. ReactDOM.render(<Demo />, mountNode);

可滑动

  1. import { Tabs } from 'zarm';
  2. const { Panel } = Tabs;
  3. ReactDOM.render(
  4. <Tabs canSwipe onChange={(i) => { console.log(i); }}>
  5. <Panel title="选项卡1">
  6. <div className="content">试试点我左滑</div>
  7. </Panel>
  8. <Panel title="选项卡2">
  9. <div className="content">试试点我右滑</div>
  10. </Panel>
  11. </Tabs>
  12. , mountNode);

指定默认选项

  1. import { Tabs } from 'zarm';
  2. const { Panel } = Tabs;
  3. ReactDOM.render(
  4. <Tabs defaultValue={1}>
  5. <Panel title="选项卡1">
  6. <div className="content">选项卡1内容</div>
  7. </Panel>
  8. <Panel title="选项卡2">
  9. <div className="content">选项卡2内容</div>
  10. </Panel>
  11. <Panel title="选项卡3">
  12. <div className="content">选项卡3内容</div>
  13. </Panel>
  14. </Tabs>
  15. , mountNode);

指定线条宽度

  1. import { Tabs } from 'zarm';
  2. const { Panel } = Tabs;
  3. ReactDOM.render(
  4. <Tabs lineWidth={60}>
  5. <Panel title="选项卡1">
  6. <div className="content">选项卡1内容</div>
  7. </Panel>
  8. <Panel title="选项卡2">
  9. <div className="content">选项卡2内容</div>
  10. </Panel>
  11. <Panel title="选项卡3">
  12. <div className="content">选项卡3内容</div>
  13. </Panel>
  14. </Tabs>
  15. , mountNode);

禁用指定选项

  1. import { Tabs } from 'zarm';
  2. const { Panel } = Tabs;
  3. ReactDOM.render(
  4. <Tabs>
  5. <Panel title="选项卡1">
  6. <div className="content">选项卡1内容</div>
  7. </Panel>
  8. <Panel title="选项卡2" disabled>
  9. <div className="content">选项卡2内容</div>
  10. </Panel>
  11. <Panel title="选项卡3">
  12. <div className="content">选项卡3内容</div>
  13. </Panel>
  14. </Tabs>
  15. , mountNode);

API

Tabs

属性类型默认值说明
valuenumber-
defaultValuenumber-初始值
disabledbooleanfalse是否禁用
canSwipebooleanfalse是否支持滑动切换
lineWidthnumber | string-线条宽度
onChange(index?: number) => void-值变化时触发的回调函数

Panel

属性类型默认值说明
titleReactNode-标题
childrenReactNode-内容
disabledbooleanfalse是否禁用