Carousel
Scrolls slides sideways or up and down, with previous and next buttons, dots that jump to a slide and a bar that shows how far the shopper has scrolled.
Parts
| Part | File | Does |
|---|---|---|
| Carousel | Carousel.vue | Groups all parts of the carousel, which scrolls through items sideways. |
| CarouselContent | CarouselContent.vue | Holds the slides of the carousel in a scrollable row. |
| CarouselDots | CarouselDots.vue | Shows one dot per slide and lets the user jump to a slide. |
| CarouselItem | CarouselItem.vue | Holds the content of one slide in the carousel. |
| CarouselNext | CarouselNext.vue | Lets the user scroll the carousel to the next slide. |
| CarouselPrevious | CarouselPrevious.vue | Lets the user scroll the carousel to the previous slide. |
| CarouselProgress | CarouselProgress.vue | Shows how far the user has scrolled through the carousel. |
Anatomy
<Carousel>
<CarouselContent>
<CarouselItem />
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
<CarouselDots />
<CarouselProgress />
</Carousel>Styling
All of Carousel’s styles live in carousel.json. New to styling in Frontic UI? How styling works →
Install
- Installs with it
- button
- npm packages
- @lucide/vue
- @vueuse/core
- class-variance-authority
- embla-carousel-vue@9.0.0-rc04
- reka-ui
Built from
API reference
Groups all parts of the carousel, which scrolls through items sideways. Renders a <div>.
Props 4
| Prop | Type | Default | |
|---|---|---|---|
| opts | Partial<OptionsType> | — | |
| |||
| plugins | (LoosePluginType & { name: string; options: Partial<{ active: boolean; breakpoints: { [key: string]: Omit<Partial<any>, 'breakpoints'>; }; }>; init: (emblaApi: EmblaCarouselType, OptionsHandler: OptionsHandlerType) => void; destroy: () => void; })[] | — | |
| |||
| orientation | 'vertical' | 'horizontal' | 'horizontal' | |
| |||
| roleDescription | string | 'carousel' | |
| |||
Events 1
| Event | Payload | |
|---|---|---|
| init-api | payload: EmblaCarouselType | undefined | |
| ||
Slots 1
| Slot | Slot props | |
|---|---|---|
| default | { canScrollNext: boolean; canScrollPrev: boolean; carouselApi: EmblaCarouselType | undefined; carouselRef: HTMLElement | undefined; orientation: "vertical" | "horizontal" | undefined; scrollNext: () => void; scrollPrev: () => void; } | |
| ||
Recipe focus-ring 1 group
Multi slide
1<!-- SPDX-License-Identifier: FSL-1.1-MIT AND MIT -->2<!-- Frontic UI © Frontic · Portions © 2023 unovue (shadcn-vue, MIT) · ui.frontic.com/license -->3<script setup lang="ts">4import { Image } from '@/components/ui/image'5import {6Carousel,7CarouselContent,8CarouselItem,9CarouselNext,10CarouselPrevious,11} from '@/components/ui/carousel'1213const image = (name: string) =>14`https://static.frontic.com/cdn-cgi/image/width=480,format=auto/ui/products/${name}.jpg`1516// Three slides at a time: each item takes a third of the viewport.17const jackets = [18{ name: 'Blizzard Defender', image: 'blizzard-defender-aubergine' },19{ name: 'Glacier Explorer', image: 'glacier-explorer' },20{ name: 'Arctic Fox Winter Jacket', image: 'arctic-fox-winter-jacket' },21{ name: 'Frost Escape Parka', image: 'frost-escape-parka' },22]23</script>2425<template>26<div class="mx-auto w-full max-w-2xl px-12">27<Carousel :opts="{ align: 'start' }" class="w-full">28<CarouselContent>29<CarouselItem30v-for="jacket in jackets"31:key="jacket.name"32class="basis-1/3">33<figure class="flex flex-col gap-2">34<Image35:src="image(jacket.image)"36:alt="jacket.name"37class="aspect-square w-full" />38<figcaption>{{ jacket.name }}</figcaption>39</figure>40</CarouselItem>41</CarouselContent>42<CarouselPrevious />43<CarouselNext />44</Carousel>45</div>46</template>