Skip to content

Commit 6460675

Browse files
committedApr 26, 2020
leandrowdgh-429: Emit types from source and update README
1 parent 59c7d1b commit 6460675

6 files changed

+88
-121
lines changed
 

‎README.md

+62-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# React Responsive Carousel
22

3-
# Help wanted
4-
5-
Things here are running very slowly as I have a lot of other stuff to take care at the moment so please don't be upset if I don't answer your question or if a PR sits unreviewed for a few days or weeks. Anyone interested in helping it move faster can help by submitting or reviewing PR's and answering each other's questions. (https://github.com/leandrowd/react-responsive-carousel/issues/160)
6-
73
[![npm version](https://badge.fury.io/js/react-responsive-carousel.svg)](https://badge.fury.io/js/react-responsive-carousel)
84
[![Build Status](https://travis-ci.org/leandrowd/react-responsive-carousel.svg?branch=master)](https://travis-ci.org/leandrowd/react-responsive-carousel)
95
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel?ref=badge_shield)
@@ -16,16 +12,19 @@ Powerful, lightweight and fully customizable carousel component for React apps.
1612
- Mobile friendly
1713
- Swipe to slide
1814
- Mouse emulating touch
19-
- Server side rendering
15+
- Server side rendering compatible
2016
- Keyboard navigation
2117
- Custom animation duration
22-
- Auto play
23-
- Custom auto play interval
18+
- Auto play w/ custom interval
2419
- Infinite loop
2520
- Horizontal or Vertical directions
2621
- Supports images, videos, text content or anything you want. Each direct child represents one slide!
27-
- Supports any flux library (use `selectedItem` prop to set from the app state, and `onChange` callback to get the new position)
28-
- Show/hide anything (thumbs, indicators, arrows, status)
22+
- Supports external controls
23+
- Highly customizable:
24+
- Custom thumbs
25+
- Custom arrows
26+
- Custom indicators
27+
- Custom status
2928

3029
### Important links:
3130

@@ -54,7 +53,7 @@ Customize it yourself:
5453
```javascript
5554
import React, { Component } from 'react';
5655
import ReactDOM from 'react-dom';
57-
import "react-responsive-carousel/lib/styles/carousel.min.css";
56+
import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
5857
import { Carousel } from 'react-responsive-carousel';
5958

6059
class DemoCarousel extends Component {
@@ -82,11 +81,60 @@ ReactDOM.render(<DemoCarousel />, document.querySelector('.demo-carousel'));
8281

8382
// Don't forget to include the css in your page
8483

85-
// Using webpack
84+
// Using webpack or parcel with a style loader
8685
// import styles from 'react-responsive-carousel/lib/styles/carousel.min.css';
8786

8887
// Using html tag:
8988
// <link rel="stylesheet" href="<NODE_MODULES_FOLDER>/react-responsive-carousel/lib/styles/carousel.min.css"/>
89+
```
90+
91+
### Customizing
92+
93+
#### Items (Slides)
94+
95+
By default, each slide will be rendered as passed as children. If you need to customize them, use the prop `renderItem`.
96+
97+
```
98+
renderItem: (item: React.ReactNode, options?: { isSelected: boolean }) => React.ReactNode;
99+
```
100+
101+
#### Thumbs
102+
103+
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.
104+
105+
```
106+
renderThumbs: (children: React.ReactChild[]) => React.ReactChild[]
107+
```
108+
109+
#### Arrows
110+
111+
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.
112+
113+
```
114+
renderArrowPrev: (clickHandler: () => void, hasPrev: boolean, label: string) => React.ReactNode;
115+
renderArrowNext: (clickHandler: () => void, hasNext: boolean, label: string) => React.ReactNode;
116+
```
117+
118+
#### Indicators
119+
120+
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.
121+
122+
```
123+
renderIndicator: (
124+
clickHandler: (e: React.MouseEvent | React.KeyboardEvent) => void,
125+
isSelected: boolean,
126+
index: number,
127+
label: string
128+
) => React.ReactNode;
129+
```
130+
131+
#### Take full control of the carousel
132+
133+
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
134+
135+
### Videos
136+
137+
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
90138

91139
=======================
92140

@@ -107,4 +155,7 @@ When raising an issue, please add as much details as possible. Screenshots, vide
107155
## License
108156

109157
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fleandrowd%2Freact-responsive-carousel?ref=badge_large)
158+
159+
```
160+
110161
```

‎index.d.ts

-76
This file was deleted.

‎package.json

+13-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"main": "lib/cjs/index.js",
1010
"module": "lib/es/index.js",
11+
"types": "lib/ts/index.d.ts",
1112
"license": "MIT",
1213
"keywords": [
1314
"react",
@@ -21,7 +22,14 @@
2122
"react-component",
2223
"view"
2324
],
24-
"types": "index.d.ts",
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/leandrowd/react-responsive-carousel.git"
28+
},
29+
"bugs": {
30+
"url": "https://github.com/leandrowd/react-responsive-carousel/issues"
31+
},
32+
"homepage": "http://leandrowd.github.io/react-responsive-carousel/",
2533
"scripts": {
2634
"start": "parcel src/index.html src/assets/**/*",
2735
"storybook": "start-storybook -p 9001 -s ./src -c .storybook",
@@ -30,16 +38,17 @@
3038
"format": "prettier '**/*.{js,json}'",
3139
"format:check": "yarn format --check",
3240
"format:write": "yarn format --write",
33-
"test": "yarn format:check && yarn jest && yarn jest-ssr",
41+
"test": "yarn format:check && yarn typecheck && yarn jest && yarn jest-ssr",
3442
"jest": "jest",
35-
"jest-ssr": "jest --testEnvironment=node ./src/__tests__/SSR.js",
43+
"jest-ssr": "jest --testEnvironment=node ./src/__tests__/SSR.tsx",
3644
"typecheck": "tsc -p tsconfig.json --noEmit",
3745
"update-snapshots": "jest --updateSnapshot",
3846
"build": "yarn lib:build",
39-
"lib:build": "yarn lib:build-cjs && yarn lib:build-es && yarn lib:build-styles",
47+
"lib:build": "yarn lib:build-cjs && yarn lib:build-es && yarn lib:build-styles && yarn lib:build-types",
4048
"lib:build-cjs": "babel ./src -d lib/cjs --ignore './src/__tests__'",
4149
"lib:build-es": "MODULE=true babel ./src -d lib/es --ignore './src/__tests__'",
4250
"lib:build-styles": "mkdir -p lib/styles && node-sass src/carousel.scss > lib/styles/carousel.css && node-sass --output-style compressed src/carousel.scss > lib/styles/carousel.min.css",
51+
"lib:build-types": "tsc -p tsconfig.types.json",
4352
"lib:pre-publish": "npm version patch && git push origin master",
4453
"lib:publish": "npm publish && git push --tags",
4554
"lib:post-publish": "yarn changelog && yarn update-codesandbox && git add . && git commit -m 'Updating changelog and codesandbox' && git push origin master",
@@ -55,14 +64,6 @@
5564
"prepublish-prerelease-to-npm": "git pull && yarn build && git add . && git commit -m 'Prepare for publishing prerelease'",
5665
"publish-prerelease-to-npm": "(git pull && npm version prerelease --preid=next && npm publish)"
5766
},
58-
"repository": {
59-
"type": "git",
60-
"url": "https://github.com/leandrowd/react-responsive-carousel.git"
61-
},
62-
"bugs": {
63-
"url": "https://github.com/leandrowd/react-responsive-carousel/issues"
64-
},
65-
"homepage": "http://leandrowd.github.io/react-responsive-carousel/",
6667
"devDependencies": {
6768
"@babel/cli": "^7.8.4",
6869
"@babel/core": "^7.9.0",

‎tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"strict": true,
1010
"target": "es5",
1111
"jsx": "react",
12-
"outDir": "./ts-output",
1312
"baseUrl": "./src",
1413
"typeRoots": ["./node_modules/@types", "./types"],
1514
"paths": {

‎tsconfig.types.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "lib/ts",
5+
"declaration": true,
6+
"declarationMap": true,
7+
"isolatedModules": false,
8+
"noEmit": false,
9+
"allowJs": false,
10+
"emitDeclarationOnly": true
11+
},
12+
"exclude": ["src/__tests__"]
13+
}

‎types/react-easy-swipe.d.ts

-21
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.