From d0a9451d72db709e1fc7eacd84e87d8e6d9ba2be Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Mon, 19 Jul 2021 16:34:53 -0400 Subject: [PATCH] update types / add `VariantProps` type --- packages/core/types/index.d.ts | 3 +++ packages/core/types/styled-component.d.ts | 4 ++-- packages/react/types/index.d.ts | 4 ++++ packages/react/types/styled-component.d.ts | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/core/types/index.d.ts b/packages/core/types/index.d.ts index 175899a7..d92a43df 100644 --- a/packages/core/types/index.d.ts +++ b/packages/core/types/index.d.ts @@ -29,6 +29,9 @@ export type PropertyValue = { readonly [C /** Returns a type that expects a value to be a kind of theme scale value. */ export type ScaleValue = { readonly [CSSUtil.$$ScaleValue]: K } +/** Returns a type that suggests variants from a component as possible prop values. */ +export type VariantProps = Component[StyledComponent.$$StyledComponentProps] + /** Returns a library used to create styles. */ export declare const createCss: CreateCss diff --git a/packages/core/types/styled-component.d.ts b/packages/core/types/styled-component.d.ts index aafeadbe..ef76823f 100644 --- a/packages/core/types/styled-component.d.ts +++ b/packages/core/types/styled-component.d.ts @@ -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 = ( +export type StyledComponentType = ( T[0] extends never ? 'span' : T[0] extends string @@ -64,7 +64,7 @@ type StyledComponentType = ( ) /** Returns the cumulative variants from the given array of compositions. */ -type StyledComponentProps = ( +export type StyledComponentProps = ( & ( $$StyledComponentProps extends keyof T[0] ? T[0][$$StyledComponentProps] diff --git a/packages/react/types/index.d.ts b/packages/react/types/index.d.ts index e8d2aafa..eb35f037 100644 --- a/packages/react/types/index.d.ts +++ b/packages/react/types/index.d.ts @@ -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' @@ -29,6 +30,9 @@ export type PropertyValue = { readonly [C /** Returns a type that expects a value to be a kind of theme scale value. */ export type ScaleValue = { readonly [CSSUtil.$$ScaleValue]: K } +/** Returns a type that suggests variants from a component as possible prop values. */ +export type VariantProps = Component[StyledComponent.$$StyledComponentProps] + /** Returns a library used to create styles. */ export declare const createCss: CreateCss diff --git a/packages/react/types/styled-component.d.ts b/packages/react/types/styled-component.d.ts index fb202aa1..13027794 100644 --- a/packages/react/types/styled-component.d.ts +++ b/packages/react/types/styled-component.d.ts @@ -87,7 +87,7 @@ type ForwardRefExoticComponent = React.ForwardRefExoticCompo > /** Returns the first Styled Component type from the given array of compositions. */ -type StyledComponentType = ( +export type StyledComponentType = ( T[0] extends never ? 'span' : T[0] extends string @@ -100,7 +100,7 @@ type StyledComponentType = ( ) /** Returns the cumulative variants from the given array of compositions. */ -type StyledComponentProps = ( +export type StyledComponentProps = ( & ( $$StyledComponentProps extends keyof T[0] ? T[0][$$StyledComponentProps]