Skip to content

Commit bb2a4a5

Browse files
authored
Add typescript types (#630)
* Move TS Types from DefinitelyTyped to here * Update PR template
1 parent 93337e0 commit bb2a4a5

File tree

6 files changed

+449
-12
lines changed

6 files changed

+449
-12
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Please describe the tests that you ran to verify your changes. Provide instructi
3333
- [ ] I have made corresponding changes to the documentation
3434
- [ ] My changes generate no new warnings
3535
- [ ] Any dependent changes have been merged and published in downstream modules
36-
- [ ] I have updated type definitions in [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/spectacle/index.d.ts) for any breaking API changes
36+
- [ ] I have updated type definitions in `index.d.ts` for any breaking API changes

LICENSE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013
3+
Copyright (c) 2013-2018 Formidable Labs, Inc.
4+
5+
Copyright (c) 2016-2018 Zachary Maybury, Kylie Stewart, and potentially other
6+
DefinitelyTyped contributors
47

58
Permission is hereby granted, free of charge, to any person obtaining a copy of
69
this software and associated documentation files (the "Software"), to deal in
@@ -17,4 +20,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1720
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1821
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1922
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

index.d.ts

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
// Definitions by: Zachary Maybury <https://github.com/zmaybury>
2+
// Kylie Stewart <https://github.com/kale-stew>
3+
4+
declare module 'spectacle' {
5+
import * as CSS from 'csstype';
6+
import * as React from 'react';
7+
8+
/**
9+
* Alignment Types for Spectacle
10+
*/
11+
type alignType =
12+
| 'flex-start flex-start'
13+
| 'flex-start center'
14+
| 'flex-start flex-end'
15+
| 'center flex-start'
16+
| 'center center'
17+
| 'center flex-end'
18+
| 'flex-end flex-start'
19+
| 'flex-end center'
20+
| 'flex-end flex-end';
21+
22+
/**
23+
* Animation Types for Spectacle
24+
*/
25+
type easeType =
26+
| 'back'
27+
| 'backIn'
28+
| 'backOut'
29+
| 'backInOut'
30+
| 'bounce'
31+
| 'bounceIn'
32+
| 'bounceOut'
33+
| 'bounceInOut'
34+
| 'circle'
35+
| 'circleIn'
36+
| 'circleOut'
37+
| 'circleInOut'
38+
| 'linear'
39+
| 'linearIn'
40+
| 'linearOut'
41+
| 'linearInOut'
42+
| 'cubic'
43+
| 'cubicIn'
44+
| 'cubicOut'
45+
| 'cubicInOut'
46+
| 'elastic'
47+
| 'elasticIn'
48+
| 'elasticOut'
49+
| 'elasticInOut'
50+
| 'exp'
51+
| 'expIn'
52+
| 'expOut'
53+
| 'expInOut'
54+
| 'poly'
55+
| 'polyIn'
56+
| 'polyOut'
57+
| 'polyInOut'
58+
| 'quad'
59+
| 'quadIn'
60+
| 'quadOut'
61+
| 'quadInOut'
62+
| 'sin'
63+
| 'sinIn'
64+
| 'sinOut'
65+
| 'sinInOut';
66+
67+
/**
68+
* Progress Types for Spectacle
69+
*/
70+
type progressType = 'pacman' | 'bar' | 'number' | 'none';
71+
72+
/**
73+
* S Types for StyledS in Spectacle
74+
*/
75+
type sType = 'italic' | 'bold' | 'line-through' | 'underline';
76+
77+
/**
78+
* Target Types for links
79+
*/
80+
type targetType = '_blank' | '_self' | '_parent' | '_top';
81+
82+
/**
83+
* Theme Types for CodePane in Spectacle
84+
*/
85+
type themeType = 'dark' | 'light' | 'external';
86+
87+
/**
88+
* Transition Types for Spectacle
89+
*/
90+
type transitionType = 'slide' | 'zoom' | 'fade' | 'spin';
91+
92+
/**
93+
* All available DOM style properties and their types
94+
* https://www.npmjs.com/package/csstype
95+
*/
96+
interface CSSProperties extends CSS.Properties<string | number> {}
97+
98+
interface AnimProps {
99+
easing: easeType;
100+
fromStyle: CSSProperties | CSSProperties[];
101+
onAnim?: (forwards?: boolean, animIndex?: number) => void;
102+
order?: number;
103+
route?: object;
104+
style?: CSSProperties;
105+
toStyle: CSSProperties | CSSProperties[];
106+
transitionDuration: number;
107+
}
108+
109+
interface AppearProps {
110+
easing?: easeType;
111+
endValue?: object;
112+
fid?: string;
113+
order?: number;
114+
startValue?: object;
115+
style?: BaseProps['style'];
116+
transitionDuration?: number;
117+
}
118+
119+
/**
120+
* Base props for many Spectacle components
121+
*/
122+
interface BaseProps {
123+
bgColor?: string;
124+
bgDarken?: number;
125+
bgImage?: string;
126+
bold?: boolean;
127+
caps?: boolean;
128+
className?: string;
129+
italic?: boolean;
130+
margin?: number | string;
131+
padding?: number | string;
132+
style?: CSSProperties;
133+
textAlign?: string;
134+
textColor?: string;
135+
textFont?: string;
136+
textSize?: string;
137+
}
138+
139+
interface CodePaneProps {
140+
className?: BaseProps['className'];
141+
contentEditable?: boolean;
142+
lang?: string;
143+
source?: string;
144+
style?: BaseProps['style'];
145+
theme?: themeType;
146+
}
147+
148+
interface ComponentPlaygroundProps {
149+
code?: string;
150+
previewBackgroundColor?: string;
151+
scope?: object;
152+
theme?: themeType;
153+
transformCode?: (code: string) => string;
154+
}
155+
156+
interface DeckProps {
157+
autoplay?: boolean;
158+
autoplayDuration?: number;
159+
autoplayLoop?: boolean;
160+
controls?: boolean;
161+
globalStyles?: boolean;
162+
history?: any; // Needs a type, see https://github.com/ReactTraining/history
163+
onStateChange?: (previousState?: string, nextState?: string) => void;
164+
progress?: progressType;
165+
theme?: Theme;
166+
transition?: transitionType[];
167+
transitionDuration?: number;
168+
}
169+
170+
interface FillProps {
171+
className?: string;
172+
style?: CSSProperties;
173+
}
174+
175+
interface FitProps extends FillProps {} // tslint:disable-line:no-empty-interface
176+
177+
interface GoToActionProps {
178+
margin?: BaseProps['margin'];
179+
padding?: BaseProps['padding'];
180+
render?: (goToSlide?: (slide: number | string) => void) => void;
181+
slide?: number | string;
182+
style?: BaseProps['style'];
183+
}
184+
185+
interface HeadingProps extends BaseProps {
186+
fit?: boolean;
187+
lineHeight?: number;
188+
size?: number;
189+
}
190+
191+
interface ImageProps {
192+
alt?: string;
193+
className?: BaseProps['className'];
194+
display?: string;
195+
height?: number | string;
196+
margin?: BaseProps['margin'];
197+
padding?: BaseProps['padding'];
198+
src?: string;
199+
width?: number | string;
200+
}
201+
202+
interface LayoutProps {
203+
style?: CSSProperties;
204+
}
205+
206+
interface LinkProps extends BaseProps {
207+
href?: string;
208+
target?: targetType;
209+
}
210+
211+
interface MarkdownProps {
212+
mdastConfig?: { [key: string]: number | string };
213+
source?: string;
214+
}
215+
216+
interface SlideProps extends BaseProps {
217+
align?: alignType;
218+
contentStyles?: CSSProperties;
219+
controlColor?: string;
220+
dispatch?: () => void;
221+
hash?: number | string;
222+
progressColor?: string;
223+
history?: any; // Needs a type, see https://github.com/ReactTraining/history
224+
id?: string;
225+
lastSlideIndex?: number;
226+
notes?: string;
227+
onActive?: (slideIndex: string | number) => void;
228+
slideIndex?: number;
229+
state?: string;
230+
transition?: transitionType[];
231+
transitionDuration?: number;
232+
transitionIn?: transitionType[];
233+
transitionOut?: transitionType[];
234+
}
235+
236+
interface SProps extends BaseProps {
237+
type?: sType | sType[];
238+
}
239+
240+
interface TextProps extends BaseProps {
241+
fit?: boolean;
242+
lineHeight?: number;
243+
}
244+
245+
interface Theme {
246+
[key: string]: number | string;
247+
}
248+
249+
class Anim extends React.Component<AnimProps> {}
250+
251+
class Appear extends React.Component<AppearProps> {}
252+
253+
class BlockQuote extends React.Component<BaseProps> {}
254+
255+
class Cite extends React.Component<BaseProps> {}
256+
257+
class Code extends React.Component<BaseProps> {}
258+
259+
class CodePane extends React.Component<CodePaneProps> {}
260+
261+
class ComponentPlayground extends React.Component<ComponentPlaygroundProps> {}
262+
263+
class Deck extends React.Component<DeckProps> {}
264+
265+
class Fill extends React.Component<FillProps> {}
266+
267+
class Fit extends React.Component<FitProps> {}
268+
269+
class GoToAction extends React.Component<GoToActionProps> {}
270+
271+
class Heading extends React.Component<HeadingProps> {}
272+
273+
class Image extends React.Component<ImageProps> {}
274+
275+
class Layout extends React.Component<LayoutProps> {}
276+
277+
class Link extends React.Component<LinkProps> {}
278+
279+
class List extends React.Component<BaseProps> {}
280+
281+
class ListItem extends React.Component<BaseProps> {}
282+
283+
class Markdown extends React.Component<MarkdownProps> {}
284+
285+
class Notes extends React.Component<BaseProps> {}
286+
287+
class Quote extends React.Component<BaseProps> {}
288+
289+
class S extends React.Component<SProps> {}
290+
291+
class Slide extends React.Component<SlideProps> {}
292+
293+
class SlideSet extends React.Component<BaseProps> {}
294+
295+
class Table extends React.Component<BaseProps> {}
296+
297+
class TableBody extends React.Component<BaseProps> {}
298+
299+
class TableHeader extends React.Component<BaseProps> {}
300+
301+
class TableHeaderItem extends React.Component<BaseProps> {}
302+
303+
class TableItem extends React.Component<BaseProps> {}
304+
305+
class TableRow extends React.Component<BaseProps> {}
306+
307+
class Text extends React.Component<TextProps> {}
308+
}
309+
310+
declare module 'spectacle/lib/utils/preloader' {
311+
const preloader: (obj: object) => void;
312+
export default preloader;
313+
}
314+
315+
declare module 'spectacle/lib/themes/default' {
316+
import { Theme } from 'spectacle';
317+
const createTheme: (...args: object[]) => Theme;
318+
export default createTheme;
319+
}

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"description": "ReactJS Powered Presentation Framework",
55
"main": "lib/index.js",
66
"module": "es/index.js",
7+
"types": "index.d.ts",
78
"jsnext:main": "es/index.js",
89
"scripts": {
9-
"preversion": "npm run test && npm run lint",
10+
"preversion": "npm run check",
1011
"version": "npm run build:publish",
1112
"clean:lib": "rimraf lib",
1213
"clean:dist": "rimraf dist",
@@ -22,16 +23,19 @@
2223
"build:dist-umd-prod": "builder run build-webpack -- --config webpack.config.umd.production.js",
2324
"build": "builder concurrent --buffer build:es build:lib build:dist build:dist-umd build:dist-umd-prod",
2425
"build:publish": "npm run clean && npm run build",
25-
"lint": "eslint src example *.js",
26-
"lint-fix": "npm run lint -- --fix",
27-
"prettier": "prettier \"**/*.{js,json,css,md}\"",
26+
"lint": "npm run lint-js && npm run lint-dts",
27+
"lint-js": "eslint src example *.js",
28+
"lint-fix": "npm run lint-js -- --fix && npm run lint-dts -- --fix",
29+
"lint-dts": "tslint index.d.ts --format verbose",
30+
"prettier": "prettier \"**/*.{js,json,ts,css,md}\"",
2831
"prettier-fix": "npm run prettier -- --write",
2932
"prettier-check": "npm run prettier -- --list-different",
3033
"deploy": "npm run build:dist && surge -p .",
3134
"start": "builder run --env \"{\\\"BABEL_ENV\\\":\\\"esm\\\"}\" build-wds-base -- --port=3000 --hot",
3235
"test": "jest --verbose",
3336
"test-debug": "node --inspect-brk node_modules/jest/bin/jest.js --runInBand",
34-
"check": "npm run lint && npm run test",
37+
"check-typescript": "tsc index.d.ts && npm run lint-dts",
38+
"check": "npm run lint-js && npm run check-typescript && npm run test",
3539
"check-ci": "npm run check && npm run prettier-check"
3640
},
3741
"author": "",
@@ -41,6 +45,7 @@
4145
"url": "https://github.com/FormidableLabs/spectacle.git"
4246
},
4347
"dependencies": {
48+
"csstype": "^2.6.0",
4449
"deep-object-diff": "^1.0.4",
4550
"emotion": "^8.0.8",
4651
"history": "^4.6.1",
@@ -102,6 +107,8 @@
102107
"rimraf": "^2.6.1",
103108
"style-loader": "^0.20.3",
104109
"surge": "^0.19.0",
110+
"tslint": "^5.12.0",
111+
"typescript": "^3.2.2",
105112
"url-loader": "^1.0.1",
106113
"webpack": "^4.26.1",
107114
"webpack-cli": "^3.1.2",

0 commit comments

Comments
 (0)