Skip to content

Commit

Permalink
update types / add VariantProps<Component> type
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Jul 22, 2021
1 parent 161812b commit d0a9451
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export type PropertyValue<K extends keyof CSSUtil.CSSProperties> = { readonly [C
/** Returns a type that expects a value to be a kind of theme scale value. */
export type ScaleValue<K> = { readonly [CSSUtil.$$ScaleValue]: K }

/** Returns a type that suggests variants from a component as possible prop values. */
export type VariantProps<Component> = Component[StyledComponent.$$StyledComponentProps]

/** Returns a library used to create styles. */
export declare const createCss: CreateCss

Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/styled-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export declare const $$StyledComponentProps: unique symbol
export type $$StyledComponentProps = typeof $$StyledComponentProps

/** Returns the first Styled Component type from the given array of compositions. */
type StyledComponentType<T extends any[]> = (
export type StyledComponentType<T extends any[]> = (
T[0] extends never
? 'span'
: T[0] extends string
Expand All @@ -64,7 +64,7 @@ type StyledComponentType<T extends any[]> = (
)

/** Returns the cumulative variants from the given array of compositions. */
type StyledComponentProps<T extends any[]> = (
export type StyledComponentProps<T extends any[]> = (
& (
$$StyledComponentProps extends keyof T[0]
? T[0][$$StyledComponentProps]
Expand Down
4 changes: 4 additions & 0 deletions packages/react/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type CreateCss from './create-css'
import type Sheet from './sheet'
import type StyledComponent from './styled-component'

import type * as CSSUtil from './css-util'
import type * as Default from './default'
Expand Down Expand Up @@ -29,6 +30,9 @@ export type PropertyValue<K extends keyof CSSUtil.CSSProperties> = { readonly [C
/** Returns a type that expects a value to be a kind of theme scale value. */
export type ScaleValue<K> = { readonly [CSSUtil.$$ScaleValue]: K }

/** Returns a type that suggests variants from a component as possible prop values. */
export type VariantProps<Component> = Component[StyledComponent.$$StyledComponentProps]

/** Returns a library used to create styles. */
export declare const createCss: CreateCss

Expand Down
4 changes: 2 additions & 2 deletions packages/react/types/styled-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ForwardRefExoticComponent<ElementType, Props> = React.ForwardRefExoticCompo
>

/** Returns the first Styled Component type from the given array of compositions. */
type StyledComponentType<T extends any[]> = (
export type StyledComponentType<T extends any[]> = (
T[0] extends never
? 'span'
: T[0] extends string
Expand All @@ -100,7 +100,7 @@ type StyledComponentType<T extends any[]> = (
)

/** Returns the cumulative variants from the given array of compositions. */
type StyledComponentProps<T extends any[]> = (
export type StyledComponentProps<T extends any[]> = (
& (
$$StyledComponentProps extends keyof T[0]
? T[0][$$StyledComponentProps]
Expand Down

0 comments on commit d0a9451

Please sign in to comment.