Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Udpate ts typings #1155

Merged
merged 4 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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.

### Improvements

- [react-jss] Improve TypeScript definitions and add missing definition for `createUseStyles` ([1155](https://github.com/cssinjs/jss/pull/1155))

### Bug fixes

- [react-jss] Fix nested dynamic rule updating ([1144](https://github.com/cssinjs/jss/pull/1144))

---

## 10.0.0-alpha.22 (2019-7-2)
Expand Down
1 change: 1 addition & 0 deletions packages/jss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@babel/runtime": "^7.3.1",
"csstype": "^2.6.5",
HenriBeck marked this conversation as resolved.
Show resolved Hide resolved
"is-in-browser": "^1.1.3",
"tiny-warning": "^1.0.2"
}
Expand Down
13 changes: 9 additions & 4 deletions packages/jss/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export type Style = {[key: string]: Style | any}
export type Styles<Name extends string = string> = Record<Name, Style>
export type Classes<Name extends string = string> = Record<Name, string>
import * as css from 'csstype'

// @ts-ignore
export type Style = css.StandardProperties<string | number | (() => string | number)> & {
[key: string]: Style | string | number
}
export type Styles<Name extends string = string> = Record<Name, Style | string>
export type Classes<Name extends string | number | symbol = string> = Record<Name, string>
export type Keyframes<Name extends string = string> = Record<Name, string>

export interface CreateGenerateIdOptions {
Expand Down Expand Up @@ -204,7 +209,7 @@ export interface StyleSheet<RuleName extends string = string> {
export interface JssOptions {
createGenerateId: CreateGenerateId
plugins: ReadonlyArray<Plugin>
Renderer?: Renderer | null
Renderer?: {new (): Renderer} | null
insertionPoint: InsertionPoint
}

Expand Down
32 changes: 27 additions & 5 deletions packages/react-jss/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
SheetsRegistry,
Styles,
StyleSheetFactoryOptions,
CreateGenerateIdOptions
CreateGenerateIdOptions,
Classes,
Style
} from 'jss'
import {createTheming, useTheme, withTheme, ThemeProvider, Theming} from 'theming'

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

interface WithStyles<S extends Styles<string> | ThemedStyles<any>> {
classes: Record<S extends ThemedStyles<any> ? keyof ReturnType<S> : keyof S, string>
classes: Classes<S extends ThemedStyles<any> ? keyof ReturnType<S> : keyof S>
}

interface Options extends StyleSheetFactoryOptions {
interface WithStylesOptions extends StyleSheetFactoryOptions {
index?: number
injectTheme?: boolean
jss?: Jss
Expand All @@ -51,9 +53,28 @@ interface Options extends StyleSheetFactoryOptions {

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

export {Styles}

declare function createUseStyles<C extends string>(
styles: Record<C, Style | string>,
options?: {
index?: number
name?: string
} & StyleSheetFactoryOptions
): (data?: any) => Record<C, string>

declare function createUseStyles<T, C extends string>(
styles: (theme: T) => Record<C, Style | string>,
options?: {
index?: number
name?: string
theming?: Theming<T>
} & StyleSheetFactoryOptions
): (data?: any) => Record<C, string>

declare function withStyles<S extends Styles<string> | ThemedStyles<any>>(
styles: S,
options?: Options
options?: WithStylesOptions
): <Props extends WithStyles<S>>(
comp: ComponentType<Props>
) => ComponentType<Omit<Props, 'classes'> & {classes?: Partial<Props['classes']>}>
Expand All @@ -68,7 +89,8 @@ export {
withTheme,
createTheming,
useTheme,
JssContext
JssContext,
createUseStyles
}

export default withStyles
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,11 @@ csstype@^2.2.0:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff"
integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw==

csstype@^2.6.5:
version "2.6.5"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.5.tgz#1cd1dff742ebf4d7c991470ae71e12bb6751e034"
integrity sha512-JsTaiksRsel5n7XwqPAfB0l3TFKdpjW/kgAELf9vrb5adGA7UCPLajKK5s3nFrcFm3Rkyp/Qkgl73ENc1UY3cA==

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
Expand Down