Step 步骤

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

安装方法

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

API

Step

参数说明类型默认值
current当前步骤Number0
shape类型可选值:'circle', 'arrow', 'dot'Enum'circle'
direction展示方向可选值:'hoz', 'ver'Enum'hoz'
labelPlacement横向布局时的内容排列可选值:'hoz', 'ver'Enum'ver'
readOnly是否只读模式Boolean-
animation是否开启动效Booleantrue
itemRenderStepItem 的自定义渲染签名:Function(index: Number, status: String) => Node参数:index: {Number} 节点索引status: {String} 节点状态返回值:{Node} 节点的渲染结果Functionnull

Step.Item

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

代码示例

基本

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

circle类型可通过labelPlacement设置文本排列方向。

Step 步骤 - 图1

查看源码在线预览

  1. import { Step } from '@alifd/next';
  2. const steps = [['Step 1', 'Open the refrigerator door'], ['Step 2', 'Put the elephant in the refrigerator'], ['Step 3', 'Close the refrigerator door']].map((item, index) => <Step.Item aria-current={index === 1 ? 'step' : null} key={index} title={item[0]} content={item[1]}/>);
  3. ReactDOM.render(<div>
  4. <h3>Arrow</h3>
  5. <Step current={1} shape="arrow">
  6. {steps}
  7. </Step>
  8. <h3>Circle</h3>
  9. <Step current={1} shape="circle">
  10. {steps}
  11. </Step>
  12. <h3>Circle(Horizontal content)</h3>
  13. <Step current={1} shape="circle" labelPlacement="hoz">
  14. {steps}
  15. </Step>
  16. <h3>Dot</h3>
  17. <Step current={1} shape="dot">
  18. {steps}
  19. </Step>
  20. </div>, mountNode);

垂直模式

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

Step 步骤 - 图2

查看源码在线预览

  1. import { Step } from '@alifd/next';
  2. ReactDOM.render(<div>
  3. <Step current={1} direction="ver" animation={false}>
  4. <Step.Item title="Step 1" content="Open the refrigerator door" />
  5. <Step.Item title="Step 2" content="Put the elephant in the refrigerator" />
  6. <Step.Item title="Step 3" content="Close the refrigerator door" />
  7. </Step>
  8. <br /><br />
  9. <Step current={1} direction="ver" shape="dot" animation={false}>
  10. <Step.Item title="Step 1" content="Open the refrigerator door" />
  11. <Step.Item title="Step 2" content="Put the elephant in the refrigerator" />
  12. <Step.Item title="Step 3" content="Close the refrigerator door" />
  13. </Step>
  14. </div>, mountNode);

图标和百分比

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

Step 步骤 - 图3

查看源码在线预览

  1. import { Step } from '@alifd/next';
  2. ReactDOM.render(<div>
  3. <Step current={1} animation={false} shape="dot">
  4. <Step.Item title="Step 1" content="Open the refrigerator door" icon="calendar" />
  5. <Step.Item title="Step 2" content="Put the elephant in the refrigerator" percent={40}/>
  6. <Step.Item title="Step 3" content="Close the refrigerator door" icon="smile" />
  7. </Step>
  8. <br />
  9. <br />
  10. <Step current={1} animation={false}>
  11. <Step.Item title="Step 1" content="Open the refrigerator door" icon="calendar" />
  12. <Step.Item title="Step 2" content="Put the elephant in the refrigerator" percent={40}/>
  13. <Step.Item title="Step 3" content="Close the refrigerator door" icon="smile" />
  14. </Step>
  15. </div>, mountNode);

禁用步骤项

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

Step 步骤 - 图4

查看源码在线预览

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

Step.Item 自定义渲染

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

Step 步骤 - 图5

查看源码在线预览

  1. import { Step, Icon } from '@alifd/next';
  2. const steps = ['one', 'two', 'three', 'four'];
  3. function itemRender(index) {
  4. return <div className="custom-node1"><span>{index + 1}</span></div>;
  5. }
  6. function itemRender2(index, status) {
  7. return <div className="custom-node2">{status === 'finish' ? <Icon type="success" /> : <span>{index + 1}</span>} </div>;
  8. }
  9. ReactDOM.render(<div className="fusion-demo">
  10. <div className="fusion-demo-item">
  11. <Step current={2} animation={false} itemRender={itemRender}>
  12. {
  13. steps.map(item => <Step.Item key={item} title={item} />)
  14. }
  15. </Step>
  16. </div>
  17. <div className="fusion-demo-item">
  18. <Step current={2} animation={false} itemRender={itemRender2}>
  19. {
  20. steps.map(item => <Step.Item key={item} title={item} />)
  21. }
  22. </Step>
  23. </div>
  24. </div>, mountNode);
  1. .fusion-demo-item {
  2. margin: 15px 0;
  3. }
  4. .custom-node1 {
  5. height: 100%;
  6. width: 100%;
  7. border-radius: 20%;
  8. border: 1px dashed #3E71F1;
  9. text-align: center;
  10. }
  11. .custom-node1 span {
  12. font-size: 12px;
  13. position: absolute;
  14. top: 50%;
  15. text-align: center;
  16. width: 100%;
  17. left: 0;
  18. transform: translateY(-50%);
  19. }
  20. .custom-node2 {
  21. height: 100%;
  22. width: 100%;
  23. border-radius: 20%;
  24. border: 1px dashed #3E71F1;
  25. text-align: center;
  26. background: #3E71F1;
  27. color: #fff;
  28. position: relative;
  29. }
  30. .custom-node2 span, .custom-node2 i {
  31. position: absolute;
  32. top: 50%;
  33. transform: translateY(-50%);
  34. left: 0;
  35. width: 100%;
  36. text-align: center;
  37. }

只读模式

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

Step 步骤 - 图6

查看源码在线预览

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

受控模式

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

Step 步骤 - 图7

查看源码在线预览

  1. import { Step, Button, Select } from '@alifd/next';
  2. const StepItem = Step.Item, ButtonGroup = Button.Group;
  3. class Component extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. currentStep: 3,
  8. stepType: 'circle',
  9. stepAnimation: true,
  10. labelPlacement: 'ver'
  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. onLabelPlacementChange(value) {
  39. this.setState({ labelPlacement: value });
  40. }
  41. render() {
  42. const {currentStep} = this.state;
  43. return (
  44. <div>
  45. <div className="custom-step-option">
  46. <Select placeholder="Choose the dispaly type" onChange={this.onStepTypeChange.bind(this)} className="custom-select" defaultValue="circle">
  47. {
  48. ['circle', 'arrow', 'dot'].map(item => <Select.Option value={item} key={item}>{item}</Select.Option>)
  49. }
  50. </Select>
  51. <Select placeholder="Label placement" onChange={this.onLabelPlacementChange.bind(this)} className="custom-select" defaultValue="ver">
  52. {
  53. ['hoz', 'ver'].map(item => <Select.Option value={item} key={item}>{item}</Select.Option>)
  54. }
  55. </Select>
  56. <Select placeholder="Enable animation" onChange={this.onStepAnimation.bind(this)} className="custom-select" defaultValue>
  57. {
  58. [true, false].map((item, index) => <Select.Option value={item} key={index}>{item ? 'animation on' : 'animation off'}</Select.Option>)
  59. }
  60. </Select>
  61. </div>
  62. <Step current={currentStep} shape={this.state.stepType} animation={this.state.stepAnimation} labelPlacement={this.state.labelPlacement}>
  63. <StepItem title="Step 1" onClick={this.onClick} content="Description" />
  64. <StepItem title="Step 2" onClick={this.onClick} content="Description" />
  65. <StepItem title="Step 3" onClick={this.onClick} content="Description" />
  66. <StepItem title="Step 4" onClick={this.onClick} content="Description" />
  67. <StepItem title="Step 5" onClick={this.onClick} content="Description" />
  68. <StepItem title="Step 6" onClick={this.onClick} content="Description" />
  69. </Step>
  70. <br />
  71. <br />
  72. <ButtonGroup>
  73. <Button onClick={this.prev.bind(this)} type="primary" disabled={currentStep === 0}>Backward</Button>
  74. <Button onClick={this.next.bind(this)} type="primary" disabled={currentStep === 6}>Forward</Button>
  75. </ButtonGroup>
  76. </div>
  77. );
  78. }
  79. }
  80. ReactDOM.render(<Component />, mountNode);
  1. .custom-step-option {
  2. margin-bottom: 20px;
  3. }
  4. .custom-select {
  5. margin-right: 20px;
  6. }

相关区块

Step 步骤 - 图8

暂无相关区块