Skip to content

Commit 2cb3fee

Browse files
author
Henri
authored
Udpate ts typings (#1155)
* Add types for createUseStyles and improve Style type * Add string support for createUseStyles * Update changelog
1 parent 0b135af commit 2cb3fee

5 files changed

Lines changed: 50 additions & 9 deletions

File tree

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Since you are interested in what happens next, in case, you work for a for-profit company that benefits from using the project, please consider supporting it on https://opencollective.com/jss.
44

5+
### Improvements
6+
7+
- [react-jss] Improve TypeScript definitions and add missing definition for `createUseStyles` ([1155](https://github.com/cssinjs/jss/pull/1155))
8+
9+
### Bug fixes
10+
11+
- [react-jss] Fix nested dynamic rule updating ([1144](https://github.com/cssinjs/jss/pull/1144))
12+
513
---
614

715
### Bug fixes

packages/jss/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@babel/runtime": "^7.3.1",
41+
"csstype": "^2.6.5",
4142
"is-in-browser": "^1.1.3",
4243
"tiny-warning": "^1.0.2"
4344
}

packages/jss/src/index.d.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
export type Style = {[key: string]: Style | any}
2-
export type Styles<Name extends string = string> = Record<Name, Style>
3-
export type Classes<Name extends string = string> = Record<Name, string>
1+
import * as css from 'csstype'
2+
3+
// @ts-ignore
4+
export type Style = css.StandardProperties<string | number | (() => string | number)> & {
5+
[key: string]: Style | string | number
6+
}
7+
export type Styles<Name extends string = string> = Record<Name, Style | string>
8+
export type Classes<Name extends string | number | symbol = string> = Record<Name, string>
49
export type Keyframes<Name extends string = string> = Record<Name, string>
510

611
export interface CreateGenerateIdOptions {
@@ -204,7 +209,7 @@ export interface StyleSheet<RuleName extends string = string> {
204209
export interface JssOptions {
205210
createGenerateId: CreateGenerateId
206211
plugins: ReadonlyArray<Plugin>
207-
Renderer?: Renderer | null
212+
Renderer?: {new (): Renderer} | null
208213
insertionPoint: InsertionPoint
209214
}
210215

packages/react-jss/src/index.d.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
SheetsRegistry,
77
Styles,
88
StyleSheetFactoryOptions,
9-
CreateGenerateIdOptions
9+
CreateGenerateIdOptions,
10+
Classes,
11+
Style
1012
} from 'jss'
1113
import {createTheming, useTheme, withTheme, ThemeProvider, Theming} from 'theming'
1214

@@ -39,10 +41,10 @@ declare const JssContext: Context<{
3941
type ThemedStyles<Theme> = (theme: Theme) => Styles<string>
4042

4143
interface WithStyles<S extends Styles<string> | ThemedStyles<any>> {
42-
classes: Record<S extends ThemedStyles<any> ? keyof ReturnType<S> : keyof S, string>
44+
classes: Classes<S extends ThemedStyles<any> ? keyof ReturnType<S> : keyof S>
4345
}
4446

45-
interface Options extends StyleSheetFactoryOptions {
47+
interface WithStylesOptions extends StyleSheetFactoryOptions {
4648
index?: number
4749
injectTheme?: boolean
4850
jss?: Jss
@@ -51,9 +53,28 @@ interface Options extends StyleSheetFactoryOptions {
5153

5254
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
5355

56+
export {Styles}
57+
58+
declare function createUseStyles<C extends string>(
59+
styles: Record<C, Style | string>,
60+
options?: {
61+
index?: number
62+
name?: string
63+
} & StyleSheetFactoryOptions
64+
): (data?: any) => Record<C, string>
65+
66+
declare function createUseStyles<T, C extends string>(
67+
styles: (theme: T) => Record<C, Style | string>,
68+
options?: {
69+
index?: number
70+
name?: string
71+
theming?: Theming<T>
72+
} & StyleSheetFactoryOptions
73+
): (data?: any) => Record<C, string>
74+
5475
declare function withStyles<S extends Styles<string> | ThemedStyles<any>>(
5576
styles: S,
56-
options?: Options
77+
options?: WithStylesOptions
5778
): <Props extends WithStyles<S>>(
5879
comp: ComponentType<Props>
5980
) => ComponentType<Omit<Props, 'classes'> & {classes?: Partial<Props['classes']>}>
@@ -68,7 +89,8 @@ export {
6889
withTheme,
6990
createTheming,
7091
useTheme,
71-
JssContext
92+
JssContext,
93+
createUseStyles
7294
}
7395

7496
export default withStyles

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,6 +3168,11 @@ csstype@^2.2.0:
31683168
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff"
31693169
integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw==
31703170

3171+
csstype@^2.6.5:
3172+
version "2.6.5"
3173+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.5.tgz#1cd1dff742ebf4d7c991470ae71e12bb6751e034"
3174+
integrity sha512-JsTaiksRsel5n7XwqPAfB0l3TFKdpjW/kgAELf9vrb5adGA7UCPLajKK5s3nFrcFm3Rkyp/Qkgl73ENc1UY3cA==
3175+
31713176
currently-unhandled@^0.4.1:
31723177
version "0.4.1"
31733178
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"

0 commit comments

Comments
 (0)