Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

generateSystem

generateSystem builds light and dark themes from one brand color. You get shade ramps, background and text pairs, and semantic colors for roles such as error and success. Your brand color stays exactly as given whenever it meets the contrast target, and text colors are chosen to pass contrast in both modes.

Example

import { generateSystem } from 'colore-js';
import { generateSystem as generateTheme } from 'colore-js/fn';

const system = generateSystem('#0f766e');

system.light.primaryBase.css(); // '#0f766e'
system.light.text.css();        // '#000000'
system.dark.text.css();         // '#ffffff'
system.audit().passed;          // true

generateTheme('#0f766e').dark.background.css(); // '#070707'

Syntax

generateSystem<M extends readonly ThemeMode[] = readonly ['light', 'dark']>(
  brand: ColorInput | Color,
  config?: SystemConfig & { modes?: M }
): GeneratedSystem<M>

Parameters

NameTypeDescription
brandColorInput | ColorSeed color for the primary role and the theme.
config.modesreadonly ThemeMode[]Generate 'light', 'dark' or both. Defaults to both.
config.rolesSemanticRole[]Defaults to primary, secondary, error, warning, success, info and neutral.
config.algorithm / config.levelContrastAlgorithm / ContrastLevelDefaults to WCAG 2 AA. Use AAA or an APCA preset for the text pairs.
config.roleSeedsPartial<Record<SemanticRole, ColorInput>>Override specific role colors. Each seed appears in its shade ramp.
config.neutralHuenumber | 'auto'Tune the neutral hue. Defaults to 'auto'.
config.preserveSeedbooleanDefaults to true. Keeps a seed as the role’s base when it meets that mode’s requirements.

Returns

Both exports return a generated system with the requested modes, resolved config, original seed, audit() and export methods. Each named mode has page tokens such as background and text. An omitted mode is undefined.

Throws

A ColorError for invalid colors or config. system.theme(mode) also throws if that mode was omitted.

Generate only a dark theme

import { generateSystem } from 'colore-js';

const darkOnly = generateSystem('#0f766e', { modes: ['dark'] });

darkOnly.dark.background.css(); // '#070707'
darkOnly.light;                 // undefined

You can audit the system before exporting it. The audit checks the role text pairs and page text tokens against the configured contrast target.