2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 4
|
2016-07-26 15:42:04 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 动态展示
|
|
|
|
en-US: Dynamic
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-06-15 14:43:27 +08:00
|
|
|
|
2016-07-26 15:42:04 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-06-15 14:43:27 +08:00
|
|
|
会动的进度条才是好进度条。
|
|
|
|
|
2016-07-26 15:42:04 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
A dynamic progress bar is better.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2019-11-28 12:34:33 +08:00
|
|
|
import { MinusOutlined, PlusOutlined } from '@ant-design/icons';
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Button, Progress } from 'antd';
|
|
|
|
import React, { useState } from 'react';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [percent, setPercent] = useState(0);
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const increase = () => {
|
|
|
|
let newPercent = percent + 10;
|
|
|
|
if (newPercent > 100) {
|
|
|
|
newPercent = 100;
|
2015-09-22 20:11:28 +08:00
|
|
|
}
|
2022-05-19 09:46:26 +08:00
|
|
|
setPercent(newPercent);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const decline = () => {
|
|
|
|
let newPercent = percent - 10;
|
|
|
|
if (newPercent < 0) {
|
|
|
|
newPercent = 0;
|
2015-09-22 20:11:28 +08:00
|
|
|
}
|
2022-05-19 09:46:26 +08:00
|
|
|
setPercent(newPercent);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Progress percent={percent} />
|
|
|
|
<Button.Group>
|
|
|
|
<Button onClick={decline} icon={<MinusOutlined />} />
|
|
|
|
<Button onClick={increase} icon={<PlusOutlined />} />
|
|
|
|
</Button.Group>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2015-06-15 14:43:27 +08:00
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|