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

@gluedigital/react-carousel

v2.0.2

Published

react-carousel React component

Downloads

18

Readme

react-carousel

A simple but customizable carousel component for React.

Can be used horizontally or vertically, with or without looping, and with different-sized slides. It can also show any number of slides at the same time.

Usage

Install it on your project with:

npm install @GlueDigital/react-carousel

Then just import it and use it like this:

import Carousel from '@GlueDigital/react-carousel'

function MyComponent() {
  return (
    <Carousel>
      <div className="slide">Slide #1</div>
      <div className="slide">Slide #2</div>
      <div className="slide">Slide #3</div>
    </Carousel>
  )
}

Options

These are the available props you can use with Carousel:

  • vertical: boolean, make the carousel vertical
  • loop: boolean, make the carousel loop around (ie: infinite)
  • align: [start|center|end], how to align elements relative to the viewport
  • lockOnFit: boolean, make the carousel static if all elements fit into it (instead of adding padding to align each slide)
  • dots: component to show the "dots" indicating the current slide
  • transform: func, add other custom transforms to the one generated by Carousel
  • id: string, id for the wrapper div created by carousel
  • className: string, extra className for the wrapper div created by carousel

Transform

This component sets c.style.transform = 'translateX(...)' on the child elements, so if you want to add other transforms to them, they would get overwritten.

To fix this, you can provide a transform function which will receive our translate string, and an active index (number between 0 and 1 that indicates how close to the center is the child) so you can generate the full transform.

It's easier to grasp it with an example:

const transform = ({ baseTransform, activePercent }) => baseTransform + " scaleY(" + activePercent + ")"
// ...
return <Carousel transform={transform}>...</Carousel>

Styling guide

Carousel wraps your contents with a div.carousel-wrapper with position: relative so the slides can be positioned easily.

By default, each slide is stretched to the wrapper size so it fits exactly, but you can override the width and height, and Carousel will calculate the right snap points.

Please don't set left/top, as these properties are controlled by Carousel.