10.9 C
United States of America
Thursday, January 30, 2025

Design Token-Based mostly UI Structure


Design tokens, or “tokens” are elementary design choices represented
as information. They’re the foundational constructing blocks of design programs.

For the reason that launch of the second editor’s
draft
of the
design token specification in 2022 and the name for device
makers

to begin implementing and offering suggestions, the panorama of design token
instruments has advanced quickly. Instruments like code mills, documentation
programs, and UI design software program are actually higher geared up to help design
tokens, underscoring their rising significance in fashionable UI structure.

On this article, I am going to clarify what design tokens are, when they’re helpful and the right way to apply
them successfully. We’ll give attention to key architectural choices which might be typically troublesome to vary later, together with:

  1. How one can manage design tokens in layers to stability scalability, maintainability and developer expertise.
  2. Whether or not all tokens must be made accessible to product groups or only a subset.
  3. How one can automate the distribution means of tokens throughout groups.

Function of design tokens

Round 2017, I used to be concerned in a big challenge that used the Micro
Frontend
Structure
to
scale improvement groups. On this setup, completely different groups had been accountable
for various components of the person interface, which could possibly be even on the identical
web page. Every workforce might deploy its micro-frontend independently.

There have been varied instances the place parts can be displayed on high of
one another (comparable to dialogs or toasts showing on high of content material areas),
which weren’t a part of the identical micro frontend. Groups used the CSS
property z-index to regulate the stacking order, typically counting on magic
numbers—arbitrary values that weren’t documented or standardized. This strategy
didn’t scale because the challenge grew. It led to points that took effort to
repair, as cross-team collaboration was wanted.

The difficulty was ultimately addressed with design tokens and I believe makes
a great instance to introduce the idea. The respective token file would possibly
have seemed just like this:

{
  "z-index": {
    "$sort": "quantity",
    "default": {
      "$worth": 1
    },
    "sticky": {
      "$worth": 100
    },
    "navigation": {
      "$worth": 200
    },
    "spinner": {
      "$worth": 300
    },
    "toast": {
      "$worth": 400
    },
    "modal": {
      "$worth": 500
    }
  }
}

The design tokens above characterize the set of z-index values that may
be used within the software and the identify provides builders a good suggestion of
the place to make use of them. A token file like this may be built-in into the
designers’ workflow and likewise be used to generate code, in a format that
every workforce requires. For instance, on this case, the token file may need
been used to generate CSS or SCSS variables:

css

  :root {
    --z-index-default: 1;
    --z-index-sticky: 100;
    --z-index-navigation: 200;
    --z-index-spinner: 300;
    --z-index-toast: 400;
    --z-index-modal: 500;
  }

scss

  
  $z-index-default: 1;
  $z-index-sticky: 100;
  $z-index-navigation: 200;
  $z-index-spinner: 300;
  $z-index-toast: 400;
  $z-index-modal: 500;

What are design tokens?

Salesforce initially launched design tokens to streamline design
updates to a number of
platforms.

The Design Tokens Neighborhood Group describes design tokens as “a
methodology for expressing design choices in a platform-agnostic means so
that they are often shared throughout completely different disciplines, instruments, and
applied sciences

Let’s break this down:

  • Cross-Disciplinary Collaboration: Design tokens act as a standard language
    that aligns designers, builders, product managers, and different disciplines. By
    providing a single supply of fact for design choices, they be sure that
    everybody concerned within the product life cycle is on the identical web page, resulting in extra
    environment friendly workflows.
  • Software integration: Design tokens might be built-in into varied design
    and improvement instruments, together with UI design software program, token editors, translation
    instruments (code mills), and documentation programs. This permits design updates
    to be shortly mirrored within the code base and are synchronized throughout groups.
  • Know-how adaptability: Design tokens might be translated into completely different
    applied sciences like CSS, SASS, and JavaScript for the net, and even used on native
    platforms like Android and iOS. This flexibility allows design consistency
    throughout quite a lot of platforms and gadgets.

Establishing a single supply of fact

A key advantage of design tokens is their capacity to function a single
supply of fact for each design and engineering groups. This ensures that
a number of services or products preserve visible and practical
consistency.

A translation
device
takes one or
extra design token recordsdata as enter and generates platform-specific code as
output. Some translation instruments also can produce documentation for the
design tokens within the type of HTML. On the time of writing, standard
translation instruments embrace Model
Dictionary
,
Theo, Diez
or Specify App.

Automated design token distribution

On this part, we’ll discover the right way to automate the distribution of
design tokens to product groups.

Let’s assume our aim is to supply groups with up to date, tech-specific
design tokens instantly after a designer makes a change. To attain
this, we will automate the interpretation and distribution course of utilizing a
deployment pipeline for design tokens. Moreover platform-specific code
artifacts (like CSS for the net, XML for Android and so on.), the pipeline would possibly
additionally deploy the documentation for the design tokens.

One essential requirement is protecting design tokens below model management.
Fortunately, plugins for standard design instruments like Figma already combine
with Git suppliers like GitHub. It is thought of finest apply to make use of the
Git repository as the only supply of fact for design tokens—not the
design device itself. Nevertheless, this requires the plugin to help syncing
each methods between the repository and the design device, which not all
plugins do. As of now, Tokens Studio is a plugin that gives this
bidirectional syncing. For detailed steerage on integrating Tokens Studio
with completely different Git suppliers, please confer with their
documentation.
The device lets you configure a goal department and helps a
trunk-based in addition to a pull-request-based workflow.

As soon as the tokens are below model management, we will arrange a deployment
pipeline to construct and deploy the artifacts wanted by the product groups,
which embrace platform-specific supply code and documentation. The supply
code is usually packaged as a library and distributed through an artifact
registry. This strategy provides product groups management over the improve
cycle. They’ll undertake up to date types by merely updating their
dependencies. These updates might also be utilized not directly via updates of element
libraries that use the token-based types.

Design Token-Based mostly UI Structure

Determine 2: Automated design token distribution

This total setup has allowed groups at Thoughtworks to roll out
smaller design adjustments throughout a number of front-ends and groups in a single
day.

Totally automated pipeline

Probably the most easy solution to design the pipeline can be a
absolutely automated trunk-based workflow. On this setup, all adjustments
pushed to the primary department will likely be instantly deployed so long as they
move the automated high quality gates.

Such a pipeline would possibly encompass the next jobs:

  1. Verify: Validate the design token recordsdata utilizing a design token validator
    or a JSON validator.
  2. Construct: Use a translation device like Model
    Dictionary
    to transform design token recordsdata into
    platform-specific codecs. This job may also construct the docs utilizing the
    translation device or by integrating a devoted documentation device.
  3. Take a look at: This job is extremely depending on the testing technique. Though
    some checks might be performed utilizing the design token file instantly (like checking the
    colour distinction), a standard strategy is to check the generated code utilizing a
    documentation device comparable to Storybook. Storybook has wonderful take a look at
    help
    for visible regression
    checks, accessibility checks, interplay checks, and different take a look at varieties.
  4. Publish: Publish up to date tokens to a package deal supervisor (for instance,
    npm). The discharge course of and versioning might be absolutely automated with a package deal
    publishing device that’s based mostly on Typical
    Commits
    like
    semantic-release.
    semantic-release additionally permits the deployment of packages to a number of platforms.
    The publish job may also deploy documentation for the design tokens.
  5. Notify: Inform groups of the brand new token model through electronic mail or chat, so
    that they’ll replace their dependencies.

Determine 3: Totally automated deployment pipeline

Pipeline together with handbook approval

Generally absolutely automated high quality gates are usually not ample. If a
handbook evaluation is required earlier than publishing, a standard strategy is to
deploy an up to date model of the documentation with the most recent design
token to a preview atmosphere (a short lived atmosphere).

If a device like Storybook is used, this preview would possibly include not
solely the design tokens but additionally present them built-in with the
parts used within the software.

An approval course of might be carried out through a pull-request workflow.
Or, it may be a handbook approval / deployment step within the pipeline.

Determine 4: Deployment pipeline with handbook approval

Organizing tokens in layers

As mentioned earlier, design tokens characterize design choices as information.
Nevertheless, not all choices function on the identical degree of element. As a substitute,
ideally, normal design choices information extra particular ones. Organizing
tokens (or design choices) into layers permits designers to make
choices on the proper degree of abstraction, supporting consistency and
scalability.

As an illustration, making particular person colour selections for each new element isn’t sensible.
As a substitute, it’s extra environment friendly to outline a foundational colour palette after which
determine how and the place these colours are utilized. This strategy reduces the
variety of choices whereas sustaining a constant feel and look.

There are three key varieties of design choices for which design tokens
are used. They construct on high of each other:

  • What design choices can be found to make use of?
  • How are these types utilized throughout the person interface?
  • The place precisely are these types utilized (during which parts)?

There are numerous names for these three varieties of tokens (as regular,
naming is the exhausting half). On this article, we’ll use the phrases proposed
by Samantha
Gordashko
:
choice tokens, determination tokens and element tokens.

Let’s use our colour instance as an instance how design tokens can
reply the three questions above.

Choice tokens: defining what design choices are offered

Choice tokens (additionally known as primitive tokens, base tokens, core
tokens
, basis tokens or reference tokens) outline what
types can be utilized within the software. They outline issues like colour
palettes, spacing/sizing scales or font households. Not all of them are
essentially used within the software, however they current affordable
choices.

Utilizing our instance, let’s assume we have now a colour palette with 9 shades for every colour,
starting from very gentle to extremely saturated. Beneath, we outline the blue tones and gray tones as option-tokens:

{
  "colour": {
    "$sort": "colour",
    "choices": {
      "blue-100": {"$worth": "#e0f2ff"},
      "blue-200": {"$worth": "#cae8ff"},
      "blue-300": {"$worth": "#b5deff"},
      "blue-400": {"$worth": "#96cefd"},
      "blue-500": {"$worth": "#78bbfa"},
      "blue-600": {"$worth": "#59a7f6"},
      "blue-700": {"$worth": "#3892f3"},
      "blue-800": {"$worth": "#147af3"},
      "blue-900": {"$worth": "#0265dc"},
      "grey-100": {"$worth": "#f8f8f8"},
      "grey-200": {"$worth": "#e6e6e6"},
      "grey-300": {"$worth": "#d5d5d5"},
      "grey-400": {"$worth": "#b1b1b1"},
      "grey-500": {"$worth": "#909090"},
      "grey-600": {"$worth": "#6d6d6d"},
      "grey-700": {"$worth": "#464646"},
      "grey-800": {"$worth": "#222222"},
      "grey-900": {"$worth": "#000000"},
      "white": {"$worth": "#ffffff"}
    }
  }
}

Though it’s extremely helpful to have affordable choices, choice tokens fall brief
of being ample for guiding builders on how and the place to use them.

Determination tokens: defining how types are utilized

Determination tokens (additionally known as semantic tokens or system tokens)
specify how these type choices must be utilized contextually throughout
the UI.

Within the context of our colour instance, they could embrace choices like the next:

  • grey-100 is used as a floor colour.
  • grey-200 is used for the background of disabled parts.
  • grey-400 is used for the textual content of disabled parts.
  • grey-900 is used as a default colour for textual content.
  • blue-900 is used as an accent colour.
  • white is used for textual content on accent colour backgrounds.

The corresponding determination token file would appear like this:

{
  "colour": {
    "$sort": "colour",
    "choices": {
      "floor": {
        "$worth": "{colour.choices.grey-100}",
        "description": "Used as a floor colour."
      },
      "background-disabled": {
        "$worth": "{colour.choices.grey-200}",
        "description":"Used for the background of disabled parts."
      },
      "text-disabled": {
        "$worth": "{colour.choices.grey-400}",
        "description": "Used for the textual content of disabled parts."
      },
      "textual content": {
        "$worth": "{colour.choices.grey-900}",
        "description": "Used as default textual content colour."
      },
      "accent": {
        "$worth": "{colour.choices.blue-900}",
        "description": "Used as an accent colour."
      },
      "text-on-accent": {
        "$worth": "{colour.choices.white}",
        "description": "Used for textual content on accent colour backgrounds."
      }
    }
  }
}

As a developer, I’d largely have an interest within the choices, not the
choices. For instance, colour tokens sometimes include a protracted checklist of choices (a
colour palette), whereas only a few of these choices are literally utilized in
the applying. The tokens which might be truly related when deciding which
types to use, can be normally the choice tokens.

Determination tokens use
references to the
choice tokens. I consider organizing tokens this manner as a layered
structure. In different articles, I’ve typically seen the time period tier being
used, however I believe layer is the higher phrase, as there isn’t any bodily
separation implied. The diagram under visualizes the 2 layers we talked
about thus far:

Determine 5: 2-layer sample

Part tokens: defining the place types are utilized

Part tokens (or component-specific tokens) map the determination
tokens
to particular components of the UI. They present the place types are
utilized.

The time period element within the context of design tokens doesn’t all the time
map to the technical time period element. For instance, a button could be
carried out as a UI element in some functions, whereas different
functions simply use the button HTML aspect as a substitute. Part
tokens
could possibly be utilized in each instances.

Part tokens might be organised in a group referencing a number of determination tokens. In our instance, this references
would possibly embrace text- and background-colors for various variants of the button (main, secondary) in addition to disabled buttons.
They could additionally embrace references to tokens of different varieties (spacing/sizing, borders and so on.) which I am going to omit within the
following instance:

{
  "button": {
    "main": {
      "background": {
        "$worth": "{colour.choices.accent}"
      },
      "textual content": {
        "$worth": "{colour.choices.text-on-accent}"
      }
    },
    "secondary": {
      "background": {
        "$worth": "{colour.choices.floor}"
      },
      "textual content": {
        "$worth": "{colour.choices.textual content}"
      }
    },
    "background-disabled": {
      "$worth": "{colour.choices.background-disabled}"
    },
    "text-disabled": {
      "$worth": "{colour.choices.text-disabled}"
    }
  }
}

To a point, element tokens are merely the results of making use of
choices to particular parts. Nevertheless, as this
instance reveals, this course of isn’t all the time easy—particularly for
builders with out design expertise. Whereas determination tokens can provide a
normal sense of which types to make use of in a given context, element tokens
present further readability.

Determine 6: 3-layer sample

Be aware: there could also be “snowflake” conditions the place layers are skipped.
For instance, it may not be potential to outline a normal determination for
each single element token, or these choices may not have been made
but (for instance in the beginning of a challenge).

Token scope

I already talked about that whereas choice tokens are very useful to
designers, they won’t be related for software builders utilizing the
platform-specific code artifacts. Utility builders will sometimes be
extra within the determination/element tokens.

Though token scope isn’t but included within the design token
spec, some design
programs already separate tokens into non-public (additionally known as inner) and
public (additionally known as world) tokens. For instance, the Salesforce Lightning
Design System launched a flag for every
token
. There are
varied the reason why this may be a good suggestion:

  • it guides builders on which tokens to make use of
  • fewer choices present a greater developer expertise
  • it reduces the file measurement as not all tokens have to be included
  • non-public/inner tokens might be modified or eliminated with out breaking
    adjustments

A draw back of constructing choice tokens non-public is that builders would rely
on designers to all the time make these types accessible as determination or element
tokens. This might change into a problem in case of restricted availability of the
designers or if not all choices can be found, for instance firstly of
a challenge.

Sadly, there isn’t any standardized answer but for implementing
scope for design tokens. So the strategy is determined by the tool-chain of the
challenge and can more than likely want some customized code.

File-based scope

Utilizing Model Dictionary, we will use a
filter to
expose solely public tokens. Probably the most easy strategy can be to
filter on the file ending. If we use completely different file endings for element,
determination and choice tokens, we will use a filter on the file path, for
instance, to make the choice tokens layer non-public.

Model Dictionary config

  const styleDictionary = new StyleDictionary({
    "supply": ["color.options.json", "color.decisions.json"],
    "platforms": {
      "css": {
        "transformGroup": "css",
        "recordsdata": [
          {
            "destination": "variables.css",
            "filter": token => !token.filePath.endsWith('options.json'),
            "format": "css/variables"
          }
        ]
      }
    }
  });

The ensuing CSS variables would include
solely these determination tokens, and never the choice tokens.

Generated CSS variables

  :root {
    --color-decisions-surface: #f8f8f8;
    --color-decisions-background-disabled: #e6e6e6;
    --color-decisions-text-disabled: #b1b1b1;
    --color-decisions-text: #000000;
    --color-decisions-accent: #0265dc;
    --color-decisions-text-on-accent: #ffffff;
  }

A extra versatile strategy

If extra flexibility is required, it could be preferable so as to add a scope
flag to every token and to filter based mostly on this flag:

Model Dictionary config

  const styleDictionary = new StyleDictionary({
    "supply": ["color.options.json", "color.decisions.json"],
    "platforms": {
      "css": {
        "transformGroup": "css",
        "recordsdata": [
          {
            "destination": "variables.css",
            "filter": {
              "public": true
            },
            "format": "css/variables"
          }
        ]
      }
    }
  });

If we then add the flag to the choice tokens, the ensuing CSS would
be the identical as above:

Tokens with scope flag

  {
    "colour": {
      "$sort": "colour",
      "choices": {
        "floor": {
          "$worth": "{colour.choices.grey-100}",
          "description": "Used as a floor colour.",
          "public": true
        },
        "background-disabled": {
          "$worth": "{colour.choices.grey-200}",
          "description":"Used for the background of disabled parts.",
          "public": true
        },
        "text-disabled": {
          "$worth": "{colour.choices.grey-400}",
          "description": "Used for the textual content of disabled parts.",
          "public": true
        },
        "textual content": {
          "$worth": "{colour.choices.grey-900}",
          "description": "Used as default textual content colour.",
          "public": true
        },
        "accent": {
          "$worth": "{colour.choices.blue-900}",
          "description": "Used as an accent colour.",
          "public": true
        },
        "text-on-accent": {
          "$worth": "{colour.choices.white}",
          "description": "Used for textual content on accent colour backgrounds.",
          "public": true
        }
      }
    }
  }

Generated CSS variables

  :root {
    --color-decisions-surface: #f8f8f8;
    --color-decisions-background-disabled: #e6e6e6;
    --color-decisions-text-disabled: #b1b1b1;
    --color-decisions-text: #000000;
    --color-decisions-accent: #0265dc;
    --color-decisions-text-on-accent: #ffffff;
  }

Such flags can now even be set via the Figma
UI

(if utilizing Figma variables as a supply of fact for design tokens). It’s
accessible as
hiddenFromPublishing
flag through the Plugins API.

Ought to I take advantage of design tokens?

Design tokens provide important advantages for contemporary UI structure,
however they is probably not the best match for each challenge.

Advantages embrace:

  • Improved lead time for design adjustments
  • Constant design language and UI structure throughout platforms and
    applied sciences
  • Design tokens being comparatively light-weight from an implementation level of
    view

Drawbacks embrace:

  • Preliminary effort for automation
  • Designers may need to (to a point) work together with Git
  • Standardization continues to be in progress

Contemplate the next when deciding whether or not to undertake design
tokens:

When to make use of design tokens

  1. Multi-Platform or Multi-Utility Environments: When working throughout
    a number of platforms (internet, iOS, Android…) or sustaining a number of functions or
    frontends, design tokens guarantee a constant design language throughout all of
    them.
  2. Frequent Design Adjustments: For environments with common design
    updates, design tokens present a structured solution to handle and propagate adjustments
    effectively.
  3. Massive Groups: For groups with many designers and builders, design
    tokens facilitate collaboration.
  4. Automated Workflows: If you happen to’re accustomed to CI/CD pipelines, the
    effort so as to add a design token pipeline is comparatively low. There are additionally
    industrial choices.

When design tokens may not be crucial

  1. Small initiatives: For smaller initiatives with restricted scope and minimal
    design complexity, the overhead of managing design tokens may not be definitely worth the
    effort.
  2. No problem with design adjustments: If the velocity of design adjustments,
    consistency and collaboration between design and engineering are usually not a problem,
    then you may additionally not want design tokens.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles