Debian Codegraph @

node/@patternfly/react-core/dist/js/deprecated/components/Wizard/WizardBody.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.WizardBody = 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 wizard_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Wizard/wizard"));
8 const react_styles_1 = require("@patternfly/react-styles");
9 const WizardDrawerWrapper_1 = require("./WizardDrawerWrapper");
10 const Drawer_1 = require("../../../components/Drawer");
11 const util_1 = require("../../../helpers/util");
12 const resizeObserver_1 = require("../../../helpers/resizeObserver");
13 const WizardBody = ({ children, hasNoBodyPadding = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, mainComponent = 'div', hasDrawer, isDrawerExpanded, onExpandDrawer, activeStep }) => {
14 const MainComponent = mainComponent;
15 const [hasScrollbar, setHasScrollbar] = (0, react_1.useState)(false);
16 const [previousWidth, setPreviousWidth] = (0, react_1.useState)(undefined);
17 const wizardBodyRef = (0, react_1.useRef)(null);
18 (0, react_1.useEffect)(() => {
19 const resize = () => {
20 if (wizardBodyRef === null || wizardBodyRef === void 0 ? void 0 : wizardBodyRef.current) {
21 const { offsetWidth, offsetHeight, scrollHeight } = wizardBodyRef.current;
22 if (previousWidth !== offsetWidth) {
23 setPreviousWidth(offsetWidth);
24 setHasScrollbar(offsetHeight < scrollHeight);
25 }
26 }
27 };
28 const handleResizeWithDelay = (0, util_1.debounce)(resize, 250);
29 let observer = () => { };
30 if (wizardBodyRef === null || wizardBodyRef === void 0 ? void 0 : wizardBodyRef.current) {
31 observer = (0, resizeObserver_1.getResizeObserver)(wizardBodyRef.current, handleResizeWithDelay);
32 const { offsetHeight, scrollHeight } = wizardBodyRef.current;
33 setHasScrollbar(offsetHeight < scrollHeight);
34 setPreviousWidth(wizardBodyRef.current.offsetWidth);
35 }
36 return () => {
37 observer();
38 };
39 }, []);
40 return ((0, jsx_runtime_1.jsx)(MainComponent, Object.assign({}, (mainComponent === 'div' && hasScrollbar && { role: 'region' }), (hasScrollbar && { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, tabIndex: 0 }), { ref: wizardBodyRef, className: (0, react_styles_1.css)(wizard_1.default.wizardMain), children: (0, jsx_runtime_1.jsx)(WizardDrawerWrapper_1.WizardDrawerWrapper, { hasDrawer: hasDrawer && activeStep.drawerPanelContent, wrapper: (children) => ((0, jsx_runtime_1.jsx)(Drawer_1.Drawer, { isInline: true, isExpanded: isDrawerExpanded, onExpand: onExpandDrawer, children: (0, jsx_runtime_1.jsx)(Drawer_1.DrawerContent, { panelContent: activeStep.drawerPanelContent, children: children }) })), children: (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(wizard_1.default.wizardMainBody, hasNoBodyPadding && wizard_1.default.modifiers.noPadding), children: children }) }) })));
41 };
42 exports.WizardBody = WizardBody;
43 exports.WizardBody.displayName = 'WizardBody';
44 //# sourceMappingURL=WizardBody.js.map