tw-colors
Version:
Tailwind plugin for switching color theme with just one className
63 lines (60 loc) • 2.51 kB
TypeScript
import * as tailwindcss_types_config from 'tailwindcss/types/config';
declare const SCHEME: unique symbol;
type NestedColors = {
[SCHEME]?: 'light' | 'dark';
} & MaybeNested<string, string>;
type TwcObjectConfig<ThemeName extends string> = Record<ThemeName, NestedColors>;
type TwcFunctionConfig<ThemeName extends string> = (scheme: {
light: typeof light;
dark: typeof dark;
}) => TwcObjectConfig<ThemeName>;
type DefaultThemeObject<ThemeName = any> = {
light: NoInfer<ThemeName> | (string & {});
dark: NoInfer<ThemeName> | (string & {});
};
type ResolvedVariants = Array<{
name: string;
definition: string[];
}>;
type ResolvedUtilities = {
[selector: string]: Record<string, any>;
};
type ResolvedColors = {
[colorName: string]: ({ opacityValue, opacityVariable, }: {
opacityValue: string;
opacityVariable: string;
}) => string;
};
type Resolved = {
variants: ResolvedVariants;
utilities: ResolvedUtilities;
colors: ResolvedColors;
};
type TwcConfig<ThemeName extends string = string> = TwcObjectConfig<ThemeName> | TwcFunctionConfig<ThemeName>;
interface TwcOptions<ThemeName extends string = string> {
produceCssVariable?: (colorName: string) => string;
produceThemeClass?: (themeName: ThemeName) => string;
produceThemeVariant?: (themeName: ThemeName) => string;
defaultTheme?: NoInfer<ThemeName> | (string & {}) | DefaultThemeObject<ThemeName>;
strict?: boolean;
}
/**
* Resolves the variants, base and colors to inject in the plugin
* Library authors might use this function instead of the createThemes function
*/
declare const resolveTwcConfig: <ThemeName extends string>(config?: TwcConfig<ThemeName>, { produceCssVariable, produceThemeClass, produceThemeVariant, defaultTheme, strict, }?: TwcOptions<ThemeName>) => Resolved;
declare const createThemes: <ThemeName extends string>(config?: TwcConfig<ThemeName>, options?: TwcOptions<ThemeName>) => {
handler: tailwindcss_types_config.PluginCreator;
config?: Partial<tailwindcss_types_config.Config>;
};
declare function dark(colors: NestedColors): {
[SCHEME]: 'dark';
} & MaybeNested<string, string>;
declare function light(colors: NestedColors): {
[SCHEME]: 'light';
} & MaybeNested<string, string>;
interface MaybeNested<K extends keyof any = string, V extends string = string> {
[key: string]: V | MaybeNested<K, V>;
}
type NoInfer<T> = [T][T extends any ? 0 : never];
export { TwcConfig, TwcOptions, createThemes, resolveTwcConfig };