Colore JS

Search documentation

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

toTailwindCss, toShadcnCss and toDTCG

Use the export methods on a system from generateSystem. Choose toTailwindCss() for @theme variables, toShadcnCss() for globals.css, or toDTCG() for a design-token document.

Example

import { generateSystem } from 'colore-js';

const system = generateSystem('#0f766e');
const tailwind = system.toTailwindCss({ format: 'hex' });

tailwind.includes('--color-primary-500: #0f766e;'); // true
tailwind.includes('.dark {');                      // true

system.toDTCG().$schema;
// 'https://www.designtokens.org/schemas/2025.10/format.json'

Syntax

system.toTailwindCss(options?: SystemTailwindCssOptions): string
system.toShadcnCss(options?: ShadcnCssOptions): string
system.toDTCG(): DTCGDocument

Parameters

NameTypeDescription
Tailwind format'hex' | 'oklch'Output format. Defaults to OKLCH.
Tailwind darkMode / darkSelector'class' | 'media' / stringDefaults to class-based dark mode and .dark.
Tailwind includeThemeDirective / prefixboolean / stringDefaults to an @theme block and color, which gives names such as --color-primary-500.
shadcn format'oklch' | 'hex' | 'hsl-channels'Defaults to OKLCH. For shadcn/ui v3 HSL variables, use 'hsl-channels'.
shadcn selector / darkSelectorstringDefault selectors are :root and .dark.
shadcn radiusstring | falseDefaults to '0.625rem'. Use false to omit the radius variable.

Returns

The two CSS methods return a stylesheet string. toDTCG returns a design-token document object with a schema and color tokens. Serialize it as JSON to write a token file.

Throws

A ColorError for unknown or unsupported CSS export options.

Prepare variables for shadcn/ui

import { generateSystem } from 'colore-js';

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

system.toShadcnCss().split('\n').find((line) => line.includes('--primary:'));
// '  --primary: oklch(0.511 0.086 186.391);'

The shadcn exporter checks its text pairs after formatting them. The check uses the system’s configured algorithm and target level.