React Keshan Carousel
React Keshan Carousel is a React component for building content galleries, content rotators and any React carousels. It is actually react-alice-carousel with several patches.
Features of react-keshan-carousel
- Infinite loop
- FadeOut animation
- AutoPlay mode
- Mobile friendly
- Responsive design
- Swipe to slide
- Start index
- Slide to index
- RTL
- Keyboard navigation
- Touch and Drag support
- Custom rendered slides
- Custom animation duration
- Multiple items in the slide
- Show / hide anything (indicators, arrows, slides indexes)
How to use
npm install react-keshan-carousel --save-dev
Style import
# SCSS
@import "react-keshan-carousel/lib/keshan-carousel.scss";
# CSS
@import "react-keshan-carousel/lib/keshan-carousel.css";
# Webpack
import "react-keshan-carousel/lib/keshan-carousel.css";
Quick start
;; const Gallery = <KeshanCarousel> <img src="/img1" className="yours-custom-class" /> <img src="/img2" className="yours-custom-class" /> <img src="/img3" className="yours-custom-class" /> <img src="/img4" className="yours-custom-class" /> <img src="/img5" className="yours-custom-class" /> </KeshanCarousel>
Advanced configuration
Props
-
items
: Array, default[]
- gallery items, preferable to use this property instead ofchildren
-
duration
: Number, default250
- Duration of slides transition (milliseconds) -
responsive
: Object, default{}
- Number of items in the slide0:items: 11024:items: 3 -
buttonsDisabled
: Boolean,false
- Disable buttons control -
dotsDisabled
: Boolean,false
- Disable dots navigation -
startIndex
: Number,0
- The starting index of the carousel -
slideToIndex
: Number,0
- Sets the carousel at the specified position -
swipeDisabled
: Boolean, defaultfalse
- Disable swipe handlers -
mouseDragEnabled
: Boolean, defaultfalse
- Enable mouse drag animation -
infinite
: Boolean, defaulttrue
- Disable infinite mode -
fadeOutAnimation
: Boolean,false
- Enable fadeout animation. Fired when 1 item is in the slide -
keysControlDisabled
: Boolean, defaultfalse
- Disable keys controls (left, right, space) -
playButtonEnabled
: Boolean, defaultfalse
- Disable play/pause button -
autoPlay
: Boolean, defaultfalse
- Set auto play mode -
autoPlayInterval
: Number, default250
- Interval of auto play animation (milliseconds). If specified, a larger value will be taken from comparing this property and theduration
one -
autoPlayDirection
: String, defaultltr
- To run auto play in the left direction specifyrtl
value -
autoPlayActionDisabled
: Boolean, defaultfalse
- If this property is identified astrue
auto play animation will be stopped after clicking user on any gallery button -
stopAutoPlayOnHover
: Boolean, defaulttrue
- If this property is identified asfalse
auto play animation won't stopped on hover -
showSlideIndex
: Boolean, defaultfalse
- Show slide info -
onSlideChange
: Function - Fired when the event object is changing / returns event object -
onSlideChanged
: Function - Fired when the event object was changed / returns event objectBoth functions return next object
item: index // index of the item`s positionslide: index // index of the slide`s position
Examples
;; Component responsive = 0: items: 1 600: items: 2 1024: items: 3 ; { console; console; }; { console; console; }; { return 1 2 3 4 5 }; { const items = this; return <KeshanCarousel items=items duration=400 autoPlay=true startIndex = 1 fadeOutAnimation=true mouseDragEnabled=true playButtonEnabled=true autoPlayInterval=2000 autoPlayDirection="rtl" responsive=thisresponsive autoPlayActionDisabled=true onSlideChange=thisonSlideChange onSlideChanged=thisonSlideChanged /> ; }
Prev / Next
buttons, dots / thumbs
navigation:
Custom - Using - refs.
;; Component items = 1 2 3 4 5; <div key=`key-` className="yours-custom-class"><h2>item</h2></div> <li key=i onClick= thisCarousel>Thumb item</li> { const items = thisitems return <div> <h3>Navigation</h3> <ul>thisitems</ul> <button onClick= thisCarousel>Prev button</button> <button onClick= thisCarousel>Next button</button> <h3>React Keshan Carousel</h3> <KeshanCarousel items=items dotsDisabled=true buttonsDisabled=true ref= thisCarousel = el /> </div> ; }
- Using props
;; Component items = 1 2 3 4 5; state = currentIndex: 0 responsive: 1024: items: 3 items: thisitems ; this; this; this; this; <li key=`key-` onClick= this>Thumb item</li> ; <div key=`key-` className="yours-custom-class"><h2>item</h2></div> ; { const items responsive currentIndex = thisstate return <div> <h3>Navigation</h3> <ul>thisitems</ul> <button onClick= this>Prev button</button> <button onClick= this>Next button</button> <h3>React Keshan Carousel</h3> <KeshanCarousel items=items dotsDisabled=true buttonsDisabled=true responsive=responsive slideToIndex=currentIndex onSlideChanged=thisonSlideChanged /> </div> ; }
Build the project locally
Clone
git clone https://github.com/keshan3262/react-keshan-carouselcd react-keshan-carousel
Run
npm inpm start
License
MIT