css-variants
Version:
Lightweight helpers to compose class names and inline styles using variants. Zero runtime deps, small bundle, and first-class TypeScript support.
17 lines (14 loc) • 716 B
TypeScript
import { Properties } from 'csstype';
type OneOrMore<T> = T | T[];
type PartialRecord<S extends string, T> = Partial<Record<S, T>>;
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
type ObjectKeyPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
[K in keyof T]?: StringToBoolean<keyof T[K]> | undefined;
};
type ObjectKeyArrayPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
[K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined;
};
type CssProperties = Properties<string | number> & {
[key: `--${string}`]: string | number;
};
export type { CssProperties as C, ObjectKeyArrayPicker as O, PartialRecord as P, ObjectKeyPicker as a };