import type {ClassNameValue as ClassValue} from "tailwind-merge"; import {TVConfig, TWMConfig} from "./config"; /** * ---------------------------------------- * Base Types * ---------------------------------------- */ export type {ClassValue}; export type ClassProp = | {class?: V; className?: never} | {class?: never; className?: V}; type TVBaseName = "base"; type TVScreens = "initial"; type TVSlots = Record | undefined; /** * ---------------------------------------------------------------------- * Utils * ---------------------------------------------------------------------- */ export type OmitUndefined = T extends undefined ? never : T; export type StringToBoolean = T extends "true" | "false" ? boolean : T; export type CnOptions = ClassValue[]; export type CnReturn = string | undefined; export declare const cnBase: (...classes: T) => CnReturn; export declare const cn: (...classes: T) => (config?: TWMConfig) => CnReturn; // compare if the value is true or array of values export type isTrueOrArray = T extends true | unknown[] ? true : false; export type WithInitialScreen> = ["initial", ...T]; /** * ---------------------------------------------------------------------- * TV Types * ---------------------------------------------------------------------- */ type TVSlotsWithBase = B extends undefined ? keyof S : keyof S | TVBaseName; type SlotsClassValue = { [K in TVSlotsWithBase]?: ClassValue; }; type TVVariantsDefault = S extends undefined ? {} : { [key: string]: { [key: string]: S extends TVSlots ? SlotsClassValue | ClassValue : ClassValue; }; }; export type TVVariants< S extends TVSlots | undefined, B extends ClassValue | undefined = undefined, EV extends TVVariants | undefined = undefined, ES extends TVSlots | undefined = undefined, > = EV extends undefined ? TVVariantsDefault : | { [K in keyof EV]: { [K2 in keyof EV[K]]: S extends TVSlots ? SlotsClassValue | ClassValue : ClassValue; }; } | TVVariantsDefault; export type TVCompoundVariants< V extends TVVariants, S extends TVSlots, B extends ClassValue, EV extends TVVariants, ES extends TVSlots, > = Array< { [K in keyof V | keyof EV]?: | (K extends keyof V ? StringToBoolean : never) | (K extends keyof EV ? StringToBoolean : never) | (K extends keyof V ? StringToBoolean[] : never); } & ClassProp | ClassValue> >; export type TVCompoundSlots< V extends TVVariants, S extends TVSlots, B extends ClassValue, > = Array< V extends undefined ? { slots: Array>; } & ClassProp : { slots: Array>; } & { [K in keyof V]?: StringToBoolean | StringToBoolean[]; } & ClassProp >; export type TVDefaultVariants< V extends TVVariants, S extends TVSlots, EV extends TVVariants, ES extends TVSlots, > = { [K in keyof V | keyof EV]?: | (K extends keyof V ? StringToBoolean : never) | (K extends keyof EV ? StringToBoolean : never); }; export type TVScreenPropsValue, S extends TVSlots, K extends keyof V> = { [Screen in TVScreens]?: StringToBoolean; }; export type TVProps< V extends TVVariants, S extends TVSlots, EV extends TVVariants, ES extends TVSlots, > = EV extends undefined ? V extends undefined ? ClassProp : { [K in keyof V]?: StringToBoolean | undefined; } & ClassProp : V extends undefined ? { [K in keyof EV]?: StringToBoolean | undefined; } & ClassProp : { [K in keyof V | keyof EV]?: | (K extends keyof V ? StringToBoolean : never) | (K extends keyof EV ? StringToBoolean : never) | undefined; } & ClassProp; export type TVVariantKeys, S extends TVSlots> = V extends Object ? Array : undefined; export type TVReturnProps< V extends TVVariants, S extends TVSlots, B extends ClassValue, EV extends TVVariants, ES extends TVSlots, // @ts-expect-error E extends TVReturnType = undefined, > = { extend: E; base: B; slots: S; variants: V; defaultVariants: TVDefaultVariants; compoundVariants: TVCompoundVariants; compoundSlots: TVCompoundSlots; variantKeys: TVVariantKeys; }; type HasSlots = S extends undefined ? ES extends undefined ? false : true : true; export type TVReturnType< V extends TVVariants, S extends TVSlots, B extends ClassValue, EV extends TVVariants, ES extends TVSlots, // @ts-expect-error E extends TVReturnType = undefined, > = { (props?: TVProps): HasSlots extends true ? { [K in keyof (ES extends undefined ? {} : ES)]: ( slotProps?: TVProps, ) => string; } & { [K in keyof (S extends undefined ? {} : S)]: (slotProps?: TVProps) => string; } & { [K in TVSlotsWithBase<{}, B>]: (slotProps?: TVProps) => string; } : string; } & TVReturnProps; export type TV = { < V extends TVVariants, CV extends TVCompoundVariants, DV extends TVDefaultVariants, B extends ClassValue = undefined, S extends TVSlots = undefined, // @ts-expect-error E extends TVReturnType = TVReturnType< V, S, B, // @ts-expect-error EV extends undefined ? {} : EV, // @ts-expect-error ES extends undefined ? {} : ES >, EV extends TVVariants = E["variants"], ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined, >( options: { /** * Extend allows for easy composition of components. * @see https://www.tailwind-variants.org/docs/composing-components */ extend?: E; /** * Base allows you to set a base class for a component. */ base?: B; /** * Slots allow you to separate a component into multiple parts. * @see https://www.tailwind-variants.org/docs/slots */ slots?: S; /** * Variants allow you to create multiple versions of the same component. * @see https://www.tailwind-variants.org/docs/variants#adding-variants */ variants?: V; /** * Compound variants allow you to apply classes to multiple variants at once. * @see https://www.tailwind-variants.org/docs/variants#compound-variants */ compoundVariants?: CV; /** * Compound slots allow you to apply classes to multiple slots at once. */ compoundSlots?: TVCompoundSlots; /** * Default variants allow you to set default variants for a component. * @see https://www.tailwind-variants.org/docs/variants#default-variants */ defaultVariants?: DV; }, /** * The config object allows you to modify the default configuration. * @see https://www.tailwind-variants.org/docs/api-reference#config-optional */ config?: TVConfig, ): TVReturnType; }; export type CreateTV = { < V extends TVVariants, CV extends TVCompoundVariants, DV extends TVDefaultVariants, B extends ClassValue = undefined, S extends TVSlots = undefined, // @ts-expect-error E extends TVReturnType = TVReturnType< V, S, B, // @ts-expect-error EV extends undefined ? {} : EV, // @ts-expect-error ES extends undefined ? {} : ES >, EV extends TVVariants = E["variants"], ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined, >( options: { /** * Extend allows for easy composition of components. * @see https://www.tailwind-variants.org/docs/composing-components */ extend?: E; /** * Base allows you to set a base class for a component. */ base?: B; /** * Slots allow you to separate a component into multiple parts. * @see https://www.tailwind-variants.org/docs/slots */ slots?: S; /** * Variants allow you to create multiple versions of the same component. * @see https://www.tailwind-variants.org/docs/variants#adding-variants */ variants?: V; /** * Compound variants allow you to apply classes to multiple variants at once. * @see https://www.tailwind-variants.org/docs/variants#compound-variants */ compoundVariants?: CV; /** * Compound slots allow you to apply classes to multiple slots at once. */ compoundSlots?: TVCompoundSlots; /** * Default variants allow you to set default variants for a component. * @see https://www.tailwind-variants.org/docs/variants#default-variants */ defaultVariants?: DV; }, /** * The config object allows you to modify the default configuration. * @see https://www.tailwind-variants.org/docs/api-reference#config-optional */ config?: TVConfig, ): TVReturnType; }; // main function export declare const tv: TV; export declare function createTV(config: TVConfig): CreateTV; export declare const defaultConfig: TVConfig; export type VariantProps any> = Omit< OmitUndefined[0]>, "class" | "className" >;