UNPKG

arto

Version:

Arto is a flexible and type-safe class name management library for building scalable UIs with variants, states, and conditional styling.

79 lines 3.87 kB
import { Plugin, PluginStage } from '../plugin-interface'; import { ClassNameBuilder } from '../classname-builder'; import { VariantValue, VariantConfig } from '../types'; /** * Checks if a given configuration object qualifies as a `VariantConfig<TStates, TContext>`. * It looks for at least one of the properties `className` or `states`. * * @template TStates - A string union representing valid state names. * @template TContext - Optional context type for class generation or plugin logic. * @param config - The object to examine. * @returns `true` if it contains a `className` or `states` property, otherwise `false`. */ export declare function isVariantConfig<TStates extends string = never, TContext = unknown>(config: unknown): config is VariantConfig<TStates, TContext>; /** * A plugin that processes the `variants` section of an Arto configuration. * It applies class names for each user-selected variant value, and merges any * variant-level states specified within each variant. * * **How it works**: * 1) Reads user's chosen variants from the builder. * 2) For each variant key, finds the config object for the chosen value. * 3) Normalizes and adds classes, or processes a `VariantConfig` (with nested `states`). * * @template TVariants - A record of variant keys & possible values. * @template TStates - A string union of valid state names. * @template TContext - Optional context type for generation or logic. */ export declare class VariantsPlugin<TVariants extends Record<string, VariantValue> = Record<string, VariantValue>, TStates extends string = string, TContext = unknown> implements Plugin<TVariants, TStates, TContext> { /** * Unique ID for the plugin to help with debugging or HMR consistency. */ id: string; /** * Runs at the 'core' stage by default. */ stage: PluginStage; /** * The order (priority) among 'core' plugins. Lower means earlier execution. * @default 0 */ order: number; /** * Constructs a `VariantsPlugin` with an optional `order`. * @param order - Plugin priority in the 'core' stage (default = 0). */ constructor(order?: number); /** * Called automatically by the builder. Iterates through each variant key in the Arto config, * checks the user's chosen value for that variant, and applies the appropriate class names. * * @param builder - The `ClassNameBuilder` to which classes are added. */ apply(builder: ClassNameBuilder<TVariants, TStates, TContext>): void; /** * Determines how to handle a specific variant config: * 1) If it's a direct `ClassName` (string, array, or function), normalize and return it. * 2) If it's a `VariantConfig`, process the base `className` and then any nested states. * 3) Otherwise, throw an error. * * @param variantKey - The variant key (e.g., 'size', 'color'). * @param variantConfig - The config for the chosen variant value. * @param builder - The `ClassNameBuilder` instance. * @param context - Optional context object. * @returns A string array of normalized classes for this variant. */ private processVariantConfig; /** * Merges any variant-level states by iterating through each state definition. * If a state is valid (either a direct class name or a `StateConfig`), the resulting * classes are stored in the builder's `variantStateClasses`. * * @param variantKey - The key of the variant whose states we're processing. * @param statesObj - The object containing state definitions for this variant. * @param builder - The `ClassNameBuilder` instance to store classes. * @param context - Optional context object for callbacks or state checks. */ private mergeVariantStates; } //# sourceMappingURL=variants-plugin.d.ts.map