Skip to content

Commit

Permalink
feat: Progress.Circle support conic (ant-design#44404)
Browse files Browse the repository at this point in the history
* feat: support conic

* test: update snapshot

* docs: update doc

* chore: clean up

* docs: update doc

* test: update snapshot

* test: update snapshot

* test: update snapshot
  • Loading branch information
zombieJ committed Aug 24, 2023
1 parent dd5628b commit d373bf3
Show file tree
Hide file tree
Showing 11 changed files with 1,592 additions and 913 deletions.
1,044 changes: 689 additions & 355 deletions components/progress/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

1,040 changes: 687 additions & 353 deletions components/progress/__tests__/__snapshots__/demo.test.ts.snap

Large diffs are not rendered by default.

140 changes: 70 additions & 70 deletions components/progress/__tests__/__snapshots__/index.test.tsx.snap

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions components/progress/demo/gradient-line.md
@@ -1,7 +1,7 @@
## zh-CN

`linear-gradient` 的封装。推荐只传两种颜色
渐变色封装,`circle``dashboard` 设置渐变时 `strokeLinecap` 会被忽略

## en-US

A package of `linear-gradient`. It is recommended to only pass two colors.
Gradient encapsulation, `circle` and `dashboard` will ignore `strokeLinecap` when setting gradient.
19 changes: 14 additions & 5 deletions components/progress/demo/gradient-line.tsx
@@ -1,15 +1,24 @@
import React from 'react';
import { Progress, Space } from 'antd';

const twoColors = { '0%': '#108ee9', '100%': '#87d068' };
const conicColors = { '0%': '#87d068', '50%': '#ffe58f', '100%': '#ffccc7' };

const App: React.FC = () => (
<>
<Progress percent={99.9} strokeColor={{ '0%': '#108ee9', '100%': '#87d068' }} />
<div style={{ display: 'flex', flexDirection: 'column', rowGap: 16 }}>
<Progress percent={99.9} strokeColor={twoColors} />
<Progress percent={99.9} status="active" strokeColor={{ from: '#108ee9', to: '#87d068' }} />
<Space wrap>
<Progress type="circle" percent={90} strokeColor={{ '0%': '#108ee9', '100%': '#87d068' }} />
<Progress type="circle" percent={100} strokeColor={{ '0%': '#108ee9', '100%': '#87d068' }} />
<Progress type="circle" percent={90} strokeColor={twoColors} />
<Progress type="circle" percent={100} strokeColor={twoColors} />
<Progress type="circle" percent={93} strokeColor={conicColors} />
</Space>
<Space wrap>
<Progress type="dashboard" percent={90} strokeColor={twoColors} />
<Progress type="dashboard" percent={100} strokeColor={twoColors} />
<Progress type="dashboard" percent={93} strokeColor={conicColors} />
</Space>
</>
</div>
);

export default App;
2 changes: 1 addition & 1 deletion components/progress/index.en-US.md
Expand Up @@ -65,7 +65,7 @@ Properties that shared by all types.

| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| strokeColor | The color of circular progress, render `linear-gradient` when passing an object | string \| object | - | - |
| strokeColor | The color of circular progress, render gradient when passing an object | string \| { number%: string } | - | - |
| strokeWidth | To set the width of the circular progress, unit: percentage of the canvas width | number | 6 | - |

### `type="dashboard"`
Expand Down
2 changes: 1 addition & 1 deletion components/progress/index.zh-CN.md
Expand Up @@ -66,7 +66,7 @@ demo:

| 属性 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| strokeColor | 圆形进度条线的色彩,传入 object 时为渐变 | string \| object | - | - |
| strokeColor | 圆形进度条线的色彩,传入 object 时为渐变 | string \| { number%: string } | - | - |
| strokeWidth | 圆形进度条线的宽度,单位是进度条画布宽度的百分比 | number | 6 | - |

### `type="dashboard"`
Expand Down
12 changes: 7 additions & 5 deletions components/progress/progress.tsx
@@ -1,10 +1,11 @@
import * as React from 'react';
import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
import CheckOutlined from '@ant-design/icons/CheckOutlined';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import omit from 'rc-util/lib/omit';
import * as React from 'react';

import warning from '../_util/warning';
import type { ConfigConsumerProps } from '../config-provider';
import { ConfigContext } from '../config-provider';
Expand All @@ -15,10 +16,11 @@ import useStyle from './style';
import { getSize, getSuccessPercent, validProgress } from './utils';

export const ProgressTypes = ['line', 'circle', 'dashboard'] as const;
export type ProgressType = (typeof ProgressTypes)[number];
export type ProgressType = typeof ProgressTypes[number];
const ProgressStatuses = ['normal', 'exception', 'active', 'success'] as const;
export type ProgressSize = 'default' | 'small';
export type StringGradients = { [percentage: string]: string };
export type StringGradients = Record<string, string>;

type FromToGradients = { from: string; to: string };
export type ProgressGradient = { direction?: string } & (StringGradients | FromToGradients);

Expand All @@ -38,7 +40,7 @@ export interface ProgressProps extends ProgressAriaProps {
type?: ProgressType;
percent?: number;
format?: (percent?: number, successPercent?: number) => React.ReactNode;
status?: (typeof ProgressStatuses)[number];
status?: typeof ProgressStatuses[number];
showInfo?: boolean;
strokeWidth?: number;
strokeLinecap?: 'butt' | 'square' | 'round';
Expand Down Expand Up @@ -82,7 +84,7 @@ const Progress = React.forwardRef<HTMLDivElement, ProgressProps>((props, ref) =>
);
}, [percent, props.success, props.successPercent]);

const progressStatus = React.useMemo<(typeof ProgressStatuses)[number]>(() => {
const progressStatus = React.useMemo<typeof ProgressStatuses[number]>(() => {
if (!ProgressStatuses.includes(status!) && percentNumber >= 100) {
return 'success';
}
Expand Down
120 changes: 60 additions & 60 deletions components/steps/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

0 comments on commit d373bf3

Please sign in to comment.