Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Introduce Tokens Structure Decision #1763

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/decisions/009-tokens-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Tokens Structure

Date: 2024-11-19

Status: accepted

## Context

Our Design System uses design tokens.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (if-minor): Can you please provide some experience? Like that, we have started to use Figma variables and thus the tokens are exported based on this. Or if there were some pain points with the tokens, so we have created a new structure that solves these issues and so on...

I would like to have here more about why we are doing this, please :-)


## Decision

This is what we decided on:

1. We divide tokens into `Global Tokens` and `Theme Tokens`. The `Global Tokens` are non-themed tokens – their
values are the same in all themes, for example breakpoints. The `Theme Tokens` have the same structure, but in each theme,
their value can differ, for example colors.
2. Global tokens are divided into `Borders`, `Gradients`, `Other`, `Radii`, `Shadows`, `Spacing` and `Typography`. Each category
has its own file and contains tokens that are related to the category. The `Other` category contains tokens that do not fit
into any other category.
3. The `Gradients` and `Shadows` tokens use CSS variables to define the colors. This allows us to theme them.
4. We use scales for tokens that have multiple values. For example, the `Spacing` category contains `space-0`, `space-100`, `space-200`, etc.
We use hundreds for the scale, so our users have plenty of space to add their own values between the predefined ones.
5. The `Theme Tokens` contains folders for each theme.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (if-minor):

Suggested change
5. The `Theme Tokens` contains folders for each theme.
5. The `Theme Tokens` contains directories for each theme.

6. In `Theme Tokens` we provide a list of SCSS variables and also a mixin with CSS variables. The mixin is used to generate CSS variables
for the theme. The SCSS variables are used to define the values of the tokens.

### Color token structure

These are decisions related to the color tokens:

1. We decided to create a `component` group which contains tokens for unique components. This way, we can easily find the colors
that are used in a specific component and we know that these colors are not used anywhere else.
2. We decided to add infix `-state-` to the state tokens before the state. This way, we know which tokens are used for states
and are related to each other.
3. We decided to have a `disabled` group which covers the disabled state and is used for all components.
4. We decided to have suffixes `-basic` and `-subtle` for tokens for components which need two different contrast levels.
5. We decided to have `form-field` group which contains tokens for form fields. This group has a subgroup `filled` for
tokens which are used for filled part of the form field. In the future, we can add more subgroups for different form field types.
6. We decided to have a `neutral` group which contains tokens for neutral colors.
7. We decided to create color tokens for gradients and shadows. These tokens are used in the `Gradients` and `Shadows` categories.
To support multiple shadow or gradients colors in one `Gradients` or `Shadows` token, we use `-color-01`, `-color-02`, etc. suffixes.

## Consequences

By following this structure, we can easily find tokens and we know where to add new tokens. We can also easily add new themes
and we know where to add new tokens for the themes. This structure is easy to understand and maintain.

Our tokens follow the structure described in this decision.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (if-minor): I think this sentence is unnecessary.

Loading