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