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/tokensis an npm package with thechassis-tokenscommand, which uses Style Dictionary to write SCSS variables, Swift constants and Android resources. It also holds the Chassis token system, whichchassis-tokens initwrites into a new repository. - A repository of tokens. It holds the token sets in
source/, JSON files in Tokens Studio format synced with Figma, thechassis.buildblock of itspackage.json, and the committeddist/andPackage.swift.chassis-tokens initwrites 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.
| Group | Token sets of an option hold | Example options |
|---|---|---|
brand | The palette, the font families and weights, and the base border radius | acme, globex |
theme | The primitive and context colors, and the shadows | light, dark |
app | The component tokens, with the overrides of the app | site, mobile |
screen, optional | The font sizes, and the sizes and spacing that differ per screen | large, 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.
| Level | Holds | Example | Reference |
|---|---|---|---|
| Base tokens | The steps of a scale or the colors of a palette | size.unit.16 | {dimension.base.16} |
| Context tokens | A value named by its role | space.context.medium | {size.unit.16} |
| Component tokens | A value for a part of a component | space.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.
| Platform | Folder | Files |
|---|---|---|
web | dist/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 |
ios | dist/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 |
android | dist/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.
| Platform | Name | Format |
|---|---|---|
| Web | $cx-space-context-medium | A size in rem |
| iOS | SpaceContextMedium | A CGFloat in points |
| Android | @dimen/space_context_medium | A <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.
| Package | Name | Contents |
|---|---|---|
| The builder, on npm | @chassis-ui/tokens | The chassis-tokens command and the Gradle project of the Android libraries |
| Tokens, on npm | acme-tokens, the name of package.json | All of dist/: the web, iOS and Android folders of every brand |
| Swift package | https://github.com/acme/acme-tokens.git, with one library per app and brand, such as ChassisTokensMobileAcme | The Swift files and the icons of dist/ios/<app>/<brand>/ |
| Android library | acme-tokens-android-<app>-<brand>-<version>.aar, attached to the GitHub release | The res/ tree of dist/android/<app>/<brand>/ |
| Release archive | acme-tokens-<platform>-<app>-<brand>-<version>.zip, attached to the GitHub release | The 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
- The quick start makes a repository of your own and uses its tokens in a project.
- The web, iOS and Android guides cover the files, themes and screen sizes of each platform.
- The builder and its token system are in the repository of Chassis Tokens.