An open API service indexing awesome lists of open source software.

https://github.com/melvynx/react-clear-carousel

simple and light react carousel
https://github.com/melvynx/react-clear-carousel

carousel light react simple slider small typescript very-light

Last synced: 7 months ago
JSON representation

simple and light react carousel

Awesome Lists containing this project

README

          


Capture d’écran 2021-04-10 aΜ€ 18 44 10


npm minified size
package version
license

Chat on Discord
typescript

Starship with iTerm2 and the Snazzy theme

Clear react carousel easy to integrate, he is very light and use 0 dependency.
It is a carousel that will be customizable and offers great posibilities.

Go test the demo online [react-clear-carousel demo](https://melvynx.github.io/react-clear-carousel/).

## Why

I needed to make a really simple carousel. I looked for a library, but none was as light, simple and modular as I wanted.
So I made my carousel and once finished I wanted to share it.

## Quick startup πŸš€

#### - Install the npm dependency in a react project

```bash
npm install --save react-clear-carousel
# of
yarn add react-clear-carousel
```

## Usage πŸ› 

This is the most minimal exemple.

```tsx
import React from 'react'

import {
CarouselElement,
CarouselWrapper,
NextSlideAction,
PrevSlideAction,
SliderElementProps
} from 'react-clear-carousel'

const datas = [
{ id: 0, text: 'slider 1' },
{ id: 1, text: 'slider 2' },
{ id: 2, text: 'slider 3' }
]

const Carousel = () => {
return (







Prev


Next



)
}

const Element = ({
className,
data
}: SliderElementProps<{ id: number; text: string }>) => {
return (



{data?.text}




)
}
```

## How πŸ•΅οΈβ€β™‚οΈ

The carousel is a delimited element that has an `overflow: hidden` (🟠 orange box) with a much longer child (πŸ”΅ blue box) that contains the slides (🟒 green box) and that will change the number of pixels to be moved to the left during a slide animation.

schema exemple

## API πŸ‘

#### useSimpleSlider

This hook is used by the CarouselWrapper.

```ts
import { useSimpleSlider } from 'react-clear-carousel'

export type SimpleSliderConfig = {
listLength: number // length of your datas
size: {
element: number // size of one element
margin: number // margin of one element
}
reverse?: boolean // true and the carousel go left to right
transition?: string // transition when carousel slide change
}

function useSimpleCarousel(
config: SimpleSliderConfig
): {
nextSlide: () => void // handle the next slide
prevSlide: () => void // handle the prev slide,
setSlide: () => void // set slide to specific id,
classes: {
// different class for elements
card: string
flexBox: string
root: string
}
}
```

#### CarouselWrapper

```ts
import { CarouselWrapper } from 'react-clear-carousel'

export type CarouselWrapperProps = {
datas: T[] // data given for different slide
currentSize: {
element: number // size of one element
margin: number // margin of one element
}
children: React.ReactElement | React.ReactElement[]
reverse?: boolean // true and the carousel go left to right
transition?: string // transition when carousel slide change
}

function CarouselWrapper(props: CarouselWrapperProps)
```

#### CarouselElement

This element use the context of CarouselWrapper.

```ts
import { CarouselElement } from 'react-clear-carousel'

type HorizontalSliderProps = {
children: React.ReactElement // element for each slide
rootClassname?: string // classname for the root
elementBoxClassname?: string // classname for elements flex box
}

function CarouselElement(props: HorizontalSliderProps)
```

#### NextSlideAction

Those elements use the context of CarouselWrapper.

The children will have a `onClick` props to handle next / prev slide.

```tsx
import { NextSlideAction, PrevSlideAction } from 'react-simple-slider'

const Buttons = () => (



Prev slide


Next slide


)
```

## License

MIT Β© [Melvynx](https://github.com/Melvynx)