0.2.0 • Published 5 years ago

sky-swiper v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

sky-swiper

A versatile slot-based Vue swiper component

Installation

npm install sky-swiper

or

yarn add sky-swiper

Usage

Begin by importing and installing the SkySwiper Vue plugin

import Vue from 'vue';
import SkySwiper from 'sky-swiper';

Vue.use(SkySwiper);

The <SkySwiper /> component registers globally. It uses the items prop in conjunction with slots to allow you to render any kind of data inside the swiper.

Basic markup

Just content:

<SkySwiper
	:items="[
		{ imageSrc: '/link-to-image.jpg' },
		{ imageSrc: '/link-to-image-2.jpg' },
	]"
>
	<div slot="content" slot-scope="{ item }">
		<!-- Template for rendering an item here, ie: -->
		<img :src="item.imageSrc" />
	</div>
</SkySwiper>

Content and caption:

<SkySwiper
	:items="[
		{ imageSrc: '/link-to-image.jpg', description: 'Description text 1' },
		{ imageSrc: '/link-to-image-2.jpg', description: 'Description text 2' },
	]"
>
	<div slot="content" slot-scope="{ item }">
		<!-- Template for rendering an item here, ie: -->
		<img :src="item.imageSrc" />
	</div>

	<div slot="caption" slot-scope="{ item }">
		<!-- Template for captions, ie: -->
		<p v-text="item.description" />
	</div>
</SkySwiper>

Props

The component receives 4 props:

  • items: An array (required). Functions as the data layer of the swiper. The array can contain whichever kind of items you need since the content-slot functions as a template for rendering the data as well.
  • controls: Configure UI-elements to show inside the swiper content
  • navigation: Configure UI-elements to display outside the swiper content

Slots

The component provides these basic slots:

  • "content" - Required.. Uses data from the items prop. Scoped slot with these bindings: { item, index }
  • "caption" - Uses data from the items prop. Scoped slot with these bindings: { item, index }

Apart fron these there are more advanced slots for customizing the look in detail (more documentation needed):

  • "cursor" - Custom cursor icon. Scoped slot with these bindings: { direction, active, pressed }
  • "controls-next" - Custom next icon
  • "controls-previous" - Custom previous icon
  • "navigation-next" - Custom next icon (in the navigation)
  • "navigation-previous" - Custom previous icon (in the navigation)
  • "bullets" - Custom icon of the bullets in the navigation. Scoped slot with these bindings: { active, index }

Example

This basic concept can be expanded upon by using all available slots and configuration props to completely customize the swiper.

<SkySwiper
	:items="[
		{ imageSrc: '/link-to-image.jpg', description: 'Description text 1' },
		{ imageSrc: '/link-to-image-2.jpg', description: 'Description text 2' },
	]"
	:controls="{
		next: true,
		previous: false,
		cursor: true
	}"
	:navigation="{
		next: true,
		previous: false,
		indicator: 'bullets'
	}"
>
	<div slot="content" slot-scope="{ item }">
		<img :src="item.imageSrc" />
	</div>

	<div slot="caption" slot-scope="{ item }">
		<p v-text="item.description" />
	</div>

	<div slot="cursor" slot-scope="{ direction }">
		<img v-if="direction === 'next'" src="'/arrow-right.png'" />
		<img v-if="direction === 'previous'" src="'/arrow-left.png'" />
	</div>

	<div slot="controls-next">
		<img src="'/arrow-right.png'" />
	</div>

	<div slot="navigation-next">
		<img src="'/arrow-small-right.png'" />
	</div>

	<div slot="bullet" slot-scope="{ active }">
		<img v-if="active" src="'/bullet-active.png'" />
		<img v-else src="'/bullet.png'" />
	</div>
</SkySwiper>

Credits

This module is made by the front-end team at Skybrud.dk. Feel free to use it in any way you want. Feedback, questions and bug reports should be posted as issues. Pull-requests appreciated!

2.0.0-2

5 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago

1.0.0-1

5 years ago

1.0.0-0

5 years ago

0.2.0

6 years ago

0.2.0-0

6 years ago

0.1.1

6 years ago

0.1.1-0

6 years ago

0.1.0

6 years ago

0.1.0-0

6 years ago

0.0.7-1

6 years ago

0.0.7-0

6 years ago

0.0.6-0

6 years ago

0.0.5-0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago