import { useRef, useState, useEffect, useCallback } from "react" import { ChevronLeft, ChevronRight } from "lucide-react" import { Button } from "@/components/ui/button" type HorizontalStripProps = { children: React.ReactNode className?: string gap?: string } export function HorizontalStrip({ children, className, gap = "gap-3" }: HorizontalStripProps) { const ref = useRef(null) const [canScrollLeft, setCanScrollLeft] = useState(false) const [canScrollRight, setCanScrollRight] = useState(false) const update = useCallback(() => { const el = ref.current if (!el) return setCanScrollLeft(el.scrollLeft > 0) setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1) }, []) useEffect(() => { const el = ref.current if (!el) return update() el.addEventListener("scroll", update, { passive: true }) const ro = new ResizeObserver(update) ro.observe(el) return () => { el.removeEventListener("scroll", update) ro.disconnect() } }, [update]) function scroll(dir: -1 | 1) { ref.current?.scrollBy({ left: dir * ref.current.clientWidth * 0.75, behavior: "smooth" }) } return (
{canScrollLeft && ( )}
{children}
{canScrollRight && ( )}
) }