Debian Codegraph @

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

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