Components
Carousel
A draggable, keyboard-navigable slide carousel powered by Embla.
Installation
$ npx veil-ui@latest add carouselUsage
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselNext,
CarouselPrevious,
} from "@/components/ui/carousel";
<Carousel opts={{ loop: true }}>
<CarouselContent>
<CarouselItem>Slide one</CarouselItem>
<CarouselItem>Slide two</CarouselItem>
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>;Examples
Basic
Design tokens
A single source of truth for color, spacing and type.
Registry
Copy-paste components that live in your codebase.
CLI
Add any component with a single command.
Docs
Examples, API tables and accessibility notes.
Vertical
Design tokens — A single source of truth for color, spacing and type.
Registry — Copy-paste components that live in your codebase.
CLI — Add any component with a single command.
Docs — Examples, API tables and accessibility notes.
Loop
“A single source of truth for color, spacing and type.”
“Copy-paste components that live in your codebase.”
“Add any component with a single command.”
“Examples, API tables and accessibility notes.”
API reference
Carouseltakes Emblaopts, anorientationand asetApicallback for programmatic control.CarouselContentis the scroll viewport andCarouselItemis re-exported from the standalone item component.CarouselPreviousandCarouselNextdisable themselves at the ends unless looping.
Accessibility
- The region is labelled
carouselwith slides asgroup/slideelements. - Left and Right arrows scroll when the carousel has focus.
- Controls are named
Previous slideandNext slideand reflect disabled state.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add carousel --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed } from "vue";
import { cn } from "@/lib/utils";
import { createCarouselContext, provideCarousel } from "./use-carousel";
const props = withDefaults(
defineProps<{
orientation?: "horizontal" | "vertical";
class?: string;
label?: string;
}>(),
{ orientation: "horizontal", label: "Carousel" },
);
const state = createCarouselContext();
state.orientation.value = props.orientation;
function size() {
const element = state.track.value;
if (!element) return 0;
return props.orientation === "vertical"
? element.clientHeight
: element.clientWidth;
}
function scrollTo(index: number) {
const element = state.track.value;
if (!element) return;
const clamped = Math.min(Math.max(index, 0), Math.max(state.count.value - 1, 0));
element.scrollTo({
[props.orientation === "vertical" ? "top" : "left"]: clamped * size(),
behavior: "smooth",
});
}
function scrollPrev() {
scrollTo(state.index.value - 1);
}
function scrollNext() {
scrollTo(state.index.value + 1);
}
function sync() {
const element = state.track.value;
if (!element) return;
const itemSize = size() || 1;
const offset =
props.orientation === "vertical" ? element.scrollTop : element.scrollLeft;
state.index.value = Math.round(offset / itemSize);
const max =
props.orientation === "vertical"
? element.scrollHeight - element.clientHeight
: element.scrollWidth - element.clientWidth;
state.canPrev.value = offset > 2;
state.canNext.value = offset < max - 2;
}
provideCarousel({
...state,
orientation: computed(() => props.orientation),
scrollPrev,
scrollNext,
scrollTo,
sync,
});
</script>
<template>
<div
role="region"
aria-roledescription="carousel"
data-slot="carousel"
:aria-label="label"
:class="cn('relative', props.class)"
@keydown.left.prevent="scrollPrev"
@keydown.right.prevent="scrollNext"
>
<slot />
</div>
</template>