Progress 进度条

展示操作的当前进度。

何时使用

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

  • 当一个操作会打断当前界面,或者需要在后台运行,且耗时可能超过2秒时;
  • 当需要显示一个操作完成的百分比时。

代码演示

进度条

标准的进度条。

Progress进度条 - 图1

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

进度圈

圈形的进度。

Progress进度条 - 图2

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

小型进度条

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

Progress进度条 - 图3

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

小型进度圈

小一号的圈形进度。

Progress进度条 - 图4

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

动态展示

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

Progress进度条 - 图5

  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Progress, Button } from 'choerodon-ui';
  4. const ButtonGroup = Button.Group;
  5. class App extends React.Component {
  6. state = {
  7. percent: 0,
  8. };
  9. increase = () => {
  10. let percent = this.state.percent + 10;
  11. if (percent > 100) {
  12. percent = 100;
  13. }
  14. this.setState({ percent });
  15. };
  16. decline = () => {
  17. let percent = this.state.percent - 10;
  18. if (percent < 0) {
  19. percent = 0;
  20. }
  21. this.setState({ percent });
  22. };
  23. render() {
  24. return (
  25. <div>

进度圈动态展示

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

Progress进度条 - 图6

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

自定义文字格式

format 属性指定格式。

Progress进度条 - 图7

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

仪表盘

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

Progress进度条 - 图8

  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Progress } from 'choerodon-ui';
  4. ReactDOM.render(<>
  5. <Progress type="dashboard" percent={75} />
  6. <Progress type="dashboard" showPointer percent={75} />
  7. </>, document.getElementById('container'));

加载

加载。

Progress进度条 - 图9

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

分段进度条

标准的进度条。

Progress进度条 - 图10

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

API

属性说明类型默认值
format内容的模板函数function(percent)percent => percent + ‘%’
gapDegree (type=circle)圆形进度条缺口角度,可取值 0 ~ 360number0
gapPosition (type=circle)圆形进度条缺口位置Enum{ ‘top’, ‘bottom’, ‘left’, ‘right’ }top
percent百分比number0
showInfo是否显示进度数值或状态图标booleantrue
showPointer (type=dashboard)是否显示指针booleanfalse
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
strokeColor进度条的色彩string-