Steps步骤条

    当任务复杂或者存在先后关系时,将其分解成一系列步骤,从而简化任务。

    基本用法

    简单的步骤条。

    Steps步骤条 - 图2

    迷你版的步骤条,通过设置 启用.

    1. import { Steps } from 'antd';
    2. const { Step } = Steps;
    3. ReactDOM.render(
    4. <Steps size="small" current={1}>
    5. <Step title="Finished" />
    6. <Step title="In Progress" />
    7. <Step title="Waiting" />
    8. </Steps>,
    9. mountNode,
    10. );

    带图标的步骤条

    通过设置 Steps.Stepicon 属性,可以启用自定义图标。

    1. import { Steps, Icon } from 'antd';
    2. const { Step } = Steps;
    3. ReactDOM.render(
    4. <Steps>
    5. <Step status="finish" title="Login" icon={<Icon type="user" />} />
    6. <Step status="finish" title="Verification" icon={<Icon type="solution" />} />
    7. <Step status="process" title="Pay" icon={<Icon type="loading" />} />
    8. <Step status="wait" title="Done" icon={<Icon type="smile-o" />} />
    9. </Steps>,
    10. mountNode,
    11. );

    通常配合内容及按钮使用,表示一个流程的处理进度。

    1. import { Steps, Button, message } from 'antd';
    2. const { Step } = Steps;
    3. const steps = [
    4. {
    5. title: 'First',
    6. content: 'First-content',
    7. },
    8. {
    9. title: 'Second',
    10. content: 'Second-content',
    11. },
    12. {
    13. title: 'Last',
    14. content: 'Last-content',
    15. },
    16. ];
    17. class App extends React.Component {
    18. constructor(props) {
    19. super(props);
    20. this.state = {
    21. current: 0,
    22. };
    23. }
    24. next() {
    25. const current = this.state.current + 1;
    26. this.setState({ current });
    27. }
    28. prev() {
    29. const current = this.state.current - 1;
    30. this.setState({ current });
    31. }
    32. const { current } = this.state;
    33. return (
    34. <div>
    35. <Steps current={current}>
    36. {steps.map(item => (
    37. <Step key={item.title} title={item.title} />
    38. ))}
    39. <div className="steps-content">{steps[current].content}</div>
    40. <div className="steps-action">
    41. {current < steps.length - 1 && (
    42. <Button type="primary" onClick={() => this.next()}>
    43. Next
    44. </Button>
    45. )}
    46. {current === steps.length - 1 && (
    47. <Button type="primary" onClick={() => message.success('Processing complete!')}>
    48. Done
    49. </Button>
    50. )}
    51. {current > 0 && (
    52. <Button style={{ marginLeft: 8 }} onClick={() => this.prev()}>
    53. Previous
    54. </Button>
    55. )}
    56. </div>
    57. </div>
    58. );
    59. }
    60. }
    61. ReactDOM.render(<App />, mountNode);

    Steps步骤条 - 图5

    竖直方向的步骤条

    简单的竖直方向的步骤条。

    1. import { Steps } from 'antd';
    2. const { Step } = Steps;
    3. ReactDOM.render(
    4. <Steps direction="vertical" current={1}>
    5. <Step title="Finished" description="This is a description." />
    6. <Step title="In Progress" description="This is a description." />
    7. <Step title="Waiting" description="This is a description." />
    8. </Steps>,
    9. mountNode,
    10. );

    简单的竖直方向的小型步骤条。

    1. import { Steps } from 'antd';
    2. const { Step } = Steps;
    3. ReactDOM.render(
    4. <Steps direction="vertical" size="small" current={1}>
    5. <Step title="Finished" description="This is a description." />
    6. <Step title="In Progress" description="This is a description." />
    7. <Step title="Waiting" description="This is a description." />
    8. </Steps>,
    9. mountNode,
    10. );

    Steps步骤条 - 图7

    步骤运行错误

    1. import { Steps } from 'antd';
    2. const { Step } = Steps;
    3. ReactDOM.render(
    4. <Steps current={1} status="error">
    5. <Step title="Finished" description="This is a description" />
    6. <Step title="In Process" description="This is a description" />
    7. <Step title="Waiting" description="This is a description" />
    8. </Steps>,
    9. mountNode,

    包含步骤点的进度条。

    Steps步骤条 - 图9

    自定义点状步骤条

    为点状步骤条增加自定义展示。

    1. import { Steps, Popover } from 'antd';
    2. const { Step } = Steps;
    3. const customDot = (dot, { status, index }) => (
    4. <Popover
    5. content={
    6. <span>
    7. step {index} status: {status}
    8. </span>
    9. }
    10. {dot}
    11. </Popover>
    12. );
    13. ReactDOM.render(
    14. <Steps current={1} progressDot={customDot}>
    15. <Step title="Finished" description="You can hover on the dot." />
    16. <Step title="In Progress" description="You can hover on the dot." />
    17. <Step title="Waiting" description="You can hover on the dot." />
    18. <Step title="Waiting" description="You can hover on the dot." />
    19. </Steps>,
    20. mountNode,
    21. );

    设置 onChange 后,Steps 变为可点击状态。

    1. import { Steps, Divider } from 'antd';
    2. const { Step } = Steps;
    3. class Demo extends React.Component {
    4. state = {
    5. current: 0,
    6. };
    7. onChange = current => {
    8. console.log('onChange:', current);
    9. this.setState({ current });
    10. };
    11. render() {
    12. const { current } = this.state;
    13. return (
    14. <div>
    15. <Steps current={current} onChange={this.onChange}>
    16. <Step title="Step 1" description="This is a description." />
    17. <Step title="Step 2" description="This is a description." />
    18. <Step title="Step 3" description="This is a description." />
    19. </Steps>
    20. <Divider />
    21. <Steps current={current} onChange={this.onChange} direction="vertical">
    22. <Step title="Step 1" description="This is a description." />
    23. <Step title="Step 2" description="This is a description." />
    24. <Step title="Step 3" description="This is a description." />
    25. </Steps>
    26. </div>
    27. );
    28. }
    29. }
    30. ReactDOM.render(<Demo />, mountNode);
    1. <Steps>
    2. <Step title="第一步" />
    3. <Step title="第二步" />
    4. <Step title="第三步" />

    整体步骤条。

    Steps.Step

    参数说明类型默认值
    description步骤的详情描述,可选string|ReactNode-
    icon步骤图标的类型,可选string|ReactNode-
    status指定状态。当不配置该属性时,会使用 Steps 的 current 来自动指定状态。可选:wait process errorstringwait
    title标题string|ReactNode-