Snap Scroller
A horizontal scroll-snap rail with native touch scrolling, overlay arrows that disable at the ends, and a hook and header arrows for your own controls.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/snap-scroller.jsonDependencies:
lucide-reactUses:carousel-hooks
Header arrows
Usage
snap-scroller-example.tsx
"use client";
import { SnapArrows, SnapScroller, useSnapScroller } from "@dbs/ui";
const CARDS = ["hero-meadow", "hero-wave", "hero-landscape", "field-land", "case-sunset", "cta-aerial"].map((n, i) => (
<article key={n} className="overflow-hidden rounded-2xl border border-line bg-canvas">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={`/samples/${n}.jpg`} alt="" className="aspect-[4/3] w-full object-cover" />
<p className="p-4 text-sm font-medium">Card {i + 1}</p>
</article>
));
function WithHeaderArrows() {
const api = useSnapScroller();
return (
<div>
<div className="mb-4 flex items-center justify-between px-4">
<h3 className="text-lg font-medium">Header arrows</h3>
<SnapArrows api={api} />
</div>
<ul ref={api.ref} onScroll={api.update} className="flex snap-x snap-mandatory scroll-px-4 gap-4 overflow-x-auto px-4 [scrollbar-width:none]">
{CARDS.map((c, i) => (
<li key={i} className="w-[70%] shrink-0 snap-start sm:w-[34%]">{c}</li>
))}
</ul>
</div>
);
}
export default function SnapScrollerExample() {
return (
<div className="grid w-full min-w-0 grid-cols-[minmax(0,1fr)] gap-10">
<SnapScroller label="Overlay arrows" items={CARDS} itemClassName="w-[70%] sm:w-[34%]" />
<WithHeaderArrows />
</div>
);
}





