2020-10-11 13:31:57 +00:00
|
|
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
2020-06-22 06:21:40 +00:00
|
|
|
import { getOptionProps, getComponent } from '../_util/props-util';
|
2020-07-24 06:23:14 +00:00
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2020-10-12 05:27:16 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2018-03-19 02:16:27 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function isString(str) {
|
|
|
|
return typeof str === 'string';
|
2018-03-07 02:50:11 +00:00
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
function noop() {}
|
2020-10-12 05:27:16 +00:00
|
|
|
export default defineComponent({
|
2018-03-07 02:50:11 +00:00
|
|
|
name: 'Step',
|
2020-07-24 06:23:14 +00:00
|
|
|
mixins: [BaseMixin],
|
2018-03-07 02:50:11 +00:00
|
|
|
props: {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
wrapperStyle: PropTypes.object,
|
2018-03-11 04:48:04 +00:00
|
|
|
itemWidth: PropTypes.string,
|
2020-10-10 10:16:28 +00:00
|
|
|
active: PropTypes.looseBool,
|
|
|
|
disabled: PropTypes.looseBool,
|
2018-03-07 02:50:11 +00:00
|
|
|
status: PropTypes.string,
|
|
|
|
iconPrefix: PropTypes.string,
|
2018-12-15 14:11:21 +00:00
|
|
|
icon: PropTypes.any,
|
2018-03-11 04:48:04 +00:00
|
|
|
adjustMarginRight: PropTypes.string,
|
2018-03-07 02:50:11 +00:00
|
|
|
stepNumber: PropTypes.string,
|
2020-03-07 11:45:13 +00:00
|
|
|
stepIndex: PropTypes.number,
|
2018-03-07 02:50:11 +00:00
|
|
|
description: PropTypes.any,
|
|
|
|
title: PropTypes.any,
|
2020-03-07 11:45:13 +00:00
|
|
|
subTitle: PropTypes.any,
|
2020-10-11 13:31:57 +00:00
|
|
|
progressDot: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func])),
|
2018-03-07 02:50:11 +00:00
|
|
|
tailContent: PropTypes.any,
|
2018-11-09 09:51:56 +00:00
|
|
|
icons: PropTypes.shape({
|
|
|
|
finish: PropTypes.any,
|
|
|
|
error: PropTypes.any,
|
|
|
|
}).loose,
|
2020-06-22 06:21:40 +00:00
|
|
|
onClick: PropTypes.func,
|
|
|
|
onStepClick: PropTypes.func,
|
2018-03-07 02:50:11 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-06-22 06:21:40 +00:00
|
|
|
onItemClick(...args) {
|
2020-07-24 06:23:14 +00:00
|
|
|
this.__emit('click', ...args);
|
|
|
|
this.__emit('stepClick', this.stepIndex);
|
2020-03-07 11:45:13 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
renderIconNode() {
|
2020-06-22 06:21:40 +00:00
|
|
|
const { prefixCls, stepNumber, status, iconPrefix, icons, progressDot } = getOptionProps(
|
|
|
|
this,
|
|
|
|
);
|
|
|
|
const icon = getComponent(this, 'icon');
|
|
|
|
const title = getComponent(this, 'title');
|
|
|
|
const description = getComponent(this, 'description');
|
2019-01-12 03:33:27 +00:00
|
|
|
let iconNode;
|
2018-03-07 02:50:11 +00:00
|
|
|
const iconClassName = {
|
|
|
|
[`${prefixCls}-icon`]: true,
|
|
|
|
[`${iconPrefix}icon`]: true,
|
|
|
|
[`${iconPrefix}icon-${icon}`]: icon && isString(icon),
|
2019-12-21 10:37:33 +00:00
|
|
|
[`${iconPrefix}icon-check`]: !icon && status === 'finish' && icons && !icons.finish,
|
|
|
|
[`${iconPrefix}icon-close`]: !icon && status === 'error' && icons && !icons.error,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
const iconDot = <span class={`${prefixCls}-icon-dot`} />;
|
2018-03-07 02:50:11 +00:00
|
|
|
// `progressDot` enjoy the highest priority
|
|
|
|
if (progressDot) {
|
|
|
|
if (typeof progressDot === 'function') {
|
|
|
|
iconNode = (
|
|
|
|
<span class={`${prefixCls}-icon`}>
|
2018-03-13 02:19:00 +00:00
|
|
|
{progressDot({ index: stepNumber - 1, status, title, description, prefixCls })}
|
2018-03-07 02:50:11 +00:00
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-07 02:50:11 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={`${prefixCls}-icon`}>{iconDot}</span>;
|
2018-03-07 02:50:11 +00:00
|
|
|
}
|
|
|
|
} else if (icon && !isString(icon)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={`${prefixCls}-icon`}>{icon}</span>;
|
2018-11-09 09:51:56 +00:00
|
|
|
} else if (icons && icons.finish && status === 'finish') {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={`${prefixCls}-icon`}>{icons.finish}</span>;
|
2018-11-09 09:51:56 +00:00
|
|
|
} else if (icons && icons.error && status === 'error') {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={`${prefixCls}-icon`}>{icons.error}</span>;
|
2018-03-07 02:50:11 +00:00
|
|
|
} else if (icon || status === 'finish' || status === 'error') {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={iconClassName} />;
|
2018-03-07 02:50:11 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
iconNode = <span class={`${prefixCls}-icon`}>{stepNumber}</span>;
|
2018-03-07 02:50:11 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return iconNode;
|
2018-03-07 02:50:11 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2018-03-07 02:50:11 +00:00
|
|
|
const {
|
2019-01-12 03:33:27 +00:00
|
|
|
prefixCls,
|
|
|
|
itemWidth,
|
2020-03-07 11:45:13 +00:00
|
|
|
active,
|
2019-01-12 03:33:27 +00:00
|
|
|
status = 'wait',
|
|
|
|
tailContent,
|
2018-03-11 04:48:04 +00:00
|
|
|
adjustMarginRight,
|
2020-03-07 11:45:13 +00:00
|
|
|
disabled,
|
2020-06-22 06:21:40 +00:00
|
|
|
onClick,
|
|
|
|
onStepClick,
|
2019-01-12 03:33:27 +00:00
|
|
|
} = getOptionProps(this);
|
2018-03-07 02:50:11 +00:00
|
|
|
|
2020-06-22 06:21:40 +00:00
|
|
|
const title = getComponent(this, 'title');
|
|
|
|
const subTitle = getComponent(this, 'subTitle');
|
|
|
|
const description = getComponent(this, 'description');
|
2018-03-10 12:46:57 +00:00
|
|
|
|
2018-03-07 02:50:11 +00:00
|
|
|
const classString = {
|
|
|
|
[`${prefixCls}-item`]: true,
|
|
|
|
[`${prefixCls}-item-${status}`]: true,
|
2020-06-22 06:21:40 +00:00
|
|
|
[`${prefixCls}-item-custom`]: getComponent(this, 'icon'),
|
2020-03-07 11:45:13 +00:00
|
|
|
[`${prefixCls}-item-active`]: active,
|
|
|
|
[`${prefixCls}-item-disabled`]: disabled === true,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-07 02:50:11 +00:00
|
|
|
const stepProps = {
|
|
|
|
class: classString,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
const stepItemStyle = {};
|
2018-03-11 04:48:04 +00:00
|
|
|
if (itemWidth) {
|
2019-01-12 03:33:27 +00:00
|
|
|
stepItemStyle.width = itemWidth;
|
2018-03-11 04:48:04 +00:00
|
|
|
}
|
|
|
|
if (adjustMarginRight) {
|
2019-01-12 03:33:27 +00:00
|
|
|
stepItemStyle.marginRight = adjustMarginRight;
|
2018-03-11 04:48:04 +00:00
|
|
|
}
|
2020-06-22 06:21:40 +00:00
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
const accessibilityProps = {
|
2020-06-22 06:21:40 +00:00
|
|
|
onClick: onClick || noop,
|
2020-03-07 11:45:13 +00:00
|
|
|
};
|
2020-06-22 06:21:40 +00:00
|
|
|
|
|
|
|
if (onStepClick && !disabled) {
|
|
|
|
accessibilityProps.role = 'button';
|
2020-07-17 09:13:30 +00:00
|
|
|
accessibilityProps.tabindex = 0;
|
2020-06-22 06:21:40 +00:00
|
|
|
accessibilityProps.onClick = this.onItemClick;
|
2020-03-07 11:45:13 +00:00
|
|
|
}
|
2018-03-07 02:50:11 +00:00
|
|
|
return (
|
2019-01-12 03:33:27 +00:00
|
|
|
<div {...stepProps} style={stepItemStyle}>
|
2020-03-07 11:45:13 +00:00
|
|
|
<div {...accessibilityProps} class={`${prefixCls}-item-container`}>
|
|
|
|
<div class={`${prefixCls}-item-tail`}>{tailContent}</div>
|
|
|
|
<div class={`${prefixCls}-item-icon`}>{this.renderIconNode()}</div>
|
|
|
|
<div class={`${prefixCls}-item-content`}>
|
|
|
|
<div class={`${prefixCls}-item-title`}>
|
|
|
|
{title}
|
|
|
|
{subTitle && (
|
|
|
|
<div title={subTitle} class={`${prefixCls}-item-subtitle`}>
|
|
|
|
{subTitle}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{description && <div class={`${prefixCls}-item-description`}>{description}</div>}
|
|
|
|
</div>
|
2018-03-07 02:50:11 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-07 02:50:11 +00:00
|
|
|
},
|
2020-10-12 05:27:16 +00:00
|
|
|
});
|