Carousel Hooks
Hooks behind the carousels: usePrefersReducedMotion and useSnapScroller, which tracks scroll edges and scrolls one card at a time.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/carousel-hooks.jsonusePrefersReducedMotion: motion is allowed
useSnapScroller drives this row
Usage
carousel-hooks-example.tsx
"use client";
import { usePrefersReducedMotion, useSnapScroller, SnapArrows } from "@dbs/ui";
export default function CarouselHooksExample() {
const reduced = usePrefersReducedMotion();
const api = useSnapScroller();
return (
<div className="grid w-full max-w-md gap-4">
<p className="text-sm text-ink-muted">
usePrefersReducedMotion: <strong>{reduced ? "reduced motion is on" : "motion is allowed"}</strong>
</p>
<div className="flex items-center justify-between">
<span className="text-sm">useSnapScroller drives this row</span>
<SnapArrows api={api} />
</div>
<ul ref={api.ref} onScroll={api.update} className="flex snap-x snap-mandatory gap-3 overflow-x-auto [scrollbar-width:none]">
{Array.from({ length: 8 }, (_, i) => (
<li key={i} className="flex h-24 w-36 shrink-0 snap-start items-center justify-center rounded-xl bg-surface text-sm">Card {i + 1}</li>
))}
</ul>
</div>
);
}