tdesign-react
Version:
TDesign Component for React
146 lines (142 loc) • 6 kB
JavaScript
/**
* tdesign v1.13.2
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-8618a2f1.js';
import { _ as _slicedToArray } from '../_chunks/dep-118954e6.js';
import React, { useMemo, useCallback } from 'react';
import classNames from 'classnames';
import useConfig from '../hooks/useConfig.js';
import useControlled from '../hooks/useControlled.js';
import forwardRefWithStatics from '../_util/forwardRefWithStatics.js';
import StepItem from './StepItem.js';
import StepsContext from './StepsContext.js';
import { stepsDefaultProps } from './defaultProps.js';
import useDefaultProps from '../hooks/useDefaultProps.js';
import '../_chunks/dep-c37cc2fd.js';
import '../_chunks/dep-61f5e3d1.js';
import '../config-provider/ConfigContext.js';
import 'lodash-es';
import '../locale/zh_CN.js';
import '../_chunks/dep-ab140eb0.js';
import 'dayjs';
import '../_chunks/dep-95bd7102.js';
import '../_util/noop.js';
import 'hoist-non-react-statics';
import 'tdesign-icons-react';
import '../hooks/useGlobalIcon.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Steps = forwardRefWithStatics(function (originalProps, ref) {
var props = useDefaultProps(originalProps, stepsDefaultProps);
var style = props.style,
readonly = props.readonly,
layout = props.layout,
theme = props.theme,
sequence = props.sequence,
separator = props.separator,
children = props.children,
options = props.options;
var _useConfig = useConfig(),
classPrefix = _useConfig.classPrefix;
var _useControlled = useControlled(props, "current", props.onChange),
_useControlled2 = _slicedToArray(_useControlled, 2),
current = _useControlled2[0],
onChange = _useControlled2[1];
var indexMap = useMemo(function () {
var map = {};
if (options) {
options.forEach(function (item, index) {
if (item.value !== void 0) {
map[item.value] = index;
}
});
} else {
React.Children.forEach(children, function (child, index) {
if (! /*#__PURE__*/React.isValidElement(child)) {
return;
}
if (child.props.value !== void 0) {
map[child.props.value] = index;
}
});
}
return map;
}, [options, children]);
var handleStatus = useCallback(function (item, index) {
var _item$value;
if (current === "FINISH") {
return "finish";
}
if (item.status && item.status !== "default") {
return item.status;
}
if (item.value === void 0) {
if (sequence === "positive" && typeof current === "number" && index < current) {
return "finish";
}
if (sequence === "reverse" && typeof current === "number" && index > current) {
return "finish";
}
}
if (item.value !== void 0) {
var matchIndex = indexMap[current];
if (matchIndex === void 0) {
console.warn("TDesign Steps Warn: The current `value` is not exist.");
return "default";
}
if (sequence === "positive" && index < matchIndex) {
return "finish";
}
if (sequence === "reverse" && index > matchIndex) {
return "finish";
}
}
var key = (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : index;
if (key === current) {
return "process";
}
return "default";
}, [current, sequence, indexMap]);
var stepItemList = useMemo(function () {
if (options) {
var optionsDisplayList = sequence === "reverse" ? options.reverse() : options;
return options.map(function (item, index) {
var stepIndex = sequence === "reverse" ? optionsDisplayList.length - index - 1 : index;
return /* @__PURE__ */React.createElement(StepItem, _objectSpread(_objectSpread({
key: index
}, item), {}, {
index: stepIndex,
status: handleStatus(item, index)
}));
});
}
var childrenList = React.Children.toArray(children);
var childrenDisplayList = sequence === "reverse" ? childrenList.reverse() : childrenList;
return childrenList.map(function (child, index) {
var stepIndex = sequence === "reverse" ? childrenDisplayList.length - index - 1 : index;
return /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, {
index: stepIndex,
status: handleStatus(child.props, index)
}));
});
}, [options, children, sequence, handleStatus]);
return /* @__PURE__ */React.createElement(StepsContext.Provider, {
value: {
current: current,
theme: theme,
readonly: readonly,
onChange: onChange
}
}, /* @__PURE__ */React.createElement("div", {
ref: ref,
style: style,
className: classNames(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(classPrefix, "-steps"), true), "".concat(classPrefix, "-steps--").concat(theme, "-anchor"), theme), "".concat(classPrefix, "-steps--").concat(layout), layout), "".concat(classPrefix, "-steps--").concat(sequence), sequence), "".concat(classPrefix, "-steps--").concat(separator, "-separator"), separator), props.className, !!props.className))
}, stepItemList));
}, {
StepItem: StepItem
});
Steps.displayName = "Steps";
export { Steps as default };
//# sourceMappingURL=Steps.js.map