react-id-swiper ( Newest version 1.6.1 )
A library to use Swiper as a ReactJs component.
What is Swiper?
Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing native behavior. It is intended to be used in mobile websites, mobile web apps, and mobile native/hybrid apps. Designed mostly for iOS, but also works great on latest Android, Windows Phone 8 and modern Desktop browsers
Swiper is not compatible with all platforms, it is a modern touch slider which is focused only on modern apps/platforms to bring the best experience and simplicity.
React-id-swiper's original props
Name | Type | Default value | Description |
---|---|---|---|
ContainerEl | String | 'div' | Element type for container |
containerClass | String | swiper-container | Swiper container class name |
WrapperEl | String | 'div' | Element type for wrapper |
wrapperClass | String | swiper-wrapper | Swiper wrapper class name |
slideClass | String | swiper-slide | Swiper slide class name |
prevButtonCustomizedClass | String | '' | Swiper prev button class name |
nextButtonCustomizedClass | String | '' | Swiper next button class name |
paginationCustomizedClass | String | '' | Swiper pagination class name |
shouldSwiperUpdate | Boolean | false | Update swiper when component is updated |
rebuildOnUpdate | Boolean | false | Rebuild swiper when component is updated |
noSwiping | Boolean | false | Disable swiping by condition |
renderCustomPrevButton | function | Use to customize rendering for prev button | |
renderCustomNextButton | function | Use to customize rendering for next button | |
renderCustomScrolbar | function | Use to customize rendering for scrollbar | |
renderCustomPagination | function | Use to customize rendering for pagination | |
renderCustomParallax | function | Use to customize rendering for parallax |
NOTE: You can also use Swiper's original params too.Swiper API documentation HERE
DEMO
You can see the demo with example code HERE
Installation
By npm
npm install --save react-id-swiper
By Yarn
yarn add react-id-swiper
You can also use the standalone UMD build
Recommendation
Swiper stylesheet file is required
Use Swiper stylesheet file from CDN
OR
Use stylesheet file from src/styles/ folder (supporting css, less, scss)
Usage
Example with default
Example with default params
ES5
var React = ;var Swiper = ; var Example = React; moduleexports = Example;
ES6
;; Component { return <Swiper> <div>Slide 1</div> <div>Slide 2</div> <div>Slide 3</div> <div>Slide 4</div> <div>Slide 5</div> </Swiper> } ;
Example with params
Example with navigation buttons
ES5
var React = ;var Swiper = ; var Example = React; moduleexports = Example;
ES6
;; Component { const params = pagination: el: '.swiper-pagination' type: 'bullets' clickable: true navigation: nextEl: '.swiper-button-next' prevEl: '.swiper-button-prev' spaceBetween: 30 return <Swiper ...params> <div>Slide 1</div> <div>Slide 2</div> <div>Slide 3</div> <div>Slide 4</div> <div>Slide 5</div> </Swiper> } ;
Example with manipulating swiper from outside swiper component
Example with navigation button
ES6
;; Component { superprops thisgoNext = thisgoNext thisgoPrev = thisgoPrev thisswiper = null } { if thisswiper thisswiper } { if thisswiper thisswiper } { const params = pagination: el: '.swiper-pagination' type: 'bullets' clickable: true navigation: nextEl: '.swiper-button-next' prevEl: '.swiper-button-prev' return <div> <Swiper ...params ref= ifnode thisswiper = nodeswiper /> <button onClick=thisgoNext>Next</button> <button onClick=thisgoPrev>Prev</button> </div> }
How to add customized class for swiper?
Example with navigation button
const params = paginationCustomizedClass: 'customized-swiper-pagination' // Add your class name for pagination container nextButtonCustomizedClass: 'nextButtonCustomizedClass' // Add your class name for next button prevButtonCustomizedClass: 'customized-swiper-button-prev' // Add your class name for prev button containerClass: 'customized-swiper-container' // Replace swiper-container with customized-swiper-container
How to add customized components ?
Example with customized navigation button
For customized rendering to work, you have to use same classname with params el.
const params = navigation: nextEl: '.swiper-button-next' prevEl: '.swiper-button-prev' <button className="swiper-button-prev">Prev</button> <button className="swiper-button-next">Next</button>
Build demo in local
First, clone this repo to your local
https://github.com/kidjp85/react-id-swiper-demo.git
Install node packages
npm install
or
yarn
Run webpack server
yarn start
Run tests
yarn testyarn test --watch
License
MIT