/** * Definition of the available variants and their options. * @example * { * color: { * white: "bg-white" * green: "bg-green-500", * }, * size: { * small: "text-xs", * large: "text-lg" * } * } */ export type Variants = Record>; /** * Configuration including defaults and compound variants. */ export interface VariantsConfig { base?: string; variants: V; compoundVariants?: CompoundVariant[]; defaultVariants?: Partial>; forwardProps?: ReadonlyArray>; } /** * Rules for class names that are applied for certain variant combinations. */ export interface CompoundVariant { variants: Partial>; className: string; } /** * Only the boolean variants, i.e. ones that have "true" or "false" as options. */ type BooleanVariants = { [K in keyof V as V[K] extends { true: any; } | { false: any; } ? K : never]: V[K]; }; /** * Only the variants for which a default options is set. */ type DefaultVariants, V extends Variants = C["variants"]> = { [K in keyof V as K extends keyof C["defaultVariants"] ? K : never]: C["variants"][K]; }; /** * Names of all optional variants, i.e. booleans or ones with default options. */ type OptionalVariantNames, V extends Variants = C["variants"]> = keyof BooleanVariants | keyof DefaultVariants; /** * Possible options for all the optional variants. * * @example * { * color?: "white" | "green", * rounded?: boolean | undefined * } */ type OptionalOptions, V extends Variants = C["variants"]> = { [K in keyof V as K extends OptionalVariantNames ? K : never]?: OptionsOf[K]; }; /** * Possible options for all required variants. * * @example { * size: "small" | "large" * } */ type RequiredOptions, V extends Variants = C["variants"]> = { [K in keyof V as K extends OptionalVariantNames ? never : K]: OptionsOf[K]; }; /** * Utility type to extract the possible options. * Converts "true" | "false" options into booleans. * * @example * OptionsOf<{ * size: { small: "text-xs"; large: "text-lg" }; * rounded: { true: "rounded-full" } * }> * ==> * { * size: "text-xs" | "text-lg"; * rounded: boolean; * } */ type OptionsOf = { [K in keyof V]: keyof V[K] extends "true" | "false" ? boolean : keyof V[K]; }; /** * Extracts the possible options. */ export type VariantOptions, V extends Variants = C["variants"]> = RequiredOptions & OptionalOptions; /** * Without this conversion step, defaultVariants and compoundVariants will * allow extra keys, i.e. non-existent variants. * See https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts */ export type Simplify = { [K in keyof T]: T[K]; }; export declare const classNames: { combine: (...classes: Array) => string; }; export declare function variants, V extends Variants = C["variants"]>(config: Simplify): (props: VariantOptions) => string; /** * No-op function to mark template literals as tailwind strings. */ export declare const tw: (template: { raw: readonly string[] | ArrayLike; }, ...substitutions: any[]) => string; export {};