npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@braedencrankd/alpine-swiper

v0.2.1

Published

An AlpineJS plugin for using the SwiperJS with Alpine Directives

Downloads

33

Readme

alpine-swiper

DISCLAIMER: This package is still in active development and is not ready for production use. I'm open to any suggestions on improving this package.

An AlpineJS plugin to create a SwiperJS slider using the elegance alpine directives.

Resources

Table of Contents

Installation

To install the "alpine-swiper" package, you can use npm, pnpm or yarn. Run the following command in your project directory:

npm install @braedencrankd/alpine-swiper
# or
yarn add @braedencrankd/alpine-swiper
# or
pnpm add @braedencrankd/alpine-swiper

Setup

Import the alpine-swiper plugin in your project entry point.

import alpineSwiper from "alpine-swiper";
Alpine.plugin(alpineSwiper);

Usage

Basic Usage

Define the x-swiper directive on the swiper container element. Inside the container element, you must define a wrapper element with the class swiper-wrapper. Each child element can be defined as a slide using the class swiper-slide.

Note: make sure to add the x-init or x-data directive to the container element to ensure the swiper is initialized when Alpine is loaded.

<div x-init>
  <div x-swiper>
    <!-- Additional required wrapper -->
    <div class="swiper-wrapper">
      <!-- Slides -->
      <div class="swiper-slide">Slide 1</div>
      <div class="swiper-slide">Slide 2</div>
      <div class="swiper-slide">Slide 3</div>
      <div class="swiper-slide">Slide 4</div>
    </div>
  </div>
</div>

Modifiers Syntax

Use the x-swiper directive to initialize the swiper component.

The simplist way to configure the slider is to use modifiers. The following example will create a slider with 3 slides per view, space between slides of 20px.

<div x-swiper.space-between.20.slides-per-view.3>...</div>

You can also define the breakpoints for the slider using modifiers. The following example will create a slider with 3 slides per view, space between slides of 20px on screens larger than 640px, and 1 slide per view, space between slides of 10px on screens smaller than 640px.

<div x-swiper.space-between.20.slides-per-view.1.lg:slides-per-view.3>...</div>

Each modifier usually has a following modifier to define the value. Eg. slides-per-view.1 or slides-per-view.3.

Properties that are booleans are defined without a value for brevity. Eg. loop or autoplay.

Note: Each modifier corresponds to the options defined by the SwiperJS package: the documentation can be found here.

Config Object Syntax

Alternativly you can use the x-swiper directive with a config object. The following example will create a slider with 3 slides per view, space between slides of 20px.

<div x-swiper="{ spaceBetween: 20, slidesPerView: 3 }">...</div>

Available Swiper Modules

Only some of the SwiperJS modules are available for now. The following modules are listed below:

These modules can be used by there associated properties. For example autoplay can be used by addding the autoplay modifier to the x-swiper directive.

<div x-swiper.autoplay>...</div>

The swiper navigation buttons can be added by adding an additional navigation directive type.

<div
  x-swiper
  x-swiper:navigation="{
      nextEl: '.product-swiper-next',
      prevEl: '.product-swiper-prev'
    }"
>
  ...
</div>