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

@jpd.nz/react-card-carousel

v0.0.24

Published

A basic card carousel for react, usable with items of either fixed or variable widths.

Downloads

116

Readme

React Card Carousel

@jpd.nz/react-card-carousel

A basic card carousel for react, usable with items of either fixed or variable widths.

To play around with the example code, head over to the github repo and download the source. Change (cd) into the example/ directory, run npm install then npm run start. Open /example/src/__example.js to modify the carousel settings.

Install

Instal the package via npm or yarn:

npm i -s '@jpd.nz/react-card-carousel'
yarn add '@jpd.nz/react-card-carousel'

Usage

import { useRef } from 'react'
import CardCarousel from '@jpd.nz/react-card-carousel'

const MyComponent = () => {

  const myCarouselRef = useRef()

  const settings = {
    pagination: true,
    arrows: true,
    touchControls: true,
    beforeChange: (currentIndex, newIndex) => {
      console.log('Before Change', currentIndex, newIndex)
    },
    afterChange: (newIndex) => {
      console.log('After Change', newIndex)
    }
  }

  const carouselItems = [
    {
      title: 'Carousel Card 01',
      image: '/path/to/my-image-01.jpg',
      alt: 'my image alt text'
    },
    {
      title: 'Carousel Card 02',
      image: '/path/to/my-image-02.jpg',
      alt: 'my image alt text'
    },
    {
      title: 'Carousel Card 03',
      image: '/path/to/my-image-03.jpg',
      alt: 'my image alt text'
    }
  ]

  return (
    <div className='my-component'>

      {/* Optionally you can define your own completely custom buttons */}
      {/* <button onClick={ () => myCarouselRef?.current?.prevCard() }>Prev</button> */}
      {/* <button onClick={ () => myCarouselRef?.current?.nextCard() }>Next</button> */}

      <CardCarousel ref={myCarouselRef} settings={settings}>
        {
          carouselItems?.map((card, key) => {
            return (
              <div key={key} className='my-carousel-card'>
                <img src={card.image} alt={card.title || card.alt} />
                { card.title && <p>{card.title}</p> }
              </div>
            )
          })
        }
      </CardCarousel>
    </div>
  )
}

export default MyComponent

Optional settings

Presentation settings

| Property | Type | Unit | Default | Description | | -------- | ---- | ---- | ------- | ------------------------------------- | | gap | int | px | 20 | Gap size between each card/silde | | padding | int | px | 50 | Padding value either side of the main card slider | | cardsToShow | int | n/a | 0 | Number of cards to display in one view. Set to 0 to inherit widths from card contents and support variable widths | | transitionSpeed | int | ms | 300 | Speed of the carousel move transition |

Control settings

| Property | Type | Unit | Default | Description | | -------- | ---- | ---- | ------- | ------------------------------------- | | pagination | bool | n/a | false | Enable or disable pagination | | touchControls | bool | n/a | true | Enable or disable touch controls | | arrows | bool | n/a | true | Enable or disable arrows | | nextArrow | html | n/a | false | Provide custom markup for the next button | | prevArrow | html | n/a | false | Provide custom markup for the prev button | | yieldToImages | bool | n/a | false | Whether to defer calculating the overall container width till all images have loaded. Useful if images have intrinsic dimentions. | | centerMode | bool | n/a | false | Center carousel on the current item. |

Event Hooks

| Name | Description | | ---- | ----------- | | beforeChange | Fires just before the change takes place, returns the currentIndex and the newIndex | | afterChange | Fires immediately after the change takes place, returns the newIndex | | onTouchStart | Fires immediately after the user touch starts, returns the startX | | onTouchMove | Fires immediately after the user touch move, returns the moveX | | onTouchEnd | Fires immediately after the user touch end, no return val |

Functions

| Name | Description | | ---- | ----------- | | nextCard() | Change to the next card | | prevCard() | Change to the previous card | | goToCard(index) | Change to a specific card, ignored if card is currently in view (must provide an index) | | getCurrentIndex() | Retrieve the current index the carousel is at |