import React from 'react' ; import { createComponent } from './createComponent' ; import { extendStaticConfig } from './helpers/extendStaticConfig' ; import { MediaProps , StaticComponent , StaticConfig , TamaguiConfig , Themes , Tokens } from './types' ; export function styled < ParentComponent extends StaticComponent | React . Component < any > , Variants extends GetVariants < ParentComponent > > ( Component , options ? , staticExtractionOptions ? ) { const staticConfigProps = ( ( ) => { if ( options ) { const { variants , ... defaultProps } = options ; return { ... staticExtractionOptions , variants , defaultProps } ; } return { } ; } ) ( ) ; const config = extendStaticConfig ( Component , staticConfigProps ) ; const component = createComponent ( config ! ) ; type VariantProps = GetVariantProps < Variants > ; return component as StaticComponent < keyof VariantProps extends never ? GetProps < ParentComponent > : Omit < GetProps < ParentComponent > , keyof VariantProps > & VariantProps & MediaProps < VariantProps > , void > ; } export type GetProps < A > = A extends StaticComponent < infer Props > ? Props : A extends React . Component < infer Props > ? Props : { } ; export type GetVariants < ParentComponent extends StaticComponent | React . Component < any > > = void | { [ key ] : { [ key ] : Partial < GetProps < ParentComponent > > | ( ( val : any , config : { tokens : TamaguiConfig [ 'tokens' ] ; theme : Themes extends { [ key ] : infer B ; } ? B : unknown ; props : GetProps < ParentComponent > ; } ) => Partial < GetProps < ParentComponent > > ) ; } ; } ; export type GetVariantProps < Variants > = Variants extends void ? { } : { [ Key in keyof Variants ] ? : keyof Variants [ Key ] extends `...${ infer VariantSpread }` ? VariantSpread extends keyof Tokens ? keyof Tokens [ VariantSpread ] extends string | number ? `$${ keyof Tokens [ VariantSpread ] }` | null : unknown : unknown : keyof Variants [ Key ] extends 'true' ? boolean | null : keyof Exclude < Variants [ Key ] , undefined > ; } ;