import React, { useEffect, useRef } from "react" import { motion } from "framer-motion" import { cn } from "../../design-lib/utils" interface ScrollerProps { axis?: "vertical" | "horizontal" | "free" className?: string children?: React.ReactNode height?: string width?: string } const Scroller: React.FC = ({ axis = "vertical", className = "", children, height, width, }) => { const containerRef = useRef(null) const [blurEdges, setBlurEdges] = React.useState>({ top: false, left: false, bottom: false, right: false, }) useEffect(() => { const container = containerRef.current as HTMLDivElement const checkScroll = () => { const { scrollTop, scrollLeft, scrollHeight, clientHeight, scrollWidth, clientWidth, } = container setBlurEdges({ top: scrollTop > 0, left: scrollLeft > 0, bottom: scrollTop < scrollHeight - clientHeight, right: scrollLeft < scrollWidth - clientWidth, }) } checkScroll() const handleScroll = () => { checkScroll() } container.addEventListener("scroll", handleScroll) return () => { container.removeEventListener("scroll", handleScroll) } }, [axis, containerRef]) return (
{blurEdges.top && ( )} {blurEdges.left && ( )} {blurEdges.bottom && ( )} {blurEdges.right && ( )}
*]:z-10", className )} style={{ overflowX: axis === "free" || axis === "horizontal" ? "auto" : "hidden", overflowY: axis === "free" || axis === "vertical" ? "auto" : "hidden", WebkitOverflowScrolling: "touch", }} > {children}
) } export default Scroller