@ -2,7 +2,7 @@ import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin' ;
import BaseMixin from '../_util/BaseMixin' ;
import debounce from 'lodash/debounce' ;
import debounce from 'lodash/debounce' ;
import isFlexSupported from '../_util/isFlexSupported' ;
import isFlexSupported from '../_util/isFlexSupported' ;
import { filterEmpty , getEvents , getPropsData , getListeners } from '../_util/props-util' ;
import { filterEmpty } from '../_util/props-util' ;
import { cloneElement } from '../_util/vnode' ;
import { cloneElement } from '../_util/vnode' ;
export default {
export default {
@ -59,6 +59,7 @@ export default {
const { current } = this . $props ;
const { current } = this . $props ;
if ( current !== next ) {
if ( current !== next ) {
this . $emit ( 'change' , next ) ;
this . $emit ( 'change' , next ) ;
this . $emit ( 'update:current' , next ) ;
}
}
} ,
} ,
calcStepOffsetWidth ( ) {
calcStepOffsetWidth ( ) {
@ -97,17 +98,14 @@ export default {
status ,
status ,
size ,
size ,
current ,
current ,
$scopedSlots ,
$slots ,
progressDot ,
initial ,
initial ,
icons ,
icons ,
} = this ;
} = this ;
const isNav = type === 'navigation' ;
const isNav = type === 'navigation' ;
let progressDot = this . progressDot ;
if ( progressDot === undefined ) {
progressDot = $scopedSlots . progressDot ;
}
const { lastStepOffsetWidth , flexSupported } = this ;
const { lastStepOffsetWidth , flexSupported } = this ;
const filteredChildren = filterEmpty ( this . $slots . default ) ;
const filteredChildren = filterEmpty ( $slots . default && $slots . default ( ) ) ;
const lastIndex = filteredChildren . length - 1 ;
const lastIndex = filteredChildren . length - 1 ;
const adjustedlabelPlacement = progressDot ? 'vertical' : labelPlacement ;
const adjustedlabelPlacement = progressDot ? 'vertical' : labelPlacement ;
const classString = {
const classString = {
@ -119,42 +117,36 @@ export default {
[ ` ${ prefixCls } -navigation ` ] : isNav ,
[ ` ${ prefixCls } -navigation ` ] : isNav ,
[ ` ${ prefixCls } -flex-not-supported ` ] : ! flexSupported ,
[ ` ${ prefixCls } -flex-not-supported ` ] : ! flexSupported ,
} ;
} ;
const listeners = getListeners ( this ) ;
const stepsProps = {
const stepsProps = {
class : classString ,
class : classString ,
ref : 'vcStepsRef' ,
ref : 'vcStepsRef' ,
on : listeners ,
} ;
} ;
return (
return (
< div { ...stepsProps } >
< div { ...stepsProps } >
{ filteredChildren . map ( ( child , index ) => {
{ filteredChildren . map ( ( child , index ) => {
const childProps = getPropsData( child ) ;
const childProps = child. props || { } ;
const stepNumber = initial + index ;
const stepNumber = initial + index ;
const stepProps = {
const stepProps = {
props : {
stepNumber : ` ${ stepNumber + 1 } ` ,
stepNumber : ` ${ stepNumber + 1 } ` ,
stepIndex : stepNumber ,
stepIndex : stepNumber ,
prefixCls ,
prefixCls ,
iconPrefix ,
iconPrefix ,
progressDot : this . progressDot ,
progressDot ,
icons ,
icons ,
... childProps ,
... childProps ,
} ,
on : getEvents ( child ) ,
scopedSlots : $scopedSlots ,
} ;
} ;
if ( listeners . change ) {
stepProps . on . stepClick = this . onStepClick ;
const { onChange } = this . $attrs ;
if ( onChange || this . $attrs [ 'onUpdate:current' ] ) {
stepProps . onStepClick = this . onStepClick ;
}
}
if ( ! flexSupported && direction !== 'vertical' ) {
if ( ! flexSupported && direction !== 'vertical' ) {
if ( isNav ) {
if ( isNav ) {
stepProps . props. itemWidth = ` ${ 100 / ( lastIndex + 1 ) } % ` ;
stepProps . itemWidth = ` ${ 100 / ( lastIndex + 1 ) } % ` ;
stepProps . props. adjustMarginRight = 0 ;
stepProps . adjustMarginRight = 0 ;
} else if ( index !== lastIndex ) {
} else if ( index !== lastIndex ) {
stepProps . props . itemWidth = ` ${ 100 / lastIndex } % ` ;
stepProps . itemWidth = ` ${ 100 / lastIndex } % ` ;
stepProps . props . adjustMarginRight = ` ${ - Math . round (
stepProps . adjustMarginRight = ` ${ - Math . round ( lastStepOffsetWidth / lastIndex + 1 ) } px ` ;
lastStepOffsetWidth / lastIndex + 1 ,
) } px ` ;
}
}
}
}
/ / f i x t a i l c o l o r
/ / f i x t a i l c o l o r
@ -163,14 +155,14 @@ export default {
}
}
if ( ! childProps . status ) {
if ( ! childProps . status ) {
if ( stepNumber === current ) {
if ( stepNumber === current ) {
stepProps . props. status = status ;
stepProps . status = status ;
} else if ( stepNumber < current ) {
} else if ( stepNumber < current ) {
stepProps . props. status = 'finish' ;
stepProps . status = 'finish' ;
} else {
} else {
stepProps . props. status = 'wait' ;
stepProps . status = 'wait' ;
}
}
}
}
stepProps . props. active = stepNumber === current ;
stepProps . active = stepNumber === current ;
return cloneElement ( child , stepProps ) ;
return cloneElement ( child , stepProps ) ;
} ) }
} ) }
< / div >
< / div >