You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-steps/Step.jsx

112 lines
3.8 KiB

import PropTypes from '../_util/vue-types';
import { getOptionProps, getComponentFromProp } from '../_util/props-util';
function isString(str) {
return typeof str === 'string';
7 years ago
}
export default {
name: 'Step',
props: {
prefixCls: PropTypes.string,
wrapperStyle: PropTypes.object,
7 years ago
itemWidth: PropTypes.string,
7 years ago
status: PropTypes.string,
iconPrefix: PropTypes.string,
icon: PropTypes.any,
7 years ago
adjustMarginRight: PropTypes.string,
7 years ago
stepNumber: PropTypes.string,
description: PropTypes.any,
title: PropTypes.any,
progressDot: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
7 years ago
tailContent: PropTypes.any,
icons: PropTypes.shape({
finish: PropTypes.any,
error: PropTypes.any,
}).loose,
7 years ago
},
methods: {
renderIconNode() {
const { prefixCls, stepNumber, status, iconPrefix, icons } = getOptionProps(this);
let progressDot = this.progressDot;
7 years ago
if (progressDot === undefined) {
progressDot = this.$scopedSlots.progressDot;
7 years ago
}
const icon = getComponentFromProp(this, 'icon');
const title = getComponentFromProp(this, 'title');
const description = getComponentFromProp(this, 'description');
let iconNode;
7 years ago
const iconClassName = {
[`${prefixCls}-icon`]: true,
[`${iconPrefix}icon`]: true,
[`${iconPrefix}icon-${icon}`]: icon && isString(icon),
[`${iconPrefix}icon-check`]: !icon && status === 'finish' && (icons && !icons.finish),
[`${iconPrefix}icon-close`]: !icon && status === 'error' && (icons && !icons.error),
};
const iconDot = <span class={`${prefixCls}-icon-dot`} />;
7 years ago
// `progressDot` enjoy the highest priority
if (progressDot) {
if (typeof progressDot === 'function') {
iconNode = (
<span class={`${prefixCls}-icon`}>
7 years ago
{progressDot({ index: stepNumber - 1, status, title, description, prefixCls })}
7 years ago
</span>
);
7 years ago
} else {
iconNode = <span class={`${prefixCls}-icon`}>{iconDot}</span>;
7 years ago
}
} else if (icon && !isString(icon)) {
iconNode = <span class={`${prefixCls}-icon`}>{icon}</span>;
} else if (icons && icons.finish && status === 'finish') {
iconNode = <span class={`${prefixCls}-icon`}>{icons.finish}</span>;
} else if (icons && icons.error && status === 'error') {
iconNode = <span class={`${prefixCls}-icon`}>{icons.error}</span>;
7 years ago
} else if (icon || status === 'finish' || status === 'error') {
iconNode = <span class={iconClassName} />;
7 years ago
} else {
iconNode = <span class={`${prefixCls}-icon`}>{stepNumber}</span>;
7 years ago
}
return iconNode;
7 years ago
},
},
render() {
7 years ago
const {
prefixCls,
itemWidth,
status = 'wait',
tailContent,
7 years ago
adjustMarginRight,
} = getOptionProps(this);
7 years ago
const title = getComponentFromProp(this, 'title');
const description = getComponentFromProp(this, 'description');
7 years ago
7 years ago
const classString = {
[`${prefixCls}-item`]: true,
[`${prefixCls}-item-${status}`]: true,
[`${prefixCls}-item-custom`]: getComponentFromProp(this, 'icon'),
};
7 years ago
const stepProps = {
class: classString,
on: this.$listeners,
};
const stepItemStyle = {};
7 years ago
if (itemWidth) {
stepItemStyle.width = itemWidth;
7 years ago
}
if (adjustMarginRight) {
stepItemStyle.marginRight = adjustMarginRight;
7 years ago
}
7 years ago
return (
<div {...stepProps} style={stepItemStyle}>
<div class={`${prefixCls}-item-tail`}>{tailContent}</div>
<div class={`${prefixCls}-item-icon`}>{this.renderIconNode()}</div>
7 years ago
<div class={`${prefixCls}-item-content`}>
<div class={`${prefixCls}-item-title`}>{title}</div>
7 years ago
{description && <div class={`${prefixCls}-item-description`}>{description}</div>}
</div>
</div>
);
7 years ago
},
};