1.0.0 • Published 4 years ago

vue-card-carousel v1.0.0

Weekly downloads
20
License
MIT
Repository
github
Last release
4 years ago

Installation

npm i vue-card-carousel

You can choose to install either globally or locally:

Globally:

import Vue from 'vue'
import App from './App.vue'
import VueCardCarousel from "vue-card-carousel";

Vue.use(VueCardCarousel)

new Vue({
  el: '#app',
  render: h => h(App)
})

or locally to a component:

import { VueCardCarousel } from "vue-card-carousel";

export default {
    components: {
        VueCardCarousel
    }
}

Usage

Most basic usage would be adding the component and passing in the array of items you want displayed. Note you will need to set the minimum height of the component, otherwise it won't display. The width will take up 100% by default. These can be easily configured via CSS.

<template>
  <div id="app">
    <VueCardCarousel class="vcc" :items="listOfTodos" />
  </div>
</template>

<script>
import { VueCardCarousel } from "vue-card-carousel";

export default {
  components: {
    VueCardCarousel
  },
  data() {
    return {
      listOfTodos: [{ id: 1 }, { id: 2 }, { id: 3 }]
    };
  }
};
</script>

<style scoped>
  .vcc {
    height: 50vh;
    width: 60vw;
  }
</style>

However this will be relatively uninteresting. To make the most use of this component, you'll want to add customizations via props and slots like below:

<template>
  <div id="app">
    <VueCardCarousel
      class="vcc"
      :items="listOfTodos"
      :header-options="headerOpt"
      :footer-options="footerOpt"
    >
      <template v-slot:header="slotProps">
        <strong>Header. Id: {{ slotProps.headerProp.id }}</strong>
      </template>
      <template v-slot:default="slotProps">
        <div v-for="n in 5" :key="n">
          {{ slotProps.bodyProp.cMainId }}. Hello from the Parent.
        </div>
      </template>
      <template v-slot:footer="slotProps">
        <strong>Footer. Id: {{ slotProps.footerProp.id }}</strong>
      </template>
    </VueCardCarousel>
  </div>
</template>

<script>
import { VueCardCarousel } from "vue-card-carousel";

export default {
  components: {
    VueCardCarousel
  },
  data() {
    return {
      listOfTodos: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }],
      headerOpt: { isVisible: true, backgroundColor: "green" },
      footerOpt: { isVisible: false }
    };
  }
};
</script>

<style scoped>
  .vcc {
    height: 50vh;
    width: 60vw;
  }
</style>

Props

PropertyTypeDefaultRequiredDescription
itemsArraytrueList of items to used to generate the scrollable cards.
startIndexNumber0falseIndex of the card you want to be centered on first. Removes trailing digits if found.
hideBackdropBooleanfalsetrueShows/hides the backdrop. Akin to a modal backdrop.
sideCardOpacityNumber0.25falseSets the minimum opacity for the cards on either side of the center card.
headerOptionsObjectfalseSee details below for available properties.
footerOptionsObjectfalseSee details below for available properties.

headerOptions

PropertyTypeDefaultRequiredDescription
isVisibleBooleantrueControls whether or not the header is displayed.
backgroundColorStringfalseAny valid CSS color.

footerOptions

PropertyTypeDefaultRequiredDescription
isVisibleBooleantrueControls whether or not the footer is displayed.
backgroundColorStringfalseAny valid CSS color.

Slots

Scoped slots are exposed for each sub-section of the card: header, body, and footer. Each slot has slot props which give access to the individual item from the list that was passed in through the items property, so you can use that data to fully customize the card.

NameDescriptionScope
headerIndividual item from the list passed in through the items prop.headerProp
defaultIndividual item from the list passed in through the items prop.bodyProp
footerIndividual item from the list passed in through the items prop.footerProp

In the above example, we have named the object containing all our slot props slotProps, but you can choose to call this anything. More info can be found here: https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots

Demo

Interactive demo located here along with the source code.

License

MIT

1.0.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago