2.0.1 • Published 3 years ago

react-rapid-carousel v2.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

react-rapid-carousel

A simple but epic React Responsive Carousel.

NPM JavaScript Style Guide

Install

npm install --save react-rapid-carousel

USAGE

clone and test our github repo https://github.com/chineduogada/react-rapid-carousel, and cd ./example/src/Demos for more examples

import React, { useState } from 'react'

import { Slider, Fader } from 'react-rapid-carousel'
import 'react-rapid-carousel/dist/index.css'
import Card from 'card' // this Component are `children` of the `Slider`. For the best visual results, don't add `width` style property on it or `width: auto` is still okay.

const App = () => {
  const [products, setHeroes] = useState([])
  useEffect(() => {
    setTimeout(() => {
      setHeroes([
        { id: 1, title: 'car' },
        { id: 1, title: 'bike' },
        { id: 1, title: 'phone' },
        { id: 1, title: 'laptop' }
      ])
    }, 1000)
  }, [])

  return (
    <div>
      <Slider>
        {products.map((hero) => (
          <Card data={hero} key={hero.id} />
        ))}
      </Slider>
      
      <Slider
        // the `length` is endless :)
        breakpoints={[
          // define any width you want to break, but from from small to large widths
          { width: 391, slidesToShow: 1 },
          { width: 592, slidesToShow: 2 },
          { width: 830, slidesToShow: 3 },
          { width: 920, slidesToShow: 4 }
        ]}
      >
        {products.map((hero) => (
          <Card data={hero} key={hero.id} style={{ width: 'auto' }} />

          // Bad `width` style prop :(, Don't do it! Allow the Component do it for you, or use `breakpoints`
      for responsive desire
          // <Card  style={{ width: '200px' }} data={hero} key={hero.id} />
        ))}
      </Slider>
      // Best for rendering static content (Synchronous rendering)
      <Fader>
        <div>hi</div>
        <div>hello</div>
        <div>welcome</div>
        <div>goodbye</div>
      </Fader>
    </div>
  )
}

API

Components

Slider

PropType/DefaultDescription
quickSlideboolean/falseWorks with autoSlide and depends on slidesToShow: basically moves in sections: which makes much faster
dotsboolean/falseDepends on slidesToShow: display dots below the Component for moving the slides to a particular section
buttonsboolean/trueDisplay caret button: (next and prev buttons) for moving the slide back and forth
slidesToShownumber/1The amount of slides to display at a time
transitionstring/"0.5s ease-in"Css transition property
childrenArray<HTMLElement> || HTMLElement/nullThese are the total amount slides to be eventually displayed: all slides, For the best visual results, don't add width style property on it or width: auto is still okay
breakpointsArray<{width: number: slidesToShow: number}>/nullFor responsive experience: widths should be arranged in an ascending manner/order to get the desired result
autoSlideboolean/false || {reverse: boolean/false, pauseOnHover: boolean/true, pauseOnTab: boolean/true, interval: number/3800}Adds animation: which happens after every interval which can be paused when the user hovers on the Slider or tabs on any focusable element and move in a reverse mode, if specified though

Fader component

Fader can only render one slide at a time: perfect for heroes, banners, ads etc.... has lesser functionalities (but slower in performance, and should be used for rendering static content for best performance).
PropType/DefaultDescription
dotsboolean/trueDepends on slidesToShow: display dots below the Component for moving the slides to a particular section
buttonsboolean/falseDisplay caret button: (next and prev buttons) for moving the slide back and forth
transitionstring/"0.5s ease-in"Css transition property
childrenArray<HTMLElement> || HTMLElement /nullThese are the total amount slides to be eventually displayed: all slides, For the best visual results, don't add width style property on it or width: auto is still okay
autoSlideboolean/true || {pauseOnHover: boolean/true, pauseOnTab: boolean/true, , interval: number/3800}Adds animation: which happens after every interval which can be paused when the user hovers on the Slider or tabs on any focusable element and move in a reverse mode, if specified though

ThemeProvider component

For changing the looks of buttons to match your brand

USAGE

import React, { useState } from 'react'

import { ThemeProvider, Slider, Fader } from 'react-rapid-carousel'
import 'react-rapid-carousel/dist/index.css'

const App = () => {
  return (
    <ThemeProvider
      theme={{
        dots: { 1: 'red', 2: 'orange' },
        carets: { 1: '#333', 2: '#3332' }
      }}
    >
      <Slider>
        <div>hi</div>
        <div>hello</div>
      </Slider>

      <ThemeProvider
        theme={{
          dots: { 1: 'blue', 2: 'cyan' },
          carets: { 1: 'gold', 2: 'rbg(20, 100, 225)' }
        }}
      >
        <Fader>
          <div>hi</div>
          <div>hello</div>
        </Fader>
      </ThemeProvider>
    </ThemeProvider>
  )
}

API

PropType / Default
themeObject / { dots: { 1: '#333', 2: '#3332' }, carets: { 1: '#333', 2: 'transparent' } }

License

MIT © chineduogada

2.0.1

3 years ago

2.0.0

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.3

4 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago