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

@glitch-txs/react-swiper

v0.3.7

Published

1. import Swiper component 2. import useSwiper hook 3. setup CSS files for the swiper component

Downloads

46

Readme

Important steps:

  1. import Swiper component
  2. import useSwiper hook
  3. setup CSS files for the swiper component

NPM URL

How to use:

Install npm package

npm i @glitch-txs/react-swiper

import Swiper component and useSwiper hook:

import { Swiper, useSwiper } from '@glitch-txs/react-swiper'

Set up the swiper, you will need to pass CSS classes to the swiper to be able to have full control on styling (wrapperClass and containerClass).

Here I'm using CSS modules:

export default function YourComponent() {

  const { provider, handleNext, handlePrev } = useSwiper()
  
  return (
    <div className={styles.container}>

        <Swiper provider={provider} wrapperClass={styles.wrapperClass} containerClass={styles.containerClass}>

            Your slides here...

        </Swiper>

        <div className={styles.controlsContainer} >
            <button onClick={handlePrev}>
                Left
            </button>

            <button onClick={handleNext}>
                Right
            </button>
        </div>

    </div>    

Clickable

If you want to have clickable components inside the swiper use the prop clickable.

If you are using images remember to add the prop draggable={false}

        <Swiper provider={provider} clickable wrapperClass={styles.wrapperClass} containerClass={styles.containerClass}>

          <Image src='mySrc' draggable={false} alt='myImg' />

        </Swiper>

Adding auto-slide:

  const { provider, handleNext, handlePrev, handleGoTo, autoStart, autoStop, inView } = useSwiper()

  useEffect(()=>{

    //the auto-slide will only be active when the component is in view.
    if(inView){
      //the argument taken by autoStart is the time in miliseconds for each slide. 
      autoStart()
    } else {
      autoStop()
    }

    //autoStart uses eventListeners so we need to pass the same params used when returning.
    return ()=> autoStop()

  },[inView])

CSS files:

The Swiper component is built with two HTML Div's. One is the window (it will have overflow: hidden, so you will only see through it) that will wrap everything. And the child div that will be the container for all your slides, this one will be hidden by the most part.

.wrapperClass{
    /* the width and height must be equal to each slide individuly including their margins */
    width: 100%;
    max-width: 1000px;
    height: 250px;

    /* Needed overflow hidden - comment this line to see how the swiper works internaly */
    overflow: hidden;
}

.containerClass{
    /* Display flex will align the slides elements in one row */
    display: flex;

    /* Width is calculated multiplying the full width of the parent container by the number of slider elements inside the swiper,
    this way THIS container will take the width of the sum of all children elements. Width: calc(100% * numberOfCards) */

    /* Here there's number four because I'm using 4 cards */
    width: calc(100% * 4);
    height: 100%;

    z-index: 10;
}

Progress Points/bars

if you want to add a fixed component INSIDE the swiper you can pass a JSX variable to the component as progress

Hooks functions and variables

  • provider
  • handleNext
  • handlePrev
  • handleGoTo
  • autoStart
  • autoStop
  • inView
  • currentIndex

useSwiper arguments (Not Mandatory)

useSwiper hook takes an object as arguments with the following vaiables:

rerender: default = true, (This will render the whole component each time the currentIndex changes, you can turn this off if you're not using curentIndex variable)

widthOffset: default = 0, ( margin of the sliders if any. E.g: margin: 0 5px 0 5px ==> widthOffset = 10 )

transitionTime: default = 300 (The time in miliseconds it takes to slide)

animationTime: default = 4000 (The time in miliseconds it will automatically move to the next slide)

async: default = false (if contenct is async set this to true and add a conditional for the Swipper component to render, you won't need to add width to the containerClass in this case.)

example:

export default function YourComponent() {

  const { provider } = useSwiper({ async: true })

  const [isData, setIsData] = useState<boolean>(false)

  useEffect(()=>{
    setIsData(true)
  },[isData])

  
  return (

    {
      isData && <Swiper provider={provider} wrapperClass={s.container} containerClass={s.slideContainer}>

        { data?.map((item, index)=>(
            <div key={index} className={s.slide}>

                Content Here

            </div>
        ))}

      </Swiper>
    }

  )
}

All functions must be disabled until the content is loaded.

GitHub examples are currently outdated.