| 1 |
import { jsx as _jsx } from "react/jsx-runtime"; |
| 2 |
import { useEffect, useRef, useState } from 'react'; |
| 3 |
import styles from '@patternfly/react-styles/css/components/Wizard/wizard.mjs'; |
| 4 |
import { css } from '@patternfly/react-styles'; |
| 5 |
import { WizardDrawerWrapper } from './WizardDrawerWrapper'; |
| 6 |
import { Drawer, DrawerContent } from '../../../components/Drawer'; |
| 7 |
import { debounce } from '../../../helpers/util'; |
| 8 |
import { getResizeObserver } from '../../../helpers/resizeObserver'; |
| 9 |
export const WizardBody = ({ children, hasNoBodyPadding = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, mainComponent = 'div', hasDrawer, isDrawerExpanded, onExpandDrawer, activeStep }) => { |
| 10 |
const MainComponent = mainComponent; |
| 11 |
const [hasScrollbar, setHasScrollbar] = useState(false); |
| 12 |
const [previousWidth, setPreviousWidth] = useState(undefined); |
| 13 |
const wizardBodyRef = useRef(null); |
| 14 |
useEffect(() => { |
| 15 |
const resize = () => { |
| 16 |
if (wizardBodyRef === null || wizardBodyRef === void 0 ? void 0 : wizardBodyRef.current) { |
| 17 |
const { offsetWidth, offsetHeight, scrollHeight } = wizardBodyRef.current; |
| 18 |
if (previousWidth !== offsetWidth) { |
| 19 |
setPreviousWidth(offsetWidth); |
| 20 |
setHasScrollbar(offsetHeight < scrollHeight); |
| 21 |
} |
| 22 |
} |
| 23 |
}; |
| 24 |
const handleResizeWithDelay = debounce(resize, 250); |
| 25 |
let observer = () => { }; |
| 26 |
if (wizardBodyRef === null || wizardBodyRef === void 0 ? void 0 : wizardBodyRef.current) { |
| 27 |
observer = getResizeObserver(wizardBodyRef.current, handleResizeWithDelay); |
| 28 |
const { offsetHeight, scrollHeight } = wizardBodyRef.current; |
| 29 |
setHasScrollbar(offsetHeight < scrollHeight); |
| 30 |
setPreviousWidth(wizardBodyRef.current.offsetWidth); |
| 31 |
} |
| 32 |
return () => { |
| 33 |
observer(); |
| 34 |
}; |
| 35 |
}, []); |
| 36 |
return (_jsx(MainComponent, Object.assign({}, (mainComponent === 'div' && hasScrollbar && { role: 'region' }), (hasScrollbar && { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, tabIndex: 0 }), { ref: wizardBodyRef, className: css(styles.wizardMain), children: _jsx(WizardDrawerWrapper, { hasDrawer: hasDrawer && activeStep.drawerPanelContent, wrapper: (children) => (_jsx(Drawer, { isInline: true, isExpanded: isDrawerExpanded, onExpand: onExpandDrawer, children: _jsx(DrawerContent, { panelContent: activeStep.drawerPanelContent, children: children }) })), children: _jsx("div", { className: css(styles.wizardMainBody, hasNoBodyPadding && styles.modifiers.noPadding), children: children }) }) }))); |
| 37 |
}; |
| 38 |
WizardBody.displayName = 'WizardBody'; |
| 39 |
//# sourceMappingURL=WizardBody.js.map |