Skip to content

Commit 0dae728

Browse files
author
Henri
authored
(split)Add TS type defs (cssinjs#889)
* Started on ts typings * - Added tsconfig.json - Added typings field to every package.json file * Added Options to observable plugin * Update jss typings * Rename generateClassName to generateId * Started on react-jss types * - Finished typings for react-jss - Added ts-check to CI and pre-commit hook * Update size-snapshots * Update changelog * Update snapshots
1 parent a7498d2 commit 0dae728

File tree

4 files changed

+67
-20
lines changed

4 files changed

+67
-20
lines changed

.size-snapshot.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
22
"dist/react-jss.js": {
3-
"bundled": 124994,
4-
"minified": 43271,
5-
"gzipped": 13017
3+
"bundled": 124943,
4+
"minified": 43246,
5+
"gzipped": 13007
66
},
77
"dist/react-jss.min.js": {
8-
"bundled": 101586,
9-
"minified": 36100,
10-
"gzipped": 10926
8+
"bundled": 101535,
9+
"minified": 36075,
10+
"gzipped": 10916
1111
},
1212
"dist/react-jss.cjs.js": {
13-
"bundled": 16667,
14-
"minified": 6922,
15-
"gzipped": 2420
13+
"bundled": 16617,
14+
"minified": 6893,
15+
"gzipped": 2410
1616
},
1717
"dist/react-jss.esm.js": {
18-
"bundled": 16117,
19-
"minified": 6452,
20-
"gzipped": 2306,
18+
"bundled": 16063,
19+
"minified": 6420,
20+
"gzipped": 2295,
2121
"treeshaked": {
2222
"rollup": {
23-
"code": 1896,
24-
"import_statements": 424
23+
"code": 1866,
24+
"import_statements": 410
2525
},
2626
"webpack": {
27-
"code": 3203
27+
"code": 3178
2828
}
2929
}
3030
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "dist/react-jss.cjs.js",
77
"module": "dist/react-jss.esm.js",
88
"homepage": "http://cssinjs.org/react-jss",
9+
"typings": "./src/index.d.ts",
910
"author": {
1011
"name": "Dan Abramov",
1112
"email": "dan.abramov@me.com"
@@ -40,6 +41,7 @@
4041
},
4142
"dependencies": {
4243
"@babel/runtime": "^7.0.0",
44+
"@types/react": "^16.4.18",
4345
"hoist-non-react-statics": "^2.5.0",
4446
"jss": "^9.7.0",
4547
"jss-preset-default": "^4.3.0",

src/JssProvider.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import {Component, Children, type Element, type ElementType} from 'react'
2+
import {Component, type Node} from 'react'
33
import PropTypes from 'prop-types'
44
import type {Jss, GenerateId, SheetsRegistry} from 'jss'
55
import {createGenerateIdDefault} from './jss'
@@ -16,7 +16,7 @@ type Props = {
1616
generateId?: GenerateId,
1717
classNamePrefix?: string,
1818
disableStylesGeneration?: boolean,
19-
children: Element<ElementType>
19+
children: Node
2020
}
2121

2222
export default class JssProvider extends Component<Props> {
@@ -95,8 +95,6 @@ export default class JssProvider extends Component<Props> {
9595
generateId: GenerateId
9696

9797
render() {
98-
const {children} = this.props
99-
100-
return Children.only(children)
98+
return this.props.children
10199
}
102100
}

src/index.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from 'react'
2+
import {
3+
StyleSheet,
4+
CreateGenerateId,
5+
GenerateId,
6+
Jss,
7+
SheetsRegistry,
8+
Styles,
9+
StyleSheetFactoryOptions
10+
} from 'jss'
11+
12+
export const jss: Jss
13+
export {SheetsRegistry}
14+
export const createGenerateId: CreateGenerateId
15+
16+
export const JssProvider: React.ComponentType<{
17+
jss?: Jss
18+
registry?: SheetsRegistry
19+
generateId?: GenerateId
20+
classNamePrefix?: string
21+
disableStylesGeneration?: boolean
22+
children: React.ReactNode
23+
}>
24+
25+
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
26+
type Options = {
27+
index?: number
28+
inject?: Array<'classes' | 'theme' | 'sheet'>
29+
jss?: Jss
30+
} & StyleSheetFactoryOptions
31+
32+
type InjectedProps<Styles, Theme> = {
33+
classes: {[key in keyof Styles]: string}
34+
theme?: Theme
35+
sheet?: StyleSheet
36+
}
37+
38+
export default function injectSheet<
39+
Style extends Styles,
40+
Theme extends object,
41+
Props extends InjectedProps<Styles, Theme>
42+
>(
43+
styles: Style,
44+
options?: Options
45+
): (
46+
comp: React.ComponentType<Props>
47+
) => React.ComponentType<Omit<Props, InjectedProps<Styles, Theme>>>

0 commit comments

Comments
 (0)