tdesign-react
Version:
TDesign Component for React
110 lines (106 loc) • 4.78 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js';
import { _ as _toConsumableArray } from '../_chunks/dep-87d110df.js';
import { _ as _slicedToArray } from '../_chunks/dep-48805ab8.js';
import { _ as _objectWithoutProperties } from '../_chunks/dep-6b660ef0.js';
import React, { useRef, useEffect } from 'react';
import classNames from 'classnames';
import useConfig from '../hooks/useConfig.js';
import forwardRefWithStatics from '../_util/forwardRefWithStatics.js';
import useControlled from '../hooks/useControlled.js';
import CollapsePanel from './CollapsePanel.js';
import CollapseContext from './CollapseContext.js';
import { collapseDefaultProps } from './defaultProps.js';
import useDefaultProps from '../hooks/useDefaultProps.js';
import '../_chunks/dep-eca3a3de.js';
import '../_chunks/dep-026a4c6b.js';
import '../config-provider/ConfigContext.js';
import 'lodash-es';
import '../_chunks/dep-f97636ce.js';
import '../_chunks/dep-9dbbf468.js';
import 'dayjs';
import 'hoist-non-react-statics';
import '../_util/noop.js';
import 'react-transition-group';
import '../common/FakeArrow.js';
var _excluded = ["defaultExpandAll", "disabled", "expandIconPlacement", "expandOnRowClick", "expandIcon"];
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 Collapse = forwardRefWithStatics(function (originalProps, ref) {
var props = useDefaultProps(originalProps, collapseDefaultProps);
var _useConfig = useConfig(),
classPrefix = _useConfig.classPrefix;
var componentName = "".concat(classPrefix, "-collapse");
var borderlessClass = "".concat(classPrefix, "--border-less");
var defaultExpandAll = props.defaultExpandAll,
disabled = props.disabled,
expandIconPlacement = props.expandIconPlacement,
expandOnRowClick = props.expandOnRowClick,
expandIcon = props.expandIcon,
rest = _objectWithoutProperties(props, _excluded);
var children = rest.children,
className = rest.className,
style = rest.style,
expandMutex = rest.expandMutex,
borderless = rest.borderless,
onChange = rest.onChange;
var _useControlled = useControlled(props, "value", onChange),
_useControlled2 = _slicedToArray(_useControlled, 2),
collapseValue = _useControlled2[0],
setCollapseValue = _useControlled2[1];
var collapseValues = useRef(collapseValue);
useEffect(function () {
collapseValues.current = collapseValue;
}, [collapseValue]);
var updateCollapseValue = function updateCollapseValue(value, context) {
var newValue = [].concat(collapseValues.current || []);
var index = newValue.indexOf(value);
if (index >= 0) {
newValue.splice(index, 1);
} else if (expandMutex) {
newValue = [value];
} else {
newValue.push(value);
}
collapseValues.current = _toConsumableArray(newValue);
setCollapseValue(newValue, context);
};
var classes = [componentName, _defineProperty({}, borderlessClass, !!borderless), className];
var childrenList = React.Children.toArray(children).filter(function (child) {
return child.type.displayName === CollapsePanel.displayName;
});
var collapsePanelList = function collapsePanelList() {
return childrenList.map(function (child, index) {
var key = child.key || String(index);
var childProps = _objectSpread({
key: key,
index: index + 1
}, child.props);
return /*#__PURE__*/React.cloneElement(child, childProps);
});
};
return /* @__PURE__ */React.createElement(CollapseContext.Provider, {
value: {
defaultExpandAll: defaultExpandAll,
disabled: disabled,
expandIconPlacement: expandIconPlacement,
expandOnRowClick: expandOnRowClick,
expandIcon: expandIcon,
updateCollapseValue: updateCollapseValue,
collapseValue: collapseValue
}
}, /* @__PURE__ */React.createElement("div", {
className: classNames(classes),
style: style,
ref: ref
}, collapsePanelList()));
}, {
Panel: CollapsePanel
});
Collapse.displayName = "Collapse";
export { Collapse as default };
//# sourceMappingURL=Collapse.js.map