2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2021-01-13 21:00:30 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
2016-03-18 10:31:25 +08:00
|
|
|
import RcSteps from 'rc-steps';
|
2021-07-26 16:47:55 +08:00
|
|
|
import type { ProgressDotRender } from 'rc-steps/lib/Steps';
|
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';
|
2020-11-04 13:47:13 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2020-07-27 21:40:36 +08:00
|
|
|
import Progress from '../progress';
|
2020-11-04 13:47:13 +08:00
|
|
|
import useBreakpoint from '../grid/hooks/useBreakpoint';
|
2015-06-26 10:43:01 +08:00
|
|
|
|
2016-08-10 09:46:56 +08:00
|
|
|
export interface StepsProps {
|
2019-08-14 11:18:36 +08:00
|
|
|
type?: 'default' | 'navigation';
|
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;
|
2016-08-10 09:46:56 +08:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:11:31 +08:00
|
|
|
export interface StepProps {
|
2019-02-18 20:23:04 +08:00
|
|
|
className?: string;
|
2019-01-22 17:11:31 +08:00
|
|
|
description?: React.ReactNode;
|
|
|
|
icon?: React.ReactNode;
|
2019-06-16 20:51:47 +08:00
|
|
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
2019-01-22 17:11:31 +08:00
|
|
|
status?: 'wait' | 'process' | 'finish' | 'error';
|
2019-08-14 11:18:36 +08:00
|
|
|
disabled?: boolean;
|
2019-01-22 17:11:31 +08:00
|
|
|
title?: React.ReactNode;
|
2019-08-28 15:25:12 +08:00
|
|
|
subTitle?: React.ReactNode;
|
2019-03-14 09:57:30 +08:00
|
|
|
style?: React.CSSProperties;
|
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 => {
|
2020-12-21 17:25:32 +08:00
|
|
|
const { percent, size, className, direction, responsive } = props;
|
2020-11-04 13:47:13 +08:00
|
|
|
const { xs } = useBreakpoint();
|
|
|
|
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);
|
|
|
|
const iconPrefix = getPrefixCls('', props.iconPrefix);
|
|
|
|
const stepsClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: rtlDirection === 'rtl',
|
|
|
|
[`${prefixCls}-with-progress`]: percent !== undefined,
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
|
|
|
const icons = {
|
|
|
|
finish: <CheckOutlined className={`${prefixCls}-finish-icon`} />,
|
|
|
|
error: <CloseOutlined className={`${prefixCls}-error-icon`} />,
|
2018-12-07 20:02:01 +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;
|
|
|
|
}) => {
|
|
|
|
if (status === 'process' && percent !== undefined) {
|
|
|
|
// currently it's hard-coded, since we can't easily read the actually width of icon
|
|
|
|
const progressWidth = size === 'small' ? 32 : 40;
|
|
|
|
const iconWithProgress = (
|
|
|
|
<div className={`${prefixCls}-progress-icon`}>
|
|
|
|
<Progress
|
|
|
|
type="circle"
|
|
|
|
percent={percent}
|
|
|
|
width={progressWidth}
|
|
|
|
strokeWidth={4}
|
|
|
|
format={() => null}
|
|
|
|
/>
|
|
|
|
{node}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return iconWithProgress;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<RcSteps
|
|
|
|
icons={icons}
|
2021-03-03 11:28:38 +08:00
|
|
|
{...omit(props, ['percent', 'responsive'])}
|
2020-11-04 13:47:13 +08:00
|
|
|
direction={getDirection()}
|
|
|
|
stepIcon={stepIconRender}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
iconPrefix={iconPrefix}
|
|
|
|
className={stepsClassName}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2020-11-04 13:47:13 +08:00
|
|
|
Steps.Step = RcSteps.Step;
|
|
|
|
|
|
|
|
Steps.defaultProps = {
|
|
|
|
current: 0,
|
2021-08-31 13:11:17 +08:00
|
|
|
responsive: true,
|
2020-11-04 13:47:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Steps;
|