9.1.3 • Published 20 days ago

react-simply-carousel v9.1.3

Weekly downloads
2,589
License
MIT
Repository
github
Last release
20 days ago

react-simply-carousel

npm version minified + gzip typescript GitHub license

A simple, lightweight, fully controlled isomorphic (with SSR support) React.js carousel component. Touch enabled and responsive. With support for autoplay and infinity options. Fully customizable

Table of contents

Installation

npm

npm install react-simply-carousel --save

yarn

yarn add react-simply-carousel

Usage

Basic Example:

import { useState } from 'react';
import ReactSimplyCarousel from 'react-simply-carousel';

function ReactSimplyCarouselExample() {
  const [activeSlideIndex, setActiveSlideIndex] = useState(0);

  return (
    <div>
      <ReactSimplyCarousel
        activeSlideIndex={activeSlideIndex}
        onRequestChange={setActiveSlideIndex}
        itemsToShow={1}
        itemsToScroll={1}
        forwardBtnProps={{
          //here you can also pass className, or any other button element attributes
          style: {
            alignSelf: 'center',
            background: 'black',
            border: 'none',
            borderRadius: '50%',
            color: 'white',
            cursor: 'pointer',
            fontSize: '20px',
            height: 30,
            lineHeight: 1,
            textAlign: 'center',
            width: 30,
          },
          children: <span>{`>`}</span>,
        }}
        backwardBtnProps={{
          //here you can also pass className, or any other button element attributes
          style: {
            alignSelf: 'center',
            background: 'black',
            border: 'none',
            borderRadius: '50%',
            color: 'white',
            cursor: 'pointer',
            fontSize: '20px',
            height: 30,
            lineHeight: 1,
            textAlign: 'center',
            width: 30,
          },
          children: <span>{`<`}</span>,
        }}
        responsiveProps={[
          {
            itemsToShow: 2,
            itemsToScroll: 2,
            minWidth: 768,
          },
        ]}
        speed={400}
        easing="linear"
      >
        {/* here you can also pass any other element attributes. Also, you can use your custom components as slides */}
        <div style={{ width: 300, height: 300, background: '#ff80ed' }}>
          slide 0
        </div>
        <div style={{ width: 300, height: 300, background: '#065535' }}>
          slide 1
        </div>
        <div style={{ width: 300, height: 300, background: '#000000' }}>
          slide 2
        </div>
        <div style={{ width: 300, height: 300, background: '#133337' }}>
          slide 3
        </div>
        <div style={{ width: 300, height: 300, background: '#ffc0cb' }}>
          slide 4
        </div>
        <div style={{ width: 300, height: 300, background: '#ffffff' }}>
          slide 5
        </div>
        <div style={{ width: 300, height: 300, background: '#ffe4e1' }}>
          slide 6
        </div>
        <div style={{ width: 300, height: 300, background: '#008080' }}>
          slide 7
        </div>
        <div style={{ width: 300, height: 300, background: '#ff0000' }}>
          slide 8
        </div>
        <div style={{ width: 300, height: 300, background: '#e6e6fa' }}>
          slide 9
        </div>
      </ReactSimplyCarousel>
    </div>
  );
}

export default ReactSimplyCarouselExample;

Props

NameTypeDefault ValueDescription
activeSlideIndexnumberIndex of active slide
activeSlidePropsobject{}DOM props for active slide element
autoplaybooleanfalse
autoplayDirectionstring ('forward' or 'backward')'forward'
backwardBtnPropsobject{}DOM props for carousel backward nav button element (include boolean prop show (for toggle button render) and node prop children (for render button childrens))
childrennodenullslides array
containerPropsobject{}DOM props for carousel container div element
delaynumber0Slide change delay (css transition delay) in ms
disableNavIfAllVisiblebooleantrueDisable carousel nav if all slides is visible
easingstring'linear'Slide change easing (css transition easing)
forwardBtnPropsobject{}DOM props for carousel forward nav button element (include boolean prop show (for toggle button render) and node prop children (for render button childrens))
hideNavIfAllVisiblebooleantrueHide nav buttons if all slides is visible
innerPropsobject{}DOM props for inner div element
itemsListPropsobject{}DOM props for items list div element
itemsToScrollnumber1How many slides to scroll at once
itemsToShownumber0 (automaticaly calculated)How many slides to show
onAfterChangefunctionnullactiveSlideIndex change callback
onRequestChangefunctionCallback to handle every time the active slide changes, receives the new active index as first argument and info about visible slides ({ isFirstSlideVisible: boolean;isLastSlideVisible: boolean;visibleSlides: { slideIndex: number; isFullyVisible: boolean }[];}) as second.
responsivePropsArray of objects[]carousel props for different window width. For example: [{minWidth: 768, maxWidth: 992, itemsToShow: 3}, {maxWidth: 767, itemsToShow: 1}] will show only one slide when window width is less than 767px and show 3 slides when window width is >= 768px and < 992px
speednumber0Carousel scroll speed (css transition speed) in ms
updateOnItemClickbooleanfalseUpdate active item index after click on some slide
centerMode (disabled if infinite prop disabled)booleanfalseAlign active slide to the center of the carousel container viewport
infinitebooleantrueEnable infinite loop scroll
disableNavIfEdgeVisible (disabled if infinite prop enabled)booleantrueDisable carousel forward nav if last slide is visible / Disable carousel backward nav if first slide is visible
disableNavIfEdgeActivebooleantrueDisable carousel forward nav if activeSlideIndex === lastSlideIndex / Disable carousel backward nav if activeSlideIndex === 0
dotsNav (experimental)object{}Props for carousel dots. Includes show (boolean) property for toggle dots nav visibility, containerProps (DOM Props for dots nav wrapper div) property, itemBtnProps (DOM props for all dots nav buttons) property and activeItemBtnProps (DOM props for active dots nav button)
persistentChangeCallbacksbooleanfalseEnable call onRequestChange prop even if activeSlideIndex equals new value
showSlidesBeforeInit (deprecated)booleantrueShow slides on very first (initial) carousel render
visibleSlidePropsobject{}DOM props for visible slide element
autoplayDelaynumber0after what period of time the auto-update function of the active slide will be launched
preventScrollOnSwipebooleanfalseprevent vertical scroll on swipe
disableSwipeByMousebooleanfalsedisable swipe by mouse
disableSwipeByTouchbooleanfalsedisable swipe by touch
swipeTresholdnumberhalf width of the active slideminimum swipe distance in px (by touch or by mouse drag) for change slide
touchSwipeTresholdnumberhalf width of the active slideminimum swipe distance in px (by touch) for change slide
mouseSwipeTresholdnumberhalf width of the active slideminimum swipe distance in px (by mouse drag) for change slide
swipeRationumber1swipe distance ratio (on swipe by touchmove or by mouse drag)
touchSwipeRationumberswipeRatio prop valueswipe distance ratio (on swipe by touchmove)
mouseSwipeRationumberswipeRatio prop valueswipe distance ratio (on swipe by mouse drag)
dirRTLbooleanfalseEnable support for right-to-left slides content (text) direction

Demo

Edit react-simply-carousel-demo

9.1.3

20 days ago

9.1.2

1 month ago

9.1.1

4 months ago

9.1.0

5 months ago

9.0.7

5 months ago

9.0.5

7 months ago

9.0.4

10 months ago

9.0.3

10 months ago

9.0.2

11 months ago

9.0.1

11 months ago

8.4.5

1 year ago

8.4.4

1 year ago

8.4.6

1 year ago

8.4.3

1 year ago

8.5.4

1 year ago

8.5.3

1 year ago

8.5.6

12 months ago

8.5.5

1 year ago

8.5.0

1 year ago

8.5.2

1 year ago

8.5.1

1 year ago

8.5.7

12 months ago

9.0.0

12 months ago

8.4.1

1 year ago

8.4.2

1 year ago

8.4.0

2 years ago

8.1.0

2 years ago

8.3.0

2 years ago

8.3.5

2 years ago

8.3.2

2 years ago

8.3.1

2 years ago

8.3.4

2 years ago

8.3.3

2 years ago

8.0.0

2 years ago

8.2.1

2 years ago

8.2.0

2 years ago

5.1.5

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

7.0.0

2 years ago

5.1.4

2 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.1.2

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.1.1

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.0

3 years ago

2.1.10

3 years ago

2.1.9

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago