@gluedigital/react-carousel
v2.0.2
Published
react-carousel React component
Downloads
18
Keywords
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 verticalloop
: boolean, make the carousel loop around (ie: infinite)align
: [start|center|end], how to align elements relative to the viewportlockOnFit
: 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 slidetransform
: func, add other custom transforms to the one generated by Carouselid
: string, id for the wrapper div created by carouselclassName
: 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.