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';
|
|
|
|
import type { ProgressDotRender } from 'rc-steps/lib/Steps';
|
|
|
|
import * as React from 'react';
|
2022-11-08 15:57:28 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2020-11-04 13:47:13 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
|
|
|
import useBreakpoint from '../grid/hooks/useBreakpoint';
|
2022-06-22 14:57:09 +08:00
|
|
|
import Progress from '../progress';
|
2022-09-16 15:52:14 +08:00
|
|
|
import useLegacyItems from './useLegacyItems';
|
2022-04-19 11:28:06 +08:00
|
|
|
import useStyle from './style';
|
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;
|
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
|
|
|
}
|
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
interface StepsType extends React.FC<StepsProps> {
|
2021-07-26 16:47:55 +08:00
|
|
|
Step: typeof RcSteps.Step;
|
2020-11-04 13:47:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Steps: StepsType = props => {
|
2022-09-30 17:44:24 +08:00
|
|
|
const {
|
|
|
|
percent,
|
|
|
|
size,
|
|
|
|
className,
|
|
|
|
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
|
|
|
|
2021-07-26 16:47:55 +08:00
|
|
|
const getDirection = React.useCallback(
|
|
|
|
() => (responsive && xs ? 'vertical' : direction),
|
|
|
|
[xs, direction],
|
|
|
|
);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
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,
|
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
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
const stepIconRender = ({
|
|
|
|
node,
|
|
|
|
status,
|
|
|
|
}: {
|
|
|
|
node: React.ReactNode;
|
|
|
|
index: number;
|
|
|
|
status: string;
|
|
|
|
title: string | React.ReactNode;
|
|
|
|
description: string | React.ReactNode;
|
|
|
|
}) => {
|
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}
|
2020-11-04 13:47:13 +08:00
|
|
|
width={progressWidth}
|
|
|
|
strokeWidth={4}
|
|
|
|
format={() => null}
|
|
|
|
/>
|
|
|
|
{node}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2022-09-16 15:52:14 +08:00
|
|
|
|
2022-11-08 15:57:28 +08:00
|
|
|
let itemRender;
|
|
|
|
if (isInline) {
|
|
|
|
itemRender = (item: StepProps, stepItem: React.ReactNode) =>
|
|
|
|
item.description ? <Tooltip title={item.description}>{stepItem}</Tooltip> : stepItem;
|
|
|
|
}
|
|
|
|
|
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-08 15:57:28 +08:00
|
|
|
itemRender={itemRender}
|
2020-11-04 13:47:13 +08:00
|
|
|
direction={getDirection()}
|
|
|
|
stepIcon={stepIconRender}
|
|
|
|
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;
|
|
|
|
|
|
|
|
export default Steps;
|