Debian Codegraph @

node/@patternfly/react-core/dist/js/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 WizardContext_1 = require("./WizardContext");
10 const util_1 = require("../../helpers/util");
11 const resizeObserver_1 = require("../../helpers/resizeObserver");
12 const WizardBody = (_a) => {
13 var { children, className, hasNoPadding = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, component = 'div' } = _a, props = tslib_1.__rest(_a, ["children", "className", "hasNoPadding", 'aria-label', 'aria-labelledby', "component"]);
14 const [hasScrollbar, setHasScrollbar] = (0, react_1.useState)(false);
15 const [previousWidth, setPreviousWidth] = (0, react_1.useState)(undefined);
16 const WrapperComponent = component;
17 const { activeStep, shouldFocusContent, mainWrapperRef } = (0, react_1.useContext)(WizardContext_1.WizardContext);
18 const defaultAriaLabel = ariaLabel || `${activeStep === null || activeStep === void 0 ? void 0 : activeStep.name} content`;
19 (0, react_1.useEffect)(() => {
20 const resize = () => {
21 if (mainWrapperRef === null || mainWrapperRef === void 0 ? void 0 : mainWrapperRef.current) {
22 const { offsetWidth, offsetHeight, scrollHeight } = mainWrapperRef.current;
23 if (previousWidth !== offsetWidth) {
24 setPreviousWidth(offsetWidth);
25 setHasScrollbar(offsetHeight < scrollHeight);
26 }
27 }
28 };
29 const handleResizeWithDelay = (0, util_1.debounce)(resize, 250);
30 let observer = () => { };
31 if (mainWrapperRef === null || mainWrapperRef === void 0 ? void 0 : mainWrapperRef.current) {
32 observer = (0, resizeObserver_1.getResizeObserver)(mainWrapperRef.current, handleResizeWithDelay);
33 const { offsetHeight, scrollHeight } = mainWrapperRef.current;
34 setHasScrollbar(offsetHeight < scrollHeight);
35 setPreviousWidth(mainWrapperRef.current.offsetWidth);
36 }
37 return () => {
38 observer();
39 };
40 }, [previousWidth]);
41 return ((0, jsx_runtime_1.jsx)(WrapperComponent, Object.assign({ ref: mainWrapperRef }, (shouldFocusContent && { tabIndex: -1 }), (component === 'div' && hasScrollbar && { role: 'region' }), (hasScrollbar && { 'aria-label': defaultAriaLabel, 'aria-labelledby': ariaLabelledBy, tabIndex: 0 }), { className: (0, react_styles_1.css)(wizard_1.default.wizardMain, className) }, props, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(wizard_1.default.wizardMainBody, hasNoPadding && wizard_1.default.modifiers.noPadding), children: children }) })));
42 };
43 exports.WizardBody = WizardBody;
44 exports.WizardBody.displayName = 'WizardBody';
45 //# sourceMappingURL=WizardBody.js.map