Design Tokens
Design tokens are the named visual primitives — colors, fonts, typography, spacing, radii, shadows, borders — that drive your storefront’s look and feel. Foir stores them as a single W3C Design Tokens Format Module document per project, exposes them via the public GraphQL API, and ships a console for editing them visually.
Overview
A design token is one named primitive value (e.g. color.brand.primary = #2c4433, spacing.md = 16px). Reference one from another with the W3C {path.to.token} syntax so a single change ripples through every downstream token. Foir resolves references on read, so storefronts always see fully expanded values.
Foir stores tokens, not components. Buttons, cards, badges, layout decisions — those live in your storefront. Tokens are the primitives; how they compose is the storefront’s call.
Tokens have a draft and a published channel:
- Draft is what the console Design Tokens screen edits and the CLI
apply/pushwrites. - Published is what the public GraphQL API serves to your live storefront by default.
- A release promotes the draft to published: from the unpublished list on the console home page, with
foir release publish design_tokens:design_tokens, or with everything else byfoir push --publish. An app’s own branding screen releases them through thepublishDesignTokensmutation, which answers whether the published document moved and the release that moved it; read the document throughdesignTokens.
Until they are released, your storefront keeps serving the last published snapshot — preview the draft by passing the X-Foir-Schema-Channel: draft header on a request authenticated with a key that has the drafts:read scope.
Token groups
The console Design Tokens screen splits tokens into five tabs. Each tab maps to one or more top-level groups in the W3C document.
| Tab | Groups | $type | Notes |
|---|---|---|---|
| Colors | color.* | color | Hex, rgb, hsl, or any CSS color string. Nest freely (color.brand.primary). |
| Fonts | font.family.*, font.weight.*, font.size.*, font.lineHeight.*, font.letterSpacing.* | fontFamily, fontWeight, dimension, number, dimension | Font families are arrays — list fallbacks alongside the primary face. |
| Typography | typography.* | typography | Composite tokens: a single token bundles fontFamily, fontSize, fontWeight, lineHeight and letterSpacing, with textTransform set by the foir.textTransform extension. Reference the primitives above with {font.size.body} syntax. |
| Spacing | spacing.*, radius.* | dimension | Spacing scale (xs, sm, md, …) and corner-radius scale used by storefront layout primitives. |
| Effects | shadow.*, border.* | shadow, border | Multi-layer shadows and stamped borders (width + style + color). |
Every group accepts a $description and a $value. Add $extensions['foir.label'] to override the editor display name, or $extensions['foir.tag'] on a typography token to set its default semantic HTML tag (p, h1–h4, blockquote).
In the console
- Navigate to Settings → Design Tokens.
- Pick a tab (Colors, Fonts, Typography, Spacing, Effects).
- Add, rename, or remove tokens — references update automatically.
- Click Save to write the draft, then release it from the unpublished list on the console home page (or with
foir release publish design_tokens:design_tokens).
The editor enforces the W3C contract live: cycles, unknown references, and type mismatches are rejected at save time, so the stored document is always valid.
Via the CLI
Author tokens in foir.config.ts and check them into source control. See Defining Design Tokens for the config shape and the CLI reference for every command.
# Print the current draft document
foir design-tokens get
# Print the server-resolved view (references expanded, grouped by type)
foir design-tokens get --resolved
# Release the draft
foir release publish design_tokens:design_tokensfoir push --publish applies your local designTokens block and releases it in one step.
Via the API
Query the resolved view for runtime consumers, or source for build tooling like Style Dictionary. See the GraphQL Design Tokens reference for the full shape.
query DesignTokens {
designTokens {
colors { path name value }
fontFamilies { path name value }
fontSizes { path name value }
typography { path name label tag value { fontFamily fontSize fontWeight lineHeight letterSpacing textTransform } }
spacings { path name value }
radii { path name value }
shadows { path name layers { offsetX offsetY blur spread color inset } }
borders { path name value { width style color } }
}
}Tokens are a namespace operation on the data client, so the same read is one call. It is complete by default — every group above arrives whether or not you name it:
const tokens = await foir.ns.project.designTokens();Pass X-Foir-Schema-Channel: draft (with a key that has drafts:read) to preview unpublished tokens; on the data client that is channel: 'draft' when you create it.
When to use what
source— the raw W3C document, references intact. Feed to Style Dictionary or any other token-pipeline tool that already speaks the W3C format.colors,fontSizes,spacings, … — flat resolved arrays. Iterate at build or runtime to emit CSS variables, JS objects, or Tailwind theme entries.typography— composite tokens already collapsed to the primitive values. Render directly without resolving font/size/weight by hand.
Boundary
Foir’s design-tokens contract is intentionally narrow: primitive values plus typography composites. Component patterns, layout grids, breakpoint scales, and motion timings live in your storefront’s design system, not here. If you need those, declare them as plain dimension / number tokens (the W3C escape hatch) and your storefront decides how to consume them.