Skip to main contentSkip to docs navigation

Chassis

Tokens Studio

View on GitHub

How a repository of tokens arranges its token sets and groups in Tokens Studio, how to connect the plugin to the repository, and how to add a brand.

This page is a work in progress. Parts of it may be incomplete or differ from the current version of Chassis Tokens.

Introduction

A repository of tokens keeps its design tokens as Tokens Studio files in source/. Tokens Studio is a Figma plugin that edits these files, syncs them with the Git repository, and exports them to Figma. The chassis-tokens command reads the same files, so Figma and the code of every platform get their values from one place.

This guide connects the plugin to a repository, describes the token sets and the groups that select them, and adds a brand. Its examples are the token sets that chassis-tokens init writes, in a repository with the brand acme and the web app site.

Prerequisites

The plugin needs access to Figma and to the repository, and the build needs Node.js:

  • The Tokens Studio plugin from the Figma Community, with a Pro license. Chassis Tokens stores its token sets in several files and selects them with the themes of Tokens Studio, and both features belong to the Pro plan.
  • A Figma account with edit access to the file in which you run the plugin.
  • Your repository of tokens on GitHub, as npx @chassis-ui/tokens init writes it, and a personal access token of GitHub that can read it. To push changes from the plugin, the token needs write access.
  • Node.js 22.12 or later, with @chassis-ui/tokens installed in the repository, to lint and build the tokens after a change.

Connect the repository

Tokens Studio reads and writes the token sets through a sync provider, which names the repository, the branch, and the folder of the token sets.

  1. Open Tokens Studio in a Figma file and go to Settings.
  2. Click Add new sync provider and choose GitHub.
  3. Enter a name for the provider and your personal access token.
  4. Enter the repository as <owner>/<repository>, such as acme/acme-tokens.
  5. Enter the branch, main or the branch you work on.
  6. Enter the file path, source.
  7. Save the provider, return to the Tokens tab, and pull the tokens from the repository.
  8. Select one option of each group: a brand, a theme, and an app, and a screen when the repository has the optional screen group.

The file path names a folder, so Tokens Studio keeps every token set in a file of its own. The remote storage docs of Tokens Studio describe the other providers and their settings.

Token sets

A token set is one JSON file of source/. Its name is its path without the extension, such as base/brand-base. The folder base holds the sets that every brand shares, and a folder brand-<brand> holds the sets of one brand. init writes these sets, and its options select them:

Token setTokens
base/metric-sourcedimension.base.*, the scale that the sizes reference, and modify.*, the shares of the color modifiers
base/metric-basesize.unit.*, space.unit.*, opacity.level.*, opacity.context.*
base/brand-basecolor.base.*, opacity.base.context.*, motion.base.*, typography.fontFamily.*, typography.fontWeight.*, typography.fontSize.*, typography.lineHeight.*, typography.letterSpacing.*, typography.paragraphSpacing.*, borderRadius.base.*
brand-<brand>/brand-baseThe tokens of base/brand-base that the brand changes; at first, only the switch of the brand
base/theme-basecolor.primitive.*, color.context.*, color.shadow.*, color.utility.*, gradient.primitive.*
base/theme-lightNo token except the switch of the light theme
base/theme-darkThe colors of base/theme-base, with the references of the dark theme
base/effect-baseshadow.elevation.*, shadow.glow.*, bg-blur.*
base/app-basefont.*, grid.*, icon.*, motion.timing.*, motion.easing.*, the component colors, the context and component tokens of size, space, borderRadius, borderWidth, and shadow
base/app-<app>The tokens of base/app-base that the app changes; at first, only the switch of the app

init writes one brand set per brand that it is given, such as brand-acme/brand-base, and one app set per app, such as base/app-site. The switches are the boolean tokens figma.switch.<group>.*, which show and hide layers in Figma; the Figma Variables guide lists them.

Set order

When two selected token sets declare the same token, the set that comes later overrides the earlier one. In Tokens Studio, the order is tokenSetOrder of source/$metadata.json. The build lists the sets of the selected options in the order of $themes.json. For the brand acme, the app site, and the theme light, the list is:

TEXT
base/metric-source
base/metric-base
base/brand-base
brand-acme/brand-base
base/theme-base
base/app-base
base/app-site
base/effect-base
base/theme-light

base/brand-base declares color.base.primitive.light.primary.base. When brand-acme/brand-base declares it again, the brand set comes later, so the token has the value of the brand set. Style Dictionary logs these overrides as token collisions in every build; they are expected.

A set only has to declare the tokens that it changes. brand-acme/brand-base declares the base token of a palette color, and the steps of the color stay in base/brand-base, where they reference the base token.

Set status

An option gives each token set that it selects one of two statuses in selectedTokenSets of $themes.json. A set that the option does not list is disabled for that option.

StatusIn Tokens StudioIn the build
enabledThe tokens resolve references and become Variables and styles of the group in FigmaThe set is built
sourceThe tokens resolve references and create nothing in FigmaThe set is built

The build does not tell the two statuses apart. base/metric-source is a source set in every option, and the generated files still hold dimension.base.*. The token sets docs of Tokens Studio describe the statuses in the plugin.

Selected sets

The build and npx chassis-tokens lint-source read the token sets that an option of $themes.json selects, with either status. A set that no option selects takes no part in a design or in the output until you add it to an option.

A set that you add in Tokens Studio is such a set until an option selects it.

Groups

A group is a list of options, and an option is a list of token sets with their status. Tokens Studio calls them theme groups and theme options, and keeps them in source/$themes.json. You select one option of each group, and the selected options together select the token sets of a design or of a build.

The token system is built on three core groups, brand, theme, and app. screen is an optional fourth group.

GroupIts options selectOptions that init writes
brandThe base tokens of a brand: palette, fonts, and border radiusOne per brand of --brand, such as acme
themeThe colors and shadows of a themelight, dark
appThe context and component tokens of an appOne per app of --app, such as site
screen, optionalThe tokens that differ per screen sizeNone; a repository adds them, such as large, medium, small

You can add options of your own. The build writes files for the names in chassis.build of package.json, where init lists the brands, themes, and apps that it writes; an option that chassis.build does not name is an option in Tokens Studio only.

Brand group

The options of the brand group select the tokens that make up a brand. Every option selects the same sets and adds its brand set as the last one:

Token setStatus
base/metric-sourcesource
base/metric-basesource
base/brand-baseenabled
brand-<brand>/brand-baseenabled

Theme group

The options of the theme group select the colors of a theme, and the shadows of base/effect-base.

Token setStatus
base/metric-sourcesource
base/metric-basesource
base/effect-baseenabled
base/brand-basesource
base/theme-baseenabled
base/theme-<theme>enabled

base/theme-base holds the references of the light theme: color.context.primary.bg-hover references {color.base.context.light.primary.bg-hover} there. base/theme-dark overrides the token with {color.base.context.dark.primary.bg-hover}. The options of the group must declare the same names, which npx chassis-tokens lint-source checks.

App group

The options of the app group select the context and component tokens, which are the tokens that a design or an app uses. base/metric-base is enabled here, so its sizes, spaces, and opacities become Variables of this group.

Token setStatus
base/metric-sourcesource
base/metric-baseenabled
base/brand-basesource
base/theme-basesource
base/app-baseenabled
base/app-<app>enabled

The set of an app overrides the component tokens that the app changes. init writes it with the switch of the app only, so the app has the tokens of base/app-base until its set overrides one, such as color.page.bg-body.

Screen group

The options of the optional screen group select the tokens whose value depends on the screen size, such as the padding of the sections of a website. init writes no screen group. A repository that adds one gives each option the sets that the others read, a set that every screen enables, and the set of the screen, with names of its own, such as:

Token setStatus
base/app-basesource
base/brand-basesource
base/metric-basesource
base/metric-sourcesource
base/effect-basesource
base/theme-basesource
screen/screen-baseenabled
screen/screen-<screen>enabled

The set that every screen enables holds the tokens whose value is the same on every screen, such as a font that references a font size, and the set of each screen holds the tokens that differ, such as that font size. The options of the group must declare the same names: npx chassis-tokens lint-source fails when the set of one screen lacks a token of the others.

Change the groups

Chassis Tokens is meant to be owned and customized, so the groups are yours to change. The build makes the name of every list of token sets from one option of each group, as <brand>_<app>_<theme>_<screen>, and expects the groups in this order in $themes.json.

Without a screen group, as init writes the repository, the build names the lists <brand>_<app>_<theme> and writes one number file without the name of a screen: number.scss, Number.swift, and number.xml. To add the screen group:

  1. Add the token sets of the screens, and the options of the screen group, after the other groups in $themes.json.
  2. List the options in chassis.build.screens of package.json, the default first.
  3. For an app with the android platform, give screens other than small, medium, and large a resource folder in chassis.build.options.android.screens.

The build then names the lists <brand>_<app>_<theme>_<screen> and writes one number file per screen, such as number-large.scss, NumberLarge.swift, and number_large.xml.

In Tokens Studio, a group of your own is a group like the others. The build needs a change: planBuilds in lib/build/build.js of @chassis-ui/tokens makes the name of a list from the brand, the app, the theme, and the screen, and chassis.build has no key for another group. Until you change both, the build stops with No token sets for …, because the option of the new group is a part of every list name.

Brand tokens

The brand sets hold the base tokens of color, typography, and border radius. Designs and apps do not use these tokens directly; the tokens of the theme and app groups reference them, so a change of the brand reaches every token that follows from it.

Color tokens

color.base.* holds the colors of both themes, so that the option of the theme group only has to choose between them.

TokensContent
color.base.primitive.<theme>.*The palette: black, white, primary, secondary, neutral, danger, success, warning, info
color.base.context.<theme>.*The colors by role, which reference the palette
color.base.shadow.<theme>.*The shadow colors, which reference the transparent steps of the palette

Every step of a palette color follows from its base token. The steps 05 to 40 lighten the base color and the steps 60 to 95 darken it, with a color modifier of Tokens Studio whose share is a token of modify.*. The step 50 is the base color. The transparent steps of a palette, t-5005 to t-5095, are color.primitive.* tokens of base/theme-base, not base colors. The step 40 of primary in base/brand-base:

JSON
{
  "40": {
    "$extensions": {
      "studio.tokens": {
        "modify": {
          "type": "lighten",
          "value": "{modify.lighten.40}",
          "space": "srgb"
        }
      }
    },
    "$type": "color",
    "$value": "{color.base.primitive.light.primary.base}"
  }
}

base/brand-base declares the base tokens of the light palette, such as color.base.primitive.light.primary.base, and a brand set declares the ones it changes, each with a color of the brand; as init writes it, a brand set holds only the switch of the brand. The dark palette references the light one: color.base.primitive.dark.primary.base is {color.base.primitive.light.primary.base}.

Colors with an opacity are in the brand sets too. Figma cannot change the opacity of a Variable that is an alias, so color.base.context.light.primary.fg-subtle holds the complete color, and color.context.primary.fg-subtle only references it. See the color modifier docs of Tokens Studio and the color tokens reference.

Typography tokens

The brand sets hold the typography groups that the composite font.* tokens of base/app-base reference.

TokensContent
typography.fontFamily.*The families ui, prose, display, code, and icon, and one family per text role group, such as context.heading
typography.fontWeight.*The weights of each family, such as normal, strong, mass, and elegant of ui, and one weight per text role group
typography.fontSize.*The sizes of each scaled family, from 2xsmall to 6xlarge for ui, and one size per text role, such as context.h1
typography.lineHeight.*The line height of each size and of each text role
typography.letterSpacing.*The letter spacing of each weight of ui, prose, and display, and of each text role
typography.paragraphSpacing.*The space after a paragraph, from zero to large

A brand set declares the font families and the font weights of the brand, and takes the font sizes and the line heights of base/brand-base. A font family token holds a list of font families, with the font of the brand first and its fallbacks after it.

A font weight token holds the style name that the font has in Figma, and fonts spell the same weight in different ways, with or without a space between the words. The build reads every spelling as the same weight. Keep the spelling of the font, or Figma does not find the style.

base/app-base holds no typography group. A font token names its text case and text decoration as a keyword where it has one, and has neither otherwise. See the typography tokens reference.

Border radius tokens

borderRadius.base.* holds a scale, borderRadius.base.context.*, and the radius of each component that has one, such as borderRadius.base.button.*. The tokens of base/app-base reference them one to one: borderRadius.button.medium is {borderRadius.base.button.medium}.

A brand set overrides the scale, the components, or both. The steps of the scale reference dimension.base.*, and the components reference a step of the scale. See the border radius tokens reference.

Token names

A token name is a dot path. The first segment is the category, the second is a level or a component, and the rest names the token in its group.

SegmentContentExamples
FirstThe categorycolor, size, space, font, typography, borderRadius, borderWidth, shadow, opacity
SecondA level, or a componentbase, unit, context; button, form-input
OthersThe variant, the state, or the partprimary, bg-hover, medium-padding-x

Some component groups have a segment for the variant or the state, and the last segment names the part and its state:

TEXT
color.button.primary.bg-hover       <category>.<component>.<variant>.<part>-<state>
color.form-input.focus.border       <category>.<component>.<state>.<part>

Other groups join the size and the part in the last segment:

TEXT
size.button.medium-icon             <category>.<component>.<size>-<part>
space.button.medium-padding-x       <category>.<component>.<size>-<part>

The build joins the segments to the name of each platform: color.button.primary.bg-hover is $cx-color-button-primary-bg-hover on the web, ColorButtonPrimaryBgHover on iOS, and color_button_primary_bg_hover on Android. A segment holds letters, digits, and single hyphens, and a name starts with a letter. npx chassis-tokens lint-source fails on other characters and on two names that become the same platform name.

Token names are the public API of the package. Renaming or removing a token breaks every app that uses it.

Reference chains

A component token reaches its value through the token sets of the three core groups. Each line shows a token, its token set, and what the source holds for it, with the theme light. Every chain ends at a value of the brand: a token of brand-<brand>/brand-base, or of base/brand-base while the brand set does not declare it, as after init.

The background of the primary button in its hover state:

TEXT
color.button.primary.bg-hover                base/app-base               {color.context.primary.bg-hover}
color.context.primary.bg-hover               base/theme-base             {color.base.context.light.primary.bg-hover}
color.base.context.light.primary.bg-hover    base/brand-base             {color.base.primitive.light.primary.40}
color.base.primitive.light.primary.40        base/brand-base             {color.base.primitive.light.primary.base}, lightened
color.base.primitive.light.primary.base      brand-<brand>/brand-base    A color of the brand

Another brand changes the last line only. The theme dark changes the second line to {color.base.context.dark.primary.bg-hover} of base/theme-dark, and the chain continues in the dark palette.

A color with an opacity takes both parts in base/brand-base:

TEXT
color.context.primary.fg-subtle               base/theme-base     {color.base.context.light.primary.fg-subtle}
color.base.context.light.primary.fg-subtle    base/brand-base     rgba({color.base.context.light.primary.fg-main}, {opacity.context.fg-subtle})
color.base.context.light.primary.fg-main      base/brand-base     {color.base.primitive.light.primary.60}
opacity.context.fg-subtle                     base/metric-base    A number from 0 to 1

The font of the medium button references a composite token, whose properties reference the typography tokens:

TEXT
font.button.medium         base/app-base   {font.ui.medium.strong}
font.ui.medium.strong      base/app-base
  fontFamily               {typography.fontFamily.ui}                brand-<brand>/brand-base
  fontWeight               {typography.fontWeight.ui.strong}         brand-<brand>/brand-base
  lineHeight               {typography.lineHeight.ui.medium}         base/brand-base
  fontSize                 {typography.fontSize.ui.medium}           base/brand-base
  letterSpacing            {typography.letterSpacing.ui.strong}      base/brand-base
  paragraphSpacing         {typography.paragraphSpacing.base.zero}   base/brand-base

The font family and the font weight are values of the brand. The font size, the line height, the letter spacing, and the paragraph spacing are values of base/brand-base, which a brand set can override.

Add a brand

A brand needs a token set, an option of the brand group, and its name in the build configuration. You can make the first two in Tokens Studio or in the JSON files. Tokens Studio writes $metadata.json and $themes.json when it pushes; if you edit the JSON by hand, change them too.

The token set of a brand declares the tokens of base/brand-base that the brand changes, with the names that they have there:

TokensHolds
color.base.primitive.light.<color>.baseThe base color of a palette color
typography.fontFamily.*A list of font families
typography.fontWeight.*The style name of a weight, as the font spells it in Figma
borderRadius.base.context.*A reference to a step of dimension.base.*
borderRadius.base.<component>.*A reference to a step of borderRadius.base.context.*

With the token set written, the steps are:

  1. Add the token set as brand-<brand>/brand-base, which is the file source/brand-<brand>/brand-base.json, and add its name to tokenSetOrder of $metadata.json, after base/brand-base.

  2. Add an option to the brand group with the token sets of the brand group. The option globex in $themes.json, as init writes one:

    JSON
    {
      "id": "brand-globex",
      "name": "globex",
      "group": "brand",
      "selectedTokenSets": {
        "base/metric-source": "source",
        "base/metric-base": "source",
        "base/brand-base": "enabled",
        "brand-globex/brand-base": "enabled"
      }
    }
  3. Add the name of the option to chassis.build.brands in package.json:

    JSON
    "chassis": {
      "build": {
        "brands": ["acme", "globex"]
      }
    }
  4. Lint the source, build, and review the changes of the output:

    Shell
    npx chassis-tokens lint-source
    npx chassis-tokens build
    npx chassis-tokens diff

    With the apps site on the web and mobile on iOS and Android, the build writes dist/web/site/globex/, dist/ios/mobile/globex/, and dist/android/mobile/globex/.

  5. Write the Swift package manifest again, which has one library for every app and brand with an iOS platform:

    Shell
    npx chassis-tokens swift-package

    npx chassis-tokens swift-package --check fails while Package.swift differs from the configuration. The Android libraries need no such step.

An app or a screen follows the same steps with its own group and with chassis.build.apps or chassis.build.screens. A screen of an app with the android platform also needs a resource folder in chassis.build.options.android.screens. The tokens of a new component need no set and no option: add them to base/app-base, which every app enables.

Sync to Figma

Tokens Studio exports every group as a Variable Collection and every option as a Mode. The tokens of the enabled sets become Variables, and the composite tokens, such as font.* and shadow.*, become styles. After an export, $themes.json records the Figma identifiers of all of them for each option, and they make up most of the file.

The Figma Variables guide covers the export, the Collections, and the publishing of the library.

Troubleshooting

The lint and the build name the token set and the token of a mistake in the source. Run npx chassis-tokens lint-source after every pull or edit, before the build.

No token sets

The build stops with No token sets for <brand>_site_light in source/$themes.json. chassis.build names a brand, an app, a theme, or a screen that is not an option of its group in $themes.json. Add the option, or write the name in package.json as the option spells it.

Token missing in a screen

The lint reports <token> is declared by screen "small", not by screen "large", "medium" [same-names]. The options of the screen group, and those of the theme group, must declare the same names in their enabled sets. Add the token to the other sets, or fix the name that differs.

Unknown font weight

The lint reports <token> "<weight>" is not a font weight the build knows [font-weight]. A font weight token holds the name of a weight, with or without a space between its words, and a style word such as Italic may follow it. Use the style name of the font in Figma, and check its spelling.

Value is not a token

The lint reports <token>.value is not a token: it has no $value [token-type]. The token set holds value and type without $, the format before DTCG. Write $value and $type in the set, or remove the set from the option that selects it.

Next steps