acud
Version:
acg react 组件库
171 lines • 7.94 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)); }
/* eslint-disable @typescript-eslint/no-unused-vars */
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 from 'react';
import classNames from 'classnames';
function isString(str) {
return typeof str === 'string';
}
var Step = /*#__PURE__*/function (_React$Component) {
function Step() {
var _this;
_classCallCheck(this, Step);
_this = _callSuper(this, Step, arguments);
_this.onClick = function () {
var _this$props = _this.props,
onClick = _this$props.onClick,
onStepClick = _this$props.onStepClick,
stepIndex = _this$props.stepIndex;
if (onClick) {
onClick.apply(void 0, arguments);
}
onStepClick(stepIndex);
};
return _this;
}
_inherits(Step, _React$Component);
return _createClass(Step, [{
key: "renderIconNode",
value: function renderIconNode() {
var _this$props2 = this.props,
prefixCls = _this$props2.prefixCls,
progressDot = _this$props2.progressDot,
stepIcon = _this$props2.stepIcon,
stepNumber = _this$props2.stepNumber,
status = _this$props2.status,
title = _this$props2.title,
description = _this$props2.description,
icon = _this$props2.icon,
iconPrefix = _this$props2.iconPrefix,
icons = _this$props2.icons;
var iconNode;
var iconClassName = classNames("".concat(prefixCls, "-icon"), "".concat(iconPrefix, "icon"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(iconPrefix, "icon-").concat(icon), icon && isString(icon)), "".concat(iconPrefix, "icon-check"), !icon && status === 'finish' && (icons && !icons.finish || !icons)), "".concat(iconPrefix, "icon-cross"), !icon && status === 'error' && (icons && !icons.error || !icons)));
var iconDot = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon-dot")
});
// `progressDot` enjoy the highest priority
if (progressDot) {
if (typeof progressDot === 'function') {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, progressDot(iconDot, {
index: stepNumber - 1,
status: status,
title: title,
description: description
}));
} else {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, iconDot);
}
} else if (icon && !isString(icon)) {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon self")
}, icon);
} else if (icons && icons.finish && status === 'finish') {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, icons.finish);
// iconNode = <span className={`${prefixCls}-icon self`}>{stepNumber}</span>;
} else if (icons && status === 'finish') {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, stepNumber);
} else if (icons && icons.error && status === 'error') {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, icons.error);
} else if (icon || status === 'finish' || status === 'error') {
iconNode = /*#__PURE__*/React.createElement("span", {
className: iconClassName
});
} else {
iconNode = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-icon")
}, stepNumber);
}
if (stepIcon) {
iconNode = stepIcon({
index: stepNumber - 1,
status: status,
title: title,
description: description,
node: iconNode
});
}
return iconNode;
}
}, {
key: "render",
value: function render() {
var _a = this.props,
className = _a.className,
prefixCls = _a.prefixCls,
style = _a.style,
active = _a.active,
_a$status = _a.status,
status = _a$status === void 0 ? 'wait' : _a$status,
icon = _a.icon,
disabled = _a.disabled,
description = _a.description,
title = _a.title,
subTitle = _a.subTitle,
tailContent = _a.tailContent,
onStepClick = _a.onStepClick,
onClick = _a.onClick,
stepNumber = _a.stepNumber,
stepIndex = _a.stepIndex,
iconPrefix = _a.iconPrefix,
wrapperStyle = _a.wrapperStyle,
progressDot = _a.progressDot,
stepIcon = _a.stepIcon,
restProps = __rest(_a, ["className", "prefixCls", "style", "active", "status", "icon", "disabled", "description", "title", "subTitle", "tailContent", "onStepClick", "onClick", "stepNumber", "stepIndex", "iconPrefix", "wrapperStyle", "progressDot", "stepIcon"]);
var classString = classNames("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(status), className, _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-item-custom"), icon), "".concat(prefixCls, "-item-active"), active), "".concat(prefixCls, "-item-disabled"), disabled === true));
var stepItemStyle = _extends({}, style);
var accessibilityProps = {};
if (onStepClick && !disabled) {
accessibilityProps.role = 'button';
accessibilityProps.tabIndex = 0;
accessibilityProps.onClick = this.onClick;
}
return /*#__PURE__*/React.createElement("div", _extends({}, restProps, {
className: classString,
style: stepItemStyle
}), /*#__PURE__*/React.createElement("div", _extends({
onClick: onClick
}, accessibilityProps, {
className: "".concat(prefixCls, "-item-container")
}), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-tail")
}, tailContent), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-icon")
}, this.renderIconNode()), /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-content")
}, /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-title")
}, title, subTitle && /*#__PURE__*/React.createElement("div", {
title: typeof subTitle === 'string' ? subTitle : undefined,
className: "".concat(prefixCls, "-item-subtitle")
}, subTitle)), description && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-item-description")
}, description))));
}
}]);
}(React.Component);
export { Step as default };