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 2 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
4 changes: 4 additions & 0 deletions 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'

export type ExtendProperties = {
extends: string[]
hosseinmd marked this conversation as resolved.
Show resolved Hide resolved
}

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
38 changes: 22 additions & 16 deletions packages/jss/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,38 @@ import {Observable} from 'indefinite-observable'
type Func<R> = ((data: any) => R)

type NormalCssProperties = CSSProperties<string | number>
type NormalCssValues<K> = K extends keyof NormalCssProperties
? NormalCssProperties[K]
: JssValue
type NormalCssValues<K> = K extends keyof NormalCssProperties ? NormalCssProperties[K] : JssValue

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

export type Styles<Name extends string | number | symbol = string> = Record<
export type Styles<
Name extends string | number | symbol = string,
// ADDITIONAL_PROPERTIES
A extends Record<string, any> = {}
> = Record<
Name,
| JssStyle
| JssStyle<A>
| string
| Func<JssStyle | string | null | undefined>
| Observable<JssStyle | string | null | undefined>
| Func<JssStyle<A> | 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 @@ -248,9 +254,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>>,
styles: Partial<Styles<Name, ADDITIONAL_PROPERTIES>>,
options?: StyleSheetFactoryOptions
): StyleSheet<Name>
removeStyleSheet(sheet: StyleSheet): this
Expand Down
3 changes: 2 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 @@ -73,7 +74,7 @@ interface CreateUseStylesOptions<Theme = DefaultTheme> extends BaseOptions<Theme
}

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

Expand Down