Debian Codegraph @

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

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx } from "react/jsx-runtime";
3 import { useContext, useEffect, useState } from 'react';
4 import styles from '@patternfly/react-styles/css/components/Wizard/wizard.mjs';
5 import { css } from '@patternfly/react-styles';
6 import { WizardContext } from './WizardContext';
7 import { debounce } from '../../helpers/util';
8 import { getResizeObserver } from '../../helpers/resizeObserver';
9 export const WizardBody = (_a) => {
10 var { children, className, hasNoPadding = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, component = 'div' } = _a, props = __rest(_a, ["children", "className", "hasNoPadding", 'aria-label', 'aria-labelledby', "component"]);
11 const [hasScrollbar, setHasScrollbar] = useState(false);
12 const [previousWidth, setPreviousWidth] = useState(undefined);
13 const WrapperComponent = component;
14 const { activeStep, shouldFocusContent, mainWrapperRef } = useContext(WizardContext);
15 const defaultAriaLabel = ariaLabel || `${activeStep === null || activeStep === void 0 ? void 0 : activeStep.name} content`;
16 useEffect(() => {
17 const resize = () => {
18 if (mainWrapperRef === null || mainWrapperRef === void 0 ? void 0 : mainWrapperRef.current) {
19 const { offsetWidth, offsetHeight, scrollHeight } = mainWrapperRef.current;
20 if (previousWidth !== offsetWidth) {
21 setPreviousWidth(offsetWidth);
22 setHasScrollbar(offsetHeight < scrollHeight);
23 }
24 }
25 };
26 const handleResizeWithDelay = debounce(resize, 250);
27 let observer = () => { };
28 if (mainWrapperRef === null || mainWrapperRef === void 0 ? void 0 : mainWrapperRef.current) {
29 observer = getResizeObserver(mainWrapperRef.current, handleResizeWithDelay);
30 const { offsetHeight, scrollHeight } = mainWrapperRef.current;
31 setHasScrollbar(offsetHeight < scrollHeight);
32 setPreviousWidth(mainWrapperRef.current.offsetWidth);
33 }
34 return () => {
35 observer();
36 };
37 }, [previousWidth]);
38 return (_jsx(WrapperComponent, Object.assign({ ref: mainWrapperRef }, (shouldFocusContent && { tabIndex: -1 }), (component === 'div' && hasScrollbar && { role: 'region' }), (hasScrollbar && { 'aria-label': defaultAriaLabel, 'aria-labelledby': ariaLabelledBy, tabIndex: 0 }), { className: css(styles.wizardMain, className) }, props, { children: _jsx("div", { className: css(styles.wizardMainBody, hasNoPadding && styles.modifiers.noPadding), children: children }) })));
39 };
40 WizardBody.displayName = 'WizardBody';
41 //# sourceMappingURL=WizardBody.js.map