Steps.js
5.2 KB
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
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
var _react = _interopRequireWildcard(require("react"));
var _toArray = _interopRequireDefault(require("rc-util/lib/Children/toArray"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Step = _interopRequireDefault(require("./Step"));
/* eslint react/no-did-mount-set-state: 0, react/prop-types: 0 */
var Steps = /*#__PURE__*/function (_React$Component) {
(0, _inherits2.default)(Steps, _React$Component);
var _super = (0, _createSuper2.default)(Steps);
function Steps() {
var _this;
(0, _classCallCheck2.default)(this, Steps);
_this = _super.apply(this, 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;
}
(0, _createClass2.default)(Steps, [{
key: "render",
value: function render() {
var _classNames,
_this2 = this;
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
_this$props2$style = _this$props2.style,
style = _this$props2$style === void 0 ? {} : _this$props2$style,
className = _this$props2.className,
children = _this$props2.children,
direction = _this$props2.direction,
type = _this$props2.type,
labelPlacement = _this$props2.labelPlacement,
iconPrefix = _this$props2.iconPrefix,
status = _this$props2.status,
size = _this$props2.size,
current = _this$props2.current,
progressDot = _this$props2.progressDot,
stepIcon = _this$props2.stepIcon,
initial = _this$props2.initial,
icons = _this$props2.icons,
onChange = _this$props2.onChange,
restProps = (0, _objectWithoutProperties2.default)(_this$props2, ["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 = (0, _classnames.default)(prefixCls, "".concat(prefixCls, "-").concat(direction), className, (_classNames = {}, (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-").concat(size), size), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-label-").concat(adjustedLabelPlacement), direction === 'horizontal'), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-dot"), !!progressDot), (0, _defineProperty2.default)(_classNames, "".concat(prefixCls, "-navigation"), isNav), _classNames));
return _react.default.createElement("div", Object.assign({
className: classString,
style: style
}, restProps), (0, _toArray.default)(children).map(function (child, index) {
var stepNumber = initial + index;
var childProps = (0, _objectSpread2.default)({
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 (0, _react.cloneElement)(child, childProps);
}));
}
}]);
return Steps;
}(_react.default.Component);
exports.default = Steps;
Steps.Step = _Step.default;
Steps.defaultProps = {
type: 'default',
prefixCls: 'rc-steps',
iconPrefix: 'rc',
direction: 'horizontal',
labelPlacement: 'horizontal',
initial: 0,
current: 0,
status: 'process',
size: '',
progressDot: false
};