Guides setting up @charcoal-ui/styled with styled-components, including ThemeProvider, TokenInjector, createTheme, and addThemeUtils. Use when a project's charcoal setup is unverified or incomplete.
Ships in charcoal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
@charcoal-ui/styled exists for codebases already written in styled-components. Read the next section before wiring it in.
@charcoal-ui/styled is frozen at Design Token 1.0. Its source contains no reference to Token 2.0, and it receives only maintenance commits while @charcoal-ui/tailwind-config keeps gaining v2 features.
The package is not formally deprecated — only createTheme carries @deprecated. The problem is not that it is forbidden; it is that it cannot reach the current token generation.
It also drags in the component library: @charcoal-ui/styled peer-depends on @charcoal-ui/react, because useTheme, useThemeSetter, themeSelector, and SetThemeScript are re-exports whose implementations live there. You get that dependency even if you never render a charcoal component.
For a new project, or when you only want tokens, use setting-up-charcoal-css-variables instead.
npm install @charcoal-ui/styled@^6 @charcoal-ui/theme@^6 @charcoal-ui/react@^6
Pin the major and keep every @charcoal-ui/* package on the same one. styled-components >=5.1.1 and react >=17.0.0 are peers.
Two independent mechanisms, both usually needed:
ThemeProvider (styled-components) supplies the JS theme object so ${({ theme }) => theme.color.text1} resolves. The values are literal hex strings, not var().TokenInjector (@charcoal-ui/styled) emits --charcoal-color-* CSS variables at runtime via createGlobalStyle, for anything not going through styled-components.import { ThemeProvider } from 'styled-components'
import {
TokenInjector,
addThemeUtils,
useTheme,
useThemeSetter,
themeSelector,
} from '@charcoal-ui/styled'
import { light, dark } from '@charcoal-ui/theme'
const lightTheme = addThemeUtils(light)
const darkTheme = addThemeUtils(dark)
export function ThemeRoot({ children }: { children: React.ReactNode }) {
const [mode] = useTheme()
useThemeSetter()
return (
<ThemeProvider theme={mode === 'dark' ? darkTheme : lightTheme}>
<TokenInjector
theme={{ ':root': light, [themeSelector('dark')]: dark }}
background="background1"
/>
{children}
</ThemeProvider>
)
}
TokenInjector's optional background prop takes any key of theme.color (background1, background2, surface1…) and paints it as the page background on each selector.
Because the JS objects hold literal colors, switching themes requires swapping ThemeProvider's theme prop. Rewriting CSS variables alone does not change ${({ theme }) => …} output. The two systems must be kept in sync — that is what useTheme plus useThemeSetter do here.
// styled.d.ts
import 'styled-components'
import type { CharcoalTheme } from '@charcoal-ui/theme'
import type { CharcoalThemeUtils } from '@charcoal-ui/styled'
declare module 'styled-components' {
export interface DefaultTheme extends CharcoalTheme, CharcoalThemeUtils {}
}
Use styled-components' own theming. Do not use createTheme / theme(o => [...]) — it is @deprecated for runtime performance (PR #377).
const Card = styled.div`
background-color: ${({ theme }) => theme.color.background1};
color: ${({ theme }) => theme.color.text1};
border-radius: ${({ theme }) => theme.borderRadius[8]}px;
${({ theme }) => theme.utils.padding(16)}
${({ theme }) => theme.utils.typography(16)}
`
addThemeUtils() adds theme.utils: margin*, padding*, gap, typography, focusVisibleFocusRingCss, assertiveRingCss, disabledCss.
Constraints worth knowing before you hit them:
theme.utils.typography(size) accepts only 12 | 14 | 16 | 20. 32 is not supported — expand it by hand. theme.typography.size[n] is { fontSize: number; lineHeight: number } in px, keyed by 12 | 14 | 16 | 20 | 32:
font-size: ${({ theme }) => theme.typography.size[32].fontSize}px;
line-height: ${({ theme }) => theme.typography.size[32].lineHeight}px;
theme.utils.margin / padding accept only the spacing scale (0, 4, 8, 16, 24, 40, 64, 104, 168, 272, 440) or 'auto'. Arbitrary px values are rejected by the type.
theme.spacing and theme.typography are identical in light and dark.
import { makeSetThemeScriptCode } from '@charcoal-ui/styled'
;<script dangerouslySetInnerHTML={{ __html: makeSetThemeScriptCode() }} />
Prefer makeSetThemeScriptCode() over <SetThemeScript />; the component's props type requires both localStorageKey and rootAttribute.
You do not have to leave in one step.
createTheme. The only @deprecated API here. Move to plain ${({ theme }) => theme.color.*} or addThemeUtils.TokenInjector. Import @charcoal-ui/theme/css/v2/{light,dark}.css instead — static CSS supplies the same variables with no runtime createGlobalStyle. This is also the step that unlocks Design Token 2.0.ThemeProvider. Replace theme.color.text1 reads with var(--charcoal-color-text-default).If you only render @charcoal-ui/react components, steps 1–3 are already unnecessary — since v4 it does not depend on styled-components at all.
| Mistake | Fix |
|---|---|
Reaching for createTheme because docs show it | It is @deprecated. Use styled-components theming. |
| Expecting Design Token 2.0 here | Not supported. Move to CSS variables or Tailwind. |
| Swapping CSS variables to change theme | JS theme objects hold literal colors — swap ThemeProvider's theme too. |
theme.utils.typography(32) | Type error. Expand theme.typography.size[32] manually. |
Following pages/ docs in the repo | Last updated 2023-03-22, pre-v4. Its @charcoal-ui/react instructions are wrong. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/charcoal:setting-up-charcoal-styledfrom charcoal
npx claudepluginhub pixiv/charcoal --plugin charcoal7 skills in this plugin
/choosing-charcoal-stylingUse before writing or editing any code that imports @charcoal-ui, and whenever a project's charcoal setup is unverified or incomplete. Decides between the CSS variables, Tailwind and styled-components routes, and names the setup steps that are silently missing in most projects./choosing-charcoal-tokensUse before choosing any color, text style, spacing, radius or border value in code that uses @charcoal-ui, and whenever a literal is about to be written where a token exists — a hex color, a px padding or gap, a font-size, a border-radius or border-width. Charcoal has one correct token for each of these and the choice is prescribed, not a matter of taste. Also use when reviewing such code, or when deciding how dense, how loud or how bordered a screen should be./implement-figma-designUse when building a screen from a prepared Figma design pack — a design.md, a spec.json and an assets/ directory produced by prepare-figma-design — and when checking that what you built matches it. Needs no Figma access, no token and no Dev Mode seat. If there is no pack yet, prepare-figma-design makes one from a figma.com link./prepare-figma-designUse when you have a figma.com link or a local .fig export, and someone needs to build that design — including when you will build it yourself. One command turns it into the design's structure, its materials named as your own design tokens, the text of every node and the bitmaps it uses, as three files to commit. No Dev Mode seat: a read-only personal access token, or no credential at all from a .fig. Hand those files to implement-figma-design, which needs no Figma access./setting-up-charcoal-css-variablesUse before writing or editing any code that imports @charcoal-ui/react, and whenever a project's charcoal setup is unverified, incomplete or being finished. Charcoal components render completely unstyled unless BOTH @charcoal-ui/theme/css/v2/light.css is imported AND the .ch-token-v2 class is on <html>; importing dist/index.css alone, or adding the stylesheet without the class, silently produces correct geometry with no colors at all./setting-up-charcoal-tailwindUse before writing or editing code that uses @charcoal-ui with Tailwind, and whenever such a project's charcoal setup is unverified or incomplete. The v2 token route still needs the theme CSS and the .ch-token-v2 opt-in, which the preset does not supply.Other plugins' skills for the same job