1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import _extends from 'babel-runtime/helpers/extends';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin';
import debounce from 'lodash/debounce';
import isFlexSupported from '../_util/isFlexSupported';
import { filterEmpty, getEvents, getPropsData } from '../_util/props-util';
import { cloneElement } from '../_util/vnode';
export default {
name: 'Steps',
mixins: [BaseMixin],
props: {
prefixCls: PropTypes.string.def('rc-steps'),
iconPrefix: PropTypes.string.def('rc'),
direction: PropTypes.string.def('horizontal'),
labelPlacement: PropTypes.string.def('horizontal'),
status: PropTypes.string.def('process'),
size: PropTypes.string.def(''),
progressDot: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
initial: PropTypes.number.def(0),
current: PropTypes.number.def(0),
icons: PropTypes.shape({
finish: PropTypes.any,
error: PropTypes.any
}).loose
},
data: function data() {
this.calcStepOffsetWidth = debounce(this.calcStepOffsetWidth, 150);
return {
flexSupported: true,
lastStepOffsetWidth: 0
};
},
mounted: function mounted() {
var _this = this;
this.$nextTick(function () {
_this.calcStepOffsetWidth();
if (!isFlexSupported()) {
_this.setState({
flexSupported: false
});
}
});
},
updated: function updated() {
var _this2 = this;
this.$nextTick(function () {
_this2.calcStepOffsetWidth();
});
},
beforeDestroy: function beforeDestroy() {
if (this.calcTimeout) {
clearTimeout(this.calcTimeout);
}
if (this.calcStepOffsetWidth && this.calcStepOffsetWidth.cancel) {
this.calcStepOffsetWidth.cancel();
}
},
methods: {
calcStepOffsetWidth: function calcStepOffsetWidth() {
var _this3 = this;
if (isFlexSupported()) {
return;
}
// Just for IE9
var domNode = this.$refs.vcStepsRef;
if (domNode.children.length > 0) {
if (this.calcTimeout) {
clearTimeout(this.calcTimeout);
}
this.calcTimeout = setTimeout(function () {
// +1 for fit edge bug of digit width, like 35.4px
var lastStepOffsetWidth = (domNode.lastChild.offsetWidth || 0) + 1;
// Reduce shake bug
if (_this3.lastStepOffsetWidth === lastStepOffsetWidth || Math.abs(_this3.lastStepOffsetWidth - lastStepOffsetWidth) <= 3) {
return;
}
_this3.setState({ lastStepOffsetWidth: lastStepOffsetWidth });
});
}
}
},
render: function render() {
var _classString,
_this4 = this;
var h = arguments[0];
var prefixCls = this.prefixCls,
direction = this.direction,
labelPlacement = this.labelPlacement,
iconPrefix = this.iconPrefix,
status = this.status,
size = this.size,
current = this.current,
$scopedSlots = this.$scopedSlots,
initial = this.initial,
icons = this.icons;
var progressDot = this.progressDot;
if (progressDot === undefined) {
progressDot = $scopedSlots.progressDot;
}
var lastStepOffsetWidth = this.lastStepOffsetWidth,
flexSupported = this.flexSupported;
var filteredChildren = filterEmpty(this.$slots['default']);
var lastIndex = filteredChildren.length - 1;
var adjustedlabelPlacement = progressDot ? 'vertical' : labelPlacement;
var classString = (_classString = {}, _defineProperty(_classString, prefixCls, true), _defineProperty(_classString, prefixCls + '-' + direction, true), _defineProperty(_classString, prefixCls + '-' + size, size), _defineProperty(_classString, prefixCls + '-label-' + adjustedlabelPlacement, direction === 'horizontal'), _defineProperty(_classString, prefixCls + '-dot', !!progressDot), _defineProperty(_classString, prefixCls + '-flex-not-supported', !flexSupported), _classString);
var stepsProps = {
'class': classString,
ref: 'vcStepsRef',
on: this.$listeners
};
return h(
'div',
stepsProps,
[filteredChildren.map(function (child, index) {
var childProps = getPropsData(child);
var stepNumber = initial + index;
var stepProps = {
props: _extends({
stepNumber: '' + (stepNumber + 1),
prefixCls: prefixCls,
iconPrefix: iconPrefix,
progressDot: _this4.progressDot,
icons: icons
}, childProps),
on: getEvents(child),
scopedSlots: $scopedSlots
};
if (!flexSupported && direction !== 'vertical' && index !== lastIndex) {
stepProps.props.itemWidth = 100 / lastIndex + '%';
stepProps.props.adjustMarginRight = -Math.round(lastStepOffsetWidth / lastIndex + 1) + 'px';
}
// fix tail color
if (status === 'error' && index === current - 1) {
stepProps['class'] = prefixCls + '-next-error';
}
if (!childProps.status) {
if (stepNumber === current) {
stepProps.props.status = status;
} else if (stepNumber < current) {
stepProps.props.status = 'finish';
} else {
stepProps.props.status = 'wait';
}
}
return cloneElement(child, stepProps);
})]
);
}
};