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

Preprocessor to allow token overrides within one token definition mainly for component tokens #1092

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

lukasoppermann
Copy link
Contributor

@lukasoppermann lukasoppermann commented Nov 25, 2024

Summary

Using a pre-processor allows us to define value overwrites on a token using the $extensions['org.primer.overrides'] property.

Schema

type themeString = "light" | "dark" | "dark-high-contrast" // | ...
type overrideObject = {
  $value?: DesignTokenValue
  $alpha?: number
}
  
{
  $extensions: {
    'org.primer.overrides': 
      {
        [theme: themeString]: overrideObject | string
      }
    
  }
}
topicTag: {
    borderColor: {
      $value: '{base.color.transparent}',
      $type: 'color',
      $extensions: {
        'org.primer.overrides': 
          {
          "light": {
              $value: '{base.color.neutral.10}',
            },
            dark: '{base.color.neutral.7}',
          },
      },
    },
  },

When building the tokens we need to provide a theme to the PlatformConfig options property, e.g.:

css: css(`css/${filename}.css`, options.prefix, options.buildPath, {
        themed: options.themed,
        themeOverrides: {
          theme: options.theme
        },
      }),

If a value with this theme is defined on the token, it will be used, otherwise the "default" $value will be used.

The benefit of using a pre-processor to other solutions is, that the token can still be transformed normally in the transformation flow. No custom code is required, contributors don't need to understand preprocessors or how this works, to add contributions to other parts.

List of notable changes:

Copy link

changeset-bot bot commented Nov 25, 2024

🦋 Changeset detected

Latest commit: e5d5522

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/primitives Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lukasoppermann lukasoppermann marked this pull request as ready for review November 25, 2024 13:02
@lukasoppermann lukasoppermann requested review from a team as code owners November 25, 2024 13:02
@lukasoppermann lukasoppermann marked this pull request as draft November 25, 2024 13:02
@lukasoppermann lukasoppermann changed the title Pre processor Preprocessor to allow token overrides within one token definition mainly for component tokens Dec 4, 2024
@lukasoppermann lukasoppermann self-assigned this Dec 4, 2024
Copy link
Contributor

github-actions bot commented Dec 5, 2024

Design Token Diff (Figma)

/figma/figma.json

+++ /home/runner/work/primitives/primitives/dist/figma/figma.json	2024-12-05 13:43:54.049376057 +0000
@@ -101,14 +101,6 @@
     "groups": [
       "typography"
     ]
-    },
-    "undefined": {
-      "modes": [
-        null
-      ],
-      "groups": [
-        null
-      ]
   }
 },
 "files": [

@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 09:26 Inactive
@lukasoppermann lukasoppermann force-pushed the pre-processor branch 2 times, most recently from 0cb917b to 13c0189 Compare December 5, 2024 09:33
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 09:34 Inactive
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 09:35 Inactive
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 09:42 Inactive
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 11:36 Inactive
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 12:47 Inactive
@lukasoppermann lukasoppermann marked this pull request as ready for review December 5, 2024 12:51
@github-actions github-actions bot temporarily deployed to Preview (Storybook) December 5, 2024 13:44 Inactive
@lukasoppermann lukasoppermann merged commit a17e9a7 into main Dec 5, 2024
27 checks passed
@lukasoppermann lukasoppermann deleted the pre-processor branch December 5, 2024 13:56
@primer primer bot mentioned this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant