acud
Version:
acg react 组件库
113 lines • 4.83 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _isNativeReflectConstruct from "@babel/runtime/helpers/esm/isNativeReflectConstruct";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import React, { cloneElement } from 'react';
import toArray from "rc-util/es/Children/toArray";
import classNames from 'classnames';
import Step from './step';
var Steps = /*#__PURE__*/function (_React$Component) {
function Steps() {
var _this;
_classCallCheck(this, Steps);
_this = _callSuper(this, Steps, arguments);
_this.onStepClick = function (next) {
var _this$props = _this.props,
onChange = _this$props.onChange,
current = _this$props.current;
if (onChange && current !== next) {
onChange(next);
}
};
return _this;
}
_inherits(Steps, _React$Component);
return _createClass(Steps, [{
key: "render",
value: function render() {
var _this2 = this;
var _a = this.props,
prefixCls = _a.prefixCls,
_a$style = _a.style,
style = _a$style === void 0 ? {} : _a$style,
className = _a.className,
children = _a.children,
direction = _a.direction,
type = _a.type,
labelPlacement = _a.labelPlacement,
iconPrefix = _a.iconPrefix,
status = _a.status,
size = _a.size,
current = _a.current,
progressDot = _a.progressDot,
stepIcon = _a.stepIcon,
initial = _a.initial,
icons = _a.icons,
onChange = _a.onChange,
restProps = __rest(_a, ["prefixCls", "style", "className", "children", "direction", "type", "labelPlacement", "iconPrefix", "status", "size", "current", "progressDot", "stepIcon", "initial", "icons", "onChange"]);
var isNav = type === 'navigation';
var adjustedLabelPlacement = progressDot ? 'vertical' : labelPlacement;
var classString = classNames(prefixCls, "".concat(prefixCls, "-").concat(direction), className, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-").concat(size), size), "".concat(prefixCls, "-label-").concat(adjustedLabelPlacement), direction === 'horizontal'), "".concat(prefixCls, "-dot"), !!progressDot), "".concat(prefixCls, "-navigation"), isNav));
return /*#__PURE__*/React.createElement("div", _extends({
className: classString,
style: style
}, restProps), toArray(children).map(function (child, index) {
var stepNumber = initial + index;
var childProps = _extends({
stepNumber: "".concat(stepNumber + 1),
stepIndex: stepNumber,
key: stepNumber,
prefixCls: prefixCls,
iconPrefix: iconPrefix,
wrapperStyle: style,
progressDot: progressDot,
stepIcon: stepIcon,
icons: icons,
onStepClick: onChange && _this2.onStepClick
}, child.props);
// fix tail color
if (status === 'error' && index === current - 1) {
childProps.className = "".concat(prefixCls, "-next-error");
}
if (!child.props.status) {
if (stepNumber === current) {
childProps.status = status;
} else if (stepNumber < current) {
childProps.status = 'finish';
} else {
childProps.status = 'wait';
}
}
childProps.active = stepNumber === current;
return /*#__PURE__*/cloneElement(child, childProps);
}));
}
}]);
}(React.Component);
export { Steps as default };
Steps.Step = Step;
Steps.defaultProps = {
type: 'default',
prefixCls: 'rc-steps',
iconPrefix: 'rc',
direction: 'horizontal',
labelPlacement: 'horizontal',
initial: 0,
current: 0,
status: 'process',
size: '',
progressDot: false
};