Debian Codegraph @

node/@patternfly/react-core/dist/js/components/Menu/MenuContent.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.MenuContent = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_1 = require("react");
7 const menu_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Menu/menu"));
8 const react_styles_1 = require("@patternfly/react-styles");
9 const MenuContext_1 = require("./MenuContext");
10 const c_menu__content_Height_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_menu__content_Height'));
11 const c_menu__content_MaxHeight_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/c_menu__content_MaxHeight'));
12 exports.MenuContent = (0, react_1.forwardRef)((props, ref) => {
13 const { getHeight, children, menuHeight, maxMenuHeight } = props, rest = tslib_1.__rest(props, ["getHeight", "children", "menuHeight", "maxMenuHeight"]);
14 const menuContentRef = (0, react_1.createRef)();
15 const refCallback = (el, menuId, onGetMenuHeight) => {
16 if (el) {
17 let clientHeight = el.clientHeight;
18 // if this menu is a submenu, we need to account for the root menu list's padding and root menu content's border.
19 let rootMenuList = null;
20 let parentEl = el.closest(`.${menu_1.default.menuList}`);
21 while (parentEl !== null && parentEl.nodeType === 1) {
22 if (parentEl.classList.contains(menu_1.default.menuList)) {
23 rootMenuList = parentEl;
24 }
25 parentEl = parentEl.parentElement;
26 }
27 if (rootMenuList) {
28 const rootMenuListStyles = getComputedStyle(rootMenuList);
29 const rootMenuListPaddingOffset = parseFloat(rootMenuListStyles.getPropertyValue('padding-top').replace(/px/g, '')) +
30 parseFloat(rootMenuListStyles.getPropertyValue('padding-bottom').replace(/px/g, '')) +
31 parseFloat(getComputedStyle(rootMenuList.parentElement).getPropertyValue('border-bottom-width').replace(/px/g, ''));
32 clientHeight = clientHeight + rootMenuListPaddingOffset;
33 }
34 onGetMenuHeight && onGetMenuHeight(menuId, clientHeight);
35 getHeight && getHeight(clientHeight.toString());
36 }
37 return ref || menuContentRef;
38 };
39 return ((0, jsx_runtime_1.jsx)(MenuContext_1.MenuContext.Consumer, { children: ({ menuId, onGetMenuHeight }) => ((0, jsx_runtime_1.jsx)("div", Object.assign({}, rest, { className: (0, react_styles_1.css)(menu_1.default.menuContent, props.className), ref: (el) => {
40 refCallback(el, menuId, onGetMenuHeight);
41 }, style: Object.assign(Object.assign({}, (menuHeight && { [c_menu__content_Height_1.default.name]: menuHeight })), (maxMenuHeight && { [c_menu__content_MaxHeight_1.default.name]: maxMenuHeight })), children: children }))) }));
42 });
43 exports.MenuContent.displayName = 'MenuContent';
44 //# sourceMappingURL=MenuContent.js.map