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

@notbaldrick/react-crossfade-carousel

v1.0.4

Published

A simple react component for creating crossfade image carousels.

Downloads

254

Readme

@notbaldrick/react-crossfade-carousel

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save @notbaldrick/react-crossfade-carousel
yarn add @notbaldrick/react-crossfade-carousel

Showcase

gif-0

Click here to view an example.

Usage

import CrossfadeCarousel from '@notbaldrick/react-crossfade-carousel'

function Example() {
  return (
    <CrossfadeCarousel
      interval={3000}
      transition={2000}
      images={[
        'https://picsum.photos/id/118/1500/1000',
        'https://picsum.photos/id/120/4928/3264',
        'https://picsum.photos/id/127/4032/2272'
      ]}
    />
  )
}

props.images

You can put as much or as few images in the array as you want.

<CrossfadeCarousel
  images={[
    'https://picsum.photos/id/118/1500/1000',
    'https://picsum.photos/id/120/4928/3264',
    'https://picsum.photos/id/127/4032/2272'
  ]}
/>

props.cycle

If TRUE the cycle prop will loop through all the images. You can set the cycle prop to FALSE to pause the cycling of images.

function example() {
  const [pause, setPause] = useState(false)

  return <CrossfadeCarousel cycle={pause} onClick={() => setPause(!pause)} />
}

props.interval

Interval is the time in milliseconds where the image is shown before transitioning to the next.

<CrossfadeCarousel interval={6900} />

props.transition

Transition is the time in milliseconds where one image transitions to the next.

<CrossfadeCarousel transition={4200} />

props.forceActiveImage

By default it's set to NULL, but if given a number the carousel will show the corresponding image. For example if given the value of 2 the carousel will show the third image in the array. If it's a TRUTHY value then the cycling of images will stop, even if the cycle prop is set to TRUE.

const images = [
  'https://picsum.photos/id/118/1500/1000',
  'https://picsum.photos/id/120/4928/3264',
  'https://picsum.photos/id/127/4032/2272'
]

function Example() {
  const [activeImage, setActiveImage] = useState(0)

  function nextImage() {
    setActiveImage(active === props.images.length - 1 ? 0 : active + 1)
  }

  function previousImage() {
    setActiveImage(activeImage === 0 ? images.length - 1 : active - 1)
  }

  return (
    <>
      <button onClick={nextImage}> Next Image </button>
      <button onClick={previousImage}> Previous Image </button>
      <CrossfadeCarousel images={images} forceActiveImage={activeImage} />
    </>
  )
}

props.imageProps

Add props to every image component.

<CrossfadeCarousel
  imageProps={{
    onClick: () => console.log('Heyo')
  }}
/>

props.imageStyles

Add inline styles to every image component.

<CrossfadeCarousel
  imageStyles={{
    filter: 'blur(2px)'
  }}
/>

API

| Name | Required | Type | Default | | ---------------- | -------- | ------- | ---------- | | images | no | array | [3 images] | | cycle | no | boolean | true | | interval | no | number | 5000 | | transition | no | number | 5000 | | forceActiveImage | no | number | null | | imageProps | no | object | {} | | imageStyles | no | object | {} |

License

MIT © NotBaldrick