tdesign-react
Version:
TDesign Component for React
88 lines (84 loc) • 4.26 kB
JavaScript
/**
* tdesign v1.15.1
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../../_chunks/dep-cb0a3966.js';
import React, { useMemo } from 'react';
import DropdownMenu from '../DropdownMenu.js';
import DropdownItem from '../DropdownItem.js';
import '../../_chunks/dep-eca3a3de.js';
import '../../_chunks/dep-48805ab8.js';
import '../../_chunks/dep-026a4c6b.js';
import 'classnames';
import 'lodash-es';
import 'tdesign-icons-react';
import '../../hooks/useConfig.js';
import '../../config-provider/ConfigContext.js';
import '../../_chunks/dep-f97636ce.js';
import '../../_chunks/dep-9dbbf468.js';
import 'dayjs';
import '../../divider/index.js';
import '../../divider/Divider.js';
import '../../_chunks/dep-6b660ef0.js';
import '../../divider/defaultProps.js';
import '../../hooks/useDefaultProps.js';
import '../../hooks/useGlobalIcon.js';
import '../../hooks/useDomRefCallback.js';
import '../../hooks/useRipple.js';
import '../../_chunks/dep-c48e2ca1.js';
import '../../hooks/useAnimation.js';
import '../../_chunks/dep-3a09424a.js';
import '../defaultProps.js';
import '../../_util/helper.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 _getOptionsFromChildren = function getOptionsFromChildren(children) {
if (!children) return [];
if (children.type === DropdownMenu) {
var groupChildren = children.props.children;
if (Array.isArray(groupChildren)) {
return _getOptionsFromChildren(groupChildren);
}
}
return React.Children.toArray(children).map(function (item) {
var _item$props, _item$props2;
var groupChildren = (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.children;
var contextRes = (_item$props2 = item.props) === null || _item$props2 === void 0 ? void 0 : _item$props2.content;
if (Array.isArray(groupChildren)) {
var _groupChildren$filter, _groupChildren$filter2;
var contentCtx = groupChildren === null || groupChildren === void 0 || (_groupChildren$filter = groupChildren.filter) === null || _groupChildren$filter === void 0 ? void 0 : _groupChildren$filter.call(groupChildren, function (v) {
return ![DropdownItem, DropdownMenu].includes(v.type);
});
var childrenCtx = groupChildren === null || groupChildren === void 0 || (_groupChildren$filter2 = groupChildren.filter) === null || _groupChildren$filter2 === void 0 ? void 0 : _groupChildren$filter2.call(groupChildren, function (v) {
return [DropdownItem, DropdownMenu].includes(v.type);
});
return _objectSpread(_objectSpread({}, item.props), {}, {
content: contentCtx || groupChildren,
children: childrenCtx.length > 0 ? _getOptionsFromChildren(groupChildren[1]) : null
});
}
return _objectSpread(_objectSpread({}, item.props), {}, {
content: groupChildren || contextRes,
children: null
});
}).filter(function (v) {
return !!v.content;
});
};
function useDropdownOptions(children, options) {
var dropdownOptions = useMemo(function () {
if (options && options.length > 0) return options;
var dropdownMenuChild;
React.Children.forEach(children, function (child) {
if (! /*#__PURE__*/React.isValidElement(child)) return;
if (child.type === DropdownMenu && child.props.children) {
dropdownMenuChild = child.props.children;
}
});
return _getOptionsFromChildren(dropdownMenuChild);
}, [options, children]);
return dropdownOptions;
}
export { useDropdownOptions as default, _getOptionsFromChildren as getOptionsFromChildren };
//# sourceMappingURL=useDropdownOptions.js.map