Closed Bug 1850611 Opened 10 months ago Closed 3 months ago

Create a JSON file source of truth for our design tokens

Categories

(Toolkit :: Themes, task)

task

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 --- fixed

People

(Reporter: jules, Assigned: jules)

References

(Blocks 3 open bugs)

Details

(Whiteboard: [recomp])

Attachments

(2 files, 14 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

We are moving our design tokens source of truth to a JSON file as this is an agnostic 'styling' file format (i.e. not in CSS, SCSS, or Swift specifically).

This is needed so that we can have one file that remains the source of truth and can generate our design tokens for multiple styling languages via a build system such as Style Dictionary.

We're working on generating Scss tokens for the OMC team so this is a required step.

Blocks: 1850614
Assignee: nobody → jules
Depends on: 1857330
Blocks: 1857330
No longer depends on: 1857330
Attachment #9354942 - Attachment description: WIP: Bug 1850611 - Create a JSON file source of truth for our design tokens → Bug 1850611 - Create a JSON file source of truth for our design tokens
Attachment #9354942 - Attachment description: Bug 1850611 - Create a JSON file source of truth for our design tokens → WIP: Bug 1850611 - Create a JSON file source of truth for our design tokens
Depends on: 1878343
Whiteboard: [fidefe-reusable-components] → [recomp]
Depends on: 1881080
Depends on: 1881821
Attachment #9354942 - Attachment description: WIP: Bug 1850611 - Create a JSON file source of truth for our design tokens → Bug 1850611 - Create a JSON file source of truth for our design tokens r=#recomp-reviewers,#desktop-theme-reviewers

FIDEFE-4623
I originally thought we would be able to use a transformer to handle
this case, but outputting references causes my transformer to fail.
Because of this, I switched to using a custom CSS formatter and adding
the variable references in this formatter.

Additionally, I also switched over to using config.js instead of
config.json using PR FirefoxUX#3 as a starting point.

I also changed the design tokens JSON format to fit what I needed for
the light-dark formatting. I'll need to consolidate my changes with the
changes in PR FirefoxUX#3, but wanted to get this PR updated.

  • Remove build.js, use css/variables formatter, update tokens structure

This removes the build.js file in favor of using config.js (which
requires style-dictionary build to build our files). I also removed
the custom file formatting code in favor of the included css/variables
formatter. Lastly, I updated the tokens structure so instead of
"darkValue", we use "dark".

Most likely the structure of the tokens file will change again, but
I'll create a new PR with those proposed changes.

  • Restore custom file formatting, simplify ref logic.

So we can't use the "css/variables" built-in formatter, otherwise we'll
lose our light-dark value. I reverted those changes back to the
mappedValues loop so that we maintain the light-dark formatting.

I additionally sorted the token so that referenced tokens come after
the referenced definitions. I don't think we have to do this for CSS,
but it does make the generated CSS a little easier to follow in my
opinion.

  • Remove light-dark formatter and replace with transformer.

We can greatly simplify the config.js file by doing two things:

  1. Use a transformer for dealing with light-dark.
  2. In this transformer, modify the original value of the token.

By modifying the value of the original token, we are able to take
advantage of the built-in css/variables formatting and so we don't need
custom CSS file formatting.

Additionally, we can use ...StyleDictionary.transformGroup["group_name"]
to get the individual transforms of a group. By doing this we can extend
an existing group as seen in this patch.

  • fix eslint error

Depends on D204108

  • FIDEFE-4643

By using the composite design token value structure, we gain flexibility
in handling themed and non-themed tokens as well as other cases that
we are not aware of. For example, this composite value structure can be
used to handle prefers-contrast theming, forced-colors (HCM) theming,
etc.

We also add the ability to use "default" as the default value of tokens.
This handles the case where a token has the same value in light and dark
mode but has a different value in perfers-contrast or forced-colors
mode. Currently "default" is the highest priority property of the value
object. If you have "light", "dark" and "default" for a token's
value, then the "default" property will be in the generated token and
not the "light" or "dark" property values.

  • fix broken matcher function in lightDarkTransform

Depends on D204109

  • FIDEFE-4626

  • remove some of the 'default' references from JSON, fix test fixtures

  • address review comments

Depends on D204110

  • FIDEFE-4640

  • Add custom file header function that deals with the MPL and how to edit

Depends on D204111

  • strip '-default' from token names and values

  • use @base in JSON, only replace -base at word boundary

  • fix tests

Depends on D204112

FIDEFE-4687

According to a11y's recommendation,
https://firefox-source-docs.mozilla.org/accessible/HCMMediaQueries.html#writing-maintainable-frontend-code,
we should move the generated media queries within the :root block.

Depends on D204113

  • FIDEFE-4635

  • rebase, address review comments

  • rebuild CSS + fix tests after rebase

  • cleanup matcher and transformer logic

  • cleanup

Depends on D204114

  • simplify string, add comma

  • rebase + fix tests

Depends on D204115

FIDEFE-4631

Sort tokens when exporting in CSS and add section headers to match
existing tokens-*.css files in mozilla-central

Depends on D204116

RECOMP-226

This brings our Style Dictionary CSS generator in line with our current
CSS tokens files.

I had to rewrite the createDesktopFormat and formatTokens to get the
formatting of the CSS string correct.

Depends on D204117

Depends on D204120

Attachment #9390282 - Attachment is obsolete: true
Attachment #9390283 - Attachment is obsolete: true
Attachment #9390284 - Attachment is obsolete: true
Attachment #9390285 - Attachment is obsolete: true
Attachment #9390286 - Attachment is obsolete: true
Attachment #9390287 - Attachment is obsolete: true
Attachment #9390288 - Attachment is obsolete: true
Attachment #9390289 - Attachment is obsolete: true
Attachment #9390290 - Attachment is obsolete: true
Attachment #9390291 - Attachment is obsolete: true
Attachment #9390292 - Attachment is obsolete: true
Attachment #9390293 - Attachment is obsolete: true
Attachment #9390294 - Attachment is obsolete: true
Attachment #9388220 - Attachment description: WIP: Bug 1850611 - Part 2: Adding simple tests for JSON tokens → WIP: Bug 1850611 - Add simple tests for JSON tokens
Attachment #9354942 - Attachment is obsolete: true
Attachment #9388220 - Attachment description: WIP: Bug 1850611 - Add simple tests for JSON tokens → Bug 1850611 - Add simple tests for JSON tokens r=#recomp-reviewers
Pushed by jsimplicio@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/865f28810747
Create a JSON file source of truth for our design tokens. r=reusable-components-reviewers,desktop-theme-reviewers,hjones,dao
https://hg.mozilla.org/integration/autoland/rev/883e713c3013
Add simple tests for JSON tokens r=reusable-components-reviewers,desktop-theme-reviewers,mstriemer,dao
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 126 Branch
Duplicate of this bug: 1826844
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: