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

127 lines
3.9 KiB

7 years ago
import PropTypes from '../_util/vue-types'
7 years ago
import { getOptionProps, getComponentFromProp } from '../_util/props-util'
7 years ago
function isString (str) {
return typeof str === 'string'
}
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.node,
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,
]),
tailContent: PropTypes.any,
icons: PropTypes.shape({
finish: PropTypes.any,
error: PropTypes.any,
}).loose,
7 years ago
},
methods: {
renderIconNode () {
const {
7 years ago
prefixCls, stepNumber, status,
iconPrefix, icons,
7 years ago
} = getOptionProps(this)
7 years ago
let progressDot = this.progressDot
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')
7 years ago
let iconNode
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),
7 years ago
}
const iconDot = <span class={`${prefixCls}-icon-dot`}></span>
// `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>
)
} else {
iconNode = <span class={`${prefixCls}-icon`}>{iconDot}</span>
}
} 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} />
} else {
iconNode = <span class={`${prefixCls}-icon`}>{stepNumber}</span>
}
return iconNode
},
},
render () {
const {
7 years ago
prefixCls, itemWidth,
status = 'wait', tailContent,
7 years ago
adjustMarginRight,
7 years ago
} = 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,
}
7 years ago
const stepItemStyle = {}
if (itemWidth) {
stepItemStyle.width = itemWidth
}
if (adjustMarginRight) {
stepItemStyle.marginRight = adjustMarginRight
}
7 years ago
return (
<div
{...stepProps}
7 years ago
style={stepItemStyle}
7 years ago
>
<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}
</div>
{description && <div class={`${prefixCls}-item-description`}>{description}</div>}
</div>
</div>
)
},
}