antd-mobile
Version:
基于 React 的移动设计规范实现
76 lines (67 loc) • 2.61 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
/* tslint:disable:jsx-no-multiline-js */
import React from 'react';
import RNStepsItem from './StepsItem';
import { View } from 'react-native';
import StepStyle from './style';
var Steps = function (_React$Component) {
_inherits(Steps, _React$Component);
function Steps(props) {
_classCallCheck(this, Steps);
var _this = _possibleConstructorReturn(this, (Steps.__proto__ || Object.getPrototypeOf(Steps)).call(this, props));
_this.onLayout = function (e) {
_this.setState({
wrapWidth: e.nativeEvent.layout.width
});
};
_this.state = {
wrapWidth: 0
};
return _this;
}
_createClass(Steps, [{
key: 'render',
value: function render() {
var _this2 = this;
var children = this.props.children;
var wrapView = this.props.direction === 'vertical' ? '' : 'warp_row';
var styles = this.props.styles;
return React.createElement(
View,
{ style: styles[wrapView], onLayout: function onLayout(e) {
_this2.onLayout(e);
} },
React.Children.map(children, function (ele, idx) {
var errorTail = -1;
if (idx < children.length - 1) {
var status = children[idx + 1].props.status;
if (status === 'error') {
errorTail = idx;
}
}
return React.cloneElement(ele, {
index: idx,
last: idx === children.length - 1,
direction: _this2.props.direction,
current: _this2.props.current,
width: 1 / (children.length - 1) * _this2.state.wrapWidth,
size: _this2.props.size,
finishIcon: _this2.props.finishIcon,
errorTail: errorTail,
styles: styles
});
})
);
}
}]);
return Steps;
}(React.Component);
export default Steps;
Steps.defaultProps = {
direction: '',
styles: StepStyle
};
Steps.Step = RNStepsItem;