Skip to content

Commit 134d6da

Browse files
authored
Merge pull request #66 from superjose/AddTypings
Add TypeScript typings
2 parents 7ad636f + 3f7eff3 commit 134d6da

File tree

4 files changed

+6444
-2722
lines changed

4 files changed

+6444
-2722
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"build-doc": "docz build",
2525
"deploy-doc": "gh-pages -d demo"
2626
},
27+
"types": "./dist/index.d.ts",
2728
"peerDependencies": {
2829
"prop-types": "^15.5.4",
2930
"react": "^15.0.0 || ^16.0.0",
@@ -84,6 +85,7 @@
8485
"rollup-plugin-alias": "^1.4.0",
8586
"rollup-plugin-babel": "^4.3.2",
8687
"rollup-plugin-commonjs": "^9.1.3",
88+
"rollup-plugin-copy": "^3.3.0",
8789
"rollup-plugin-node-resolve": "^3.3.0",
8890
"rollup-plugin-peer-deps-external": "^2.2.0",
8991
"rollup-plugin-postcss": "^1.6.2",

rollup.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import babel from 'rollup-plugin-babel';
22
import commonjs from 'rollup-plugin-commonjs';
3+
import copy from "rollup-plugin-copy";
34
import external from 'rollup-plugin-peer-deps-external';
45
import postcss from 'rollup-plugin-postcss';
56
import resolve from 'rollup-plugin-node-resolve';
@@ -44,6 +45,9 @@ export default {
4445
namedExports: {
4546
'node_modules/react-is/index.js': ['isValidElementType']
4647
}
48+
}),
49+
copy({
50+
targets: [{ src: `src/${libName}/index.d.ts`, dest: "dist" }],
4751
})
4852
]
4953
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import React from "react";
2+
3+
type RenderArrowProps = {
4+
type: "PREV" | "NEXT";
5+
onClick: () => void;
6+
};
7+
8+
type RenderPaginationProps = {
9+
pages: number;
10+
activatePage: number;
11+
// The onClick event that sets the state of the carousel and sends
12+
// it to a specific page.
13+
onClick: (indicatorId: string) => void;
14+
};
15+
16+
type ItemObject = {
17+
// Children's props
18+
object: any;
19+
index: number;
20+
};
21+
22+
type Breakpoint = {
23+
itemsToScroll: number;
24+
itemsToShow: number;
25+
};
26+
27+
export interface ReactElasticCarouselProps {
28+
className?: string;
29+
itemsToShow?: number;
30+
// Defaults to false
31+
verticalMode?: boolean;
32+
// Defaults to true
33+
pagination?: boolean;
34+
// Defaults to 500
35+
transitionMs?: number;
36+
// Defaults to "ease"
37+
easing?: string;
38+
// Defaults to "ease"
39+
tiltEasing?: string;
40+
// Defaults to true.
41+
enableTilt?: boolean;
42+
// Defaults to 1
43+
itemsToScroll?: number;
44+
breakpoints?: {
45+
width: number;
46+
itemsToShow: number;
47+
itemsToScroll: number;
48+
}[];
49+
// Defaults to 0
50+
initialFirstItem?: number;
51+
// Defaults to true
52+
showArrows?: boolean;
53+
// Defaults to true
54+
disableArrosOnEnd?: boolean;
55+
// Defaults to boolean
56+
focusOnSelect?: boolean;
57+
// Function to generate your own navigation arrows.
58+
renderArrow?: (props: RenderArrowProps) => void;
59+
// Function to generate your own pagination component.
60+
renderPagination?: (props: RenderPaginationProps) => JSX.Element;
61+
// Defaults to "CENTER"
62+
itemPosition?: "START" | "CENTER" | "END";
63+
// A padding for each element - Defaults to [0,0,0,0]
64+
itemPadding: number[];
65+
// Enable or disable swipe - Defaults to true
66+
enableSwipe?: boolean;
67+
/** Enable or disable mouse swipe */
68+
enableMouseSwipe?: boolean;
69+
/** Prevent page scroll on touchmove.
70+
* Use this to stop the browser from scrolling while a user swipes.
71+
* More details: https://github.com/FormidableLabs/react-swipeable#preventdefaulttouchmoveevent-details
72+
*/
73+
preventDefaultTouchmoveEvent?: boolean;
74+
// Enable or disable auto play - Defaults to true
75+
enableAutoPlay?: boolean;
76+
/** Set auto play speed (ms) - Defaults to 2000 */
77+
autoPlaySpeed?: number;
78+
onChange?: (currentItemObject: ItemObject, currentPageIndex: number) => void;
79+
// A callback for the beginning of the next transition
80+
onNextStart?: (
81+
prevItemObject: ItemObject,
82+
nextItemObject: ItemObject
83+
) => void;
84+
// A callback for the beginning of the prev transition
85+
onPrevStart?: (
86+
prevItemObject: ItemObject,
87+
nextItemObject: ItemObject
88+
) => void;
89+
// A callback for the end of the next transition
90+
onNextEnd?: (nextItemObject: ItemObject, currentPageIndex: number) => void;
91+
// A callback for the end of the prev transition
92+
onPrevEnd?: (nextItemObject: ItemObject, currentPageIndex: number) => void;
93+
// A callback for the "slider-container" resize
94+
onResize?: (currentBreakpoint: Breakpoint) => void;
95+
}
96+
97+
declare class ReactElasticCarousel extends React.Component<
98+
ReactElasticCarouselProps
99+
> {}
100+
101+
export default ReactElasticCarousel;

0 commit comments

Comments
 (0)