UNPKG

tdesign-react

Version:
125 lines (121 loc) 5.57 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { _ as _objectWithoutProperties } from '../_chunks/dep-6b660ef0.js'; import { _ as _defineProperty } from '../_chunks/dep-cb0a3966.js'; import classNames from 'classnames'; import React, { useMemo } from 'react'; import { isObject } from 'lodash-es'; import { Tabs } from '../tabs/index.js'; import useConfig from '../hooks/useConfig.js'; import useMenuContext from './hooks/useMenuContext.js'; import { MenuContext } from './MenuContext.js'; import checkSubMenuActive from './_util/checkSubMenuActive.js'; import '../_chunks/dep-eca3a3de.js'; import '../tabs/Tabs.js'; import '../_chunks/dep-48805ab8.js'; import '../_chunks/dep-026a4c6b.js'; import '../_util/forwardRefWithStatics.js'; import 'hoist-non-react-statics'; import '../tabs/TabNav.js'; import 'tdesign-icons-react'; import '../_util/noop.js'; import '../tabs/useTabClass.js'; import '../config-provider/ConfigContext.js'; import '../locale/zh_CN.js'; import '../_chunks/dep-e29214cb.js'; import 'dayjs'; import '../_chunks/dep-3c9ab31a.js'; import '../tabs/TabNavItem.js'; import '../hooks/useRipple.js'; import '../_chunks/dep-c48e2ca1.js'; import '../hooks/useAnimation.js'; import '../_chunks/dep-3a09424a.js'; import '../hooks/useDomRefCallback.js'; import '../hooks/useGlobalIcon.js'; import '../tabs/TabBar.js'; import '../hooks/useMutationObserver.js'; import '../hooks/useLatest.js'; import '../hooks/useResizeObserver.js'; import '../hooks/useLayoutEffect.js'; import '../_util/parseTNode.js'; import '../_chunks/dep-f53c91cd.js'; import '../_chunks/dep-b908e1fe.js'; import '../tabs/TabPanel.js'; import '../tabs/defaultProps.js'; import '../hooks/useDefaultProps.js'; import '../hooks/useDragSorter.js'; import '../hooks/useEventCallback.js'; import '../hooks/useControlled.js'; import '../tabs/style/index.js'; import '../tabs/type.js'; import './_util/getMenuTree.js'; import '../_chunks/dep-87d110df.js'; import '../_chunks/dep-83726008.js'; import './_util/checkMenuType.js'; import './_util/type.js'; import './_util/checkSubMenuChildrenActive.js'; var _excluded = ["children"]; 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 TabPanel = Tabs.TabPanel; var HeadMenu = function HeadMenu(props) { var children = props.children, className = props.className, _props$theme = props.theme, theme = _props$theme === void 0 ? "light" : _props$theme, style = props.style, logo = props.logo, operations = props.operations; var _useConfig = useConfig(), classPrefix = _useConfig.classPrefix; var _useMenuContext = useMenuContext(_objectSpread(_objectSpread({}, props), {}, { children: children, mode: "title" })), value = _useMenuContext.value; var childList = useMemo(function () { if (value.expandType === "popup") return null; var activeMenu = checkSubMenuActive(children, value.active); if (!activeMenu) return null; var child = activeMenu.props.children; if (Array.isArray(child)) return child; if (isObject(child)) return [child]; return activeMenu.props.children; }, [children, value.expandType, value.active]); var currentChildListValues = (childList === null || childList === void 0 ? void 0 : childList.length) > 0 ? childList.map(function (item) { return item.props.value; }) : []; return /* @__PURE__ */React.createElement(MenuContext.Provider, { value: value }, /* @__PURE__ */React.createElement("div", { className: classNames("".concat(classPrefix, "-head-menu"), "".concat(classPrefix, "-menu--").concat(theme), className), style: _objectSpread({}, style) }, /* @__PURE__ */React.createElement("div", { className: "".concat(classPrefix, "-head-menu__inner") }, logo && /* @__PURE__ */React.createElement("div", { className: "".concat(classPrefix, "-menu__logo") }, logo), /* @__PURE__ */React.createElement("ul", { className: "".concat(classPrefix, "-menu") }, children), operations && /* @__PURE__ */React.createElement("div", { className: "".concat(classPrefix, "-menu__operations") }, operations)), (childList === null || childList === void 0 ? void 0 : childList.length) > 0 && /* @__PURE__ */React.createElement("ul", { className: "".concat(classPrefix, "-head-menu__submenu ").concat(classPrefix, "-submenu") }, /* @__PURE__ */React.createElement(Tabs, { value: currentChildListValues.includes(value.active) ? value.active : currentChildListValues[0], onChange: value.onChange }, childList.map(function (_ref) { var _ref$props = _ref.props, children2 = _ref$props.children, restProps = _objectWithoutProperties(_ref$props, _excluded); return /* @__PURE__ */React.createElement(TabPanel, _objectSpread(_objectSpread({ key: props.value }, restProps), {}, { label: children2 })); }))))); }; export { HeadMenu as default }; //# sourceMappingURL=HeadMenu.js.map