Progress进度条

展示操作的当前进度。

何时使用

在操作需要较长时间才能完成时,为用户显示该操作的当前进度和状态。

  • 当一个操作会打断当前界面,或者需要在后台运行,且耗时可能超过2秒时;

  • 当需要显示一个操作完成的百分比时。

代码演示

Progress 进度条 - 图1

进度条

标准的进度条。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div>
  4. <Progress percent={30} />
  5. <Progress percent={50} status="active" />
  6. <Progress percent={70} status="exception" />
  7. <Progress percent={100} />
  8. <Progress percent={50} showInfo={false} />
  9. </div>,
  10. mountNode);

Progress 进度条 - 图2

小型进度条

适合放在较狭窄的区域内。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div style={{ width: 170 }}>
  4. <Progress percent={30} size="small" />
  5. <Progress percent={50} size="small" status="active" />
  6. <Progress percent={70} size="small" status="exception" />
  7. <Progress percent={100} size="small" />
  8. </div>,
  9. mountNode);

Progress 进度条 - 图3

进度圈动态展示

会动的进度条才是好进度条。

  1. import { Progress, Button } from 'choerodon-ui';
  2. const ButtonGroup = Button.Group;
  3. class App extends React.Component {
  4. state = {
  5. percent: 0,
  6. };
  7. increase = () => {
  8. let percent = this.state.percent + 10;
  9. if (percent > 100) {
  10. percent = 100;
  11. }
  12. this.setState({ percent });
  13. };
  14. decline = () => {
  15. let percent = this.state.percent - 10;
  16. if (percent < 0) {
  17. percent = 0;
  18. }
  19. this.setState({ percent });
  20. };
  21. render() {
  22. return (
  23. <div>
  24. <Progress type="circle" percent={this.state.percent} />
  25. <ButtonGroup>
  26. <Button onClick={this.decline} icon="minus" />
  27. <Button onClick={this.increase} icon="plus" />
  28. </ButtonGroup>
  29. </div>
  30. );
  31. }
  32. }
  33. ReactDOM.render(<App />, mountNode);

Progress 进度条 - 图4

自定义文字格式

format 属性指定格式。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div>
  4. <Progress type="circle" percent={75} format={percent => `${percent} Days`} />
  5. <Progress type="circle" percent={100} format={() => 'Done'} />
  6. </div>,
  7. mountNode);

Progress 进度条 - 图5

加载

加载。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div>
  4. <Progress type="loading" size="small" />
  5. <Progress type="loading" status="success" />
  6. <Progress type="loading" size="large" status="exception" />
  7. </div>,
  8. mountNode,
  9. );

Progress 进度条 - 图6

进度圈

圈形的进度。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div>
  4. <Progress type="circle" percent={75} />
  5. <Progress type="circle" percent={70} status="exception" />
  6. <Progress type="circle" percent={100} />
  7. </div>,
  8. mountNode);

Progress 进度条 - 图7

小型进度圈

小一号的圈形进度。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <div>
  4. <Progress type="circle" percent={30} width={80} />
  5. <Progress type="circle" percent={70} width={80} status="exception" />
  6. <Progress type="circle" percent={100} width={80} />
  7. </div>,
  8. mountNode);

Progress 进度条 - 图8

动态展示

会动的进度条才是好进度条。

  1. import { Progress, Button } from 'choerodon-ui';
  2. const ButtonGroup = Button.Group;
  3. class App extends React.Component {
  4. state = {
  5. percent: 0,
  6. };
  7. increase = () => {
  8. let percent = this.state.percent + 10;
  9. if (percent > 100) {
  10. percent = 100;
  11. }
  12. this.setState({ percent });
  13. };
  14. decline = () => {
  15. let percent = this.state.percent - 10;
  16. if (percent < 0) {
  17. percent = 0;
  18. }
  19. this.setState({ percent });
  20. };
  21. render() {
  22. return (
  23. <div>
  24. <Progress percent={this.state.percent} />
  25. <ButtonGroup>
  26. <Button onClick={this.decline} icon="minus" />
  27. <Button onClick={this.increase} icon="plus" />
  28. </ButtonGroup>
  29. </div>
  30. );
  31. }
  32. }
  33. ReactDOM.render(<App />, mountNode);

Progress 进度条 - 图9

仪表盘

通过设置 type=dashboard,可以很方便地实现仪表盘样式的进度条。

  1. import { Progress } from 'choerodon-ui';
  2. ReactDOM.render(<Progress type="dashboard" percent={75} />, mountNode);

Progress 进度条 - 图10

分段进度条

标准的进度条。

  1. import { Tooltip, Progress } from 'choerodon-ui';
  2. ReactDOM.render(
  3. <Tooltip title="3 done / 3 in progress / 4 to do">
  4. <Progress percent={60} successPercent={30} />
  5. </Tooltip>,
  6. mountNode);

API

属性说明类型默认值
format内容的模板函数function(percent)percent => percent + '%'
gapDegree (type=circle)圆形进度条缺口角度,可取值 0 ~ 360number0
gapPosition (type=circle)圆形进度条缺口位置Enum{ 'top', 'bottom', 'left', 'right' }top
percent百分比number0
showInfo是否显示进度数值或状态图标booleantrue
status状态,可选:success exception activestring-
strokeWidth (type=line)进度条线的宽度,单位 pxnumber10
strokeWidth (type=circle)圆形进度条线的宽度,单位是进度条画布宽度的百分比number6
type类型,可选 line circle dashboard loadingstringline
width (type=circle)圆形进度条画布宽度,单位 pxnumber132
successPercent已完成的分段百分比,type="line" 时有效number0