2022-10-31 10:23:26 +08:00
|
|
|
import { presetPrimaryColors } from '@ant-design/colors';
|
|
|
|
import type { CircleProps } from './Circle';
|
|
|
|
import type { ProgressProps } from './progress';
|
2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../_util/warning';
|
2020-08-20 15:27:16 +08:00
|
|
|
|
2022-10-31 10:23:26 +08:00
|
|
|
export function validProgress(progress?: number) {
|
2019-01-18 15:19:36 +08:00
|
|
|
if (!progress || progress < 0) {
|
|
|
|
return 0;
|
2019-08-14 18:21:24 +08:00
|
|
|
}
|
|
|
|
if (progress > 100) {
|
2019-01-18 15:19:36 +08:00
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
return progress;
|
2019-03-06 13:45:40 +08:00
|
|
|
}
|
2020-08-20 15:27:16 +08:00
|
|
|
|
2022-10-31 10:23:26 +08:00
|
|
|
export function getSuccessPercent({ success, successPercent }: ProgressProps) {
|
2020-08-20 15:27:16 +08:00
|
|
|
let percent = successPercent;
|
|
|
|
/** @deprecated Use `percent` instead */
|
|
|
|
if (success && 'progress' in success) {
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2020-08-20 15:27:16 +08:00
|
|
|
false,
|
|
|
|
'Progress',
|
|
|
|
'`success.progress` is deprecated. Please use `success.percent` instead.',
|
|
|
|
);
|
|
|
|
percent = success.progress;
|
|
|
|
}
|
|
|
|
if (success && 'percent' in success) {
|
|
|
|
percent = success.percent;
|
|
|
|
}
|
|
|
|
return percent;
|
|
|
|
}
|
2022-10-31 10:23:26 +08:00
|
|
|
|
|
|
|
export const getPercentage = ({ percent, success, successPercent }: ProgressProps) => {
|
|
|
|
const realSuccessPercent = validProgress(getSuccessPercent({ success, successPercent }));
|
|
|
|
return [realSuccessPercent, validProgress(validProgress(percent) - realSuccessPercent)];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getStrokeColor = ({
|
|
|
|
success = {},
|
|
|
|
strokeColor,
|
|
|
|
}: Partial<CircleProps>): (string | Record<PropertyKey, string>)[] => {
|
|
|
|
const { strokeColor: successColor } = success;
|
|
|
|
return [successColor || presetPrimaryColors.green, strokeColor || null!];
|
|
|
|
};
|