To make carousel more flexible, I created layout system.
You need to pass layout
prop to define how the carousel should look like.
And optionally you can pass layout-props
prop to pass some props to the specific layout.
Put the layout component in the layout
prop. You can also pass layout props there:
<template> <GSCarousel :layout="GSLayoutNumeric" :layout-props="{ disableArrows: true, }" > <!-- ... --> </GSCarousel></template>
import { GSCarousel, GSLayoutDefault } from 'gitart-scroll-carousel/bundled'import 'gitart-scroll-carousel/dist/index.css'import 'gitart-scroll-carousel/dist/GSArrow.css' import 'gitart-scroll-carousel/dist/ExampleLayoutDefault.css'
GSArrow.css
is unnecessary if disableArrows=true
disableArrows
Boolean
false
import { GSCarousel, GSLayoutDefault } from 'gitart-scroll-carousel/bundled'import 'gitart-scroll-carousel/dist/index.css'import 'gitart-scroll-carousel/dist/GSArrow.css' import 'gitart-scroll-carousel/dist/GSLayoutNumeric.css'
GSArrow.css
is unnecessary if disableArrows=true
disableArrows
Boolean
false
disableCounter
Boolean
false
percentCounter
Boolean
false
How pre-defined layouts are made you can see here
Our layouts can accept few props and slots from the GSCarousel.
onMove
- method to move the carousel. pass 1 or -1 to move the carousel.disabledSide
- 'left' | 'right' | 'none'
- disabled side of the carousel.currentItem
currentItemByPercent
items
initialized
<!-- ... --><slot name="track" /><div> <slot name="indicator" /></div><!-- ... -->
CustomLayout.vue
<script lang="ts">import type { PropType } from 'vue'import { defineComponent } from 'vue'export default defineComponent({ name: 'CustomLayout', props: { onMove: { type: Function as PropType<(to: number) => void>, required: true, }, disabledSide: { type: String as PropType<'left' | 'right' | 'none'>, required: true, }, currentItem: { type: Number, required: true, }, items: { type: Array as PropType<any[]>, required: true, }, /** * layout specific props */ title: { type: String, required: true, }, },})</script><template> <div> <div class="custom-layout-header"> <div class="custom-layout-header__title"> {{ title }} </div> <div class="custom-layout-header__indicator"> <slot name="indicator" /> </div> </div> <slot name="track" /> <div class="custom-layout-arrows"> <div @click="onMove(-1)"> {{ '<' }} </div> <div @click="onMove(1)"> {{ '>' }} </div> </div> </div></template><style lang="scss" scoped>.custom-layout-header { display: flex; align-items: center; gap: 20px; &__title { font-size: 1.5rem; font-weight: 500; line-height: 1.5; } &__indicator { flex: 1; }}.custom-layout-arrows { display: flex; div { background: #6366f1; margin: 5px; padding: 10px; }}</style>
<template> <GSCarousel :items="items" :items-to-show="2" :layout="CustomLayout" :layout-props="{ title: 'Hello Custom Layout', }" > <template #item="{ data }"> <!-- ... --> </template> </GSCarousel></template>