2021-06-26 09:35:40 +08:00
|
|
|
import type { App, ExtractPropTypes, Plugin } from 'vue';
|
|
|
|
import { defineComponent, inject } 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';
|
2020-10-11 21:31:57 +08:00
|
|
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
2020-10-20 12:44:06 +08:00
|
|
|
import { getOptionProps, getComponent, getSlot } from '../_util/props-util';
|
|
|
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcSteps from '../vc-steps';
|
2020-09-30 10:47:18 +08:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2020-10-20 12:44:06 +08:00
|
|
|
import { tuple } from '../_util/type';
|
2018-03-09 18:52:31 +08:00
|
|
|
|
2020-10-20 12:44:06 +08:00
|
|
|
const stepsProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
iconPrefix: PropTypes.string,
|
|
|
|
current: PropTypes.number,
|
|
|
|
initial: PropTypes.number,
|
|
|
|
labelPlacement: PropTypes.oneOf(tuple('horizontal', 'vertical')).def('horizontal'),
|
|
|
|
status: PropTypes.oneOf(tuple('wait', 'process', 'finish', 'error')),
|
|
|
|
size: PropTypes.oneOf(tuple('default', 'small')),
|
|
|
|
direction: PropTypes.oneOf(tuple('horizontal', 'vertical')),
|
|
|
|
progressDot: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func])),
|
|
|
|
type: PropTypes.oneOf(tuple('default', 'navigation')),
|
|
|
|
onChange: PropTypes.func,
|
2020-10-26 18:31:50 +08:00
|
|
|
'onUpdate:current': PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-09 18:52:31 +08:00
|
|
|
|
2020-10-20 12:44:06 +08:00
|
|
|
export type StepsProps = Partial<ExtractPropTypes<typeof stepsProps>>;
|
|
|
|
|
|
|
|
const Steps = defineComponent({
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ASteps',
|
2020-09-07 17:18:50 +08:00
|
|
|
inheritAttrs: false,
|
2020-10-20 12:44:06 +08:00
|
|
|
props: initDefaultProps(stepsProps, {
|
2018-03-09 18:52:31 +08:00
|
|
|
current: 0,
|
|
|
|
}),
|
2020-10-20 12:44:06 +08:00
|
|
|
emits: ['update:current', 'change'],
|
2020-06-22 14:21:40 +08:00
|
|
|
setup() {
|
|
|
|
return {
|
2020-09-30 10:47:18 +08:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-06-22 14:21:40 +08:00
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
},
|
2018-04-08 21:17:20 +08:00
|
|
|
Step: { ...VcSteps.Step, name: 'AStep' },
|
2020-09-07 17:18:50 +08:00
|
|
|
methods: {
|
2020-10-26 18:31:50 +08:00
|
|
|
handleChange(current: number) {
|
2020-09-07 17:18:50 +08:00
|
|
|
this.$emit('update:current', current);
|
|
|
|
this.$emit('change', current);
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2020-10-20 12:44:06 +08:00
|
|
|
const props: StepsProps = { ...getOptionProps(this), ...this.$attrs };
|
2019-03-18 20:35:24 +08:00
|
|
|
const { prefixCls: customizePrefixCls, iconPrefix: customizeIconPrefixCls } = props;
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-18 20:35:24 +08:00
|
|
|
const prefixCls = getPrefixCls('steps', customizePrefixCls);
|
|
|
|
const iconPrefix = getPrefixCls('', customizeIconPrefixCls);
|
2020-06-22 14:21:40 +08:00
|
|
|
const progressDot = getComponent(this, 'progressDot', this, false);
|
2019-03-18 20:35:24 +08:00
|
|
|
|
2018-11-30 10:50:26 +08:00
|
|
|
const icons = {
|
2020-03-31 00:02:28 +08:00
|
|
|
finish: <CheckOutlined class={`${prefixCls}-finish-icon`} />,
|
|
|
|
error: <CloseOutlined class={`${prefixCls}-error-icon`} />,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-09 18:52:31 +08:00
|
|
|
const stepsProps = {
|
2020-06-22 14:21:40 +08:00
|
|
|
icons,
|
|
|
|
iconPrefix,
|
|
|
|
prefixCls,
|
|
|
|
progressDot,
|
|
|
|
...props,
|
2020-09-07 17:18:50 +08:00
|
|
|
canClick: !!(this.onChange || this['onUpdate:current']),
|
|
|
|
onChange: this.handleChange,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2020-06-22 16:26:10 +08:00
|
|
|
return <VcSteps {...stepsProps}>{getSlot(this)}</VcSteps>;
|
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-06-23 23:08:16 +08:00
|
|
|
Steps.install = function (app: App) {
|
2020-06-22 14:21:40 +08:00
|
|
|
app.component(Steps.name, Steps);
|
|
|
|
app.component(Steps.Step.name, Steps.Step);
|
2020-10-13 19:14:56 +08:00
|
|
|
return app;
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2021-06-23 21:47:53 +08:00
|
|
|
export const Step = Steps.Step;
|
|
|
|
|
2020-11-01 15:03:33 +08:00
|
|
|
export default Steps as typeof Steps &
|
|
|
|
Plugin & {
|
|
|
|
readonly Step: typeof VcSteps.Step;
|
|
|
|
};
|