Use o componente Carousel para exibir uma lista de itens em um carrossel.
Use a prop items como um array e renderize cada item usando o slot padrão:
Você também pode passar um array de objetos com as seguintes propriedades:
class?: anyui?: { item?: ClassNameValue }Você pode controlar quantos itens ficam visíveis usando as classes utilitárias basis / width no item:
Use a prop orientation para alterar a orientação do Progress. O padrão é horizontal.
height no container na orientação vertical.Use a prop arrows para exibir os botões de anterior e próximo.
Use as props prev e next para personalizar os botões de anterior e próximo com quaisquer props do Button.
Use as props prev-icon e next-icon para personalizar o Icon dos botões. O padrão é i-lucide-arrow-left / i-lucide-arrow-right.
app.config.ts nas chaves ui.icons.arrowLeft / ui.icons.arrowRight.vite.config.ts nas chaves ui.icons.arrowLeft / ui.icons.arrowRight.Use a prop dots para exibir uma lista de pontos para rolar até um slide específico.
O número de pontos é baseado no número de slides exibidos na visualização:
O componente Carousel implementa os plugins oficiais do Embla Carousel.
Este plugin é usado para estender o Embla Carousel com a funcionalidade de reprodução automática.
Use a prop autoplay como um booleano ou um objeto para configurar o plugin Autoplay.
loop para um carrossel infinito.Este plugin é usado para estender o Embla Carousel com a funcionalidade de rolagem automática.
Use a prop auto-scroll como um booleano ou um objeto para configurar o plugin Auto Scroll.
loop para um carrossel infinito.Este plugin é usado para estender o Embla Carousel com a funcionalidade de altura automática. Ele altera a altura do container do carrossel para se ajustar à altura do slide mais alto em exibição.
Use a prop auto-height como um booleano ou um objeto para configurar o plugin Auto Height.
transition-[height] no container para animar a mudança de altura.O Class Names é um plugin utilitário de alternância de nomes de classe para o Embla Carousel que permite automatizar a alternância de nomes de classe no seu carrossel.
Use a prop class-names como um booleano ou um objeto para configurar o plugin Class Names.
transition-opacity [&:not(.is-snapped)]:opacity-10 no item para animar a mudança de opacidade.Este plugin é usado para substituir a funcionalidade de rolagem do Embla Carousel por transições de fade.
Use a prop fade como um booleano ou um objeto para configurar o plugin Fade.
Este plugin é usado para estender o Embla Carousel com a capacidade de usar a roda do mouse/trackpad para navegar pelo carrossel.
Use a prop wheel-gestures como um booleano ou um objeto para configurar o plugin Wheel Gestures.
Você pode usar a função scrollTo da emblaApi para exibir miniaturas sob o carrossel que permitem navegar até um slide específico.
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
prev | { size: 'md', color: 'neutral', variant: 'link' } | Omit<ButtonProps, LinkPropsKeys>Configure the prev button when arrows are enabled. |
prevIcon | appConfig.ui.icons.arrowLeft | anyThe icon displayed in the prev button. |
next | { size: 'md', color: 'neutral', variant: 'link' } | Omit<ButtonProps, LinkPropsKeys>Configure the next button when arrows are enabled. |
nextIcon | appConfig.ui.icons.arrowRight | anyThe icon displayed in the next button. |
arrows | false | boolean Display prev and next buttons to scroll the carousel. |
dots | false | boolean Display dots to scroll to a specific slide. |
orientation | 'horizontal' | "vertical" | "horizontal"The orientation of the carousel. |
items | T[] | |
autoplay | false | boolean | Partial<CreateOptionsType<OptionsType>> Enable Autoplay plugin |
autoScroll | false | boolean | Partial<CreateOptionsType<OptionsType>> Enable Auto Scroll plugin |
autoHeight | false | boolean | Partial<CreateOptionsType<{ active: boolean; breakpoints: { [key: string]: Omit<Partial<any>, "breakpoints">; }; }>> Enable Auto Height plugin |
classNames | false | boolean | Partial<CreateOptionsType<OptionsType>> Enable Class Names plugin |
fade | false | boolean | Partial<CreateOptionsType<{ active: boolean; breakpoints: { [key: string]: Omit<Partial<any>, "breakpoints">; }; }>> Enable Fade plugin |
wheelGestures | false | boolean | WheelGesturesPluginOptions Enable Wheel Gestures plugin |
align | 'center' | "start" | "center" | "end" | (viewSize: number, snapSize: number, index: number): number |
containScroll | 'trimSnaps' | false | "trimSnaps" | "keepSnaps" |
slidesToScroll | 1 | number | "auto" |
dragFree | false | boolean |
dragThreshold | 10 | number |
inViewThreshold | 0 | number | number[] |
loop | false | boolean |
skipSnaps | false | boolean |
duration | 25 | number |
startIndex | 0 | number |
watchDrag | true | false | true | (emblaApi: EmblaCarouselType, evt: PointerEventType): boolean | void |
watchResize | true | false | true | (emblaApi: EmblaCarouselType, entries: ResizeObserverEntry[]): boolean | void |
watchSlides | true | false | true | (emblaApi: EmblaCarouselType, mutations: MutationRecord[]): boolean | void |
watchFocus | true | false | true | (emblaApi: EmblaCarouselType, evt: FocusEvent): boolean | void |
active | true | boolean |
breakpoints | {} | { [key: string]: Omit<Partial<CreateOptionsType<{ align: AlignmentOptionType; axis: AxisOptionType; container: string | HTMLElement | null; slides: string | HTMLElement[] | NodeListOf<HTMLElement> | null; containScroll: ScrollContainOptionType; direction: AxisDirectionOptionType; slidesToScroll: SlidesToScrollOptionType; dragFree: boolean; dragThreshold: number; inViewThreshold: number | number[] | undefined; loop: boolean; skipSnaps: boolean; duration: number; startIndex: number; watchDrag: DragHandlerOptionType; watchResize: ResizeHandlerOptionType; watchSlides: SlidesHandlerOptionType; watchFocus: FocusHandlerOptionType; }>>, "breakpoints">; } |
ui | { root?: SlotClass; viewport?: SlotClass; container?: SlotClass; item?: SlotClass; controls?: SlotClass; arrows?: SlotClass; prev?: SlotClass; next?: SlotClass; dots?: SlotClass; dot?: SlotClass; } |
| Slot | Type |
|---|---|
default | { item: T; index: number; } |
| Event | Type |
|---|---|
select | [selectedIndex: number] |
Você pode acessar a instância tipada do componente usando useTemplateRef.
<script setup lang="ts">
const carousel = useTemplateRef('carousel')
</script>
<template>
<NCarousel ref="carousel" />
</template>
Isso dará a você acesso ao seguinte:
| Name | Type |
|---|---|
emblaRef | Ref<HTMLElement | null> |
emblaApi | Ref<EmblaCarouselType | null> |
export default defineAppConfig({
ui: {
carousel: {
slots: {
root: 'relative focus:outline-none',
viewport: 'overflow-hidden',
container: 'flex items-start',
item: 'min-w-0 shrink-0 basis-full',
controls: '',
arrows: '',
prev: 'absolute rounded-full',
next: 'absolute rounded-full',
dots: 'absolute inset-x-0 -bottom-7 flex flex-wrap items-center justify-center gap-3',
dot: 'cursor-pointer size-3 bg-accented rounded-full transition'
},
variants: {
orientation: {
vertical: {
container: 'flex-col -mt-4',
item: 'pt-4',
prev: 'top-4 sm:-top-12 left-1/2 -translate-x-1/2 rotate-90 rtl:-rotate-90',
next: 'bottom-4 sm:-bottom-12 left-1/2 -translate-x-1/2 rotate-90 rtl:-rotate-90'
},
horizontal: {
container: 'flex-row -ms-4',
item: 'ps-4',
prev: 'start-4 sm:-start-12 top-1/2 -translate-y-1/2',
next: 'end-4 sm:-end-12 top-1/2 -translate-y-1/2'
}
},
active: {
true: {
dot: 'data-[state=active]:bg-inverted'
}
}
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
carousel: {
slots: {
root: 'relative focus:outline-none',
viewport: 'overflow-hidden',
container: 'flex items-start',
item: 'min-w-0 shrink-0 basis-full',
controls: '',
arrows: '',
prev: 'absolute rounded-full',
next: 'absolute rounded-full',
dots: 'absolute inset-x-0 -bottom-7 flex flex-wrap items-center justify-center gap-3',
dot: 'cursor-pointer size-3 bg-accented rounded-full transition'
},
variants: {
orientation: {
vertical: {
container: 'flex-col -mt-4',
item: 'pt-4',
prev: 'top-4 sm:-top-12 left-1/2 -translate-x-1/2 rotate-90 rtl:-rotate-90',
next: 'bottom-4 sm:-bottom-12 left-1/2 -translate-x-1/2 rotate-90 rtl:-rotate-90'
},
horizontal: {
container: 'flex-row -ms-4',
item: 'ps-4',
prev: 'start-4 sm:-start-12 top-1/2 -translate-y-1/2',
next: 'end-4 sm:-end-12 top-1/2 -translate-y-1/2'
}
},
active: {
true: {
dot: 'data-[state=active]:bg-inverted'
}
}
}
}
}
})
]
})