Skip to content

Commit 975f52e

Browse files
authored
feat(Progress): support size props (#609)
* feat(Progress): support size props * test: update snapshots * chore: tool functions moved to the tdesign-common repo
1 parent 693ecb1 commit 975f52e

File tree

12 files changed

+151
-26
lines changed

12 files changed

+151
-26
lines changed

src/progress/Progress.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import useConfig from '../hooks/useConfig';
1515
import getBackgroundColor from '../_util/linearGradient';
1616
import { progressDefaultProps } from './defaultProps';
1717
import useDefaultProps from '../hooks/useDefaultProps';
18-
import { PRO_THEME, CIRCLE_SIZE_PX, STATUS_ICON, PLUMP_SEPARATE } from './constants';
18+
import { PRO_THEME, STATUS_ICON } from '../_common/js/progress/const';
19+
import { getDiameter, getCircleStokeWidth } from '../_common/js/progress/utils';
20+
import { PLUMP_SEPARATE } from './constants';
1921

2022
export interface ProgressProps extends TdProgressProps, StyledProps {}
2123

@@ -33,6 +35,7 @@ const Progress = forwardRef<HTMLDivElement, ProgressProps>((props, ref) => {
3335
className,
3436
style,
3537
status,
38+
size,
3639
} = useDefaultProps<ProgressProps>(props, progressDefaultProps);
3740

3841
const computedStatus = percentage >= 100 ? 'success' : status || 'default';
@@ -125,12 +128,10 @@ const Progress = forwardRef<HTMLDivElement, ProgressProps>((props, ref) => {
125128
</div>
126129
);
127130
} else if (theme === PRO_THEME.CIRCLE) {
128-
// 获取环形进度条 环的宽度
129-
const getCircleStokeWidth = (): number => (strokeWidth ? Number(strokeWidth) : 6);
130131
// 环形进度条尺寸(进度条占位空间,长宽占位)
131-
const circleStokeWidth = getCircleStokeWidth();
132+
const circleStokeWidth = getCircleStokeWidth(strokeWidth, size);
132133
// 直径
133-
const diameter = CIRCLE_SIZE_PX;
134+
const diameter = getDiameter(size);
134135
// 半径
135136
const radius = diameter / 2;
136137
// 内环半径

src/progress/_example/base.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ export default function Base() {
99
<div className="example-progress__item">
1010
<Progress percentage={80} />
1111
</div>
12+
13+
<div className="summary">百分比内显</div>
1214
<div className="example-progress__item">
1315
<Progress theme="plump" percentage={80} />
1416
</div>
17+
18+
<div className="summary">环形进度条</div>
1519
<div className="example-progress__item">
1620
<Progress theme="circle" percentage={30} />
1721
</div>
22+
23+
<div className="summary">微型环形进度条</div>
24+
<div className="example-progress__item">
25+
<Progress theme="circle" size={'micro'} percentage={30} label={false} />
26+
</div>
1827
</div>
1928
);
2029
}

src/progress/_example/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ export default function ProgressDemo() {
1414
return (
1515
<div className="tdesign-mobile-demo">
1616
<TDemoHeader title="Progress 进度条" summary="展示操作的当前进度" />
17-
<TDemoBlock title="01 类型" summary="基础进度条" padding={true}>
17+
<TDemoBlock title="01 类型" summary="基础进度条">
1818
<BaseDemo />
1919
</TDemoBlock>
20-
<TDemoBlock summary="过渡样式" padding={true}>
20+
<TDemoBlock summary="过渡样式" padding>
2121
<TransitionDemo />
2222
</TDemoBlock>
23-
<TDemoBlock summary="自定义颜色/圆角" padding={true}>
23+
<TDemoBlock summary="自定义颜色/圆角">
2424
<CustomDemo />
2525
</TDemoBlock>
26-
<TDemoBlock title="02 组件状态" summary="线性进度条" padding={true}>
26+
<TDemoBlock title="02 组件状态" summary="线性进度条">
2727
<LineDemo />
2828
</TDemoBlock>
29-
<TDemoBlock summary="百分比内显进度条" padding={true}>
29+
<TDemoBlock summary="百分比内显进度条">
3030
<PlumpDemo />
3131
</TDemoBlock>
32-
<TDemoBlock summary="环形进度条" padding={true}>
32+
<TDemoBlock summary="环形进度条">
3333
<CircleDemo />
3434
</TDemoBlock>
3535
</div>

src/progress/_example/style/index.less

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
}
44

55
.example-progress {
6-
&__item:not(:last-child) {
6+
&__item {
7+
padding: 0 16px;
8+
margin-bottom: 16px;
9+
}
10+
11+
.summary {
712
margin-bottom: 16px;
813
}
914

src/progress/constants.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
export { PRO_THEME, STATUS_ICON } from '../_common/js/progress/const';
2-
3-
export const CIRCLE_SIZE_PX = 112;
4-
51
// 进度大于 10 ,进度百分比显示在内部;进度百分比小于 10 进度显示在外部
62
export const PLUMP_SEPARATE = 10;

src/progress/defaultProps.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const progressDefaultProps: TdProgressProps = {
88
color: '',
99
label: true,
1010
percentage: 0,
11+
size: 'default',
1112
theme: 'line',
1213
trackColor: '',
1314
};

src/progress/progress.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProper
1111
color | String / Object / Array | '' | Typescript:`string \| Array<string> \| Record<string, string>` | N
1212
label | TNode | true | Typescript:`string \| boolean \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
1313
percentage | Number | 0 | \- | N
14+
size | String / Number | 'default' | \- | N
1415
status | String | - | options: success/error/warning/active。Typescript:`ProgressStatus` `type ProgressStatus = 'success' \| 'error' \| 'warning' \| 'active'`[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/progress/type.ts) | N
1516
strokeWidth | String / Number | - | \- | N
1617
theme | String | line | options: line/plump/circle。Typescript:`ProgressTheme` `type ProgressTheme = 'line' \| 'plump' \| 'circle'`[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/progress/type.ts) | N

src/progress/progress.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
1111
color | String / Object / Array | '' | 进度条颜色。示例:'#ED7B2F' 或 'orange' 或 `['#f00', '#0ff', '#f0f']``{ '0%': '#f00', '100%': '#0ff' }``{ from: '#000', to: '#000' }` 等。TS 类型:`string \| Array<string> \| Record<string, string>` | N
1212
label | TNode | true | 进度百分比,可自定义。TS 类型:`string \| boolean \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
1313
percentage | Number | 0 | 进度条百分比 | N
14+
size | String / Number | 'default' | 进度条尺寸,仅对环形进度条有效。可选值:default/micro。default 值为 112; micro 值为 24 | N
1415
status | String | - | 进度条状态。可选项:success/error/warning/active。TS 类型:`ProgressStatus` `type ProgressStatus = 'success' \| 'error' \| 'warning' \| 'active'`[详细类型定义](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/progress/type.ts) | N
1516
strokeWidth | String / Number | - | 进度条线宽。宽度数值不能超过 size 的一半,否则不能输出环形进度 | N
1617
theme | String | line | 进度条风格。值为 line,标签(label)显示在进度条右侧;值为 plump,标签(label)显示在进度条里面;值为 circle,标签(label)显示在进度条正中间。可选项:line/plump/circle。TS 类型:`ProgressTheme` `type ProgressTheme = 'line' \| 'plump' \| 'circle'`[详细类型定义](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/progress/type.ts) | N

src/progress/type.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export interface TdProgressProps {
2222
* @default 0
2323
*/
2424
percentage?: number;
25+
/**
26+
* 进度条尺寸,仅对环形进度条有效。可选值:default/micro。default 值为 112; micro 值为 24
27+
* @default 'default'
28+
*/
29+
size?: string | number;
2530
/**
2631
* 进度条状态
2732
*/

0 commit comments

Comments
 (0)