Colore JS

Search documentation

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

Generate a shadcn/ui theme from one color

Your shadcn/ui app has a brand color, but the cards, buttons and dark theme still use the starter palette. Start with #0f766e and you get teal primary buttons with white text, tinted light surfaces, and a separate dark palette. Components can keep using the token names they already know. To see the theme on sample screens in light and dark mode first, open it in the theme generator.

npm install colore-js
yarn add colore-js

Generate light and dark tokens

Pass the brand to generateSystem. Use the .toShadcnCss() exporter with radius: false to keep your app's existing corner radius. This guide uses a shadcn/ui project on Tailwind CSS v4 with CSS variables enabled.

import { generateSystem } from 'colore-js';

const css = generateSystem('#0f766e').toShadcnCss({ radius: false });
console.log(css);

Here are the primary and page colors from the generated stylesheet. The rest of the output includes tokens for cards, muted surfaces, charts and more.

:root {
  --background: oklch(0.971 0.003 174.483);
  --foreground: oklch(0.13 0.002 186.391);
  --primary: oklch(0.511 0.086 186.391);
  --primary-foreground: oklch(1 0 0);
}

.dark {
  --background: oklch(0.129 0 0);
  --foreground: oklch(0.97 0.003 186.391);
  --primary: oklch(0.511 0.086 186.391);
  --primary-foreground: oklch(1 0 0);
}

Put the colors in your app

In globals.css, replace matching color declarations inside the existing :root and .dark blocks. If you need to add a block, use the generated declarations for that mode. Keep the Tailwind import, @theme inline aliases, radius and any custom variables. The aliases connect the underlying color tokens to utility classes. shadcn/ui theming

For example, a primary button can use the two tokens as a pair. Once the CSS is loaded, it gets the theme's background and text in either mode.

<button type="button" class="bg-primary text-primary-foreground">
  Save changes
</button>

The dark block applies when your theme switch adds .dark to an ancestor such as <html>. If your app already has a switch, check that it uses the same selector. shadcn/ui dark mode

If a primary action stays gray after you swap the tokens, inspect its classes. A fixed utility such as bg-zinc-900 bypasses the primary token. Change that action to bg-primary and pair it with text-primary-foreground so both colors respond to your theme.

Export a checked stylesheet

Save this as generate-shadcn-theme.mjs. auditCssVariables reads the exported CSS. The script sends the check count to stderr and writes CSS to stdout, so you can save it to a separate file and review the changes before applying them.

import { auditCssVariables, generateSystem } from 'colore-js';

const css = generateSystem('#0f766e', { level: 'aa' }).toShadcnCss({ radius: false });
const report = auditCssVariables(css, { level: 'aa' });

console.error(`${report.checked} pairs checked, ${report.issues.length} issues`);
if (!report.passed) {
  throw new Error('The generated theme has contrast issues');
}

process.stdout.write(css + '\n');
node generate-shadcn-theme.mjs > shadcn-colors.css
24 pairs checked, 0 issues

What Colore checks for you

The generator chooses foregrounds for the surfaces it creates. The shadcn/ui exporter checks those pairs again after rounding the values for CSS, and the audit checks recognized pairs in the resulting stylesheet. If you change a token or use a foreground on a different surface, check the pair your component actually renders.