Skip to content
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
9 changes: 2 additions & 7 deletions packages/core/types/css-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ type TokenByPropertyName<PropertyName, Theme, ThemeMap> = PropertyName extends k

type TokenByScaleName<ScaleName, Theme> = ScaleName extends keyof Theme ? Util.Prefixed<'$', keyof Theme[ScaleName]> : never

/** Returns a Style interface, leveraging the given media and style map. */
/** Returns a Style interface, leveraging the given style map. */
export type CSS<
Media = {},
Theme = {},
ThemeMap = Config.DefaultThemeMap,
Utils = {},
> = (
// nested at-rule css styles
& {
[K in Util.Prefixed<'@', keyof Media>]?: CSS<Media, Theme, ThemeMap, Utils>
}
// known property styles
& {
[K in keyof CSSProperties as K extends keyof Utils ? never : K]?: (
Expand Down Expand Up @@ -95,7 +90,7 @@ export type CSS<
[K: string]: (
| number
| string
| CSS<Media, Theme, ThemeMap, Utils>
| CSS<Theme, ThemeMap, Utils>
| {}
| undefined
)
Expand Down
4 changes: 1 addition & 3 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type CSS<
utils: {}
}
> = CSSUtil.CSS<
Config['media'],
Config['theme'],
Config['themeMap'],
Config['utils']
Expand All @@ -39,7 +38,6 @@ export type PropertyValue<Property extends keyof CSSUtil.CSSProperties, Config =
? CSSUtil.WithPropertyValue<Property>
: Config extends { [K: string]: any }
? CSSUtil.CSS<
Config['media'],
Config['theme'],
Config['themeMap'],
Config['utils']
Expand All @@ -59,7 +57,7 @@ export type ScaleValue<Scale, Config = null> = (
)

/** Returns a type that suggests variants from a component as possible prop values. */
export type VariantProps<Component extends {[key: symbol | string]: any}> = StyledComponent.TransformProps<Component[StyledComponent.$$StyledComponentProps], Component[StyledComponent.$$StyledComponentMedia]>
export type VariantProps<Component extends {[key: symbol | string]: any}> = Component[StyledComponent.$$StyledComponentProps]

/** Map of CSS properties to token scales. */
export declare const defaultThemeMap: DefaultThemeMap
Expand Down
14 changes: 7 additions & 7 deletions packages/core/types/stitches.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type RemoveIndex<T> = {[k in keyof T as string extends k ? never : number
export interface CssFunctionType<Media extends {} = {}, Theme extends {} = {}, ThemeMap extends {} = {}, Utils extends {} = {}> {
<Composers extends (string | Util.Function | {
[name: string]: unknown
})[], CSS = CSSUtil.CSS<Media, Theme, ThemeMap, Utils>>(...composers: {
})[], CSS = CSSUtil.CSS<Theme, ThemeMap, Utils>>(...composers: {
[K in keyof Composers]: (
// Strings and Functions can be skipped over
string extends Composers[K] ? Composers[K] : Composers[K] extends string | Util.Function ? Composers[K] : RemoveIndex<CSS> & {
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface CssFunctionType<Media extends {} = {}, Theme extends {} = {}, T
} & CSS & {
[K2 in keyof Composers[K]]: K2 extends 'compoundVariants' | 'defaultVariants' | 'variants' ? unknown : K2 extends keyof CSS ? CSS[K2] : unknown
})
}): StyledComponent.CssComponent<StyledComponent.StyledComponentType<Composers>, StyledComponent.StyledComponentProps<Composers>, Media, CSS>
}): StyledComponent.CssComponent<StyledComponent.StyledComponentType<Composers>, StyledComponent.StyledComponentProps<Composers>, CSS>
}

/** Stitches interface. */
Expand Down Expand Up @@ -82,11 +82,11 @@ export default interface Stitches<
? CSSUtil.Native.AtRule.FontFace | Array<CSSUtil.Native.AtRule.FontFace>
: K extends `@keyframes ${string}`
? {
[KeyFrame in string]: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
[KeyFrame in string]: CSSUtil.CSS<Theme, ThemeMap, Utils>
}
: K extends `@property ${string}`
? CSSUtil.Native.AtRule.Property
: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
: CSSUtil.CSS<Theme, ThemeMap, Utils>
)
}
)[]
Expand All @@ -96,7 +96,7 @@ export default interface Stitches<
},
keyframes: {
(style: {
[offset: string]: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
[offset: string]: CSSUtil.CSS<Theme, ThemeMap, Utils>
}): {
(): string
name: string
Expand Down Expand Up @@ -174,8 +174,8 @@ export default interface Stitches<
componentId?: string
displayName?: string
shouldForwardStitchesProp?: (prop: 'css' | (string & {})) => boolean | void
}) => CssFunctionType<Media, Theme, ThemeMap, Utils>
} & CssFunctionType<Media, Theme, ThemeMap, Utils>
}) => CssFunctionType<Theme, ThemeMap, Utils>
} & CssFunctionType<Theme, ThemeMap, Utils>
}

type ThemeTokens<Values, Prefix> = {
Expand Down
23 changes: 0 additions & 23 deletions packages/core/types/styled-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import type * as Util from './util.js'
export interface CssComponent<
Type = 'span',
Props = {},
Media = {},
CSS = {}
> {
(
props?:
& TransformProps<Props, Media>
& {
css?: CSS
}
Expand All @@ -27,21 +25,6 @@ export interface CssComponent<

[$$StyledComponentType]: Type
[$$StyledComponentProps]: Props
[$$StyledComponentMedia]: Media
}

export type TransformProps<Props, Media> = {
[K in keyof Props]: (
| Props[K]
| (
& {
[KMedia in Util.Prefixed<'@', 'initial' | keyof Media>]?: Props[K]
}
& {
[KMedia in string]: Props[K]
}
)
)
}

/** Unique symbol used to reference the type of a Styled Component. */
Expand All @@ -56,12 +39,6 @@ export declare const $$StyledComponentProps: unique symbol
/** Unique symbol used to reference the props of a Styled Component. */
export type $$StyledComponentProps = typeof $$StyledComponentProps

/** Unique symbol used to reference the media passed into a Styled Component. */
export declare const $$StyledComponentMedia: unique symbol

/** Unique symbol used to reference the media passed into a Styled Component. */
export type $$StyledComponentMedia = typeof $$StyledComponentMedia

/** Returns the first Styled Component type from the given array of compositions. */
export type StyledComponentType<T extends any[]> = (
T[0] extends never
Expand Down
9 changes: 2 additions & 7 deletions packages/react/types/css-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ type TokenByPropertyName<PropertyName, Theme, ThemeMap> = PropertyName extends k

type TokenByScaleName<ScaleName, Theme> = ScaleName extends keyof Theme ? Util.Prefixed<'$', keyof Theme[ScaleName]> : never

/** Returns a Style interface, leveraging the given media and style map. */
/** Returns a Style interface, leveraging the given style map. */
export type CSS<
Media = {},
Theme = {},
ThemeMap = Config.DefaultThemeMap,
Utils = {},
> = (
// nested at-rule css styles
& {
[K in Util.Prefixed<'@', keyof Media>]?: CSS<Media, Theme, ThemeMap, Utils>
}
// known property styles
& {
[K in keyof CSSProperties as K extends keyof Utils ? never : K]?: (
Expand Down Expand Up @@ -95,7 +90,7 @@ export type CSS<
[K: string]: (
| number
| string
| CSS<Media, Theme, ThemeMap, Utils>
| CSS<Theme, ThemeMap, Utils>
| {}
| undefined
)
Expand Down
4 changes: 1 addition & 3 deletions packages/react/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type CSS<
utils: {}
}
> = CSSUtil.CSS<
Config['media'],
Config['theme'],
Config['themeMap'],
Config['utils']
Expand All @@ -39,7 +38,6 @@ export type PropertyValue<Property extends keyof CSSUtil.CSSProperties, Config =
? CSSUtil.WithPropertyValue<Property>
: Config extends { [K: string]: any }
? CSSUtil.CSS<
Config['media'],
Config['theme'],
Config['themeMap'],
Config['utils']
Expand All @@ -59,7 +57,7 @@ export type ScaleValue<Scale, Config = null> = (
)

/** Returns a type that suggests variants from a component as possible prop values. */
export type VariantProps<Component extends {[key: symbol | string]: any}> = StyledComponent.TransformProps<Component[StyledComponent.$$StyledComponentProps], Component[StyledComponent.$$StyledComponentMedia]>
export type VariantProps<Component extends {[key: symbol | string]: any}> = Component[StyledComponent.$$StyledComponentProps];

/** Map of CSS properties to token scales. */
export declare const defaultThemeMap: DefaultThemeMap
Expand Down
26 changes: 13 additions & 13 deletions packages/react/types/stitches.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type * as Util from './util'
/** Remove an index signature from a type */
export type RemoveIndex<T> = {[k in keyof T as string extends k ? never : number extends k ? never : k]: T[k]}

export interface CssFunctionType<Media extends {} = {}, Theme extends {} = {}, ThemeMap extends {} = {}, Utils extends {} = {}> {
export interface CssFunctionType<Theme extends {} = {}, ThemeMap extends {} = {}, Utils extends {} = {}> {
<Composers extends (string | Util.Function | {
[name: string]: unknown
})[], CSS = CSSUtil.CSS<Media, Theme, ThemeMap, Utils>>(...composers: {
})[], CSS = CSSUtil.CSS<Theme, ThemeMap, Utils>>(...composers: {
[K in keyof Composers]: (
// Strings and Functions can be skipped over
string extends Composers[K] ? Composers[K] : Composers[K] extends string | Util.Function ? Composers[K] : RemoveIndex<CSS> & {
Expand Down Expand Up @@ -41,13 +41,13 @@ export interface CssFunctionType<Media extends {} = {}, Theme extends {} = {}, T
} & CSS & {
[K2 in keyof Composers[K]]: K2 extends 'compoundVariants' | 'defaultVariants' | 'variants' ? unknown : K2 extends keyof CSS ? CSS[K2] : unknown
})
}): StyledComponent.CssComponent<StyledComponent.StyledComponentType<Composers>, StyledComponent.StyledComponentProps<Composers>, Media, CSS>
}): StyledComponent.CssComponent<StyledComponent.StyledComponentType<Composers>, StyledComponent.StyledComponentProps<Composers>, CSS>
}

export interface StyledFunctionType<Media extends {} = {}, Theme extends {} = {}, ThemeMap extends {} = {}, Utils extends {} = {}> {
export interface StyledFunctionType<Theme extends {} = {}, ThemeMap extends {} = {}, Utils extends {} = {}> {
<Type extends keyof JSX.IntrinsicElements | React.ComponentType<any> | Util.Function, Composers extends (string | React.ComponentType<any> | Util.Function | {
[name: string]: unknown
})[], CSS = CSSUtil.CSS<Media, Theme, ThemeMap, Utils>>(type: Type, ...composers: {
})[], CSS = CSSUtil.CSS<Theme, ThemeMap, Utils>>(type: Type, ...composers: {
[K in keyof Composers]: (
// Strings, React Components, and Functions can be skipped over
string extends Composers[K] ? Composers[K] : Composers[K] extends string | React.ComponentType<any> | Util.Function ? Composers[K] : RemoveIndex<CSS> & {
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface StyledFunctionType<Media extends {} = {}, Theme extends {} = {}
} & CSS & {
[K2 in keyof Composers[K]]: K2 extends 'compoundVariants' | 'defaultVariants' | 'variants' ? unknown : K2 extends keyof CSS ? CSS[K2] : unknown
})
}): StyledComponent.StyledComponent<Type, StyledComponent.StyledComponentProps<Composers>, Media, CSSUtil.CSS<Media, Theme, ThemeMap, Utils>>
}): StyledComponent.StyledComponent<Type, StyledComponent.StyledComponentProps<Composers>, CSSUtil.CSS<Theme, ThemeMap, Utils>>
}

/** Stitches interface. */
Expand Down Expand Up @@ -120,11 +120,11 @@ export default interface Stitches<
? CSSUtil.Native.AtRule.FontFace | Array<CSSUtil.Native.AtRule.FontFace>
: K extends `@keyframes ${string}`
? {
[KeyFrame in string]: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
[KeyFrame in string]: CSSUtil.CSS<Theme, ThemeMap, Utils>
}
: K extends `@property ${string}`
? CSSUtil.Native.AtRule.Property
: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
: CSSUtil.CSS<Theme, ThemeMap, Utils>
)
}
)[]
Expand All @@ -134,7 +134,7 @@ export default interface Stitches<
},
keyframes: {
(style: {
[offset: string]: CSSUtil.CSS<Media, Theme, ThemeMap, Utils>
[offset: string]: CSSUtil.CSS<Theme, ThemeMap, Utils>
}): {
(): string
name: string
Expand Down Expand Up @@ -212,15 +212,15 @@ export default interface Stitches<
componentId?: string
displayName?: string
shouldForwardStitchesProp?: (prop: 'css' | (string & {})) => boolean | void
}) => CssFunctionType<Media, Theme, ThemeMap, Utils>
} & CssFunctionType<Media, Theme, ThemeMap, Utils>
}) => CssFunctionType<Theme, ThemeMap, Utils>
} & CssFunctionType<Theme, ThemeMap, Utils>
styled: {
withConfig: (config: {
componentId?: string
displayName?: string
shouldForwardStitchesProp?: (prop: 'css' | (string & {})) => boolean | void
}) => StyledFunctionType<Media, Theme, ThemeMap, Utils>
} & StyledFunctionType<Media, Theme, ThemeMap, Utils>
}) => StyledFunctionType<Theme, ThemeMap, Utils>
} & StyledFunctionType<Theme, ThemeMap, Utils>
}

type ThemeTokens<Values, Prefix> = {
Expand Down
33 changes: 4 additions & 29 deletions packages/react/types/styled-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ export type IntrinsicElementsKeys = keyof JSX.IntrinsicElements;
export interface StyledComponent<
Type = 'span',
Props = {},
Media = {},
CSS = {}
> extends React.ForwardRefExoticComponent<
Util.Assign<
Type extends IntrinsicElementsKeys | React.ComponentType<any>
? React.ComponentPropsWithRef<Type>
: never,
TransformProps<Props, Media> & { css?: CSS }
Props & { css?: CSS }
>
> {
(
props: Util.Assign<
Type extends IntrinsicElementsKeys | React.ComponentType<any>
? React.ComponentPropsWithRef<Type>
: {},
TransformProps<Props, Media> & {
Props & {
as?: never,
css?: CSS
}
Expand All @@ -33,11 +32,11 @@ export interface StyledComponent<
<
C extends CSS,
As extends string | React.ComponentType<any> = Type extends string | React.ComponentType<any> ? Type : any,
InnerProps = Type extends StyledComponent<any, infer IP, any, any> ? IP : {},
InnerProps = Type extends StyledComponent<any, infer IP, any> ? IP : {},
>(
props: Util.Assign<
React.ComponentPropsWithRef<As extends IntrinsicElementsKeys | React.ComponentType<any> ? As : never>,
TransformProps<Util.Assign<InnerProps, Props>, Media> & {
Util.Assign<InnerProps, Props> & {
as?: As,
css?: {
[K in keyof C]: K extends keyof CSS ? CSS[K] : never
Expand All @@ -51,19 +50,16 @@ export interface StyledComponent<

[$$StyledComponentType]: Type
[$$StyledComponentProps]: Props
[$$StyledComponentMedia]: Media
}

/** Returns a new CSS Component. */
export interface CssComponent<
Type = 'span',
Props = {},
Media = {},
CSS = {}
> {
(
props?:
& TransformProps<Props, Media>
& {
css?: CSS
}
Expand All @@ -81,21 +77,6 @@ export interface CssComponent<

[$$StyledComponentType]: Type
[$$StyledComponentProps]: Props
[$$StyledComponentMedia]: Media
}

export type TransformProps<Props, Media> = {
[K in keyof Props]: (
| Props[K]
| (
& {
[KMedia in Util.Prefixed<'@', 'initial' | keyof Media>]?: Props[K]
}
& {
[KMedia in string]: Props[K]
}
)
)
}

/** Unique symbol used to reference the type of a Styled Component. */
Expand All @@ -110,12 +91,6 @@ export declare const $$StyledComponentProps: unique symbol
/** Unique symbol used to reference the props of a Styled Component. */
export type $$StyledComponentProps = typeof $$StyledComponentProps

/** Unique symbol used to reference the media passed into a Styled Component. */
export declare const $$StyledComponentMedia: unique symbol

/** Unique symbol used to reference the media passed into a Styled Component. */
export type $$StyledComponentMedia = typeof $$StyledComponentMedia

/** Returns a narrowed JSX element from the given tag name. */
type IntrinsicElement<TagName> = TagName extends IntrinsicElementsKeys ? TagName : never

Expand Down