1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | var _extends2 = require('babel-runtime/helpers/extends');
|
6 |
|
7 | var _extends3 = _interopRequireDefault(_extends2);
|
8 |
|
9 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
10 |
|
11 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
12 |
|
13 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
14 |
|
15 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
16 |
|
17 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
18 |
|
19 | var _inherits3 = _interopRequireDefault(_inherits2);
|
20 |
|
21 | var _class, _temp;
|
22 |
|
23 | var _reactDom = require('react-dom');
|
24 |
|
25 | var _reactDom2 = _interopRequireDefault(_reactDom);
|
26 |
|
27 | var _propTypes = require('prop-types');
|
28 |
|
29 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
30 |
|
31 | var _classnames = require('classnames');
|
32 |
|
33 | var _classnames2 = _interopRequireDefault(_classnames);
|
34 |
|
35 | var _react = require('react');
|
36 |
|
37 | var _react2 = _interopRequireDefault(_react);
|
38 |
|
39 | var _reactLifecyclesCompat = require('react-lifecycles-compat');
|
40 |
|
41 | var _configProvider = require('../../config-provider');
|
42 |
|
43 | var _configProvider2 = _interopRequireDefault(_configProvider);
|
44 |
|
45 | var _util = require('../../util');
|
46 |
|
47 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48 |
|
49 | var getHeight = function getHeight(el) {
|
50 | return _util.dom.getStyle(el, 'height');
|
51 | };
|
52 | var setHeight = function setHeight(el, height) {
|
53 | return _util.dom.setStyle(el, 'height', height);
|
54 | };
|
55 |
|
56 |
|
57 | var Step = (_temp = _class = function (_Component) {
|
58 | (0, _inherits3.default)(Step, _Component);
|
59 |
|
60 | Step.getDerivedStateFromProps = function getDerivedStateFromProps(newProps) {
|
61 | if ('current' in newProps) {
|
62 | return {
|
63 | current: newProps.current
|
64 | };
|
65 | }
|
66 | };
|
67 |
|
68 | function Step(props, context) {
|
69 | (0, _classCallCheck3.default)(this, Step);
|
70 |
|
71 | var _this = (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props, context));
|
72 |
|
73 | _this._stepRefHandler = function (ref) {
|
74 | _this.step = ref;
|
75 | };
|
76 |
|
77 | _this.state = {
|
78 | parentWidth: 'auto',
|
79 | parentHeight: 'auto',
|
80 | currentfocus: 0
|
81 | };
|
82 | _this.resize = _this.resize.bind(_this);
|
83 | return _this;
|
84 | }
|
85 |
|
86 | Step.prototype.componentDidMount = function componentDidMount() {
|
87 |
|
88 | if (!_util.support.flex) {
|
89 | this.resize();
|
90 | _util.events.on(window, 'resize', this.resize);
|
91 | }
|
92 | this.adjustHeight();
|
93 | };
|
94 |
|
95 | Step.prototype.componentDidUpdate = function componentDidUpdate() {
|
96 | this.adjustHeight();
|
97 | };
|
98 |
|
99 | Step.prototype.componentWillUnmount = function componentWillUnmount() {
|
100 |
|
101 | if (!_util.support.flex) {
|
102 | _util.events.off(window, 'resize', this.resize);
|
103 | }
|
104 | };
|
105 |
|
106 | Step.prototype.adjustHeight = function adjustHeight() {
|
107 | var _props = this.props,
|
108 | shape = _props.shape,
|
109 | direction = _props.direction,
|
110 | prefix = _props.prefix,
|
111 | labelPlacement = _props.labelPlacement;
|
112 |
|
113 | var step = _reactDom2.default.findDOMNode(this.step);
|
114 | if (shape !== 'arrow' && (direction === 'horizontal' || direction === 'hoz') && (labelPlacement === 'vertical' || labelPlacement === 'ver')) {
|
115 | var height = Array.prototype.slice.call(step.getElementsByClassName(prefix + 'step-item')).reduce(function (ret, re) {
|
116 | var itemHeight = getHeight(re.getElementsByClassName(prefix + 'step-item-container')[0]) + getHeight(re.getElementsByClassName(prefix + 'step-item-body')[0]);
|
117 | return Math.max(itemHeight, ret);
|
118 | }, 0);
|
119 | setHeight(step, height);
|
120 | } else {
|
121 | setHeight(step, '');
|
122 | }
|
123 | };
|
124 |
|
125 | Step.prototype.resize = function resize() {
|
126 | if (this.step) {
|
127 | this.setState({
|
128 | parentWidth: this.step.offsetWidth || 0,
|
129 | parentHeight: this.step.offsetHeight || 0
|
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 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | Step.prototype._getValidChildren = function _getValidChildren(children) {
|
169 | var result = [];
|
170 | _react2.default.Children.forEach(children, function (child) {
|
171 | if (_react2.default.isValidElement(child)) {
|
172 | result.push(child);
|
173 | }
|
174 | });
|
175 | return result;
|
176 | };
|
177 |
|
178 | Step.prototype.render = function render() {
|
179 | var _this2 = this,
|
180 | _classNames;
|
181 |
|
182 |
|
183 | var _props2 = this.props,
|
184 | className = _props2.className,
|
185 | current = _props2.current,
|
186 | labelPlacement = _props2.labelPlacement,
|
187 | shape = _props2.shape,
|
188 | readOnly = _props2.readOnly,
|
189 | animation = _props2.animation,
|
190 | itemRender = _props2.itemRender,
|
191 | rtl = _props2.rtl,
|
192 | stretch = _props2.stretch;
|
193 |
|
194 | var others = _util.obj.pickOthers(Step.propTypes, this.props);
|
195 | var _props3 = this.props,
|
196 | prefix = _props3.prefix,
|
197 | direction = _props3.direction,
|
198 | children = _props3.children;
|
199 |
|
200 | prefix = this.context.prefix || prefix;
|
201 | var _state = this.state,
|
202 | parentWidth = _state.parentWidth,
|
203 | parentHeight = _state.parentHeight;
|
204 |
|
205 |
|
206 |
|
207 | direction = shape === 'arrow' ? 'hoz' : direction;
|
208 |
|
209 |
|
210 | children = this._getValidChildren(children);
|
211 |
|
212 |
|
213 | var cloneChildren = _react.Children.map(children, function (child, index) {
|
214 | var status = index < current ? 'finish' : index === current ? 'process' : 'wait';
|
215 |
|
216 | return _react2.default.cloneElement(child, {
|
217 | prefix: prefix,
|
218 | key: index,
|
219 | index: index,
|
220 | total: children.length,
|
221 | status: child.props.status || status,
|
222 | shape: shape,
|
223 | direction: direction,
|
224 | labelPlacement: labelPlacement,
|
225 | parentWidth: parentWidth,
|
226 | parentHeight: parentHeight,
|
227 | readOnly: readOnly,
|
228 | animation: animation,
|
229 | tabIndex: 0,
|
230 |
|
231 | 'aria-current': status === 'process' ? 'step' : null,
|
232 | itemRender: child.props.itemRender ? child.props.itemRender : itemRender,
|
233 | onResize: function onResize() {
|
234 | _this2.step && _this2.adjustHeight();
|
235 | },
|
236 | stretch: stretch
|
237 | });
|
238 | });
|
239 |
|
240 | var _direction = direction === 'ver' || direction === 'vertical' ? 'vertical' : 'horizontal';
|
241 | var _labelPlacement = labelPlacement === 'ver' || labelPlacement === 'vertical' ? 'vertical' : 'horizontal';
|
242 | var stepCls = (0, _classnames2.default)((_classNames = {}, _classNames[prefix + 'step'] = true, _classNames[prefix + 'step-' + shape] = shape, _classNames[prefix + 'step-' + _direction] = _direction, _classNames[prefix + 'step-label-' + _labelPlacement] = _labelPlacement, _classNames[className] = className, _classNames));
|
243 |
|
244 | if (rtl) {
|
245 | others.dir = 'rtl';
|
246 | }
|
247 |
|
248 |
|
249 | return _react2.default.createElement(
|
250 | 'ol',
|
251 | (0, _extends3.default)({}, others, { className: stepCls, ref: this._stepRefHandler }),
|
252 | cloneChildren
|
253 | );
|
254 | };
|
255 |
|
256 | return Step;
|
257 | }(_react.Component), _class.propTypes = (0, _extends3.default)({}, _configProvider2.default.propTypes, {
|
258 | prefix: _propTypes2.default.string,
|
259 | rtl: _propTypes2.default.bool,
|
260 | |
261 |
|
262 |
|
263 | current: _propTypes2.default.number,
|
264 | |
265 |
|
266 |
|
267 | direction: _propTypes2.default.oneOf(['hoz', 'ver']),
|
268 | |
269 |
|
270 |
|
271 | labelPlacement: _propTypes2.default.oneOf(['hoz', 'ver']),
|
272 | |
273 |
|
274 |
|
275 | shape: _propTypes2.default.oneOf(['circle', 'arrow', 'dot']),
|
276 | |
277 |
|
278 |
|
279 | readOnly: _propTypes2.default.bool,
|
280 | |
281 |
|
282 |
|
283 | animation: _propTypes2.default.bool,
|
284 | |
285 |
|
286 |
|
287 | className: _propTypes2.default.string,
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | itemRender: _propTypes2.default.func,
|
295 | |
296 |
|
297 |
|
298 | stretch: _propTypes2.default.bool
|
299 | }), _class.defaultProps = {
|
300 | prefix: 'next-',
|
301 | current: 0,
|
302 | direction: 'hoz',
|
303 | labelPlacement: 'ver',
|
304 | shape: 'circle',
|
305 | animation: true,
|
306 | itemRender: null,
|
307 | stretch: false
|
308 | }, _class.contextTypes = {
|
309 | prefix: _propTypes2.default.string
|
310 | }, _temp);
|
311 | Step.displayName = 'Step';
|
312 | exports.default = (0, _reactLifecyclesCompat.polyfill)(Step);
|
313 | module.exports = exports['default']; |
\ | No newline at end of file |