import type { FlexProps } from '@chakra-ui/react'; import { Flex, useToken } from '@chakra-ui/react'; import React from 'react'; export interface Props extends FlexProps { gradientHeight: number; onScrollVisibilityChange?: (isVisible: boolean) => void; }; const ContainerWithScrollY = ({ gradientHeight, children, onScrollVisibilityChange, ...rest }: Props) => { const ref = React.useRef(null); const [ hasScroll, setHasScroll ] = React.useState(false); const gradientStopColor = useToken('colors', 'bg.primary'); React.useEffect(() => { if (!ref.current) { return; } const hasScroll = ref.current.scrollHeight >= ref.current.clientHeight + gradientHeight / 2; setHasScroll(hasScroll); onScrollVisibilityChange?.(hasScroll); }, [ gradientHeight, onScrollVisibilityChange ]); return ( { children } ); }; export default ContainerWithScrollY;