2020-03-02 12:09:38 +08:00
|
|
|
import CheckOutlined from '@ant-design/icons/CheckOutlined';
|
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
2020-01-02 19:10:16 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import RcSteps from 'rc-steps';
|
2022-11-18 23:11:03 +08:00
|
|
|
import type {
|
|
|
|
ProgressDotRender,
|
|
|
|
StepsProps as RcStepsProps,
|
2023-05-12 14:53:47 +08:00
|
|
|
StepIconRender,
|
2022-11-18 23:11:03 +08:00
|
|
|
} from 'rc-steps/lib/Steps';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2020-11-04 13:47:13 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-05-12 14:53:47 +08:00
|
|
|
import useSize from '../config-provider/hooks/useSize';
|
2020-11-04 13:47:13 +08:00
|
|
|
import useBreakpoint from '../grid/hooks/useBreakpoint';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Progress from '../progress';
|
2023-05-12 14:53:47 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2022-04-19 11:28:06 +08:00
|
|
|
import useStyle from './style';
|
2023-05-12 14:53:47 +08:00
|
|
|
import useLegacyItems from './useLegacyItems';
|
2015-06-26 10:43:01 +08:00
|
|
|
|
2022-09-16 15:52:14 +08:00
|
|
|
export interface StepProps {
|
|
|
|
className?: string;
|
|
|
|
description?: React.ReactNode;
|
|
|
|
icon?: React.ReactNode;
|
|
|
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
|
|
status?: 'wait' | 'process' | 'finish' | 'error';
|
|
|
|
disabled?: boolean;
|
|
|
|
title?: React.ReactNode;
|
|
|
|
subTitle?: React.ReactNode;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
}
|
2015-06-26 10:43:01 +08:00
|
|
|
|
2016-08-10 09:46:56 +08:00
|
|
|
export interface StepsProps {
|
2022-11-08 15:57:28 +08:00
|
|
|
type?: 'default' | 'navigation' | 'inline';
|
2018-12-13 22:03:12 +08:00
|
|
|
className?: string;
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName?: string;
|
2016-08-10 09:46:56 +08:00
|
|
|
current?: number;
|
2019-02-18 20:23:04 +08:00
|
|
|
direction?: 'horizontal' | 'vertical';
|
|
|
|
iconPrefix?: string;
|
2018-08-22 13:54:51 +08:00
|
|
|
initial?: number;
|
2018-10-10 16:48:26 +08:00
|
|
|
labelPlacement?: 'horizontal' | 'vertical';
|
2019-02-18 20:23:04 +08:00
|
|
|
prefixCls?: string;
|
2021-07-26 16:47:55 +08:00
|
|
|
progressDot?: boolean | ProgressDotRender;
|
2020-12-21 17:25:32 +08:00
|
|
|
responsive?: boolean;
|
2019-02-18 20:23:04 +08:00
|
|
|
size?: 'default' | 'small';
|
|
|
|
status?: 'wait' | 'process' | 'finish' | 'error';
|
2018-01-26 10:38:28 +08:00
|
|
|
style?: React.CSSProperties;
|
2020-07-27 21:40:36 +08:00
|
|
|
percent?: number;
|
2019-05-29 00:09:38 +08:00
|
|
|
onChange?: (current: number) => void;
|
2022-04-18 18:39:23 +08:00
|
|
|
children?: React.ReactNode;
|
2022-09-16 15:52:14 +08:00
|
|
|
items?: StepProps[];
|
2019-01-22 17:11:31 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 16:56:23 +08:00
|
|
|
type CompoundedComponent = React.FC<StepsProps> & {
|
2021-07-26 16:47:55 +08:00
|
|
|
Step: typeof RcSteps.Step;
|
2022-11-19 16:56:23 +08:00
|
|
|
};
|
2020-11-04 13:47:13 +08:00
|
|
|
|
2022-11-19 16:56:23 +08:00
|
|
|
const Steps: CompoundedComponent = (props) => {
|
2022-09-30 17:44:24 +08:00
|
|
|
const {
|
|
|
|
percent,
|
2023-05-11 19:26:04 +08:00
|
|
|
size: customizeSize,
|
2022-09-30 17:44:24 +08:00
|
|
|
className,
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName,
|
2022-09-30 17:44:24 +08:00
|
|
|
direction,
|
2022-10-11 14:54:30 +08:00
|
|
|
items,
|
2022-09-30 17:44:24 +08:00
|
|
|
responsive = true,
|
|
|
|
current = 0,
|
2022-10-11 14:54:30 +08:00
|
|
|
children,
|
2022-09-30 17:44:24 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
2022-02-21 16:48:39 +08:00
|
|
|
const { xs } = useBreakpoint(responsive);
|
2020-11-04 13:47:13 +08:00
|
|
|
const { getPrefixCls, direction: rtlDirection } = React.useContext(ConfigContext);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2022-11-18 23:11:03 +08:00
|
|
|
const realDirectionValue = React.useMemo<RcStepsProps['direction']>(
|
2021-07-26 16:47:55 +08:00
|
|
|
() => (responsive && xs ? 'vertical' : direction),
|
|
|
|
[xs, direction],
|
|
|
|
);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2023-05-11 19:26:04 +08:00
|
|
|
const size = useSize(customizeSize);
|
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
const prefixCls = getPrefixCls('steps', props.prefixCls);
|
2022-04-19 11:28:06 +08:00
|
|
|
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
|
2022-11-08 15:57:28 +08:00
|
|
|
const isInline = props.type === 'inline';
|
2020-11-04 13:47:13 +08:00
|
|
|
const iconPrefix = getPrefixCls('', props.iconPrefix);
|
2022-09-16 15:52:14 +08:00
|
|
|
const mergedItems = useLegacyItems(items, children);
|
2022-11-08 15:57:28 +08:00
|
|
|
const mergedPercent = isInline ? undefined : percent;
|
2022-09-16 15:52:14 +08:00
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
const stepsClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: rtlDirection === 'rtl',
|
2022-11-08 15:57:28 +08:00
|
|
|
[`${prefixCls}-with-progress`]: mergedPercent !== undefined,
|
2020-11-04 13:47:13 +08:00
|
|
|
},
|
|
|
|
className,
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName,
|
2022-04-19 11:28:06 +08:00
|
|
|
hashId,
|
2020-11-04 13:47:13 +08:00
|
|
|
);
|
|
|
|
const icons = {
|
|
|
|
finish: <CheckOutlined className={`${prefixCls}-finish-icon`} />,
|
|
|
|
error: <CloseOutlined className={`${prefixCls}-error-icon`} />,
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2022-09-16 15:52:14 +08:00
|
|
|
|
2022-11-18 23:11:03 +08:00
|
|
|
const stepIconRender: StepIconRender = ({ node, status }) => {
|
2022-11-08 15:57:28 +08:00
|
|
|
if (status === 'process' && mergedPercent !== undefined) {
|
2020-11-04 13:47:13 +08:00
|
|
|
// currently it's hard-coded, since we can't easily read the actually width of icon
|
|
|
|
const progressWidth = size === 'small' ? 32 : 40;
|
2022-09-16 15:52:14 +08:00
|
|
|
// iconWithProgress
|
|
|
|
return (
|
2020-11-04 13:47:13 +08:00
|
|
|
<div className={`${prefixCls}-progress-icon`}>
|
|
|
|
<Progress
|
|
|
|
type="circle"
|
2022-11-08 15:57:28 +08:00
|
|
|
percent={mergedPercent}
|
2023-03-01 11:49:42 +08:00
|
|
|
size={progressWidth}
|
2020-11-04 13:47:13 +08:00
|
|
|
strokeWidth={4}
|
|
|
|
format={() => null}
|
|
|
|
/>
|
|
|
|
{node}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2022-09-16 15:52:14 +08:00
|
|
|
|
2022-11-18 23:11:03 +08:00
|
|
|
const itemRender = (item: StepProps, stepItem: React.ReactNode) =>
|
|
|
|
item.description ? <Tooltip title={item.description}>{stepItem}</Tooltip> : stepItem;
|
2022-11-08 15:57:28 +08:00
|
|
|
|
2022-04-19 11:28:06 +08:00
|
|
|
return wrapSSR(
|
2020-11-04 13:47:13 +08:00
|
|
|
<RcSteps
|
|
|
|
icons={icons}
|
2022-02-21 16:48:39 +08:00
|
|
|
{...restProps}
|
2022-09-30 17:44:24 +08:00
|
|
|
current={current}
|
2022-02-21 16:48:39 +08:00
|
|
|
size={size}
|
2022-09-16 15:52:14 +08:00
|
|
|
items={mergedItems}
|
2022-11-18 23:11:03 +08:00
|
|
|
itemRender={isInline ? itemRender : undefined}
|
2020-11-04 13:47:13 +08:00
|
|
|
stepIcon={stepIconRender}
|
2022-11-18 23:11:03 +08:00
|
|
|
direction={realDirectionValue}
|
2020-11-04 13:47:13 +08:00
|
|
|
prefixCls={prefixCls}
|
|
|
|
iconPrefix={iconPrefix}
|
|
|
|
className={stepsClassName}
|
2022-04-19 11:28:06 +08:00
|
|
|
/>,
|
2020-11-04 13:47:13 +08:00
|
|
|
);
|
|
|
|
};
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
Steps.Step = RcSteps.Step;
|
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Steps.displayName = 'Steps';
|
|
|
|
}
|
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
export default Steps;
|