@carbon/themes 12.0.0-alpha.1 → 12.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/es/index.js +5572 -0
  2. package/lib/__tests__/themes-test.d.ts +1 -0
  3. package/lib/__tests__/tools-test.d.ts +1 -0
  4. package/lib/tokens/__tests__/Token-test.d.ts +1 -0
  5. package/lib/tokens/__tests__/TokenFormat-test.d.ts +1 -0
  6. package/lib/tokens/__tests__/TokenGroup-test.d.ts +1 -0
  7. package/lib/tokens/__tests__/TokenSet-test.d.ts +1 -0
  8. package/lib/tokens/__tests__/metadata-test.d.ts +1 -0
  9. package/lib/tokens/__tests__/v11-test.d.ts +1 -0
  10. package/lib/v10/__tests__/themes-test.d.ts +1 -0
  11. package/lib/v10/__tests__/tokens-test.d.ts +1 -0
  12. package/package.json +12 -4
  13. package/umd/index.js +6322 -0
  14. package/docs/sass.md +0 -189
  15. package/js/generated/component-tokens/button.d.ts +0 -98
  16. package/js/generated/component-tokens/button.js +0 -98
  17. package/js/generated/component-tokens/content-switcher.d.ts +0 -25
  18. package/js/generated/component-tokens/content-switcher.js +0 -25
  19. package/js/generated/component-tokens/notification.d.ts +0 -65
  20. package/js/generated/component-tokens/notification.js +0 -65
  21. package/js/generated/component-tokens/status.d.ts +0 -63
  22. package/js/generated/component-tokens/status.js +0 -63
  23. package/js/generated/component-tokens/tag.d.ts +0 -247
  24. package/js/generated/component-tokens/tag.js +0 -247
  25. package/js/generated/themes/g10.d.ts +0 -242
  26. package/js/generated/themes/g10.js +0 -242
  27. package/js/generated/themes/g100.d.ts +0 -242
  28. package/js/generated/themes/g100.js +0 -242
  29. package/js/generated/themes/g90.d.ts +0 -242
  30. package/js/generated/themes/g90.js +0 -242
  31. package/js/generated/themes/white.d.ts +0 -242
  32. package/js/generated/themes/white.js +0 -242
  33. package/src/dtcg/README.md +0 -336
  34. package/src/dtcg/color-palette.json +0 -4424
  35. package/src/dtcg/components/button.json +0 -193
  36. package/src/dtcg/components/content-switcher.json +0 -60
  37. package/src/dtcg/components/notification.json +0 -130
  38. package/src/dtcg/components/status.json +0 -122
  39. package/src/dtcg/components/tag.json +0 -486
  40. package/src/dtcg/themes.json +0 -3356
  41. package/src/index.ts +0 -129
  42. package/src/tokens/Token.ts +0 -41
  43. package/src/tokens/TokenFormat.ts +0 -93
  44. package/src/tokens/TokenGroup.ts +0 -185
  45. package/src/tokens/TokenSet.ts +0 -91
  46. package/src/tokens/components.ts +0 -120
  47. package/src/tokens/index.ts +0 -59
  48. package/src/tokens/layout.ts +0 -39
  49. package/src/tokens/type.ts +0 -49
  50. package/src/tokens/types.ts +0 -28
  51. package/src/tokens/v10.ts +0 -188
  52. package/src/tokens/v11TokenGroup.ts +0 -546
  53. package/src/tokens/v11TokenSet.ts +0 -93
  54. package/src/tools.ts +0 -69
  55. package/src/v10/g10.ts +0 -349
  56. package/src/v10/g100.ts +0 -348
  57. package/src/v10/g90.ts +0 -350
  58. package/src/v10/index.ts +0 -22
  59. package/src/v10/metadata.yml +0 -217
  60. package/src/v10/tokens.ts +0 -397
  61. package/src/v10/white.ts +0 -352
  62. package/style-dictionary/formats/js-component-tokens.js +0 -128
  63. package/style-dictionary/formats/js-themes.js +0 -84
  64. package/style-dictionary/formats/scss-component-tokens.js +0 -149
  65. package/style-dictionary/formats/scss-themes.js +0 -127
  66. package/style-dictionary/formats/scss-tokens.js +0 -91
  67. package/style-dictionary/preprocessors/component-tokens.js +0 -172
  68. package/style-dictionary/preprocessors/dual-role.js +0 -157
  69. package/style-dictionary/preprocessors/theme-metadata.js +0 -46
  70. package/style-dictionary/sd.config.js +0 -449
  71. package/style-dictionary/transforms/alpha-modifier.js +0 -68
  72. package/style-dictionary/transforms/color-flatten.js +0 -79
  73. package/test-dtcg.scss +0 -28
  74. package/tsconfig.json +0 -8
  75. package/tsconfig.types.json +0 -10
@@ -1,336 +0,0 @@
1
- # Carbon Design Tokens (DTCG Format)
2
-
3
- This directory contains Carbon Design System tokens in the
4
- [Design Tokens Community Group (DTCG)](https://tr.designtokens.org/format/)
5
- format. All Carbon themes and component tokens have been migrated to this
6
- industry-standard format.
7
-
8
- ## Structure
9
-
10
- ```
11
- dtcg/
12
- ├── themes.json # All four themes in one file (white, g10, g90, g100)
13
- ├── color-palette.json # Color palette aliases (generated from @carbon/colors)
14
- └── components/
15
- ├── button.json # Button component tokens
16
- ├── tag.json # Tag component tokens
17
- ├── notification.json # Notification component tokens
18
- ├── status.json # Status indicator tokens
19
- └── content-switcher.json # Content switcher tokens
20
- ```
21
-
22
- ## Token categories in each theme file
23
-
24
- `themes.json` is organised into top-level groups. When searching for a token,
25
- start with the group that matches the first segment of its name:
26
-
27
- | Top-level key | Token name prefix examples |
28
- | ------------- | ----------------------------------------------------------- |
29
- | `ai` | `ai-aura-*`, `ai-popover-*`, `ai-skeleton-*` |
30
- | `background` | `background`, `background-active`, `background-hover` |
31
- | `border` | `border-subtle-*`, `border-strong-*`, `border-tile-*` |
32
- | `button` | _(component tokens — see `components/button.json` instead)_ |
33
- | `field` | `field-01`, `field-02`, `field-hover-01` |
34
- | `focus` | `focus`, `focus-inset`, `focus-inverse` |
35
- | `icon` | `icon-primary`, `icon-on-color`, `icon-disabled` |
36
- | `layer` | `layer-01`, `layer-active-01`, `layer-hover-01` |
37
- | `link` | `link-primary`, `link-visited`, `link-inverse` |
38
- | `overlay` | `overlay` |
39
- | `skeleton` | `skeleton-background`, `skeleton-element` |
40
- | `support` | `support-error`, `support-warning`, `support-success` |
41
- | `text` | `text-primary`, `text-on-color`, `text-disabled` |
42
-
43
- > **Note:** Component tokens (`button`, `tag`, etc.) live in
44
- > `components/<name>.json`, **not** in `themes.json`.
45
-
46
- ## Nested key → flat token name mapping
47
-
48
- Token names in Carbon use a hyphenated convention (e.g. `border-subtle-02`,
49
- `text-on-color-disabled`). In the DTCG JSON files these are represented as
50
- **nested objects**, where each hyphen-separated segment becomes a JSON key
51
- level:
52
-
53
- | Flat token name | JSON path |
54
- | ------------------------ | ------------------------------------ |
55
- | `border-subtle-02` | `border` → `subtle` → `02` |
56
- | `text-on-color-disabled` | `text` → `on-color` → `disabled` |
57
- | `layer-accent-active-03` | `layer` → `accent` → `active` → `03` |
58
-
59
- > **Tip for agents:** Do not `grep` for the full hyphenated name — it will not
60
- > match. Instead grep for the last segment (`"02"`, `"disabled"`) and navigate
61
- > up the JSON hierarchy to confirm the full path, or read the surrounding
62
- > context to resolve ambiguity when short keys like `"01"` or `"02"` appear in
63
- > multiple token groups.
64
-
65
- ## Contextual layer tokens (`$layer-*` without numbers)
66
-
67
- In component styles (e.g. `$layer-accent`, `$layer-hover`, `$field`,
68
- `$border-subtle`), you will often see unnumbered tokens used. These are
69
- **dynamic layer-set tokens** defined in
70
- `packages/styles/scss/layer/_layer-sets.scss`.
71
-
72
- In DTCG JSON, tokens only exist as explicit numbered levels (`01`, `02`, `03`):
73
-
74
- - `layer.01` / `layer.02` / `layer.03`
75
- - `layer.accent.01` / `layer.accent.02` / `layer.accent.03`
76
- - `layer.accent.active.01` / `layer.accent.active.02` / `layer.accent.active.03`
77
-
78
- At runtime or inside a `<Layer>` component context, Carbon automatically
79
- resolves the unnumbered token (e.g. `$layer-accent`) to its corresponding
80
- numbered tier (`01`, `02`, or `03`) based on container nesting depth.
81
-
82
- ## Dual-role nodes (tokens that are also groups)
83
-
84
- Some tokens are simultaneously a value **and** a group of related tokens. For
85
- example, `background` has its own per-theme value but also has children like
86
- `background-active` and `background-hover`. In `themes.json` these look like:
87
-
88
- ```json
89
- "background": {
90
- "$type": "color",
91
- "$description": "…",
92
- "$extensions": {
93
- "carbon.themes": {
94
- "white": "{white.default}", "g10": "{gray.10}",
95
- "g90": "{gray.90}", "g100": "{gray.100}"
96
- }
97
- },
98
- "active": {
99
- "$type": "color",
100
- "$extensions": { "carbon.themes": { "white": { "value": "{gray.50}", "alpha": 0.5 }, … } }
101
- },
102
- "hover": {
103
- "$type": "color",
104
- "$extensions": { "carbon.themes": { "white": { "value": "{gray.50}", "alpha": 0.12 }, … } }
105
- }
106
- }
107
- ```
108
-
109
- The flat names generated are `background`, `background-active`,
110
- `background-hover` — all siblings in the output even though they are
111
- parent/child in the source JSON.
112
-
113
- > **Tip for agents:** If you read a node and it has both a
114
- > `$extensions["carbon.themes"]` entry and non-`$` children, both the node
115
- > itself **and** every child are valid tokens. Do not assume a node with
116
- > children is only a group.
117
-
118
- ## `carbon.themes` value aliases and `color-palette.json`
119
-
120
- The `value` field inside each `carbon.themes` entry uses curly-brace alias
121
- syntax referencing the color palette, e.g. `"{blue.60}"` or `"{gray.20}"`. These
122
- references are resolved during the build against
123
- `packages/themes/src/dtcg/color-palette.json`, which contains the full Carbon
124
- color ramp (`gray.10` … `gray.100`, `blue.10` … `blue.100`, etc.) with their hex
125
- values. If you need the actual hex for an alias, look it up in that file.
126
-
127
- ## Token Format
128
-
129
- All tokens follow the DTCG specification with a structured format using specific
130
- keys:
131
-
132
- ### DTCG Format Keys
133
-
134
- #### Required Keys
135
-
136
- - **`$schema`** - References the DTCG specification version. Always set to
137
- `"https://tr.designtokens.org/format/"` at the root level.
138
-
139
- - **`$type`** - Defines the token type (e.g., `"color"`, `"dimension"`,
140
- `"fontFamily"`). This enables proper validation and tooling support.
141
-
142
- - **`$value`** - The actual token value. Can be:
143
-
144
- - A reference to another token: `"{blue.60}"`, `"{gray.80}"`
145
- - References use curly brace syntax and resolve during build
146
-
147
- - **`$description`** - Human-readable description explaining the token's purpose
148
- and usage. Should be clear and actionable for designers and developers.
149
-
150
- #### Optional Keys
151
-
152
- - **`$extensions`** - Custom metadata and vendor-specific information. Carbon
153
- uses two namespaces — see the dedicated sections below for full details.
154
-
155
- ## Semi-transparent tokens — the `alpha` field
156
-
157
- Some tokens are a base color with an opacity applied. In `themes.json` the
158
- opacity is expressed as an `alpha` field co-located with `value` inside the
159
- per-theme entry:
160
-
161
- ```json
162
- "background": {
163
- "hover": {
164
- "$type": "color",
165
- "$description": "Background color for hover state.",
166
- "$extensions": {
167
- "carbon.themes": {
168
- "white": { "value": "{gray.50}", "alpha": 0.12 },
169
- "g10": { "value": "{gray.50}", "alpha": 0.12 },
170
- "g90": { "value": "{gray.50}", "alpha": 0.16 },
171
- "g100": { "value": "{gray.50}", "alpha": 0.16 }
172
- }
173
- }
174
- }
175
- }
176
- ```
177
-
178
- During the build the `carbon/alpha-modifier` Style Dictionary transform resolves
179
- `{gray.50}` to its hex (`#8d8d8d`) and then emits `rgba(141, 141, 141, 0.12)`.
180
-
181
- > **Reading the source:** When a `carbon.themes` entry is an object, the `value`
182
- > field alone does **not** tell you the final color. The real output is
183
- > `rgba(<palette hex at value>, <alpha>)`. Check `color-palette.json` for the
184
- > hex, then apply `alpha` mentally.
185
-
186
- > **`alpha: 0`** means fully transparent (`rgba(…, 0)`). Used for gradient "fade
187
- > to transparent" endpoints (e.g. `ai-aura-end`).
188
-
189
- > **Note for component token files:** `components/*.json` still use the legacy
190
- > `$extensions["org.carbon"].alphaModifiers` map (plural, keyed by theme) rather
191
- > than the co-located `alpha` field. The build preprocessor accepts both forms.
192
-
193
- ## `$extensions["carbon.themes"]` — the unified per-theme format
194
-
195
- Both theme tokens (`themes.json`) and component tokens (`components/*.json`)
196
- store per-theme values under the same `$extensions["carbon.themes"]` key. Each
197
- entry for a theme is either:
198
-
199
- - **A bare string** (palette alias or hex) when there is no alpha modifier:
200
- ```json
201
- "white": "{gray.10}"
202
- ```
203
- - **An object `{ value, alpha }`** when an opacity modifier is needed:
204
- ```json
205
- "white": { "value": "{gray.50}", "alpha": 0.12 }
206
- ```
207
-
208
- Example token from `themes.json`:
209
-
210
- ```json
211
- "background": {
212
- "hover": {
213
- "$type": "color",
214
- "$description": "Background color for hover state.",
215
- "$extensions": {
216
- "carbon.themes": {
217
- "white": { "value": "{gray.50}", "alpha": 0.12 },
218
- "g10": { "value": "{gray.50}", "alpha": 0.12 },
219
- "g90": { "value": "{gray.50}", "alpha": 0.16 },
220
- "g100": { "value": "{gray.50}", "alpha": 0.16 }
221
- }
222
- }
223
- }
224
- }
225
- ```
226
-
227
- The `carbon/component-tokens` preprocessor understands both entry shapes and
228
- expands them into per-theme leaf tokens before Style Dictionary processes them.
229
-
230
- ### Comparison: theme tokens vs. component tokens
231
-
232
- | | Theme token (`themes.json`) | Component token (`components/button.json`) |
233
- | ------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------- |
234
- | File scope | All four themes | All four themes |
235
- | Value field | `$extensions["carbon.themes"]["<theme>"]` (string or `{value,alpha}`) | `$extensions["carbon.themes"]["<theme>"]` (string) |
236
- | Alpha opacity | Co-located: `{ "value": "…", "alpha": 0.12 }` | Separate: `$extensions["org.carbon"].alphaModifiers.<theme>` (note plural) |
237
- | Grepping | Navigate nested keys | Same nesting rules apply |
238
-
239
- > **Note:** Component files still use the legacy `org.carbon.alphaModifiers` map
240
- > for backwards compatibility. Both forms are accepted by the preprocessor.
241
-
242
- > **Reading theme token values:** Navigate to the nested key in `themes.json`,
243
- > then read the value for the theme you care about from `carbon.themes`.
244
-
245
- ## Theme Tokens
246
-
247
- All four Carbon themes are consolidated into `themes.json`:
248
-
249
- - **white** — Light theme, high contrast for optimal readability
250
- - **g10** — Gray 10 light theme, subtle contrast for data-dense interfaces
251
- - **g90** — Gray 90 dark theme
252
- - **g100** — Gray 100 dark theme, high contrast
253
-
254
- The file contains 250+ tokens organised into categories:
255
-
256
- - **Color tokens**: Background, layer, field, border, text, link, icon, support
257
- colors
258
- - **Semantic tokens**: Focus, interactive, highlight, overlay, skeleton
259
- - **AI tokens**: AI-specific colors for popover, chat, and skeleton states
260
-
261
- ## Using These Tokens
262
-
263
- ### Build Process
264
-
265
- The DTCG tokens are automatically processed during the build:
266
-
267
- ```bash
268
- cd packages/themes
269
- yarn build
270
- ```
271
-
272
- This generates SCSS files in `scss/generated/`:
273
-
274
- - `_themes.scss` - All four theme token maps
275
- - `_button-tokens.scss` - Button component tokens
276
- - `_tag-tokens.scss` - Tag component tokens
277
- - `_notification-tokens.scss` - Notification component tokens
278
- - `_status-tokens.scss` - Status indicator tokens
279
- - `_content-switcher-tokens.scss` - Content switcher tokens
280
-
281
- These generated files are automatically forwarded by:
282
-
283
- - `scss/_themes.scss` - Forwards theme tokens
284
- - `scss/_component-tokens.scss` - Forwards component tokens
285
-
286
- ## Validation
287
-
288
- All DTCG token files are validated against the official DTCG JSON Schema during
289
- the build process. The validation ensures:
290
-
291
- - Correct `$schema` reference
292
- - Valid `$type` values (color, dimension, etc.)
293
- - Proper token structure
294
- - Required fields are present
295
-
296
- Manual validation can be performed using any JSON Schema validator:
297
-
298
- ```bash
299
- # Using ajv-cli
300
- ajv validate -s https://tr.designtokens.org/format/schema.json -d themes.json
301
- ```
302
-
303
- ## Contributing
304
-
305
- When adding or modifying tokens:
306
-
307
- 1. **Follow the DTCG specification** - Ensure all tokens conform to the official
308
- spec
309
- 2. **Include meaningful descriptions** - Every token should have a clear
310
- `$description`
311
- 3. **Use appropriate types** - Set correct `$type` values (color, dimension,
312
- etc.)
313
- 4. **Add theme-specific values** - Edit `themes.json` for theme tokens; use
314
- `$extensions["carbon.themes"]` in `components/<name>.json` for component
315
- tokens
316
- 5. **Validate your changes** - Run `yarn build` to validate against DTCG schema
317
- 6. **Test generated output** - Verify SCSS generation works correctly
318
- 7. **Update documentation** - Update this README if adding new token categories
319
- or components
320
-
321
- ### Adding a New Component Token File
322
-
323
- 1. Create `src/dtcg/components/your-component.json`
324
- 2. Follow the structure of existing component token files
325
- 3. Use `$extensions.carbon.themes` for theme-specific values
326
- 4. Add the component to the build process in `tasks/build.js`
327
- 5. Update this README to document the new component tokens
328
-
329
- ## Resources
330
-
331
- - [DTCG Specification](https://tr.designtokens.org/format/) - Official Design
332
- Tokens Community Group format specification
333
- - [DTCG JSON Schema](https://tr.designtokens.org/format/schema.json) - JSON
334
- Schema for validation
335
- - [Design Tokens Community Group](https://www.w3.org/community/design-tokens/) -
336
- W3C Community Group