chromatic-themes
Configure Chromatic to capture visual test snapshots across multiple themes (light/dark mode, design tokens, branded variants) using the Modes API and @storybook/addon-themes. Use when the user wants to test components with different themes in Chromatic, set up light/dark mode visual testing, config
- 0
- Installs
- —
- Rating
- —
- Success rate
- 8
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 be67d8417b5084aa… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Chromatic Themes
Configure multi-theme visual testing using Chromatic's Modes API and @storybook/addon-themes.
This skill covers:
- Detecting the user's theme library and configuring the right decorator
- Defining theme modes in
.storybook/modes.ts - Applying modes at project, component, and story levels
Quick start
- Scan the project for existing theme config: look for
@storybook/addon-themesimports, amodes.tsfile, orchromatic.modes. - Ask the user which theme library they use (see step 3 below).
- Fetch the relevant docs from
reference/docs-map.md. - Generate configuration files and output the checklist from
reference/output-contract.md.
Required workflow
1) Detect existing configuration
Check .storybook/preview.ts, story files, and any modes.ts:
withThemeByClassNameorwithThemeByDataAttributefound → addon already configured, help extend or wire up modeschromatic.modeswiththemekeys found → already on Modes API, help extend or fix- Neither found → fresh setup, ask the user which theme library they use
2) Fetch current docs
Use the URLs in reference/docs-map.md and fetch with WebFetch. Use fetched content as the authoritative source — do not rely on remembered examples.
3) Install @storybook/addon-themes (fresh setup only)
If @storybook/addon-themes is not already installed, detect the package manager by checking for lock files (bun.lockb/bun.lock → bun, pnpm-lock.yaml → pnpm, yarn.lock → yarn, package-lock.json → npm) and use the matching install command:
| Package manager | Command |
|---|---|
| npm | npm install --save-dev @storybook/addon-themes |
| yarn | yarn add --dev @storybook/addon-themes |
| pnpm | pnpm add --save-dev @storybook/addon-themes |
| bun | bun add --dev @storybook/addon-themes |
Then register it in .storybook/main.ts:
export default {
addons: ['@storybook/addon-themes'],
};
4) Identify the theme library and configure the decorator
Ask: "Which theme library or approach does your project use? (e.g. Tailwind, Bootstrap, Material UI, styled-components, Emotion, or plain CSS classes)"
Use the answer to pick the right path:
| Library | Decorator | Docs to fetch |
|---|---|---|
| Tailwind, plain CSS classes | withThemeByClassName | themes.txt |
| Bootstrap | withThemeByDataAttribute (data-bs-theme) | getting-started/bootstrap.md |
| Material UI | custom decorator | getting-started/material-ui.md |
| styled-components | custom decorator | getting-started/styled-components.md |
| Emotion | custom decorator | getting-started/emotion.md |
| Other / unsure | withThemeByClassName | themes.txt |
Class-based (withThemeByClassName):
// .storybook/preview.ts
import { withThemeByClassName } from '@storybook/addon-themes';
export const decorators = [
withThemeByClassName({
themes: { light: 'light-theme', dark: 'dark-theme' },
defaultTheme: 'light',
// parentSelector: 'html', // default
}),
];
Data attribute (withThemeByDataAttribute):
import { withThemeByDataAttribute } from '@storybook/addon-themes';
export const decorators = [
withThemeByDataAttribute({
themes: { light: 'light', dark: 'dark' },
defaultTheme: 'light',
attributeName: 'data-bs-theme', // default: 'data-theme'
}),
];
Custom decorator — fetch the library-specific guide from reference/docs-map.md and follow it. Use pluckThemeFromContext and initializeThemeState from @storybook/addon-themes to bridge Storybook globals with the library's theme API.
4) Define theme modes
Create or update .storybook/modes.ts. The theme key must exactly match a key in the decorator's themes object:
export const allModes = {
light: { theme: 'light' },
dark: { theme: 'dark' },
} as const;
5) Apply modes to stories
Project-wide (.storybook/preview.ts):
import { allModes } from './modes';
const preview = {
parameters: { chromatic: { modes: allModes } },
};
export default preview;
Per component or per story:
import { allModes } from '../.storybook/modes';
export default {
title: 'Button',
parameters: {
chromatic: { modes: { light: allModes.light, dark: allModes.dark } },
},
};
Disable inherited modes on a specific story:
parameters: { chromatic: { modes: { dark: { disable: true } } } }
6) Output checklist
Always render the checklist from reference/output-contract.md, then show the complete content of every file to create or modify.
Key constraints
- The
themevalue in a mode must exactly match a key in the decorator'sthemesobject — a mismatch silently falls back to the default theme - Mode names are tied to baselines — renaming a mode creates a new baseline and retires the old one
- Modes stack across project → component → story levels; lower levels add to higher ones, they do not replace them
@storybook/addon-themesrequires Storybook 7.x or later- Only one decorator approach per project — do not mix
withThemeByClassNameandwithThemeByDataAttribute
Boundaries
- Do not commit or push files — generate and show configuration only
- Do not suggest viewport or locale modes unless the user asks
- Do not install or suggest theme libraries — only wire up what already exists
References
reference/docs-map.mdreference/output-contract.md../chromatic-setup-ci/reference/package-manager.md— lock file detection and install commands per package manager
Files
8- SKILL.md
540cae17065.9 KB - evaluations/README.md
2250e30bc4583 B - evaluations/custom-decorator-mui.json
2850d782b01.0 KB - evaluations/extend-existing-viewport-modes.json
68449db2c11015 B - evaluations/fresh-setup-bootstrap.json
ac2fff5411925 B - evaluations/fresh-setup-tailwind.json
d0824db0781.0 KB - reference/docs-map.md
2ff8c9b9e11.5 KB - reference/output-contract.md
c0dbb19f291.3 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from chromaui/chromatic-skills8
Recommend Chromatic best practices for Nx and Turborepo monorepos, including one-project versus multi-project topology, workingDir, buildCommand or outputDir, storybookBaseDir, storybookConfigDir, onlyChanged, externals, untraced, shared lockfile behavior, and TurboSnap-safe CI patterns. Use when a
Configure CI/CD pipelines to run Chromatic visual tests automatically. Use when the user wants to set up Chromatic in CI, add Chromatic to GitHub Actions / GitLab / Bitbucket Pipelines / CircleCI / Jenkins / Azure Pipelines, automate visual testing, or run Chromatic on every push.
Diagnose Storybook configuration issues that block Chromatic or local Storybook, including missing stories, framework or builder mismatches, addon conflicts, preview errors, static asset path issues, and package version drift. Use when Storybook fails to build, Chromatic cannot verify Storybook, sto
Diagnose unexpected Chromatic visual diffs, snapshot inconsistencies, font and resource loading drift, animation timing issues, viewport or globals mismatches, sticky or fixed positioning quirks, and nondeterministic story output. Use when snapshots change unexpectedly or the same code produces inco
Audit a Storybook project's current TurboSnap dependency exposure using preview imports and bundler stats. Rank dependency footprints, identify configuration modules, and probe which inputs cause configuration bails. Use for an initial architecture audit without requiring pending Git changes; use a
Check local code changes for TurboSnap dependency risks before pushing. Build fresh Storybook stats, trace the selected Git changes, and review new preview imports or configuration modules. Use for preventive change checks and local hook integration, not a whole-project audit or baseline investigati
Compare TurboSnap 1 and 2 behavior using local CLI logs, v2 manifests, and bundler stats. Use for migration discrepancies, unexpected preview/configuration hash changes, or files that changed on disk but were absent from the Git changed-file list.
Diagnose TurboSnap behavior using logs, config, git context, support-shareable hosted metadata references, and targeted trace commands. Use when you need to classify why TurboSnap is enabled, disabled, unavailable, or tracing the wrong stories, then recommend the smallest valid next step.
Related frontend skillsscan passed
Set an ECC-specific frontend design direction for production UI work. Use when building or improving websites, dashboards, applications, components, landing pages, visual tools, or any web UI that needs stronger product-specific design judgment.
Build UIs with @nuxt/ui v4 — 125+ accessible Vue components with Tailwind CSS theming. Use when creating interfaces, customizing themes to match a brand, building forms, or composing layouts like dashboards, docs sites, and chat interfaces.
Design shotgun: generate multiple AI design variants, open a comparison board, collect structured feedback, and iterate. (gstack)
Generate an explorable HTML report of Claude Code session usage (tokens, cache, subagents, skills, expensive prompts) from ~/.claude/projects transcripts.
Combines all of the `better-*` skills into a single review across accessibility, layout, writing, typography, color and UI polish.
Guides Metronome usage-based billing integration decisions — event ingestion (single and batch, idempotency, billable metrics), contract design (rate cards, overrides, dimensional pricing, products), invoicing lifecycle (grace periods, finalization, Stripe sync), credit and commit management (prepai