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

Type: Resolve plugins additional properties #1464

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions packages/jss-plugin-compose/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {Plugin} from 'jss'

export type ComposeProperties = {
composes: (string | string[])[]
hosseinmd marked this conversation as resolved.
Show resolved Hide resolved
}

export default function jssPluginSyntaxCompose(): Plugin
6 changes: 5 additions & 1 deletion packages/jss-plugin-extend/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {Plugin} from 'jss'
import {JssStyle, Plugin} from 'jss'

export type ExtendProperties = {
extends: (JssStyle | string)[] | JssStyle | string
}

export default function jssPluginSyntaxExtend(): Plugin
4 changes: 4 additions & 0 deletions packages/jss-preset-default/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {Plugin, JssOptions} from 'jss'
import {Options as DefaultUnitOptions} from 'jss-plugin-default-unit'
import {Options as ObservableOptions} from 'jss-plugin-rule-value-observable'
import {ComposeProperties} from 'jss-plugin-compose'
import {ExtendProperties} from 'jss-plugin-extend'

type Options = {defaultUnit?: DefaultUnitOptions; observable?: ObservableOptions}

export type AdditionalProperties = ComposeProperties & ExtendProperties

export default function jssPresetDefault(options?: Options): JssOptions
29 changes: 17 additions & 12 deletions packages/jss/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,38 @@ type Func<P, T, R> = T extends undefined ? ((data: P) => R) : ((data: P & {theme
type NormalCssProperties = CSSProperties<string | number>
type NormalCssValues<K> = K extends keyof NormalCssProperties ? NormalCssProperties[K] : JssValue

export type JssStyle<Props = any, Theme = undefined> =
export type JssStyle<A extends Record<string, any> = {}, Props = any, Theme = undefined> =
// ADDITIONAL_PROPERTIES
| A
| {
[K in keyof NormalCssProperties]:
| NormalCssValues<K>
| JssStyle<Props, Theme>
| Func<Props, Theme, NormalCssValues<K> | JssStyle<undefined, undefined> | undefined>
| Observable<NormalCssValues<K> | JssStyle | undefined>
| JssStyle<A, Props, Theme>
| Func<Props, Theme, NormalCssValues<K> | JssStyle<A, undefined, undefined> | undefined>
| Observable<NormalCssValues<K> | JssStyle<A> | undefined>
}
| {
[K: string]:
| JssValue
| JssStyle<Props, Theme>
| Func<Props, Theme, JssValue | JssStyle<undefined, undefined> | undefined>
| Observable<JssValue | JssStyle | undefined>
| JssStyle<A, Props, Theme>
| Func<Props, Theme, JssValue | JssStyle<A, undefined, undefined> | undefined>
| Observable<JssValue | JssStyle<A> | undefined>
}

export type Styles<
Name extends string | number | symbol = string,
// ADDITIONAL_PROPERTIES
A extends Record<string, any> = {},
Props = unknown,
Theme = undefined
> = Record<
Name,
| JssStyle<Props, Theme>
| JssStyle<A, Props, Theme>
| string
| Func<Props, Theme, JssStyle<undefined, undefined> | string | null | undefined>
| Observable<JssStyle | string | null | undefined>
| Func<Props, Theme, JssStyle<A, undefined, undefined> | string | null | undefined>
| Observable<JssStyle<A> | string | null | undefined>
>

export type Classes<Name extends string | number | symbol = string> = Record<Name, string>
export type Keyframes<Name extends string = string> = Record<Name, string>

Expand Down Expand Up @@ -252,9 +257,9 @@ export interface JssOptions {
id: CreateGenerateIdOptions
}

export interface Jss {
export interface Jss<ADDITIONAL_PROPERTIES extends Record<string, any> = {}> {
createStyleSheet<Name extends string | number | symbol>(
styles: Partial<Styles<Name, any, undefined>>,
styles: Partial<Styles<Name, ADDITIONAL_PROPERTIES, any, undefined>>,
options?: StyleSheetFactoryOptions
): StyleSheet<Name>
removeStyleSheet(sheet: StyleSheet): this
Expand Down
5 changes: 4 additions & 1 deletion packages/react-jss/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Classes
} from 'jss'
import {createTheming, useTheme, withTheme, ThemeProvider, Theming} from 'theming'
import {AdditionalProperties} from 'jss-preset-default'

declare const jss: Jss

Expand Down Expand Up @@ -77,7 +78,9 @@ interface CreateUseStylesOptions<Theme = DefaultTheme> extends BaseOptions<Theme
}

declare function createUseStyles<C extends string = string, Props = unknown, Theme = DefaultTheme>(
styles: Styles<C, Props, Theme> | ((theme: Theme) => Styles<C, Props, undefined>),
styles:
| Styles<C, AdditionalProperties, Props, Theme>
| ((theme: Theme) => Styles<C, AdditionalProperties, Props, undefined>),
options?: CreateUseStylesOptions<Theme>
): (data?: Props & {theme?: Theme}) => Classes<C>

Expand Down