-
Notifications
You must be signed in to change notification settings - Fork 5
refactor: simplify tokens exposure #1161
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
Changes from all commits
fe5df01
46ae423
7e282df
1ee1891
072a2d4
7618f40
67dde6f
b086448
23324a7
b65eb64
b83a332
8223407
d368203
f1ee58c
86c789c
da50de3
064fca1
82de3a5
91abb7d
0938786
f95fdbd
f8af0b9
cda763b
726b7ca
22a5523
9576b59
c3edc49
b52531b
28fc60f
e20d59f
8c416f0
65a007a
109abae
9f94b7f
2bdf16f
25206a5
a6051ea
d3dc1e5
c488e85
8958cb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| name: remove-tokens-extras | ||
| description: Remove the $extras parameter from tokens.create() in a component SCSS file, moving the extra tokens into the component selector as CSS custom properties. Usage: /remove-tokens-extras {ComponentPath} | ||
| argument-hint: <ComponentPath> | ||
| allowed-tools: Read, Edit, Bash | ||
| --- | ||
|
|
||
| Remove the `$extras` (third argument) from a `tokens.create()` call in a component SCSS file, and move those extra tokens into the component selector as CSS custom properties. | ||
|
|
||
| ## Arguments | ||
|
|
||
| Parse `$ARGUMENTS` as: `{ComponentPath}` | ||
|
|
||
| - `ComponentPath` — path to the component SCSS file relative to the repo root (e.g. `source/components/button/style.scss` or `source/components/card/style.scss`). | ||
|
|
||
| ## Background: what you are fixing | ||
|
|
||
| The `tokens.create` mixin previously accepted a third `$extras` map argument — a Sass map of custom key-value token pairs that were emitted as CSS custom properties. This third argument has been removed from the mixin. All extra tokens must now be declared as CSS custom properties directly inside the component selector. | ||
|
|
||
| **Before:** | ||
| ```scss | ||
| @include tokens.create($_, getComponentTokens($_), ( | ||
| "border": tokens.use($_, "border-width", 1) solid tokens.get($_, "color--surface-border"), | ||
| "shadow": tokens.use($_, "shadow", 1), | ||
| )); | ||
|
|
||
| .#{$_} { | ||
| border-top: tokens.get($_, "border"); | ||
| filter: tokens.get($_, "shadow"); | ||
| } | ||
| ``` | ||
|
|
||
| **After:** | ||
| ```scss | ||
| @include tokens.create($_, getComponentTokens($_)); | ||
|
|
||
| .#{$_} { | ||
| --#{$_}--border: tokens.use($_, "border-width", 1) solid tokens.get($_, "color--surface-border"); | ||
| --#{$_}--shadow: tokens.use($_, "shadow", 1); | ||
| border-top: var(--#{$_}--border); | ||
| filter: var(--#{$_}--shadow); | ||
| } | ||
| ``` | ||
|
|
||
| Key rules: | ||
| - The extra tokens move to the **top** of the component selector block as `--#{$_}--key: value;` | ||
| - Any `tokens.get($_, "key")` call that referenced an extras key becomes `var(--#{$_}--key)` | ||
| - Global token references (`tokens.get($_, "color--surface")`) and `tokens.use(...)` calls that were NOT in extras remain unchanged | ||
|
|
||
| ## Step 1 — Read the file | ||
|
|
||
| Read the full file at `{ComponentPath}`. | ||
|
|
||
| ## Step 2 — Identify the extras map | ||
|
|
||
| Find the `tokens.create(...)` call and extract every key-value pair from the third argument (the Sass map). Note each key and its value expression exactly. | ||
|
|
||
| ## Step 3 — Find usages of extras keys | ||
|
|
||
| Search the file for any `tokens.get($_, "{key}")` calls where `{key}` is one of the extras keys. These must be replaced with `var(--#{$_}--{key})`. | ||
|
|
||
| Note: only `tokens.get` references to extras keys are affected. `tokens.use` calls that happen to use the same name are not extras references — leave them untouched. | ||
|
|
||
| ## Step 4 — Apply the changes | ||
|
|
||
| Make these edits using the Edit tool: | ||
|
|
||
| 1. **Remove the extras map** from the `tokens.create(...)` call, leaving just: | ||
| ```scss | ||
| @include tokens.create($_, getComponentTokens($_)); | ||
| ``` | ||
|
|
||
| 2. **Add CSS custom properties** at the top of the component selector block (`.#{$_} {`): | ||
| ```scss | ||
| .#{$_} { | ||
| --#{$_}--key: value; | ||
| // ... rest of existing styles | ||
| ``` | ||
|
|
||
| 3. **Replace each** `tokens.get($_, "{key}")` that referenced an extras key with `var(--#{$_}--{key})`. | ||
|
|
||
| ## Step 5 — Verify | ||
|
|
||
| Run a quick grep to confirm no extras argument remains in `tokens.create` and no `tokens.get` references to the old extras keys remain: | ||
|
|
||
| ```sh | ||
| grep -n 'tokens\.create' {ComponentPath} | ||
| grep -n 'tokens\.get' {ComponentPath} | ||
| ``` | ||
|
|
||
| ## Step 6 — Report | ||
|
|
||
| Tell the user: | ||
| - Which extras keys were moved and their values | ||
| - Which `tokens.get` calls were replaced with `var(...)` references | ||
| - Confirmation that `tokens.create` now has no third argument |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,12 +5,11 @@ | |||||
| $_: "c-accordion"; | ||||||
|
|
||||||
| /* Design tokens */ | ||||||
| @include tokens.create($_, getComponentTokens($_), | ||||||
| ("border": tokens.use($_, "border-width", 1) solid tokens.get($_, "color--surface-border"), | ||||||
| )); | ||||||
| @include tokens.create($_, getComponentTokens($_)); | ||||||
|
|
||||||
| /* Component */ | ||||||
| .#{$_} { | ||||||
| --#{$_}--border: tokens.use($_, "border-width", 1) solid tokens.get($_, "color--surface-border"); | ||||||
|
||||||
| --#{$_}--border: tokens.use($_, "border-width", 1) solid tokens.get($_, "color--surface-border"); | |
| --#{$_}--border: #{tokens.use($_, "border-width", 1)} solid #{tokens.get($_, "color--surface-border")}; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,49 +3,48 @@ | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| $_: "c-block"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @include tokens.create($_, getComponentTokens($_), | ||||||||||||||||||||||||||||||||||||||||||||||
| ("shadow": tokens.use($_, "shadow", 1), | ||||||||||||||||||||||||||||||||||||||||||||||
| "shadow-hover": tokens.use($_, "shadow", 2), | ||||||||||||||||||||||||||||||||||||||||||||||
| "radius": tokens.use($_, "border-radius", 1), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-text": tokens.get($_, "color--alpha-contrast"), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-background": tokens.get($_, "color--alpha"), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-overlay": rgb(from tokens.get($_, "color--alpha") r g b / 1), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-overlay-middle": rgba(from tokens.get($_, "color--alpha") r g b / .5), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-overlay-end": rgba(from tokens.get($_, "color--alpha") r g b / 0), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-secondary": tokens.get($_, "color--secondary"), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-hover-background": tokens.get($_, "color--alpha-border"), | ||||||||||||||||||||||||||||||||||||||||||||||
| "color-hover-overlay": tokens.get($_, "color--alpha-border"), | ||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||
| @include tokens.create($_, getComponentTokens($_)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| .#{$_} { | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--shadow: tokens.use($_, "shadow", 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--shadow-hover: tokens.use($_, "shadow", 2); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--radius: tokens.use($_, "border-radius", 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-text: tokens.get($_, "color--alpha-contrast"); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-background: tokens.get($_, "color--alpha"); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-overlay: rgb(from tokens.get($_, "color--alpha") r g b / 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-overlay-middle: rgba(from tokens.get($_, "color--alpha") r g b / .5); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-overlay-end: rgba(from tokens.get($_, "color--alpha") r g b / 0); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-secondary: tokens.get($_, "color--secondary"); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-hover-background: tokens.get($_, "color--alpha-border"); | ||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--color-hover-overlay: tokens.get($_, "color--alpha-border"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+19
|
||||||||||||||||||||||||||||||||||||||||||||||
| --#{$_}--shadow: tokens.use($_, "shadow", 1); | |
| --#{$_}--shadow-hover: tokens.use($_, "shadow", 2); | |
| --#{$_}--radius: tokens.use($_, "border-radius", 1); | |
| --#{$_}--color-text: tokens.get($_, "color--alpha-contrast"); | |
| --#{$_}--color-background: tokens.get($_, "color--alpha"); | |
| --#{$_}--color-overlay: rgb(from tokens.get($_, "color--alpha") r g b / 1); | |
| --#{$_}--color-overlay-middle: rgba(from tokens.get($_, "color--alpha") r g b / .5); | |
| --#{$_}--color-overlay-end: rgba(from tokens.get($_, "color--alpha") r g b / 0); | |
| --#{$_}--color-secondary: tokens.get($_, "color--secondary"); | |
| --#{$_}--color-hover-background: tokens.get($_, "color--alpha-border"); | |
| --#{$_}--color-hover-overlay: tokens.get($_, "color--alpha-border"); | |
| --#{$_}--shadow: #{tokens.use($_, "shadow", 1)}; | |
| --#{$_}--shadow-hover: #{tokens.use($_, "shadow", 2)}; | |
| --#{$_}--radius: #{tokens.use($_, "border-radius", 1)}; | |
| --#{$_}--color-text: #{tokens.get($_, "color--alpha-contrast")}; | |
| --#{$_}--color-background: #{tokens.get($_, "color--alpha")}; | |
| --#{$_}--color-overlay: rgb(from #{tokens.get($_, "color--alpha")} r g b / 1); | |
| --#{$_}--color-overlay-middle: rgba(from #{tokens.get($_, "color--alpha")} r g b / .5); | |
| --#{$_}--color-overlay-end: rgba(from #{tokens.get($_, "color--alpha")} r g b / 0); | |
| --#{$_}--color-secondary: #{tokens.get($_, "color--secondary")}; | |
| --#{$_}--color-hover-background: #{tokens.get($_, "color--alpha-border")}; | |
| --#{$_}--color-hover-overlay: #{tokens.get($_, "color--alpha-border")}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new CSS custom properties assign Sass function calls (tokens.use) without interpolation. To ensure Sass evaluates the tokens.* calls rather than outputting them literally, interpolate the values when setting --c-acceptance--shadow and --c-acceptance--shadow-hover.