1.0.26 • Published 4 years ago

react-slim-carousel v1.0.26

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

react-slim-carousel

Minimal but feature-rich react carousel made using hooks.

NPM JavaScript Style Guide

Install

npm install --save react-slim-carousel

Demo

Edit React Slim Carousel Example

Usage

import React from 'react'

import {
  Carousel,
  CarouselProvider,
  Dots,
  PreviousButton,
  NextButton
} from 'react-slim-carousel'
import 'react-slim-carousel/dist/index.css'

export default function Example() {
  return (
    <CarouselProvider>
      <Carousel>
        <div>Slide 1</div>
        <div>Slide 2</div>
        <div>Slide 3</div>
      </Carousel>
      <Dots />
      <PreviousButton>Previous</PreviousButton>
      <NextButton>Next</NextButton>
    </CarouselProvider>
  )
}

Alternatively, you can use the HOC approach by wrapping your component in withCarousel()(Component). You should not use the <CarouselProvider> when using the HOC approach.

import React from 'react'

import { Carousel, withCarousel, useCarousel } from 'react-slim-carousel'
import 'react-slim-carousel/dist/index.css'

function Example() {
  const { currentSlide } = useCarousel()

  return (
    <>
      <Carousel>{/* Slides here */}</Carousel>
      <span>Current slide: {currentSlide}</span>
    </>
  )
}

export default withCarousel()(Example)

Options

SettingTypeDescriptionDefault
autoPlaybooleanAutoplay through slidesfalse
autoSizebooleanSet the height (or width) to the largest slide depending on the orientationtrue
centerModebooleanShow active slide in the centerfalse
draggablebooleanEnable/disable drag to slidetrue
easingstringCSS easing'ease-in-out'
edgeFrictionnumberResistance when swiping edges of non-infinite carousels0.3
gapnumberGap in pixels between each slide0
infinitebooleanIntinite loop slidingfalse
initialSlidenumberInitial slide to display0
intervalnumberTime in ms between autoplay sliding3000
orientation'horizontal' | 'vertical'Slider orientation'horizontal'
playDirection'normal' | 'reverse'Autoplay direction'normal'
slidesToScrollnumberNumber of slides to scroll1
slideSpeednumberTransition speed in ms400
thresholdnumberDrag threshold for scrolling to next slide0.2
visibleSlidesnumberNumber of slides visible1

Responsive

The Carousel component accepts an additional prop responsive which is an object with the keys being the pixel min width, and the value being settings to override.

Example:

<Carousel
  visibleSlides={2}
  responsive={{
    768: {
      visibleSlides: 4
    }
  }}
>
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</Carousel>

Styling

The bare minimum stylesheet should be imported from 'react-slim-carousel/dist/index.css'. Styles for the previous/next buttons and dots are not included and should be done by your app.

Available classes:

Carousel

ClassDescription
carouselBase class
carousel--horizontalWhen orientation is set to 'horizontal'
carousel--verticalWhen orientation is set to 'vertical'
carousel--center-modeWhen centerMode is enabled

Tray

The tray is the direct child of the carousel and contains the slides.

ClassDescription
carousel__trayBase class

Slide

ClassDescription
carousel__slideBase class
carousel__slide--activeWhen the slide is currently active

Previous button

ClassDescription
carousel-previous-btnBase class

Next button

ClassDescription
carousel-next-btnBase class

Dots

ClassDescription
carousel-dotsBase class

Dot

ClassDescription
carousel-dotBase class
carousel-dot--activeWhen current dot is active

License

MIT © Acidic9

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.23

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.11

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

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