Step 步骤

如果项目中使用的是 1.x 版本的基础组件(@alifd/next),请在左侧导航顶部切换组件版本。

安装方法

  1. 在命令行中执行以下命令npm install @icedesign/base@latest -S

Guide

可以通过 animation 属性关闭步骤条的动画,使 Step 变为纯展示型。

API

步骤

参数说明类型默认值
prefix样式的品牌前缀String'next-'
current当前步骤Number0
direction展示方向可选值:'horizontal', 'vertical'Enum'horizontal'
type类型可选值:'circle', 'arrow', 'dot'Enum'circle'
readOnly是否只读模式Boolean-
animation是否开启动效Booleantrue
className自定义样式名String-

Step.Item

参数说明类型默认值
prefix组件的样式品牌前缀String-
status步骤的状态,如不传,会根据外层的 Step 的 current 属性生成,可选值为 wait, process, finish可选值:'wait', 'process', 'finish'Enum-
title标题ReactNode-
icon图标String-
content内容,用于垂直状态下的内容填充ReactNode-
itemRenderStepItem 的自定义渲染签名:Function(index: Number, status: String) => Node参数:index: {Number} 节点索引status: {String} 节点状态返回值:{Node} 节点的渲染结果Function-
percent百分比Number-
disabled是否禁用Boolean-
onClick点击步骤时的回调签名:Function(index: Number) => void参数:index: {Number} 节点索引Function() => {}
className自定义样式String-

代码示例

基本

在最简单的情况下,Step 有三种类型,可以通过 type 属性进行切换。

Step 步骤 - 图1

查看源码在线预览

  1. import { Step } from "@icedesign/base";
  2. const steps = ["打开冰箱门", "把大象放进冰箱", "关上冰箱门"].map(
  3. (item, index) => <Step.Item key={index} title={item} />
  4. );
  5. ReactDOM.render(
  6. <div>
  7. <h3>箭头型</h3>
  8. <Step current={1} type="arrow">
  9. {steps}
  10. </Step>
  11. <h3>圆型</h3>
  12. <Step current={1} type="circle">
  13. {steps}
  14. </Step>
  15. <h3>点型</h3>
  16. <Step current={1} type="dot">
  17. {steps}
  18. </Step>
  19. </div>,
  20. mountNode
  21. );

受控模式

默认情况下,Step 定义为展示型组件,上层组件可以通过修改传入的 current 属性值来修改当前的步骤,同时可以设置每个节点的 click 事件,来自定义回调。

Step 步骤 - 图2

查看源码在线预览

  1. import { Step, Button, Select } from "@icedesign/base";
  2. const { Item: StepItem } = Step;
  3. const { Group: ButtonGroup } = Button;
  4. class Component extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. currentStep: 3,
  9. stepType: "circle",
  10. stepAnimation: true
  11. };
  12. this.onClick = this.onClick.bind(this);
  13. }
  14. next() {
  15. const s = this.state.currentStep + 1;
  16. this.setState({
  17. currentStep: s > 6 ? 6 : s
  18. });
  19. }
  20. prev() {
  21. const s = this.state.currentStep - 1;
  22. this.setState({
  23. currentStep: s < 0 ? 0 : s
  24. });
  25. }
  26. onClick(currentStep) {
  27. console.log(currentStep);
  28. this.setState({
  29. currentStep: currentStep
  30. });
  31. }
  32. onStepTypeChange(value) {
  33. this.setState({ stepType: value });
  34. }
  35. onStepAnimation(value) {
  36. this.setState({ stepAnimation: value });
  37. }
  38. render() {
  39. const { currentStep } = this.state;
  40. return (
  41. <div>
  42. <div className="custom-step-option">
  43. <Select
  44. placeholder="选择展示类型"
  45. onChange={this.onStepTypeChange.bind(this)}
  46. className="custom-select"
  47. >
  48. {["circle", "arrow", "dot"].map(item => (
  49. <Select.Option value={item} key={item}>
  50. {item}
  51. </Select.Option>
  52. ))}
  53. </Select>
  54. <Select
  55. placeholder="是否开启动效"
  56. onChange={this.onStepAnimation.bind(this)}
  57. className="custom-select"
  58. >
  59. {[true, false].map((item, index) => (
  60. <Select.Option value={item} key={index}>
  61. {item ? "开启动效" : "关闭动效"}
  62. </Select.Option>
  63. ))}
  64. </Select>
  65. </div>
  66. <Step
  67. current={currentStep}
  68. type={this.state.stepType}
  69. animation={this.state.stepAnimation}
  70. >
  71. <StepItem title="步骤1" onClick={this.onClick} />
  72. <StepItem title="步骤2" onClick={this.onClick} />
  73. <StepItem title="步骤3" onClick={this.onClick} />
  74. <StepItem title="步骤4" onClick={this.onClick} />
  75. <StepItem title="步骤5" onClick={this.onClick} />
  76. <StepItem title="步骤6" onClick={this.onClick} />
  77. </Step>
  78. <br />
  79. <br />
  80. <ButtonGroup>
  81. <Button
  82. onClick={this.prev.bind(this)}
  83. type="primary"
  84. disabled={currentStep === 0}
  85. >
  86. 上一步
  87. </Button>
  88. <Button
  89. onClick={this.next.bind(this)}
  90. type="primary"
  91. disabled={currentStep === 6}
  92. >
  93. 下一步
  94. </Button>
  95. </ButtonGroup>
  96. </div>
  97. );
  98. }
  99. }
  100. ReactDOM.render(<Component />, mountNode);
  1. .custom-step-option {
  2. margin-bottom: 20px;
  3. }
  4. .custom-select {
  5. margin-right: 20px;
  6. }

Step.Item 自定义渲染

用户可以通过传递 itemRender 属性进行自定义的渲染。Step.Item 默认有三种状态,分别是 wait, process, finish

Step 步骤 - 图3

查看源码在线预览

  1. import { Step, Icon } from "@icedesign/base";
  2. const steps = ["one", "two", "three", "four"];
  3. function itemRender(index, status) {
  4. return index + 1;
  5. }
  6. function itemRender2(index, status) {
  7. return status === "finish" ? <Icon type="good" /> : index + 1;
  8. }
  9. ReactDOM.render(
  10. <div className="fusion-demo">
  11. <div className="fusion-demo-item">
  12. <Step current={2} animation={false}>
  13. {steps.map(item => (
  14. <Step.Item key={item} title={item} itemRender={itemRender} />
  15. ))}
  16. </Step>
  17. </div>
  18. <div className="fusion-demo-item">
  19. <Step current={2} animation={false}>
  20. {steps.map(item => (
  21. <Step.Item key={item} title={item} itemRender={itemRender2} />
  22. ))}
  23. </Step>
  24. </div>
  25. </div>,
  26. mountNode
  27. );
  1. .fusion-demo-item {
  2. margin: 15px 0;
  3. }

垂直模式

箭头形不支持垂直模式。对于点型和圆圈型的 Step 组件而言,可以通过设置 direction 属性设置其展示方向为垂直。

Step 步骤 - 图4

查看源码在线预览

  1. import { Step, Icon } from "@icedesign/base";
  2. ReactDOM.render(
  3. <div>
  4. <h3>把大象装进冰箱的正确姿势</h3>
  5. <Step current={1} direction="vertical" animation={false}>
  6. <Step.Item title="步骤1" content="打开冰箱门" />
  7. <Step.Item title="步骤2" content="把大象塞进去" />
  8. <Step.Item title="步骤3" content="关上冰箱门" />
  9. </Step>
  10. <h3>把大象装进冰箱的正确姿势</h3>
  11. <Step current={1} direction="vertical" type="dot" animation={false}>
  12. <Step.Item title="步骤1" content="打开冰箱门" />
  13. <Step.Item title="步骤2" content="把大象塞进去" />
  14. <Step.Item title="步骤3" content="关上冰箱门" />
  15. </Step>
  16. </div>,
  17. mountNode
  18. );

禁用步骤项

可以通过在 Step.Item 上设置 disabled 属性来禁用某个步骤。

Step 步骤 - 图5

查看源码在线预览

  1. import { Step } from "@icedesign/base";
  2. ReactDOM.render(
  3. <div>
  4. <Step current={1} type="arrow">
  5. <Step.Item title="步骤1" />
  6. <Step.Item title="步骤2" />
  7. <Step.Item title="步骤3" disabled />
  8. <Step.Item title="步骤4" />
  9. </Step>
  10. <br />
  11. <br />
  12. <Step current={1} type="dot">
  13. <Step.Item title="步骤1" />
  14. <Step.Item title="步骤2" />
  15. <Step.Item title="步骤3" disabled />
  16. <Step.Item title="步骤4" />
  17. </Step>
  18. <br />
  19. <br />
  20. <Step current={1} type="circle">
  21. <Step.Item title="步骤1" />
  22. <Step.Item title="步骤2" />
  23. <Step.Item title="步骤3" disabled />
  24. <Step.Item title="步骤4" />
  25. </Step>
  26. </div>,
  27. mountNode
  28. );

图标和百分比

可以在点型和圆形步骤条中使用图标,圆形步骤条还只是使用百分比。

Step 步骤 - 图6

查看源码在线预览

  1. import { Step, Icon } from "@icedesign/base";
  2. ReactDOM.render(
  3. <div>
  4. <Step current={1} animation={false} type="dot">
  5. <Step.Item title="步骤1" content="打开冰箱门" icon="box" />
  6. <Step.Item title="步骤2" content="把大象塞进去" percent={40} />
  7. <Step.Item title="步骤3" content="关闭冰箱门" icon="smile" />
  8. </Step>
  9. <br />
  10. <br />
  11. <Step current={1} animation={false}>
  12. <Step.Item title="步骤1" content="打开冰箱门" icon="box" />
  13. <Step.Item title="步骤2" content="把大象塞进去" percent={40} />
  14. <Step.Item title="步骤3" content="关闭冰箱门" icon="smile" />
  15. </Step>
  16. </div>,
  17. mountNode
  18. );

只读模式

只读模式,不可触发回调。

Step 步骤 - 图7

查看源码在线预览

  1. import { Step, Button } from "@icedesign/base";
  2. const { Item: StepItem } = Step;
  3. const { Group: ButtonGroup } = Button;
  4. class Component extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. currentStep: 3
  9. };
  10. }
  11. next() {
  12. const s = this.state.currentStep + 1;
  13. this.setState({
  14. currentStep: s > 6 ? 6 : s
  15. });
  16. }
  17. prev() {
  18. const s = this.state.currentStep - 1;
  19. this.setState({
  20. currentStep: s < 0 ? 0 : s
  21. });
  22. }
  23. onClick(currentStep) {
  24. console.log(currentStep);
  25. this.setState({
  26. currentStep: currentStep
  27. });
  28. }
  29. render() {
  30. const { currentStep } = this.state;
  31. return (
  32. <div>
  33. <Step current={currentStep} readOnly>
  34. <StepItem title="步骤1" onClick={this.onClick.bind(this)} />
  35. <StepItem title="步骤2" onClick={this.onClick.bind(this)} />
  36. <StepItem title="步骤3" onClick={this.onClick.bind(this)} />
  37. <StepItem title="步骤4" onClick={this.onClick.bind(this)} />
  38. <StepItem title="步骤5" onClick={this.onClick.bind(this)} />
  39. <StepItem title="步骤6" onClick={this.onClick.bind(this)} />
  40. </Step>
  41. <br />
  42. <br />
  43. <ButtonGroup>
  44. <Button
  45. onClick={this.prev.bind(this)}
  46. type="primary"
  47. disabled={currentStep === 0}
  48. >
  49. 上一步
  50. </Button>
  51. <Button
  52. onClick={this.next.bind(this)}
  53. type="primary"
  54. disabled={currentStep === 6}
  55. >
  56. 下一步
  57. </Button>
  58. </ButtonGroup>
  59. </div>
  60. );
  61. }
  62. }
  63. ReactDOM.render(<Component />, mountNode);

相关区块

Step 步骤 - 图8

暂无相关区块