UNPKG

@klass/core

Version:

Class variant utility

49 lines (48 loc) 1.71 kB
import type { ClassValue, TransformKey, ItFn, RestrictedVariantsKey, KlassFn } from "."; type StrictGroupVariantsSchema<B extends string, E extends string = RestrictedVariantsKey> = { [variant: string]: { [type: string]: { [key in B]?: ClassValue; }; }; } & { [variant in E]?: undefined; }; type ToVariantsSchema<B extends string, T extends StrictGroupVariantsSchema<B>> = { [variant in keyof Omit<T, RestrictedVariantsKey>]: { [type in keyof Omit<T, RestrictedVariantsKey>[variant]]: ClassValue; }; }; type GroupCompoundVariant<B extends string, T extends StrictGroupVariantsSchema<B>> = Omit<{ [K in keyof ToVariantsSchema<B, T>]?: TransformKey<keyof ToVariantsSchema<B, T>[K]>; }, RestrictedVariantsKey> & { class: { [key in B]?: ClassValue; }; }; type GroupOptions<B extends string, T extends StrictGroupVariantsSchema<B>> = { base: { [key in B]: ClassValue; }; variants: T; defaultVariants?: { [K in keyof T]?: TransformKey<keyof T[K]>; }; compoundVariants?: GroupCompoundVariant<B, T>[]; }; type GroupResult<B extends string, T extends StrictGroupVariantsSchema<B>> = { [key in B]: KlassFn<ToVariantsSchema<B, T>>; }; /** * * @param options group options * @param config additional config * @returns multiple klass * * @see {@link https://klass.pages.dev/klass/core.html#group | group} */ declare const group: <B extends string, T extends StrictGroupVariantsSchema<B, "class">>(options: GroupOptions<B, T>, config?: { it?: ItFn; }) => GroupResult<B, T>; export type { StrictGroupVariantsSchema, GroupCompoundVariant, GroupOptions, GroupResult }; export default group;