@jdcfe/yep-react
Version:
一套移动端的React组件库
96 lines (84 loc) • 3.95 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
import classNames from 'classnames';
var Steps = /*#__PURE__*/function (_React$Component) {
_inherits(Steps, _React$Component);
var _super = _createSuper(Steps);
function Steps(props) {
_classCallCheck(this, Steps);
return _super.call(this, props);
}
_createClass(Steps, [{
key: "renderStepIcon",
value: function renderStepIcon(key, stepNum) {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
icon = _this$props.icon;
if (icon && icon.length) {
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-num")
}, /*#__PURE__*/React.cloneElement(stepNum > key ? icon[0] : stepNum < key ? icon[1] : icon[2], {
className: 'Yep-steps-icon'
}));
} else {
return /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-num")
}, " ", key + 1);
}
}
}, {
key: "render",
value: function render() {
var _this = this;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
style = _this$props2.style,
stepNum = _this$props2.stepNum,
titles = _this$props2.titles,
desc = _this$props2.desc;
var wrapCls = classNames("".concat(prefixCls), className);
return /*#__PURE__*/React.createElement("div", {
className: wrapCls,
style: style
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-list")
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-line")
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-line-red"),
style: {
width: 100 / (titles.length * 2) * (stepNum === 1 ? 1 : stepNum === titles.length ? titles.length * 2 : stepNum * 2 - 1) + '%'
}
})), titles.map(function (item, key) {
return /*#__PURE__*/React.createElement("div", {
key: key,
style: {
width: 100 / titles.length + '%'
},
className: "".concat(prefixCls, "-item ").concat(stepNum > key ? 'current' : '')
}, _this.renderStepIcon(key, stepNum), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-text")
}, item), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-text fs24")
}, desc[key]));
})));
}
}]);
return Steps;
}(React.Component);
export { Steps as default };
Steps.defaultProps = {
prefixCls: 'Yep-steps',
style: {},
stepNum: 1,
titles: ['step1', 'step2', 'step3'],
desc: ['step1_text', 'step2_text', 'step3_text'],
icon: []
};