├── .editorconfig
├── .github
├── ISSUE_TEMPLATE
│ └── bug_report.md
├── stale.yml
└── workflows
│ ├── ci.yml
│ └── deploy-website.yml
├── .gitignore
├── .lgtm.yml
├── .npmignore
├── .nvmrc
├── .prettierignore
├── .prettierrc.json
├── .storybook
├── main.js
├── manager.js
└── preview-head.html
├── .travis.yml
├── CHANGELOG.md
├── CNAME
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── TROUBLESHOOTING.md
├── babel.config.json
├── codesandbox
└── default
│ ├── package.json
│ ├── public
│ └── index.html
│ └── src
│ ├── Carousel.js
│ └── index.js
├── package.json
├── setupTests.js
├── src
├── CSSTranslate.ts
├── __tests__
│ ├── Carousel.tsx
│ ├── SSR.tsx
│ ├── __snapshots__
│ │ └── Carousel.tsx.snap
│ └── animations.ts
├── assets
│ ├── 1.jpeg
│ ├── 2.jpeg
│ ├── 3.jpeg
│ ├── 4.jpeg
│ ├── 5.jpeg
│ ├── 6.jpeg
│ ├── 7.jpeg
│ └── meme.png
├── carousel.scss
├── components
│ ├── Carousel
│ │ ├── Arrow.tsx
│ │ ├── Indicator.tsx
│ │ ├── animations.ts
│ │ ├── index.tsx
│ │ ├── types.ts
│ │ └── utils.ts
│ ├── Thumbs.tsx
│ └── _carousel.scss
├── cssClasses.ts
├── dimensions.ts
├── examples
│ └── presentation
│ │ └── presentation.scss
├── index.html
├── index.ts
├── main.scss
├── main.tsx
├── shims
│ ├── document.ts
│ └── window.ts
└── styles
│ ├── _variables.scss
│ └── mixins
│ ├── _animation.scss
│ ├── _breakpoints.scss
│ └── _utils.scss
├── stories
├── 01-basic.tsx
└── 02-advanced.tsx
├── tsconfig.json
├── tsconfig.types.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 4
6 | spaces_around_brackets = both
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
15 | [{package.json,*.yml}]
16 | indent_style = space
17 | indent_size = 2
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **DISCLAIMER**
11 | This repo is not actively maintained by the owner. It depends mostly on contributions. Feel free to fork or to raise a PR and we will review when possible.
12 |
13 | **Describe the bug**
14 | A clear and concise description of what the bug is.
15 |
16 | **To Reproduce**
17 | Steps to reproduce the behavior:
18 | 1. Go to '...'
19 | 2. Click on '....'
20 | 3. Scroll down to '....'
21 | 4. See error
22 |
23 | **Expected behavior**
24 | A clear and concise description of what you expected to happen.
25 |
26 | **Example**
27 | Provide enough code to reproduce the bug (fork from https://codesandbox.io/s/lp602ljjj7 and send your link)
28 |
29 | **Screenshots**
30 | If applicable, add screenshots to help explain your problem.
31 |
32 | **Desktop (please complete the following information):**
33 | - OS: [e.g. iOS]
34 | - Browser [e.g. chrome, safari]
35 | - Version [e.g. 22]
36 |
37 | **Smartphone (please complete the following information):**
38 | - Device: [e.g. iPhone6]
39 | - OS: [e.g. iOS8.1]
40 | - Browser [e.g. stock browser, safari]
41 | - Version [e.g. 22]
42 |
43 | **Additional context**
44 | Add any other context about the problem here.
45 |
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 180
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 7
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - pinned
8 | - security
9 | # Label to use when marking an issue as stale
10 | staleLabel: wontfix
11 | # Comment to post when marking an issue as stale. Set to `false` to disable
12 | markComment: >
13 | This issue has been automatically marked as stale because it has not had
14 | recent activity. It will be closed if no further activity occurs. Thank you
15 | for your contributions.
16 | # Comment to post when closing a stale issue. Set to `false` to disable
17 | closeComment: false
18 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on: [push, pull_request]
3 | jobs:
4 | build:
5 | name: Test
6 | runs-on: ubuntu-latest
7 | steps:
8 | - uses: actions/checkout@v1
9 | - uses: actions/setup-node@v1
10 | with:
11 | node-version: '10.x'
12 |
13 | - name: install
14 | uses: borales/actions-yarn@v2.0.0
15 | with:
16 | cmd: install
17 |
18 | - name: test
19 | uses: borales/actions-yarn@v2.0.0
20 | with:
21 | cmd: test
22 |
23 | - name: build
24 | uses: borales/actions-yarn@v2.0.0
25 | with:
26 | cmd: build
27 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-website.yml:
--------------------------------------------------------------------------------
1 | name: Deploy website
2 | on:
3 | release:
4 | types: [published]
5 | jobs:
6 | deploy:
7 | name: deploy
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v1
11 | - uses: actions/setup-node@v1
12 | with:
13 | node-version: '10.x'
14 | registry-url: 'https://registry.npmjs.org'
15 |
16 | - name: install
17 | uses: borales/actions-yarn@v2.0.0
18 | with:
19 | cmd: install
20 |
21 | - name: test
22 | uses: borales/actions-yarn@v2.0.0
23 | with:
24 | cmd: jest
25 |
26 | - name: website:build
27 | uses: borales/actions-yarn@v2.0.0
28 | with:
29 | cmd: website:build
30 |
31 | - name: website:copy-assets
32 | uses: borales/actions-yarn@v2.0.0
33 | with:
34 | cmd: website:copy-assets
35 |
36 | - name: website:storybook
37 | uses: borales/actions-yarn@v2.0.0
38 | with:
39 | cmd: website:storybook
40 |
41 | - name: Deploy 🚀
42 | uses: JamesIves/github-pages-deploy-action@releases/v3
43 | with:
44 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
45 | BRANCH: gh-pages
46 | FOLDER: temp/website
47 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | .DS_Store
3 | npm-debug.log
4 | .cache/
5 | dev
6 | lib
7 | dist
8 | temp
9 | lib/main.js
10 | codesandbox/default/yarn.lock
--------------------------------------------------------------------------------
/.lgtm.yml:
--------------------------------------------------------------------------------
1 | path_classifiers:
2 | generated:
3 | - "/lib"
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 | tasks
3 | dist
4 | dev
5 | build
6 | stories
7 | temp
8 | codesandbox
9 | setupTests.js
10 | gulpfile.js
11 | lib/main.js
12 | .github
13 | .babelrc.js
14 | .lgtm.yml
15 | .prettierignore
16 | .prettierrc.json
17 | .cache
18 | .storybook
19 | stories
20 | yarn.lock
21 | .babelrc
22 | .editorconfig
23 | .nvmrc
24 | .travis.yml
25 | .gitignore
26 | CNAME
27 | generate-changelog.js
28 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v10.15.1
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | dev/
2 | dist/
3 | lib/
4 | node_modules/
5 | .cache/
6 | temp
7 | *.(jpeg|png|gif)
8 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "arrowParens": "always",
3 | "printWidth": 120,
4 | "trailingComma": "es5",
5 | "tabWidth": 4,
6 | "semi": true,
7 | "singleQuote": true
8 | }
9 |
--------------------------------------------------------------------------------
/.storybook/main.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | // Export a function. Accept the base config as the only param.
4 | module.exports = {
5 | stories: ['../stories/*.tsx'],
6 | addons: [
7 | '@storybook/addon-actions',
8 | '@storybook/addon-viewport/register',
9 | '@storybook/addon-knobs',
10 | '@storybook/addon-storysource',
11 | ],
12 | webpackFinal: async (config, { configType }) => {
13 | config.module.rules.push({
14 | test: /\.scss$/,
15 | use: ['style-loader', 'css-loader', 'sass-loader'],
16 | include: path.resolve(__dirname, '../src'),
17 | });
18 |
19 | config.module.rules.push({
20 | test: /stories\/(.+).tsx$/,
21 | loaders: [require.resolve('@storybook/addon-storysource/loader')],
22 | enforce: 'pre',
23 | });
24 |
25 | config.module.rules.push({
26 | test: /\.(ts|tsx)$/,
27 | use: [
28 | {
29 | loader: require.resolve('babel-loader'),
30 | },
31 | ],
32 | });
33 |
34 | config.resolve.extensions.push('.ts', '.tsx');
35 |
36 | config.performance.hints = false;
37 |
38 | return config;
39 | },
40 | };
41 |
--------------------------------------------------------------------------------
/.storybook/manager.js:
--------------------------------------------------------------------------------
1 | import { addons } from '@storybook/addons';
2 |
3 | addons.setConfig({
4 | showPanel: true,
5 | panelPosition: 'right',
6 | });
7 |
--------------------------------------------------------------------------------
/.storybook/preview-head.html:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '10'
4 |
--------------------------------------------------------------------------------
/CNAME:
--------------------------------------------------------------------------------
1 | react-responsive-carousel.js.org
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at leandrowd+github@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Found a bug? Want a new feature? Don't like the docs? Please send a pull request or raise an issue.
4 |
5 | ## Raising issues
6 |
7 | When raising an issue, please add as much details as possible. Screenshots, video recordings, or anything else that can make it easier to reproduce the bug you are reporting.
8 |
9 | - A new option is to create a code pen with the code that causes the bug. Fork this [example](https://www.webpackbin.com/bins/-Kxr6IEf5zXSQvGCgKBR) and add your code there, then fork and add the new link to the issue.
10 |
11 | ## Creating Pull Requests
12 |
13 | Pull requests are always welcome. To speed up the review process, please ensure that your pull request have:
14 |
15 | - A good title and description message;
16 | - Recommended that each commit follows the commit message format #{issueId}: {commitDescriptionj}
17 | - Tests covering the changes;
18 | - Story (storybook) if it's a new feature;
19 | - Green builds;
20 | - Breaking changes are commited with a message that describes the issue. Example: `BREAKING CHANGE: styles based on class X need to be update to use class Y.`
21 |
22 | In order to send a Pull Request, you will need to setup your environment - check instructions below;
23 |
24 | ## How to setup the development environment
25 |
26 | Fork and clone the repo:
27 |
28 | - `git clone git@github.com:leandrowd/react-responsive-carousel.git`
29 |
30 | Ensure you have the right node version:
31 |
32 | - `nvm use` # or `nvm install` in case the right version is not installed. Find the right version looking at the `.nvmrc` file.
33 |
34 | Install dependencies:
35 |
36 | - `yarn install`
37 |
38 | Start the dev server:
39 |
40 | - `yarn start` and open the browser on `http://localhost:1234/index.html`
41 |
42 | Run the tests:
43 |
44 | - `yarn test`
45 |
46 | Format the files:
47 |
48 | - `yarn format:write` # this will also run as part of the pre-commit hook. CI will fail the build if unformatted files are pushed.
49 |
50 | Develop on storybooks (optional):
51 |
52 | - `yarn storybook`
53 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Responsive Carousel
2 |
3 | [](https://badge.fury.io/js/react-responsive-carousel)
4 | [](https://travis-ci.org/leandrowd/react-responsive-carousel)
5 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel?ref=badge_shield)
6 |
7 | Powerful, lightweight and fully customizable carousel component for React apps.
8 |
9 | ### Important
10 |
11 | I don't have any time available to keep maintaining this package. If you have any request, try to sort it within the community. I'm able to merge pull requests that look safe from time to time but no commitment on timelines here. Feel free to fork it and publish under other name if you are in a hurry or to use another component.
12 |
13 | ### Features
14 |
15 | - Responsive
16 | - Mobile friendly
17 | - Swipe to slide
18 | - Mouse emulating touch
19 | - Server side rendering compatible
20 | - Keyboard navigation
21 | - Custom animation duration
22 | - Auto play w/ custom interval
23 | - Infinite loop
24 | - Horizontal or Vertical directions
25 | - Supports images, videos, text content or anything you want. Each direct child represents one slide!
26 | - Supports external controls
27 | - Highly customizable:
28 | - Custom thumbs
29 | - Custom arrows
30 | - Custom indicators
31 | - Custom status
32 | - Custom animation handlers
33 |
34 | ### Important links:
35 |
36 | - [Codesandbox playground](https://codesandbox.io/s/github/leandrowd/react-responsive-carousel/tree/master/codesandbox/default)
37 | - [Storybook](http://react-responsive-carousel.js.org/storybook/)
38 | - [Changelog](https://github.com/leandrowd/react-responsive-carousel/blob/master/CHANGELOG.md)
39 | - [Before contributing](https://github.com/leandrowd/react-responsive-carousel/blob/master/CONTRIBUTING.md)
40 | - [Troubleshooting](https://github.com/leandrowd/react-responsive-carousel/blob/master/TROUBLESHOOTING.md)
41 |
42 | ### Demo
43 |
44 |
45 |
46 | Check it out these [cool demos](http://react-responsive-carousel.js.org/storybook/index.html) created using [storybook](https://storybook.js.org/). The source code for each example is available [here](https://github.com/leandrowd/react-responsive-carousel/blob/master/stories/)
47 |
48 | Customize it yourself:
49 |
50 | - Codesandbox:
51 |
52 | ### Installing as a package
53 |
54 | `yarn add react-responsive-carousel`
55 |
56 | ### Usage
57 |
58 | ```javascript
59 | import React, { Component } from 'react';
60 | import ReactDOM from 'react-dom';
61 | import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
62 | import { Carousel } from 'react-responsive-carousel';
63 |
64 | class DemoCarousel extends Component {
65 | render() {
66 | return (
67 |
68 |
69 |
70 |
Legend 1
71 |
72 |
73 |
74 |
Legend 2
75 |
76 |
77 |
78 |
Legend 3
79 |
80 |
81 | );
82 | }
83 | });
84 |
85 | ReactDOM.render(, document.querySelector('.demo-carousel'));
86 |
87 | // Don't forget to include the css in your page
88 |
89 | // Using webpack or parcel with a style loader
90 | // import styles from 'react-responsive-carousel/lib/styles/carousel.min.css';
91 |
92 | // Using html tag:
93 | //
94 | ```
95 |
96 | ### Props
97 |
98 | | Name | Value | Description |
99 | | ---------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
100 | | ariaLabel | `string` | Define the `aria-label` attribute for the root carousel element. The default is `undefined`, skipping the attribute from markup. |
101 | | axis | `'horizontal'`, `'vertical'` | Define the direction of the slider, defaults to `'horizontal'`. |
102 | | autoFocus | `boolean` | Force focus on the carousel when it renders. |
103 | | autoPlay | `boolean` | Change the slide automatically based on `interval` prop. |
104 | | centerMode | `boolean` | Center the current item and set the slide width based on `centerSlidePercentage`. |
105 | | centerSlidePercentage | `number` | Define the width percentage relative to the carousel width when `centerMode` is `true`. |
106 | | dynamicHeight | `boolean` | The height of the items will not be fixed. |
107 | | emulateTouch | `boolean` | Enable swipe on non-touch screens when `swipeable` is `true`. |
108 | | infiniteLoop | `boolean` | Going after the last item will move back to the first slide. |
109 | | interval | `number` | Interval in milliseconds to automatically go to the next item when `autoPlay` is true, defaults to `3000`. |
110 | | labels | `object` | Apply `aria-label` on carousel with an `object` with the properties `leftArrow`, `rightArrow` and `item`. The default is `{leftArrow: 'previous slide / item', rightArrow: 'next slide / item', item: 'slide item'}`. |
111 | | onClickItem | `function` | Callback to handle a click event on a slide, receives the current index and item as arguments. |
112 | | onClickThumb | `function` | Callback to handle a click event on a thumb, receives the current index and item as arguments. |
113 | | onChange | `function` | Callback to handle every time the selected item changes, receives the current index and item as arguments. |
114 | | onSwipeStart | `function` | Callback to handle when the swipe starts, receives a touch event as argument. |
115 | | onSwipeEnd | `function` | Callback to handle when the swipe ends, receives a touch event as argument. |
116 | | onSwipeMove | `function` | Callback triggered on every movement while swiping, receives a touch event as argument. |
117 | | preventMovementUntilSwipeScrollTolerance | `boolean` | Don't let the carousel scroll until the user swipe to the value specified on `swipeScrollTolerance`. |
118 | | renderArrowPrev | `function` | Render custom previous arrow. Receives a click handler, a `boolean` that shows if there's a previous item, and the accessibility label as arguments. |
119 | | renderArrowNext | `function` | Render custom previous arrow. Receives a click handler, a `boolean` that shows if there's a next item, and the accessibility label as arguments. |
120 | | renderIndicator | `function` | Render custom indicator. Receives a click handler, a `boolean` that shows if the item is selected, the item index, and the accessibility label as arguments. |
121 | | renderItem | `function` | Render a custom item. Receives an item of the carousel, and an `object` with the `isSelected` property as arguments. |
122 | | renderThumbs | `function` | Render prop to show the thumbs, receives the carousel items as argument. Get the `img` tag of each item of the slider, and render it by default. |
123 | | selectedItem | `number` | Set the selected item, defaults to `0`. |
124 | | showArrows | `boolean` | Enable previous and next arrow, defaults to `true`. |
125 | | showStatus | `boolean` | Enable status of the current item to the total, defaults to `true`. |
126 | | showIndicators | `boolean` | Enable indicators to select items, defaults to `true`. |
127 | | showThumbs | `boolean` | Enable thumbs, defaults to `true`. |
128 | | statusFormatter | `function` | Formatter that returns the status as a `string`, receives the current item and the total count as arguments. Defaults to `{currentItem} of {total}` format. |
129 | | stopOnHover | `boolean` | The slide will not change by `autoPlay` on hover, defaults to `true`. |
130 | | swipeable | `boolean` | Enable the user to swipe the carousel, defaults to `true`. |
131 | | swipeScrollTolerance | `number` | How many pixels it's needed to change the slide when swiping, defaults to `5`. |
132 | | thumbWidth | `number` | Width of the thumb, defaults to `80`. |
133 | | transitionTime | `number` | Duration of the animation of changing slides. |
134 | | useKeyboardArrows | `boolean` | Enable the arrows to move the slider when focused. |
135 | | verticalSwipe | `'natural'`, `'standard'` | Set the mode of swipe when the axis is `'vertical'`. The default is `'standard'`. |
136 | | width | `number` or `string` | The width of the carousel, defaults to `100%`. |
137 |
138 | ### Customizing
139 |
140 | #### Items (Slides)
141 |
142 | By default, each slide will be rendered as passed as children. If you need to customize them, use the prop `renderItem`.
143 |
144 | ```
145 | renderItem: (item: React.ReactNode, options?: { isSelected: boolean }) => React.ReactNode;
146 | ```
147 |
148 | #### Thumbs
149 |
150 | By default, thumbs are generated extracting the images in each slide. If you don't have images on your slides or if you prefer a different thumbnail, use the method `renderThumbs` to return a new list of images to be used as thumbs.
151 |
152 | ```
153 | renderThumbs: (children: React.ReactChild[]) => React.ReactChild[]
154 | ```
155 |
156 | #### Arrows
157 |
158 | By default, simple arrows are rendered on each side. If you need to customize them and the css is not enough, use the `renderArrowPrev` and `renderArrowNext`. The click handler is passed as argument to the prop and needs to be added as click handler in the custom arrow.
159 |
160 | ```
161 | renderArrowPrev: (clickHandler: () => void, hasPrev: boolean, label: string) => React.ReactNode;
162 | renderArrowNext: (clickHandler: () => void, hasNext: boolean, label: string) => React.ReactNode;
163 | ```
164 |
165 | #### Indicators
166 |
167 | By default, indicators will be rendered as those small little dots in the bottom part of the carousel. To customize them, use the `renderIndicator` prop.
168 |
169 | ```
170 | renderIndicator: (
171 | clickHandler: (e: React.MouseEvent | React.KeyboardEvent) => void,
172 | isSelected: boolean,
173 | index: number,
174 | label: string
175 | ) => React.ReactNode;
176 | ```
177 |
178 | #### Take full control of the carousel
179 |
180 | If none of the previous options are enough, you can build your own controls for the carousel. Check an example at http://react-responsive-carousel.js.org/storybook/?path=/story/02-advanced--with-external-controls
181 |
182 | #### Custom Animations
183 |
184 | By default, the carousel uses the traditional 'slide' style animation. There is also a built in fade animation, which can be used by passing `'fade'` to the `animationHandler` prop. \*note: the 'fade' animation does not support swiping animations, so you may want to set `swipeable` to `false`
185 |
186 | If you would like something completely custom, you can pass custom animation handler functions to `animationHandler`, `swipeAnimationHandler`, and `stopSwipingHandler`. The animation handler functions accept props and state, and return styles for the contain list, default slide style, selected slide style, and previous slide style. Take a look at the fade animation handler for an idea of how they work:
187 |
188 | ```javascript
189 | const fadeAnimationHandler: AnimationHandler = (props, state): AnimationHandlerResponse => {
190 | const transitionTime = props.transitionTime + 'ms';
191 | const transitionTimingFunction = 'ease-in-out';
192 |
193 | let slideStyle: React.CSSProperties = {
194 | position: 'absolute',
195 | display: 'block',
196 | zIndex: -2,
197 | minHeight: '100%',
198 | opacity: 0,
199 | top: 0,
200 | right: 0,
201 | left: 0,
202 | bottom: 0,
203 | transitionTimingFunction: transitionTimingFunction,
204 | msTransitionTimingFunction: transitionTimingFunction,
205 | MozTransitionTimingFunction: transitionTimingFunction,
206 | WebkitTransitionTimingFunction: transitionTimingFunction,
207 | OTransitionTimingFunction: transitionTimingFunction,
208 | };
209 |
210 | if (!state.swiping) {
211 | slideStyle = {
212 | ...slideStyle,
213 | WebkitTransitionDuration: transitionTime,
214 | MozTransitionDuration: transitionTime,
215 | OTransitionDuration: transitionTime,
216 | transitionDuration: transitionTime,
217 | msTransitionDuration: transitionTime,
218 | };
219 | }
220 |
221 | return {
222 | slideStyle,
223 | selectedStyle: { ...slideStyle, opacity: 1, position: 'relative' },
224 | prevStyle: { ...slideStyle },
225 | };
226 | };
227 | ```
228 |
229 | ### Videos
230 |
231 | If your carousel is about videos, keep in mind that it's up to you to control which videos will play. Using the `renderItem` prop, you will get information saying if the slide is selected or not and can use that to change the video state. Only play videos on selected slides to avoid issues. Check an example at http://react-responsive-carousel.js.org/storybook/?path=/story/02-advanced--youtube-autoplay-with-custom-thumbs
232 |
233 | =======================
234 |
235 | ### Contributing
236 |
237 | The [contributing guide](https://github.com/leandrowd/react-responsive-carousel/blob/master/CONTRIBUTING.md) contains details on how to create pull requests and setup your dev environment. Please read it before contributing!
238 |
239 | =======================
240 |
241 | ### Raising issues
242 |
243 | When raising an issue, please add as much details as possible. Screenshots, video recordings, or anything else that can make it easier to reproduce the bug you are reporting.
244 |
245 | - A new option is to create an example with the code that causes the bug. Fork this [example from codesandbox](https://codesandbox.io/s/github/leandrowd/react-responsive-carousel/tree/master/codesandbox/default) and add your code there. Don't forget to fork, save and add the link for the example to the issue.
246 |
247 | =======================
248 |
249 | ## License
250 |
251 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel?ref=badge_large)
252 |
253 | ```
254 |
255 | ```
256 |
--------------------------------------------------------------------------------
/TROUBLESHOOTING.md:
--------------------------------------------------------------------------------
1 | # Thumbs not visible
2 |
3 | ### Error message:
4 | > No images found! Can't build the thumb list without images. If you don't need thumbs, set showThumbs={false} in the Carousel. Note that it's not possible to get images rendered inside custom components.
5 |
6 | Carousel will find the thumbs if they are rendered as direct children of the carousel or if they are inside a div or another normal html element in a way that it's possible to access the children of these elements from the carousel.
7 |
8 | For performance reasons, it's not possible to get images inside custom components.
9 |
10 | Good:
11 | ```javascript
12 |
13 | {
14 | images.map((url, index) => (
15 |
)).toMatchSnapshot();
136 | });
137 |
138 | it('renderThumbs should return a list of images extracted from the children', () => {
139 | expect(
140 | componentInstance.props.renderThumbs!([
141 |
131 | Use the buttons below to change the selected item in the carousel
132 |
133 |
134 |
135 | Note that the external controls might not respect the carousel boundaries but the
136 | carousel won't go past it.
137 |
138 |
139 |
223 | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the
224 | industry's standard dummy text ever since the 1500s, when an unknown printer took a
225 | galley of type and scrambled it to make a type specimen book.{' '}
226 |
227 |
228 |
229 |
230 | It has survived not only five centuries, but also the leap into electronic typesetting,
231 | remaining essentially unchanged.{' '}
232 |
233 |
234 |
235 |
236 | It was popularised in the 1960s with the release of Letraset sheets containing Lorem
237 | Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including
238 | versions of Lorem Ipsum.
239 |
240 |
241 |
242 |
Where does it come from?
243 |
244 |
245 |
Contrary to popular belief, Lorem Ipsum is not simply random text.
246 |
247 |
248 |
249 | It has roots in a piece of classical Latin literature from 45 BC, making it over{' '}
250 | 2000 years old.
251 |