Data & Media
@hacline/ui/carouselCarousel
Display a collection of content in a scrollable paginated view.
Usage
Switch between project phases using the previous, next, or pagination indicator controls. Carousel pages are 1-based, and CarouselContent inside CarouselViewport holds each slide card.
"use client";
import {
Carousel,
CarouselContent,
CarouselIndicator,
CarouselIndicatorGroup,
CarouselItem,
CarouselNext,
CarouselPrevious,
CarouselViewport,
} from "@/components/ui/hacline/components/carousel";
const slides = [
{
detail: "Organize interview notes",
key: "research",
title: "Design research",
},
{
detail: "Complete initial user flows",
key: "prototype",
title: "Interactive prototype",
},
{ detail: "Confirm iteration scope", key: "review", title: "Project review" },
];
export const Example = () => (
<Carousel aria-label="Project phases" className="max-w-md">
<CarouselViewport>
<CarouselContent>
{slides.map(({ detail, key, title }) => (
<CarouselItem
className="rounded-hl-lg border-hl-border bg-hl-surface flex min-h-28 flex-col items-center justify-center gap-1 border px-2 text-center"
key={key}
>
<strong>{title}</strong>
<span className="text-hl-fg-muted text-xs">{detail}</span>
</CarouselItem>
))}
</CarouselContent>
</CarouselViewport>
<CarouselPrevious aria-label="Previous project phase">‹</CarouselPrevious>
<CarouselNext aria-label="Next project phase">›</CarouselNext>
<CarouselIndicatorGroup aria-label="Project phase pagination">
{slides.map(({ key, title }) => (
<CarouselIndicator aria-label={title} key={key} />
))}
</CarouselIndicatorGroup>
</Carousel>
);Autoplay Controls
Start or pause playback with CarouselPlayToggle. The carousel loops back to the first slide after reaching the last one.
"use client";
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselPlayToggle,
CarouselViewport,
} from "@/components/ui/hacline/components/carousel";
const notes = [
"Review this week's tasks",
"Check docs awaiting review",
"Sync completed items",
];
export const Example = () => (
<Carousel
aria-label="Project brief carousel"
className="max-w-xs grid-cols-1"
interval={2500}
loop
>
<CarouselViewport className="col-start-1">
<CarouselContent>
{notes.map((note) => (
<CarouselItem
className="rounded-hl-md bg-hl-surface-muted p-4 text-center"
key={note}
>
{note}
</CarouselItem>
))}
</CarouselContent>
</CarouselViewport>
<CarouselPlayToggle className="col-start-1">
{({ playing }) => (playing ? "Pause" : "Play brief")}
</CarouselPlayToggle>
</Carousel>
);Parts
| Part | Description |
|---|---|
CarouselContent | The row, or column, of slides inside the viewport. |
CarouselIndicator | Shows a page and goes to it. Indicators past the page count hide themselves. |
CarouselIndicatorGroup | The indicators, as a tablist with one tab stop. Its children can be a function of the state. |
CarouselItem | One slide. It's labelled "1 of 5" unless it has an aria-label, and inert while out of view. |
CarouselNext | Goes to the next page. aria-disabled on the last page without loop, where it stays focusable. |
CarouselPlayToggle | Starts and stops rotation. Label it from playing in its state, as the carousel pattern asks. |
CarouselPrevious | Goes to the previous page. aria-disabled on the first page without loop, where it stays focusable. |
CarouselViewport | The scrolling window onto the slides. Touch, wheels and keys scroll it natively. |
Props
Prop
Type