Skip to content

Slide Component ​

The Slide component is a fundamental building block of the carousel that represents individual slides. It manages slide visibility, positioning, and state transitions.

Basic Usage ​

vue
<template>
  <Carousel>
    <Slide v-for="slide in 10" :key="slide">
      <div class="carousel__item">
        {{ slide }}
      </div>
    </Slide>
  </Carousel>
</template>

Props ​

NameTypeDefaultDescription
indexNumber-Zero-based index position of the slide within the carousel

Slot Props ​

The default slot exposes these reactive properties for custom slide content:

NameTypeDescription
currentIndexNumberCurrent index position of the slide
isActiveBooleanTrue when this slide is the current active slide
isCloneBooleanTrue if this is a clone slide (used for infinite scroll)
isNextBooleanTrue if this slide is immediately after the active slide
isPrevBooleanTrue if this slide is immediately before the active slide
isSlidingBooleanTrue during slide transition animations
isVisibleBooleanTrue when the slide is within the visible viewport

Examples ​

Basic Slide ​

vue
<template>
  <Carousel>
    <Slide v-for="slide in 10" :key="slide">
      <div class="carousel__item">{{ slide }}</div>
    </Slide>
  </Carousel>
</template>

Custom Slide with State ​

vue
<template>
  <Carousel>
    <Slide v-for="slide in 10" :key="slide">
      <template #default="{ isActive, isVisible }">
        <div 
          class="carousel__item"
          :class="{
            'is-active': isActive,
            'is-visible': isVisible
          }"
        >
          <h3>Slide {{ slide }}</h3>
          <p>{{ isActive ? 'Current Slide' : 'Other Slide' }}</p>
        </div>
      </template>
    </Slide>
  </Carousel>
</template>

Styling ​

The component provides these CSS classes for styling:

CSS ClassDescription
.carousel__slideBase slide styles
.carousel__slide--activeActive slide styles
.carousel__slide--cloneCloned slide styles
.carousel__slide--nextNext slide styles
.carousel__slide--prevPrevious slide styles
.carousel__slide--slidingStyles during transitions
.carousel__slide--visibleVisible slide styles

Best Practices ​

  1. Always provide a unique :key when using v-for with Slides
  2. If you have a dynamic slides which changes its position consider use index prop

Released under the MIT License.