1.0.0 • Published 5 years ago

v-slideshow v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

VSlideshow

VSlideshow is a customizable carousel. Focus on the transitions and the layout, VSlideshow will take care of the rest Under the hood, VSlideshow uses the built-in component <TransitionGroup> from Vue.js.

Download and import | Getting started | Examples

Download and import

npm i v-slideshow

Globally:

import Vue from 'vue';
import VSlideshow from 'v-slideshow';

Vue.use('VSlideshow', VSlideshow);

In component:

import VSlideshow from 'v-slideshow';

export default {
  components: { VSlideshow },
};

Via script:

<script src="https://unpkg.com/v-slideshow"></script>

Getting started

<div>
  <VSlideshow :slides="slides" @enter="enter" @leave="leave">
    <!-- Content inside a slide -->
    <template v-slot="{ slide }">
      <div>{{ slide.text }}</div>
    </template>

    <!-- Nav for the slideshow -->
    <template v-slot:nav="{ prev, next }">
      <button @click="prev">previous</button>
      <button @click="next">next</button>
    </template>
  </VSlideshow>
</div>

<script>
  import VSlideshow from '../src/v-slideshow';

  export default {
    components: { VSlideshow },

    data() {
      return {
        slides: [
          { id: 'slide-0', text: 'Slide 0' },
          { id: 'slide-1', text: 'Slide 1' },
          { id: 'slide-2', text: 'Slide 2' },
          { id: 'slide-3', text: 'Slide 3' },
          { id: 'slide-4', text: 'Slide 4' },
          { id: 'slide-5', text: 'Slide 5' },
        ],
      };
    },

    methods: {
      leave(data, done) {
        done();
      },

      enter(data, done) {
        done();
      },
    },
  };
</script>

API

Props

PropertyDescriptionTypeDefault
valueThe index of the current slideNumber0
slidesAn array of slidesArrayrequired
loopMake a loop whenever the slideshow reaches the endBooleantrue
safePrevents the slideshow to change the slide while there is a transition runningBooleantrue
listClassClass list applied on the list of the slidesString, Array, Objectnull
itemClassClass list applied on each slideString, Array, Objectnull

⚠️ The prop slides must by an array of objects. Each slide must contain a unique ID because of TransitionGroup. nanoid is a good option if you need to generate an ID.

Events

EventDescriptionParameters
before-enterBefore slide enterdata: Object
enterOn slide enter, make sure to call done when the transition is donedata: Object done: Function
after-enterAfter slide enterdata: Object
enter-cancelledOn cancellation of slide enterdata: Object
before-leaveBefore slide leavedata: Object
leaveOn slide leave, make sure to call done when the transition is donedata: Object done: Function
after-leaveAfter slide leavedata: Object
leave-cancelledOn cancellation of slide leavedata: Object
doneWhen enter and leave transitions are donedata: Object
inputWhen the current slide index changesvalue: Number

Composition of data

PropertyDescriptionType
elDOM element (not present for @done and @input)DOM Element
previousIndexThe index of the previous slideNumber
currentIndexThe index of the current slideNumber
slidesThe props slidesArray
totalThe number of slidesNumber
busyWhether a transition is runningBoolean

Scoped slots

Default

The content for each slide.

slot props
PropertyDescriptionType
previousIndexThe index of the previous slideNumber
currentIndexThe index of the current slideNumber
totalThe index of the previous slideNumber
busyThe index of the previous slideNumber
slidesThe slidesArray
goToThe method to go to a specific slideFunction
prevThe method to go to the previous slideFunction
nextThe method to go to the next slideFunction
slideThe slideObject
indexThe index of the slideNumber

Nav

The content for the nav.

slot props

Same as default slot except that there is no slide or index.

Methods

If you save a reference of VSlideshow (<VSlideshow ref="mySlideshow">), you will have access to some methods:

  • prev
  • next
  • goTo (arguments: index {number})

They all returns a promise resolved when the transition is done.

Examples

You can see some examples in the folder examples.

npm run serve