import { twMerge } from "tailwind-merge"; type BooleanString = T extends "true" ? true : T extends "false" ? false : T; type RawVariantProps>> = { [VariantKey in keyof V]?: BooleanString; }; export function vcn>>({ base, variants, defaults, }: { base?: string | undefined; variants: V; defaults: { [VariantKey in keyof V]: BooleanString; }; }): (variantProps: RawVariantProps & { className?: string }) => string { return ({ className, ...variantProps }) => { return twMerge( base, ...( Object.entries(defaults) as [keyof V, keyof V[keyof V]][] ).map( ([variantKey, defaultValue]) => variants[variantKey][ (variantProps as unknown as RawVariantProps)[variantKey] ?? defaultValue ] ), className ); }; } export type VariantProps> = F extends ( props: infer P ) => string ? P : never;