"use client"; import { useRef, useState, useEffect, type ReactNode } from "react"; interface ScrollFadeProps { children: ReactNode; className?: string; /** Tailwind max-width class, e.g. "max-w-2xs". Defaults to none. */ maxWidth?: string; } /** * Wraps children in a horizontally-scrollable container that shows left/right * gradient fade indicators when there is overflowed content in that direction. */ export function ScrollFade({ children, className, maxWidth }: ScrollFadeProps) { const scrollRef = useRef(null); const [showLeft, setShowLeft] = useState(false); const [showRight, setShowRight] = useState(false); const update = () => { const el = scrollRef.current; if (!el) return; setShowLeft(el.scrollLeft > 0); setShowRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1); }; useEffect(() => { update(); const el = scrollRef.current; if (!el) return; const ro = new ResizeObserver(update); ro.observe(el); return () => ro.disconnect(); }, [children]); return (
{children}
{showLeft && (
)} {showRight && (
)}
); }