Skip to main contentSkip to docs navigation

Chassis

Welcome to Chassis Tokens

View on GitHub

Chassis Tokens is the builder of design tokens of the Chassis Design System, which turns a repository of Tokens Studio files into SCSS, Swift and Android resources.

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

Introduction

Chassis Tokens turns design tokens into files for the web, iOS and Android. The work is split over two kinds of repository, so that a team owns its tokens and shares the build:

  • The builder. @chassis-ui/tokens is an npm package with the chassis-tokens command, which uses Style Dictionary to write SCSS variables, Swift constants and Android resources. It also holds the Chassis token system, which chassis-tokens init writes into a new repository.
  • A repository of tokens. It holds the token sets in source/, JSON files in Tokens Studio format synced with Figma, the chassis.build block of its package.json, and the committed dist/ and Package.swift. chassis-tokens init writes one, and the builder is a development dependency of it.

Once init has written the token sets, they are yours: you change their values, add brands, themes and apps, and choose the platforms. A later version of the builder never writes over them. The web output of the token system is what Chassis CSS reads. The quick start makes a repository and uses its tokens in a project. The token sets and names on this page are those that init writes, and the options are the examples of the quick start.

Token sets

A token set is one JSON file of source/, such as base/theme-base.json. source/$themes.json sorts the token sets into groups, and each option of a group selects the token sets that hold its tokens. The token system is built on three groups, brand, theme and app, which init writes. screen is an optional fourth group that a repository adds.

GroupToken sets of an option holdExample options
brandThe palette, the font families and weights, and the base border radiusacme, globex
themeThe primitive and context colors, and the shadowslight, dark
appThe component tokens, with the overrides of the appsite, mobile
screen, optionalThe font sizes, and the sizes and spacing that differ per screenlarge, medium, small

One option of each group makes a list of token sets, named <brand>_<app>_<theme>, such as acme_site_light, and <brand>_<app>_<theme>_<screen> with a screen group. A token set overrides the tokens of the sets before it in the list, as in Tokens Studio: the dark theme selects base/theme-base.json and then base/theme-dark.json, whose colors replace those of the first.

The options are yours to change. To add the screen group, add it to $themes.json in Tokens Studio and list its options in screens of chassis.build; the Style Dictionary guide describes the files it adds. A group of your own also needs a change to planBuilds in lib/build/build.js of the builder, which makes the name of a list from the brand, the app, the theme and the screen.

The Tokens Studio guide describes the token sets and how to change them, and the Figma Variables guide how they become Variables in Figma.

Token levels

Tokens reference each other on three levels, so a change to a base token reaches every token that references it. The sizes of the base level reference dimension.base.*, which holds the numbers of the scales and references nothing.

LevelHoldsExampleReference
Base tokensThe steps of a scale or the colors of a palettesize.unit.16{dimension.base.16}
Context tokensA value named by its rolespace.context.medium{size.unit.16}
Component tokensA value for a part of a componentspace.button.medium-gap{space.unit.8}

The pages of the token categories, such as the space tokens and the color tokens, list the tokens of each level.

Build output

The build reads chassis.build of the package.json of the repository of tokens, which lists the brands, themes and apps to build, the platforms of each app, and the screens when the repository has them. The configuration of the quick start builds the brands acme and globex, the app site for the web platform, and the app mobile for the ios and android platforms. An option of $themes.json that the configuration does not list is not built.

Every app and brand gets one folder per platform, dist/<platform>/<app>/<brand>/, at the root of the repository of tokens.

PlatformFolderFiles
webdist/web/<app>/<brand>/SCSS variables: main.scss, string.scss, one color file per theme and a number file, one per screen with a screen group
iosdist/ios/<app>/<brand>/Swift constants with UIKit values: ChassisTokens.swift, String.swift, one color file per theme and a number file, one per screen with a screen group; Color.swift, whose colors follow the light and dark appearance; the icons in Icons.xcassets
androiddist/android/<app>/<brand>/XML resources: main.xml, string.xml, one color file per theme and a number file, one per screen with a screen group; the same resources as a res/ tree with night qualifiers, and screen-size qualifiers with a screen group, and the icons as vector drawables

A token keeps its name on every platform, in the spelling of the platform, and its value gets the type and the unit of the platform.

PlatformNameFormat
Web$cx-space-context-mediumA size in rem
iOSSpaceContextMediumA CGFloat in points
Android@dimen/space_context_mediumA <dimen> in dp

The web platform writes SCSS for Chassis CSS: $cx-color-accordion-item-fg-color is var(--default-fg-main), the custom property that Chassis CSS generates for color.context.default.fg-main. The presets web-scss, web-px and web-vw write SCSS variables without custom properties for other CSS frameworks, and the presets ios-swiftui and android-compose write SwiftUI and Jetpack Compose values. init writes no preset; you add one to the platforms of an app. The Style Dictionary guide is the reference of the build.

Packages

The builder is an npm package at version 0.16.1. A repository of tokens publishes its tokens in three kinds of package and an archive, under its own name and its own versions. The examples are those of a repository named acme-tokens on GitHub as acme/acme-tokens.

PackageNameContents
The builder, on npm@chassis-ui/tokensThe chassis-tokens command and the Gradle project of the Android libraries
Tokens, on npmacme-tokens, the name of package.jsonAll of dist/: the web, iOS and Android folders of every brand
Swift packagehttps://github.com/acme/acme-tokens.git, with one library per app and brand, such as ChassisTokensMobileAcmeThe Swift files and the icons of dist/ios/<app>/<brand>/
Android libraryacme-tokens-android-<app>-<brand>-<version>.aar, attached to the GitHub releaseThe res/ tree of dist/android/<app>/<brand>/
Release archiveacme-tokens-<platform>-<app>-<brand>-<version>.zip, attached to the GitHub releaseThe content of dist/<platform>/<app>/<brand>/

Roadmap

Seasonal and high-contrast themes are planned. Output in other formats, such as JavaScript and JSON, is planned as well. The changelog of the builder names what each release adds.

Next steps