2.0.2 • Published 2 years ago

@gluedigital/react-carousel v2.0.2

Weekly downloads
10
License
MIT
Repository
-
Last release
2 years ago

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.

2.0.2

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago