UNPKG

7.49 kBMarkdownView Raw
1# react-slick
2
3[![Join the chat at https://gitter.im/akiran/react-slick](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akiran/react-slick?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
5
6Carousel component built with React. It is a react port of [slick carousel](http://kenwheeler.github.io/slick/)
7
8### Important
9### Breaking changes in react-slick@0.15
10 * slickGoTo prop is deprecated in favor of slickGoTo method. Check this [slickGoTo usage example](https://github.com/akiran/react-slick/blob/master/examples/SlickGoTo.js).
11 * dist folder will be removed from the repo to simplify PR review process. If you are using bower or relying on the dist files in github repo, use dist files from unpkg.com
12```
13 https://unpkg.com/react-slick@0.13.6/dist/react-slick.min.js
14```
15
16### Installation
17
18```bash
19npm install react-slick
20```
21
22Also install slick-carousel for css and font
23
24```bash
25npm install slick-carousel
26```
27
28or add cdn link in your html
29
30```html
31<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css" />
32<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css" />
33```
34
35### [Demos](http://neostack.com/opensource/react-slick)
36
37### [PlayGround](https://jsfiddle.net/kirana/20bumb4g/)
38Use [jsfiddle template](https://jsfiddle.net/kirana/20bumb4g/) to try react-slick with different settings.
39
40### Filing issues
41Please replicate your issue with [jsfiddle template](https://jsfiddle.net/kirana/20bumb4g/) and post it along with issue to make it easy for me to debug.
42
43
44### Starter Kit
45Checkout [yeoman generator](https://github.com/akiran/generator-react-slick) to quickly
46get started with react-slick.
47
48### Example
49
50```js
51var React = require('react');
52var createReactClass = require('create-react-class');
53var Slider = require('react-slick');
54
55var SimpleSlider = createReactClass({
56 render: function () {
57 var settings = {
58 dots: true,
59 infinite: true,
60 speed: 500,
61 slidesToShow: 1,
62 slidesToScroll: 1
63 };
64 return (
65 <Slider {...settings}>
66 <div><h3>1</h3></div>
67 <div><h3>2</h3></div>
68 <div><h3>3</h3></div>
69 <div><h3>4</h3></div>
70 <div><h3>5</h3></div>
71 <div><h3>6</h3></div>
72 </Slider>
73 );
74 }
75});
76```
77
78| Property | Type | Description | Working |
79| ------------- | ---- | ----------- | ------- |
80| accessibility | bool | Enables tabbing and arrow key navigation | Yes |
81| className | String |Additional class name for the inner slider div | Yes |
82| adaptiveHeight | bool | Adjust the slide's height automatically | Yes |
83| arrows | bool | Should we show Left and right nav arrows | Yes |
84| nextArrow | React Element | Use this element for the next arrow button | Yes |
85| prevArrow | React Element | Use this element for the prev arrow button | Yes |
86| autoplay | bool | Should the scroller auto scroll? | Yes |
87| autoplaySpeed | int | delay between each auto scoll. in ms | Yes |
88| centerMode | bool | Should we centre to a single item? | Yes |
89| centerPadding | | | |
90| cssEase | | | |
91| customPaging | func | Custom paging templates. [Example](https://github.com/akiran/react-slick/blob/master/examples/CustomPaging.js)| Yes |
92| dots | bool | Should we show the dots at the bottom of the gallery | Yes |
93| dotsClass | string | Class applied to the dots if they are enabled | Yes |
94| draggable | bool | Is the gallery scrollable via dragging on desktop? | Yes |
95| easing | string | | |
96| fade | bool | Slides use fade for transition | Yes |
97| focusOnSelect | bool | Go to slide on click | Yes |
98| infinite | bool | should the gallery wrap around it's contents | Yes |
99| initialSlide | int | which item should be the first to be displayed | Yes |
100| lazyLoad | bool | Loads images or renders components on demands | Yes |
101| pauseOnHover | bool | prevents autoplay while hovering | Yes |
102| responsive | array | Array of objects in the form of `{ breakpoint: int, settings: { ... } }` The breakpoint _int_ is the `maxWidth` so the settings will be applied when resolution is below this value. Breakpoints in the array should be ordered from smalles to greatest. Use 'unslick' in place of the settings object to disable rendering the carousel at that breakpoint. Example: `[ { breakpoint: 768, settings: { slidesToShow: 3 } }, { breakpoint: 1024, settings: { slidesToShow: 5 } }, { breakpoint: 100000, settings: 'unslick' } ]`| Yes |
103| rtl | bool | Reverses the slide order | Yes |
104| slide | string |||
105| slidesToShow | int | Number of slides to be visible at a time | Yes |
106| slidesToScroll | int | Number of slides to scroll for each navigation item
107| speed | int |||
108| swipe | bool |||
109| swipeToSlide | bool | Allow users to drag or swipe directly to a slide irrespective of slidesToScroll | Yes |
110| touchMove | bool |||
111| touchThreshold | int |||
112| variableWidth | bool |||
113| useCSS | bool | Enable/Disable CSS Transitions | Yes |
114| vertical | bool | Vertical slide mode | Yes |
115| afterChange | function | callback function called after the current index changes | Yes |
116| beforeChange | function | callback function called before the current index changes | Yes |
117| slickGoTo | int | go to the specified slide number | |
118
119
120### Methods
121* `slickNext()` - function called to change current slide on next slide ([Example](https://github.com/akiran/react-slick/blob/master/examples/PreviousNextMethods.js))
122* `slickPrev()` - function called to change current slide on previous slide ([Example](https://github.com/akiran/react-slick/blob/master/examples/PreviousNextMethods.js))
123* `slickGoTo(slideNumber)` - function called to change current slide to given slide number ([Example](https://github.com/akiran/react-slick/blob/master/examples/SlickGoTo.js))
124
125### Custom next/prev arrows
126
127To customize the next/prev arrow elements, simply create new React components and set them
128as the values of nextArrow and prevArrow.
129
130```js
131class LeftNavButton extends React.Component {
132 render() {
133 return <button {...this.props}>Next</button>
134 }
135}
136```
137
138Important: be sure that you pass your component's props to your clickable element
139like the example above. If you don't, your custom component won't trigger the click handler.
140
141You can also set `onClick={this.props.onClick}` if you only want to set the click handler.
142
143### Flexbox support
144If you have flex property on container div of slider, add below css
145```css
146* {
147 min-height: 0;
148 min-width: 0;
149}
150```
151
152### Test Setup
153If you try to run tests with jest in a project that uses react-slick, you my run into this error
154```
155matchMedia not present, legacy browsers require a polyfill
156```
157
158To fix this issue add below snippet in test-setup.js
159```js
160window.matchMedia = window.matchMedia || function() {
161 return {
162 matches : false,
163 addListener : function() {},
164 removeListener: function() {}
165 };
166};
167
168```
169and add below jest config in package.json
170```json
171"jest": {
172 "setupFiles": ["test-setup.js"]
173}
174```
175
176
177### Development
178Want to run demos locally
179
180```bash
181git clone https://github.com/akiran/react-slick
182npm install
183npm start
184open http://localhost:8080
185```
186
187### Polyfills for old IE support
188`matchMedia` support from [media-match](https://github.com/weblinc/media-match)
189