Opacity tokens hold the alpha values of the transparent colors, as a scale of levels and as values named by the role of a color.
This page is a work in progress. Parts of it may be incomplete or differ from the current version of Chassis Tokens.
Introduction
The token sets that this page names are the Chassis token system, as chassis-tokens init writes it into a repository of tokens. Once written, the token sets belong to the repository, which changes them as it needs.
Opacity tokens hold alpha values, as a number from 0 to 1. The color tokens reference them to build the transparent colors of the palette and the subtle colors of text, borders, and icons. The scale and the context tokens are in source/base/metric-base.json, and the alphas of the color roles in source/base/brand-base.json, which the token set of a brand overrides.
Token levels
Opacity tokens have a base and a context level, and no component level. Base tokens hold a scale of levels (opacity.level.*) and the alpha of each color role (opacity.base.context.*). Context tokens (opacity.context.*) reference the alphas of the color roles. An alpha of a color role does not reference the scale: it holds a number of its own, which need not be a level of the scale.
The scale and the context tokens are in source/base/metric-base.json. The alphas of the color roles are in source/base/brand-base.json, next to the base colors, and the token set of a brand overrides them.
Base tokens
Base tokens hold the opacity scale, opacity.level.*. The name of a level is its opacity in percent: opacity.level.30 is 30 percent opaque. The levels go from 10 to 90 in steps of ten, with 05 and 95 next to the ends of the scale; zero is fully transparent and solid is fully opaque. The transparent colors of the palette reference the levels from 05 to 95, and the transparent colors reference zero; see Usage.
Role alphas
opacity.base.context.* holds the alpha of each color role, under the name of its context token: opacity.base.context.fg-subtle is the number that opacity.context.fg-subtle references. A brand sets its own alphas by overriding these tokens in its token set, source/brand-<brand>/brand-base.json, and takes the rest from source/base/brand-base.json. The build does not write them: the output has the context tokens, with the numbers of the brand.
Context tokens
Context tokens hold the alpha of a color role, and each references the base token of the same name. The colors of color.base.context.* reference them, in the color groups of every theme. The fg-subtle colors have two alphas: opacity.context.fg-subtle in the default and alternate contexts, and opacity.context.fg-a11y in the contexts of a brand or status color, such as primary and danger.
| Token | Reference | Purpose |
|---|---|---|
opacity.context.fg-subtle | {opacity.base.context.fg-subtle} | Alpha of the fg-subtle colors of the default and alternate contexts |
opacity.context.fg-slight | {opacity.base.context.fg-slight} | Alpha of the fg-slight and fg-disabled colors |
opacity.context.fg-a11y | {opacity.base.context.fg-a11y} | Alpha of the fg-subtle colors of the primary, secondary, neutral, danger, success, warning, and info contexts |
opacity.context.border-subtle | {opacity.base.context.border-subtle} | Alpha of the border-subtle colors |
opacity.context.icon-subtle | {opacity.base.context.icon-subtle} | Alpha of the icon-subtle colors |
opacity.context.icon-slight | {opacity.base.context.icon-slight} | Alpha of the icon-slight colors |
opacity.context.cue-slight | {opacity.base.context.cue-slight} | Alpha of the cue-slight colors |
opacity.context.dim-main | {opacity.base.context.dim-main} | Alpha of the dim-main colors |
opacity.context.dim-subtle | {opacity.base.context.dim-subtle} | Alpha of the dim-subtle colors |
opacity.context.dim-slight | {opacity.base.context.dim-slight} | Alpha of the dim-slight colors, except in the default and alternate contexts |
Usage
Color tokens reference the opacity tokens, so an app that needs a transparent color uses the color token. The color tokens page lists these colors.
Opacity in colors
A transparent color holds rgba() with a reference to a color and a reference to an opacity. In source/base/theme-base.json, the black of the palette with the alpha of opacity.level.30 is defined like this:
"t-30": {
"$type": "color",
"$value": "rgba({color.primitive.black.base}, {opacity.level.30})"
}The build resolves the references and writes the color with its alpha. The colors of the palette and the context colors follow this pattern.
| Token | Reference |
|---|---|
color.primitive.black.t-30 | rgba({color.primitive.black.base}, {opacity.level.30}) |
color.primitive.primary.t-5030 | rgba({color.primitive.primary.50}, {opacity.level.30}) |
color.base.context.light.default.fg-subtle | rgba({color.base.context.light.default.fg-main}, {opacity.context.fg-subtle}) |
The names of the colors state the opacity that they reference:
- Black and white:
t-<level>appliesopacity.level.<level>to thebasecolor, fromt-05tot-95. - The other colors of the palette:
t-50<level>appliesopacity.level.<level>to step50of the color, fromt-5005tot-5095. - Context colors: a subtle or slight color applies an
opacity.context.*token to a solid color of its group, such asfg-main,icon-main, orcue-main. Thefg-hoverandfg-presscolors applyopacity.level.90in the same way. Adim-*color applies theopacity.context.dim-*token of its name to a color of a palette, exceptdim-slightin thedefaultandalternatecontexts, which appliesopacity.level.05.
opacity.level.zero is the alpha of the transparent color of each palette color and of the transparent-color of each color group.
Choosing a token
The level to change depends on how far the change must reach. A change to opacity.level.30 changes every t-30 and t-5030 color of every theme, and a change to opacity.context.fg-subtle changes the fg-subtle colors that reference it.
- A transparent color in an app: use the color token, such as
color.context.default.fg-subtle, and not a color combined with an opacity token. - A new transparent color token: reference an
opacity.context.*token when its role has one, and a level ofopacity.level.*otherwise. - The alpha of a role in one brand: override the
opacity.base.context.*token in the token set of the brand, and leave the context token as it is. - The opacity of an element: use a level of
opacity.level.*.
Platform output
An opacity prints as a number without a unit on the web, as a CGFloat on iOS, and as a float item on Android. The build writes the scale and the context tokens, and not opacity.base.context.*.
| Platform | Name | Format |
|---|---|---|
| Web | $cx-opacity-context-fg-subtle | A number without a unit |
| iOS | OpacityContextFgSubtle | A CGFloat |
| Android | @dimen/opacity_context_fg_subtle | An <item> of the type dimen with the format float |
On Android, the build writes an <item> of the type dimen with the format float instead of a <dimen> element, and the reference of the item starts with @dimen/, as for a size. The values in the examples are those of the token sets that init writes, and a brand that overrides a token has its own. The build writes this line:
<item name="opacity_context_fg_subtle" type="dimen" format="float">0.6</item>A color that references an opacity token prints with its alpha, and not with a reference to the opacity: inside rgba() on the web, as the alpha of a UIColor on iOS, and as the first two digits of the ARGB hex color on Android.
See the web, iOS, and Android docs for the files that hold these names.