import type { Leaves } from '../../theme/base/types'; import type { ComponentTheme, ITheme } from '../../theme'; import type { ResponsiveValue } from './responsiveValue'; export type VariantType< Component extends keyof ITheme['components'] > = 'variants' extends keyof ITheme['components'][Component] ? ResponsiveValue< keyof ITheme['components'][Component]['variants'] | (string & {}) > : unknown; export type SpaceType = ResponsiveValue< keyof ITheme['space'] | (string & {}) | number >; export type SizeType = ResponsiveValue< keyof ITheme['sizes'] | (string & {}) | number >; export type ThemeComponentSizeType< Component extends keyof ITheme['components'] > = ResponsiveValue< 'sizes' extends keyof ITheme['components'][Component] ? keyof ITheme['components'][Component]['sizes'] | (string & {}) | number : unknown >; export type CombinedSizeType = | SizeType | ThemeComponentSizeType; export type ColorType = ResponsiveValue< Leaves | (string & {}) >; export type ColorSchemeType = ResponsiveValue< Exclude | (string & {}) >; type ComponentType = { [Property in keyof ITheme['components'][T]]: ITheme['components'][T][Property]; }; type ParametersOf = { [Key in keyof T]: T[Key] extends (...args: any) => void ? Parameters[0] extends {} ? Parameters[0] : {} : {}; }[keyof T]; // type VariantParams = ParametersOf< // //@ts-ignore // ComponentType['variants'] // >; // type PickedVariantParams = Pick< // VariantParams, // keyof VariantParams // >; type ParameterType = ParametersOf< //@ts-ignore ComponentType[Key] >; type CustomPropType = Extract< ParameterType, Pick, keyof ParameterType> >; // export type CustomProps = // | CustomPropType // | CustomPropType // | CustomPropType // | CustomPropType; export type CustomComponentProps< T extends keyof ITheme['components'] > = Partial< Exclude< { [Key in keyof ComponentTheme]: CustomPropType; }[keyof ComponentTheme], undefined > >; export type CustomPropsTemp< T extends keyof ITheme['components'] > = CustomComponentProps extends never ? {} : // : CustomComponentProps extends Record // ? {} UnionToIntersection> & {}; export type UnionToIntersection = ( U extends any ? (k: U) => void : never ) extends (k: infer I) => void ? I : never; type VariantSizeColorScheme = { variant?: VariantType; size?: ThemeComponentSizeType; colorScheme?: ColorSchemeType; }; // export type CustomProps< // T extends keyof ITheme['components'] // > = CustomComponentProps extends never // ? {} | VariantSizeColorScheme // : // : CustomComponentProps extends Record // // ? {} // | (UnionToIntersection> & {}) // | VariantSizeColorScheme; export type CustomProps< T extends keyof ITheme['components'] > = UnionToIntersection | VariantSizeColorScheme>; // export type CustomProps< // T extends keyof ITheme['components'] // > = CustomPropsTemp; // | CustomPropsTemp // | { a: string }; // | { size?: ThemeComponentSizeType };