2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2020-07-27 21:40:36 +08:00
|
|
|
import omit from 'omit.js';
|
2016-03-18 10:31:25 +08:00
|
|
|
import RcSteps from 'rc-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;
|
2017-01-23 14:37:40 +08:00
|
|
|
progressDot?: boolean | Function;
|
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> {
|
|
|
|
Step: React.ClassicComponentClass<StepProps>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Steps: StepsType = props => {
|
|
|
|
const { percent, size, className, direction } = props;
|
|
|
|
const { xs } = useBreakpoint();
|
|
|
|
const { getPrefixCls, direction: rtlDirection } = React.useContext(ConfigContext);
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2020-12-09 17:12:32 +08:00
|
|
|
const getDirection = React.useCallback(() => (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}
|
|
|
|
{...omit(props, ['percent'])}
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Steps;
|