Data display
Carousel
Scroll-snap slides with arrows and dots; swipe, drag or use the keyboard.
lucide-react
Preview
"use client";
import { Sparkles, Target, Zap } from "lucide-react";
import { Carousel } from "@/components/ui/carousel";
const slides = [
{ icon: <Sparkles />, title: "AI prospecting", text: "Describe your ideal buyer and get a ranked list in seconds.", tone: "bg-accent-soft text-accent" },
{ icon: <Zap />, title: "Instant enrichment", text: "Verified emails, phones and firmographics on every row.", tone: "bg-success-soft text-success" },
{ icon: <Target />, title: "Score every lead", text: "ICP fit plus buying signals, refreshed every morning.", tone: "bg-warning-soft text-warning" },
{ icon: <Sparkles />, title: "Sequences that adapt", text: "Pause on reply, branch on opens, personalise with AI.", tone: "bg-info-soft text-info" },
];
export default function Example() {
return (
<Carousel label="Product highlights" perView={2} className="w-full max-w-2xl">
{slides.map((s) => (
<div key={s.title} className="flex h-44 flex-col justify-end rounded-lg border border-line bg-surface p-5 shadow-card">
<span className={`mb-auto flex size-9 items-center justify-center rounded-[10px] [&_svg]:size-4 ${s.tone}`}>{s.icon}</span>
<h3 className="text-lg font-medium text-fg">{s.title}</h3>
<p className="mt-1 text-sm text-fg-secondary">{s.text}</p>
</div>
))}
</Carousel>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install lucide-reactCreate a
carousel.tsxfile and paste the following code into it.src/components/ui/carousel.tsx"use client"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Children, type ReactNode, useCallback, useEffect, useRef, useState } from "react"; import { cx } from "@/utils/cx"; import { StepperDots } from "./step-indicator"; export interface CarouselProps { /** Each child is one slide. */ children: ReactNode; /** Accessible name for the carousel. */ label: string; /** Slides visible at once on wide screens (1–3). */ perView?: 1 | 2 | 3; showArrows?: boolean; showDots?: boolean; className?: string; } /** Scroll-snap slides with arrows and dots. Swipe, drag or use the buttons; arrows keys work when focused. */ export function Carousel({ children, label, perView = 1, showArrows = true, showDots = true, className }: CarouselProps) { const slides = Children.toArray(children); const track = useRef<HTMLDivElement>(null); const [index, setIndex] = useState(0); const pages = Math.max(1, slides.length - perView + 1); const goTo = useCallback((i: number) => { const el = track.current; const slide = el?.children[Math.max(0, Math.min(slides.length - 1, i))] as HTMLElement | undefined; if (el && slide) el.scrollTo({ left: slide.offsetLeft - el.offsetLeft, behavior: "smooth" }); }, [slides.length]); useEffect(() => { const el = track.current; if (!el) return; const onScroll = () => { const w = (el.children[0] as HTMLElement | undefined)?.offsetWidth ?? 1; setIndex(Math.round(el.scrollLeft / (w + 12))); }; el.addEventListener("scroll", onScroll, { passive: true }); return () => el.removeEventListener("scroll", onScroll); }, []); const arrow = "absolute top-1/2 z-10 inline-flex size-9 -translate-y-1/2 items-center justify-center rounded-full bg-surface text-fg-secondary shadow-button outline-none transition hover:text-fg focus-visible:shadow-focus disabled:pointer-events-none disabled:opacity-0 [&_svg]:size-4"; return ( <section aria-roledescription="carousel" aria-label={label} className={cx("relative flex flex-col gap-4", className)}> <div className="relative"> <div ref={track} tabIndex={0} onKeyDown={(e) => { if (e.key === "ArrowRight") goTo(index + 1); if (e.key === "ArrowLeft") goTo(index - 1); }} className="flex snap-x snap-mandatory gap-3 overflow-x-auto scroll-smooth rounded-lg outline-none [scrollbar-width:none] focus-visible:shadow-focus [&::-webkit-scrollbar]:hidden" > {slides.map((s, i) => ( <div key={i} role="group" aria-roledescription="slide" aria-label={`${i + 1} of ${slides.length}`} className={cx("shrink-0 snap-start", perView === 1 ? "w-full" : perView === 2 ? "w-full sm:w-[calc(50%-6px)]" : "w-full sm:w-[calc(50%-6px)] lg:w-[calc(33.333%-8px)]")} > {s} </div> ))} </div> {showArrows && ( <> <button type="button" aria-label="Previous slide" onClick={() => goTo(index - 1)} disabled={index <= 0} className={cx(arrow, "left-2")}> <ChevronLeft /> </button> <button type="button" aria-label="Next slide" onClick={() => goTo(index + 1)} disabled={index >= pages - 1} className={cx(arrow, "right-2")}> <ChevronRight /> </button> </> )} </div> {showDots && pages > 1 && <StepperDots className="self-center" count={pages} current={Math.min(index, pages - 1)} onChange={goTo} />} </section> ); }Create a
step-indicator.tsxfile and paste the following code into it.src/components/ui/step-indicator.tsximport { Check, ChevronRight } from "lucide-react"; import { Fragment } from "react"; import { cx } from "@/utils/cx"; export interface Step { label: string; description?: string; } function Marker({ index, state }: { index: number; state: "done" | "current" | "upcoming" }) { return ( <span className={cx( "flex size-5 shrink-0 items-center justify-center rounded-full text-xs font-semibold tabular", state === "done" && "bg-success text-white", state === "current" && "bg-linear-to-b from-accent-light to-accent text-white shadow-button-primary", state === "upcoming" && "bg-surface text-fg-muted ring-1 ring-inset ring-line-strong", )} > {state === "done" ? <Check className="size-3" strokeWidth={3} aria-hidden /> : index + 1} </span> ); } export interface StepIndicatorProps { steps: Step[]; /** Zero-based index of the current step. */ current: number; orientation?: "horizontal" | "vertical"; className?: string; } /** Numbered steps. Horizontal for headers (chevron separators), vertical for side panels. */ export function StepIndicator({ steps, current, orientation = "horizontal", className }: StepIndicatorProps) { const state = (i: number) => (i < current ? "done" : i === current ? "current" : "upcoming"); if (orientation === "vertical") { return ( <ol className={cx("flex flex-col", className)}> {steps.map((s, i) => ( <li key={s.label} aria-current={i === current ? "step" : undefined} className="relative flex gap-3 pb-6 last:pb-0"> {i < steps.length - 1 && ( <span aria-hidden className={cx("absolute bottom-1 left-[9.5px] top-6 w-px", i < current ? "bg-success" : "bg-line")} /> )} <Marker index={i} state={state(i)} /> <div className="-mt-px"> <div className={cx("text-base font-medium", i <= current ? "text-fg" : "text-fg-muted")}>{s.label}</div> {s.description && <div className="mt-0.5 text-sm text-fg-muted">{s.description}</div>} </div> </li> ))} </ol> ); } return ( <ol className={cx("flex flex-wrap items-center gap-x-3 gap-y-2", className)}> {steps.map((s, i) => ( <Fragment key={s.label}> {i > 0 && ( <li aria-hidden> <ChevronRight className="size-4 text-fg-disabled" /> </li> )} <li aria-current={i === current ? "step" : undefined} className="flex items-center gap-2"> <Marker index={i} state={state(i)} /> <span className={cx("text-base", i === current ? "font-medium text-fg" : i < current ? "text-fg" : "text-fg-muted")}>{s.label}</span> </li> </Fragment> ))} </ol> ); } /** Dot stepper for carousels and short flows. */ export function StepperDots({ count, current, onChange, className }: { count: number; current: number; onChange?: (i: number) => void; className?: string }) { return ( <div role="tablist" aria-label="Slides" className={cx("flex items-center gap-1.5", className)}> {Array.from({ length: count }, (_, i) => ( <button key={i} type="button" role="tab" aria-selected={i === current} aria-label={`Slide ${i + 1}`} onClick={() => onChange?.(i)} className={cx( "h-1.5 rounded-full outline-none transition-all focus-visible:shadow-focus", i === current ? "w-5 bg-accent" : "w-1.5 bg-line-strong hover:bg-fg-disabled", )} /> ))} </div> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.