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

preact-glide

v1.1.8

Published

A simple wrapper for creating Glide JS carousels with Preact components

Downloads

11

Readme

Preact Glide

A simple wrapper for creating Glide JS carousels with Preact components

Contents

Installation

npm install preact-glide

Basic Example

const Carousel = require('preact-glide')

const App = () => {
  return (
    <Carousel>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

Styles

Component

Automatically include styles. Uses glideClass if set.

const App = () => {
  return <Carousel styles>{slides}</Carousel>
}

Import

Less Import

@import './node_modules/preact-glide/styles/carousel.less';

Overriding default className

In the case that you are using a non-standard className (when overriding glideClass prop) you can override the default @glideClass less variable as follows:

@import './node_modules/preact-glide/styles/carousel.less';
@glideClass: ~'.new-class';

Scss Import

@import './node_modules/preact-glide/styles/carousel.scss';

Overriding default className

In the case that you are using a non-standard className (when overriding glideClass prop) you can override the default $glideClass less variable as follows:

@import './node_modules/preact-glide/styles/carousel.scss';
$glideClass: '.new-class';

Props

glideClass

(String)

Used to override the default Glide className glide.

Example:

const App = () => {
  return (
    <Carousel glideClass={'new-class'}>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

glideOptions

(Object)

Glide JS options object: https://glidejs.com/docs/options/

glideComponents

(Object)

Glide JS Components object: https://glidejs.com/docs/extending-components/

glideEvents

(Array)

List of Glide events with callbacks. Events are passed in the following format:

{
  event: '' // Event name
  cb: () => {} // Callback function
}

Example:

const glideEvents = [
  {
    event: 'run.after'
    cb: () => alert('Hello, world!')
  }
]

arrows

(Boolean | Component)

Set true to use default component.

Example (Default):

const App = () => {
  return (
    <Carousel arrows>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

Example (Custom Component):

const CustomArrows = () => <div>Arrows</div>

const App = () => {
  return (
    <Carousel arrows={<CustomArrows />}>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

bullets

(Boolean | Component)

Set true to use default component.

Example (Default):

const App = () => {
  return (
    <Carousel bullets>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

Example (Custom Component):

const CustomBullets = () => <div>Bullets</div>

const App = () => {
  return (
    <Carousel bullets={<CustomBullets />}>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

controls

(Boolean | Component)

Set true to use default component.

Example (Default):

const App = () => {
  return (
    <Carousel controls>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

Example (Custom Component):

const CustomControls = () => <div>Controls</div>

const App = () => {
  return (
    <Carousel controls={<CustomControls />}>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

styles

(Boolean)

Set true to include default styles - uses glideClass by default.

Example:

const Carousel = require('preact-glide')

const App = () => {
  return (
    <Carousel styles>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

title

(Component)

Used to pass in a component that sits above the carousel.

Example:

const Carousel = require('preact-glide')

const Title = () => <div>Title</div>

const App = () => {
  return (
    <Carousel title={<Title />}>
      {slides.map(slide => (
        <div>Slide</div>
      ))}
    </Carousel>
  )
}

Slide Events

onView

A function that will fire when the slide comes into view.

Note: The onView prop must be on the top most element.

Example:

const Carousel = require('preact-glide')

const App = () => {
  return (
    <Carousel>
      {slides.map(slide => (
        <div onView={() => alert('Viewed')}>Slide</div>
      ))}
    </Carousel>
  )
}

onClick

Bypasses a slight bug with GlideJs where dragging the top most element would also count as a 'click'.

Overrides the default onClick property on the top most element. Fires the function only when a 'click' occurs, not on 'drag'.

Note: Only overrides the onClick for the top most element.

Example:

const Carousel = require('preact-glide')

const App = () => {
  return (
    <Carousel>
      {slides.map(slide => (
        <div onClick={() => alert('Clicked')}>Slide</div>
      ))}
    </Carousel>
  )
}

Components

Single components can be exported from preact-glide/components

const {
  Arrows,
  Bullets,
  Container,
  Controls,
  Title,
  Track
} = require('preact-glide/components')

Arrows

  • glideClass - Override default glide class
  • arrows - Override default component
const { Arrows } = require('preact-glide/components')

const App = () => {
  return <Arrows />
}

Bullets

  • glideClass - Override default glide class
  • bullets - Override default component
  • children - Array of Slides
const { Bullets } = require('preact-glide/components')

const App = () => {
  return <Bullets>{arrayOfSlides}</Bullets>
}

Container

  • glideClass - Override default glide class
const { Container } = require('preact-glide/components')

const App = () => {
  return <Container />
}

Controls

  • glideClass - Override default glide class
  • controls - Override default component
const { Controls } = require('preact-glide/components')

const App = () => {
  return <Controls />
}

Title

  • glideClass - Override default glide class
  • title - Component or string to be rendered
const { Title } = require('preact-glide/components')

const App = () => {
  return <Title />
}

Track

  • glideClass - Override default glide class
  • children - Array of Slides
const { Track } = require('preact-glide/components')

const App = () => {
  return (
    <Track>
      {arrayOfSlides}
    <Track/>
  )
}

Hooks

The hooks can be exported from preact-glide/hooks

const { useGlide } = require('preact-glide/hooks')

useGlide

Takes an object as a parameter with the following properties

  • carouselRef - (required) useRef reference to carousel element
  • glideOptions - Glide JS options object: https://glidejs.com/docs/options/
  • glideComponents - Glide JS Components object: https://glidejs.com/docs/extending-components/
  • glideEvents - List of Glide events with callbacks.
const { useGlide } = require('preact-glide/hooks')

const App = () => {
  const carouselRef = useRef()

  useGlide({ carouselRef })

  return (
    <div className={`glide`} ref={carouselRef}>
      <div className={`glide__track`} data-glide-el='track'>
        <ul className={`glide__slides`}>
          <li className={`glide__slide`}>Slide</li>
        </ul>
      </div>
    </div>
  )
}

Note: HTML structure inside carouselRef will need to contain the glide structure and classes