UNPKG

componex

Version:

A powerful, type-safe component styling library for React that combines the best of CSS-in-JS, utility-first CSS, and component composition. Features include variant support, polymorphic components, and seamless TypeScript integration.

26 lines (21 loc) 1.77 kB
import * as react from 'react'; import { ElementType, ComponentProps } from 'react'; import * as class_variance_authority_types from 'class-variance-authority/types'; import * as clsx from 'clsx'; import { ClassValue } from 'clsx'; import { cva, VariantProps } from 'class-variance-authority'; type StyledProps<C extends ElementType> = ComponentProps<C> & { as?: ElementType; }; type RefType<C extends ElementType> = C extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[C] extends React.DOMAttributes<infer E> ? E : never : React.ComponentType<any> extends React.ComponentType<infer Instance> ? Instance : never; interface StyledComponentType<C extends ElementType> extends React.ForwardRefExoticComponent<StyledProps<C> & React.RefAttributes<RefType<C>>> { baseClassName?: string; } interface CVAConfig<CVASchema> { cva?: Parameters<typeof cva<CVASchema>>[1]; } declare const componex: <C extends ElementType, BaseProps extends Partial<ComponentProps<C>>, CVASchema>(component: C, { className: newBaseClassName, cva: cvaConfig, ...baseProps }?: BaseProps & CVAConfig<CVASchema>) => react.ForwardRefExoticComponent<react.PropsWithoutRef<Omit<StyledProps<C>, keyof BaseProps> & Partial<BaseProps> & VariantProps<(props?: (CVASchema extends { [x: string]: Record<string, clsx.ClassValue>; } ? { [Variant in keyof CVASchema]?: class_variance_authority_types.StringToBoolean<keyof CVASchema[Variant]> | null | undefined; } & class_variance_authority_types.ClassProp : class_variance_authority_types.ClassProp) | undefined) => string>> & react.RefAttributes<RefType<C>>>; declare function cn(...inputs: ClassValue[]): string; export { type CVAConfig, type RefType, type StyledComponentType, type StyledProps, cn, componex as default };