2022-03-12 09:56:32 +08:00
|
|
|
import type { App, ExtractPropTypes, PropType } from 'vue';
|
2021-09-25 16:51:32 +08:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2020-03-31 00:02:28 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
|
|
|
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
|
2022-03-12 09:56:32 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-10-20 12:44:06 +08:00
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2021-11-10 10:06:59 +08:00
|
|
|
import VcSteps, { Step as VcStep } from '../vc-steps';
|
2021-09-25 16:51:32 +08:00
|
|
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
|
|
|
import useBreakpoint from '../_util/hooks/useBreakpoint';
|
|
|
|
import classNames from '../_util/classNames';
|
|
|
|
import Progress from '../progress';
|
|
|
|
import omit from '../_util/omit';
|
2021-11-26 21:48:35 +08:00
|
|
|
import { VcStepProps } from '../vc-steps/Step';
|
2022-03-12 09:56:32 +08:00
|
|
|
import type { ProgressDotRender } from '../vc-steps/Steps';
|
|
|
|
import type { MouseEventHandler } from '../_util/EventInterface';
|
2023-05-18 21:22:58 +08:00
|
|
|
import type { CustomSlotsType } from '../_util/type';
|
2018-03-09 18:52:31 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export const stepsProps = () => ({
|
2022-03-12 09:56:32 +08:00
|
|
|
prefixCls: String,
|
|
|
|
iconPrefix: String,
|
|
|
|
current: Number,
|
|
|
|
initial: Number,
|
|
|
|
percent: Number,
|
|
|
|
responsive: { type: Boolean, default: undefined },
|
|
|
|
labelPlacement: String as PropType<'horizontal' | 'vertical'>,
|
|
|
|
status: String as PropType<'wait' | 'process' | 'finish' | 'error'>,
|
|
|
|
size: String as PropType<'default' | 'small'>,
|
|
|
|
direction: String as PropType<'horizontal' | 'vertical'>,
|
|
|
|
progressDot: {
|
|
|
|
type: [Boolean, Function] as PropType<boolean | ProgressDotRender>,
|
|
|
|
default: undefined as boolean | ProgressDotRender,
|
|
|
|
},
|
|
|
|
type: String as PropType<'default' | 'navigation'>,
|
|
|
|
onChange: Function as PropType<(current: number) => void>,
|
|
|
|
'onUpdate:current': Function as PropType<(current: number) => void>,
|
2021-09-25 16:51:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export const stepProps = () => ({
|
|
|
|
description: PropTypes.any,
|
|
|
|
icon: PropTypes.any,
|
2022-03-12 09:56:32 +08:00
|
|
|
status: String as PropType<'wait' | 'process' | 'finish' | 'error'>,
|
|
|
|
disabled: { type: Boolean, default: undefined },
|
2021-09-25 16:51:32 +08:00
|
|
|
title: PropTypes.any,
|
|
|
|
subTitle: PropTypes.any,
|
2022-03-12 09:56:32 +08:00
|
|
|
onClick: Function as PropType<MouseEventHandler>,
|
2021-09-25 16:51:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export type StepsProps = Partial<ExtractPropTypes<ReturnType<typeof stepsProps>>>;
|
2018-03-09 18:52:31 +08:00
|
|
|
|
2021-09-25 16:51:32 +08:00
|
|
|
export type StepProps = Partial<ExtractPropTypes<ReturnType<typeof stepProps>>>;
|
2020-10-20 12:44:06 +08:00
|
|
|
|
|
|
|
const Steps = defineComponent({
|
2022-09-26 21:33:41 +08:00
|
|
|
compatConfig: { MODE: 3 },
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ASteps',
|
2020-09-07 17:18:50 +08:00
|
|
|
inheritAttrs: false,
|
2021-09-25 16:51:32 +08:00
|
|
|
props: initDefaultProps(stepsProps(), {
|
2018-03-09 18:52:31 +08:00
|
|
|
current: 0,
|
2021-09-25 16:51:32 +08:00
|
|
|
responsive: true,
|
2022-03-12 09:56:32 +08:00
|
|
|
labelPlacement: 'horizontal',
|
2018-03-09 18:52:31 +08:00
|
|
|
}),
|
2023-05-18 21:22:58 +08:00
|
|
|
slots: Object as CustomSlotsType<{
|
|
|
|
progressDot: any;
|
|
|
|
default: any;
|
|
|
|
}>,
|
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
// emits: ['update:current', 'change'],
|
2021-09-25 16:51:32 +08:00
|
|
|
setup(props, { attrs, slots, emit }) {
|
|
|
|
const { prefixCls, direction: rtlDirection, configProvider } = useConfigInject('steps', props);
|
|
|
|
const screens = useBreakpoint();
|
|
|
|
const direction = computed(() =>
|
|
|
|
props.responsive && screens.value.xs ? 'vertical' : props.direction,
|
|
|
|
);
|
|
|
|
const iconPrefix = computed(() => configProvider.getPrefixCls('', props.iconPrefix));
|
|
|
|
const handleChange = (current: number) => {
|
|
|
|
emit('update:current', current);
|
|
|
|
emit('change', current);
|
2020-06-22 14:21:40 +08:00
|
|
|
};
|
2021-09-25 16:51:32 +08:00
|
|
|
const stepIconRender = ({
|
|
|
|
node,
|
|
|
|
status,
|
|
|
|
}: {
|
|
|
|
node: any;
|
|
|
|
index: number;
|
|
|
|
status: string;
|
|
|
|
title: any;
|
|
|
|
description: any;
|
|
|
|
}) => {
|
|
|
|
if (status === 'process' && props.percent !== undefined) {
|
|
|
|
// currently it's hard-coded, since we can't easily read the actually width of icon
|
|
|
|
const progressWidth = props.size === 'small' ? 32 : 40;
|
|
|
|
const iconWithProgress = (
|
|
|
|
<div class={`${prefixCls}-progress-icon`}>
|
|
|
|
<Progress
|
|
|
|
type="circle"
|
|
|
|
percent={props.percent}
|
|
|
|
width={progressWidth}
|
|
|
|
strokeWidth={4}
|
|
|
|
format={() => null}
|
|
|
|
/>
|
|
|
|
{node}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return iconWithProgress;
|
|
|
|
}
|
|
|
|
return node;
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2021-09-25 16:51:32 +08:00
|
|
|
return () => {
|
|
|
|
const stepsClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls.value}-rtl`]: rtlDirection.value === 'rtl',
|
|
|
|
[`${prefixCls.value}-with-progress`]: props.percent !== undefined,
|
|
|
|
},
|
|
|
|
attrs.class,
|
|
|
|
);
|
|
|
|
const icons = {
|
|
|
|
finish: <CheckOutlined class={`${prefixCls}-finish-icon`} />,
|
|
|
|
error: <CloseOutlined class={`${prefixCls}-error-icon`} />,
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<VcSteps
|
|
|
|
icons={icons}
|
|
|
|
{...omit(props, ['percent', 'responsive'])}
|
|
|
|
direction={direction.value}
|
|
|
|
prefixCls={prefixCls.value}
|
|
|
|
iconPrefix={iconPrefix.value}
|
|
|
|
class={stepsClassName}
|
|
|
|
onChange={handleChange}
|
|
|
|
v-slots={{ ...slots, stepIcon: stepIconRender }}
|
|
|
|
/>
|
|
|
|
);
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-09 18:52:31 +08:00
|
|
|
},
|
2020-10-20 12:44:06 +08:00
|
|
|
});
|
2018-03-19 10:16:27 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
/* istanbul ignore next */
|
2021-11-26 22:34:27 +08:00
|
|
|
export const Step = defineComponent({
|
2022-09-26 21:33:41 +08:00
|
|
|
compatConfig: { MODE: 3 },
|
2021-11-26 22:34:27 +08:00
|
|
|
...VcStep,
|
|
|
|
name: 'AStep',
|
|
|
|
props: VcStepProps(),
|
|
|
|
});
|
2021-11-10 10:06:59 +08:00
|
|
|
export default Object.assign(Steps, {
|
|
|
|
Step,
|
|
|
|
install: (app: App) => {
|
|
|
|
app.component(Steps.name, Steps);
|
|
|
|
app.component(Step.name, Step);
|
|
|
|
return app;
|
|
|
|
},
|
|
|
|
});
|