UNPKG

5.62 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# Road to 1.0
9react-slick is under active development now.
10Soon this project will have all the features of slick carousel.
11We encourage your feedback and support.
12
13### Installation
14
15```bash
16npm install react-slick
17```
18
19Also install slick-carousel for css and font
20
21```bash
22bower install slick-carousel
23```
24
25or add cdn link in your html
26
27```html
28<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.3.15/slick.css" />
29```
30
31### [Demos](http://webrafter.com/opensource/react-slick)
32
33### [PlayGround](https://jsfiddle.net/kirana/20bumb4g/)
34Use [jsfiddle template](https://jsfiddle.net/kirana/20bumb4g/) to try react-slick with different settings.
35
36### Filling issues
37Please 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.
38
39
40### Starter Kit
41Checkout [yeoman generator](https://github.com/akiran/generator-react-slick) to quickly
42get started with react-slick.
43
44### Example
45
46```js
47var React = require('react');
48var Slider = require('react-slick');
49
50var SimpleSlider = React.createClass({
51 render: function () {
52 var settings = {
53 dots: true,
54 infinite: true,
55 speed: 500,
56 slidesToShow: 1,
57 slidesToScroll: 1
58 };
59 return (
60 <Slider {...settings}>
61 <div><h3>1</h3></div>
62 <div><h3>2</h3></div>
63 <div><h3>3</h3></div>
64 <div><h3>4</h3></div>
65 <div><h3>5</h3></div>
66 <div><h3>6</h3></div>
67 </Slider>
68 );
69 }
70});
71```
72
73| Property | Type | Description | Working |
74| ------------- | ---- | ----------- | ------- |
75| className | String |Additional class name for the inner slider div | Yes |
76| adaptiveHeight | bool | Adjust the slide's height automatically | Yes |
77| arrows | bool | Should we show Left and right nav arrows | Yes |
78| nextArrow | React Component | Use this component for the next arrow button | Yes |
79| prevArrow | React Component | Use this component for the prev arrow button | Yes |
80| autoplay | bool | Should the scroller auto scroll? | Yes |
81| autoplaySpeed | int | delay between each auto scoll. in ms | Yes |
82| centerMode | bool | Should we centre to a single item? | Yes |
83| centerPadding | | | |
84| cssEase | | | |
85| dots | bool | Should we show the dots at the bottom of the gallery | Yes |
86| dotsClass | string | Class applied to the dots if they are enabled | Yes |
87| draggable | bool | Is the gallery scrollable via dragging on desktop? | Yes |
88| easing | string | | |
89| fade | bool | Slides use fade for transition | Yes |
90| focusOnSelect | bool | | |
91| infinite | bool | should the gallery wrap around it's contents | Yes |
92| initialSlide | int | which item should be the first to be displayed | Yes |
93| lazyLoad | bool | Loads images or renders components on demands | Yes |
94| 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 |
95| rtl | bool | Reverses the slide order | Yes |
96| slide | string |||
97| slidesToShow | int | Number of slides to be visible at a time | Yes |
98| slidesToScroll | int | Number of slides to scroll for each navigation item
99| speed | int |||
100| swipe | bool |||
101| swipeToSlide | bool |||
102| touchMove | bool |||
103| touchThreshold | int |||
104| variableWidth | bool |||
105| useCSS | bool | Enable/Disable CSS Transitions | Yes |
106| vertical | bool |||
107| afterChange | function | callback function called after the current index changes | Yes |
108| beforeChange | function | callback function called before the current index changes | Yes |
109| slickGoTo | int | go to the specified slide number
110
111### Custom next/prev arrows
112
113To customize the next/prev arrow elements, simply create new React components and set them
114as the values of nextArrow and prevArrow.
115
116```js
117class LeftNavButton extends React.Component {
118 render() {
119 return <button {...this.props}>Next</button>
120 }
121}
122```
123
124Important: be sure that you pass your component's props to your clickable element
125like the example above. If you don't, your custom component won't trigger the click handler.
126
127You can also set onClick={this.props.onClick} if you only want to set the click handler.
128
129
130### Development
131Want to run demos locally
132
133```shell
134git clone https://github.com/akiran/react-slick
135npm install
136npm start
137open http://localhost:8000
138```
139
140### Polyfills for old IE support
141`matchMedia` support from [media-match](https://github.com/weblinc/media-match)
142
143For premium support, contact me on codementor
144[![Contact me on Codementor](https://cdn.codementor.io/badges/contact_me_github.svg)](https://www.codementor.io/akiran?utm_source=github&utm_medium=button&utm_term=akiran&utm_campaign=github)