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

119 lines
3.5 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,
},
methods: {
renderIconNode () {
const {
7 years ago
prefixCls, stepNumber, status,
7 years ago
iconPrefix,
} = 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',
[`${iconPrefix}icon-cross`]: !icon && status === 'error',
}
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 (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,
7 years ago
status = 'wait', icon, 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`]: icon,
}
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>
)
},
}