import { forwardRef, ReactNode, useEffect, useImperativeHandle, useRef } from 'react'; import Box from '../Box'; import { Dimension, Padding } from '../boxTypes'; import { useScrollBoundaryContainer } from '../contexts/ScrollBoundaryContainerProvider'; type ScrollBoundaryContainerOverflow = 'scroll' | 'scrollX' | 'scrollY' | 'auto' | 'visible'; type InternalProps = { children?: ReactNode; includesFooter?: boolean; height?: Dimension; onScroll?: () => void; overflow?: ScrollBoundaryContainerOverflow; padding?: Padding; }; // ScrollBoundaryContainerWithForwardRef is the ScrollBoundaryContainer to be used internally, within components (e. Modal, OverlayPanel). // It has an extended API with private props (onScroll, padding, and ref) to maintain border shadows in the component main content container. const ScrollBoundaryContainerWithForwardRef = forwardRef( function ScrollBoundaryContainer( { children, onScroll, includesFooter, padding = 0, height = '100%', overflow = 'auto', }: InternalProps, ref, ) { const { addRef } = useScrollBoundaryContainer(); const anchorRef = useRef(null); // When using both forwardRef and innerRef, React.useimperativehandle() allows a parent component // that renders