@kong/design-tokens 2.0.1 → 2.0.2-pr.666.30b36ba.0

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 (41) hide show
  1. package/README.md +217 -21
  2. package/TOKENS.md +893 -893
  3. package/dist/themeable-tokens.cjs +921 -0
  4. package/dist/themeable-tokens.d.ts +929 -0
  5. package/dist/themeable-tokens.mjs +924 -0
  6. package/dist/themes/brand-a.css +169 -0
  7. package/dist/themes/brand-a.d.ts +5 -0
  8. package/dist/themes/brand-a.mjs +167 -0
  9. package/dist/themes/brand-b.css +161 -0
  10. package/dist/themes/brand-b.d.ts +5 -0
  11. package/dist/themes/brand-b.mjs +159 -0
  12. package/dist/themes/classic-day.css +340 -0
  13. package/dist/themes/classic-day.d.ts +5 -0
  14. package/dist/themes/classic-day.mjs +338 -0
  15. package/dist/themes/classic-night.css +340 -0
  16. package/dist/themes/classic-night.d.ts +5 -0
  17. package/dist/themes/classic-night.mjs +338 -0
  18. package/dist/themes/index.d.ts +11 -0
  19. package/dist/themes/index.mjs +11 -0
  20. package/dist/themes/konnect-day.css +921 -0
  21. package/dist/themes/konnect-day.d.ts +5 -0
  22. package/dist/themes/konnect-day.mjs +919 -0
  23. package/dist/themes/konnect-night.css +921 -0
  24. package/dist/themes/konnect-night.d.ts +5 -0
  25. package/dist/themes/konnect-night.mjs +919 -0
  26. package/dist/themes/paper.css +368 -0
  27. package/dist/themes/paper.d.ts +5 -0
  28. package/dist/themes/paper.mjs +366 -0
  29. package/dist/tokens/README.md +893 -893
  30. package/dist/tokens/css/custom-properties-list.css +155 -155
  31. package/dist/tokens/css/custom-properties.css +96 -96
  32. package/dist/tokens/js/cjs/index.d.ts +85 -85
  33. package/dist/tokens/js/cjs/index.js +96 -96
  34. package/dist/tokens/js/index.d.ts +146 -146
  35. package/dist/tokens/js/index.mjs +97 -97
  36. package/dist/tokens/js/tokens.json +96 -96
  37. package/dist/tokens/less/variables.less +96 -96
  38. package/dist/tokens/scss/_map.scss +97 -97
  39. package/dist/tokens/scss/_mixins.scss +60 -60
  40. package/dist/tokens/scss/_variables.scss +96 -96
  41. package/package.json +51 -20
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Kong Design Tokens for Konnect, via [Style Dictionary](https://github.com/amzn/style-dictionary).
4
4
 
5
+ - [Token Tiers](#token-tiers)
6
+ - [Semantic tokens](#semantic-tokens)
7
+ - [Component tokens — names only, value-less](#component-tokens--names-only-value-less)
8
+ - [Themeable token list](#themeable-token-list)
9
+ - [Themes](#themes)
5
10
  - [Tokens](#tokens)
6
11
  - [Token Formats](#token-formats)
7
12
  - [SCSS](#scss)
@@ -12,8 +17,12 @@ Kong Design Tokens for Konnect, via [Style Dictionary](https://github.com/amzn/s
12
17
  - [Installation](#installation)
13
18
  - [Standalone components](#standalone-components)
14
19
  - [Host applications](#host-applications)
20
+ - [Kongponents](#kongponents)
15
21
  - [Updating Tokens & Local Development](#updating-tokens--local-development)
22
+ - [Directory structure](#directory-structure)
16
23
  - [Token Requirements](#token-requirements)
24
+ - [Creating a new theme](#creating-a-new-theme)
25
+ - [Theme `$description` authoring rules](#theme-description-authoring-rules)
17
26
  - [Development Sandbox](#development-sandbox)
18
27
  - [Lint and fix](#lint-and-fix)
19
28
  - [Build for production](#build-for-production)
@@ -22,9 +31,88 @@ Kong Design Tokens for Konnect, via [Style Dictionary](https://github.com/amzn/s
22
31
  - [Approvals](#approvals)
23
32
  - [Package Publishing](#package-publishing)
24
33
 
25
- ## Tokens
34
+ ## Token Tiers
35
+
36
+ The `@kong/design-tokens` package uses a two-tier exported token taxonomy.
37
+
38
+ | Tier | Source directory | Examples | Exported as |
39
+ |------|-----------------|----------|-------------|
40
+ | **Semantic** | `tokens/source/**` | `--kui-color-background-primary`, `--kui-space-40`, `--kui-border-radius-30`, `--kui-method-color-background-get` | CSS custom properties, SCSS/LESS variables, JS constants |
41
+ | **Component** | `tokens/components/**` | `--kui-button-border-radius-medium`, `--kui-button-color-background-primary`, `--kui-button-shadow-focus` | Included in `KUI_THEMEABLE_TOKENS` — **no CSS value** |
42
+
43
+ > **Alias tokens** (`tokens/alias/**`) form a third internal directory. They hold the raw palette values (hex colors, base sizes) that semantic tokens reference. They are **never exported** — they exist only so Style Dictionary can resolve `{color.alias.blue.100}` references at build time.
44
+
45
+ ### Semantic tokens
46
+
47
+ Everything in `tokens/source/` is a semantic token — it has a concrete value and is exported to all formats (CSS, SCSS, LESS, JS). This includes:
48
+
49
+ - **Scale tokens** — `--kui-color-*`, `--kui-space-*`, `--kui-border-radius-*`, `--kui-shadow-*`, `--kui-font-*`, etc. Named after the design dimension they represent.
50
+ - **Concept tokens** — `--kui-method-*`, `--kui-status-*`, `--kui-navigation-*`, `--kui-icon-*`. Named after a cross-cutting UI concept (HTTP methods, status codes, navigation chrome, icons) rather than a design dimension. Each family lives in its own folder under `tokens/source/` (`method/`, `status/`, `navigation/`, `icon/`), following the same pattern as the scale folders. They are plain semantic tokens, valued and exported exactly like scale tokens. **These are not component tokens** even though they're used inside components.
51
+
52
+ ### Component tokens — names only, value-less
53
+
54
+ Component tokens (`--kui-button-*`, `--kui-card-*`, `--kui-input-*`, `--kui-badge-*`, …) live in `tokens/components/` and are **declared without any CSS value** — they are purely override slots. Every Kongponents component uses them in a `var()` fallback chain:
55
+
56
+ ```scss
57
+ border-radius: var(--kui-button-border-radius-medium, var(--kui-border-radius-30, $kui-border-radius-30));
58
+ // ↑ component token (empty by default) ↑ semantic fallback ↑ SCSS literal
59
+ ```
60
+
61
+ When a theme writes `--kui-button-border-radius-medium: 999px`, only buttons go pill-shaped. Inputs and other components keep their semantic default. When no theme writes the token, `var()` falls through to the semantic default — **byte-identical to the un-themed render**.
62
+
63
+ ### Themeable token list
64
+
65
+ The `./themeable-tokens` subpath exports `KUI_THEMEABLE_TOKENS` — a typed `readonly` tuple of every `--kui-*` custom property name that a theme may meaningfully override. It combines both semantic tokens and value-less component tokens.
66
+
67
+ ```ts
68
+ import { KUI_THEMEABLE_TOKENS } from '@kong/design-tokens/themeable-tokens'
69
+
70
+ // Derive a union type of all valid theme keys:
71
+ type ThemeToken = typeof KUI_THEMEABLE_TOKENS[number]
72
+ ```
73
+
74
+ **Breakpoint tokens are intentionally excluded.** `--kui-breakpoint-*` tokens are available as CSS custom properties and SCSS variables, but they cannot be consumed inside CSS `@media` feature queries — that is, `@media (min-width: var(--kui-breakpoint-md))` is invalid CSS. Kongponents uses breakpoints exclusively in `@media` rules, so overriding them via a theme has no effect on responsive behavior. Set breakpoints at the SCSS level instead if your project needs custom breakpoint values.
75
+
76
+ ## Themes
26
77
 
27
- All design tokens **must** be placed inside of the `packages/design-tokens/tokens/` directory in one of two sub-directories.
78
+ Pre-built theme CSS files activate a complete set of token overrides via a `data-kui-theme` attribute on any element. Load a theme CSS file and then set the attribute on the root element (or any subtree element):
79
+
80
+ ```html
81
+ <!-- In your HTML template or equivalent -->
82
+ <html data-kui-theme="konnect-day">
83
+ ```
84
+
85
+ ```ts
86
+ // Load the theme CSS — webpack/Vite will bundle it
87
+ import '@kong/design-tokens/themes/konnect-day.css'
88
+
89
+ // Switch the active theme at runtime
90
+ document.documentElement.setAttribute('data-kui-theme', 'konnect-night')
91
+ ```
92
+
93
+ Available themes: `classic-day`, `classic-night`, `konnect-day`, `konnect-night`, `brand-a`, `brand-b`.
94
+ `classic-day` is the default look (identical to the unthemed `:root` exports); `classic-night` is its dark counterpart.
95
+
96
+ Each theme CSS file uses `@layer kui.theme { [data-kui-theme="name"] { ... } }`. This means customer `:root {}` overrides (which are **unlayered**) beat the theme automatically — no `!important` or special selectors needed.
97
+
98
+ To respond to the system dark-mode preference, listen to the `prefers-color-scheme` media query in JS:
99
+
100
+ ```ts
101
+ const mq = window.matchMedia('(prefers-color-scheme: dark)')
102
+ const applyColorScheme = (dark: boolean) =>
103
+ document.documentElement.setAttribute('data-kui-theme', dark ? 'konnect-night' : 'konnect-day')
104
+
105
+ applyColorScheme(mq.matches)
106
+ mq.addEventListener('change', e => applyColorScheme(e.matches))
107
+ ```
108
+
109
+ You can also import the theme objects as JavaScript for runtime composition or for use with Kongponents' `applyTheme` / `defineKongponentsTheme`:
110
+
111
+ ```ts
112
+ import { konnectDay, konnectNight, brandA, brandB } from '@kong/design-tokens/themes'
113
+ ```
114
+
115
+ ## Tokens
28
116
 
29
117
  [View the lists of available tokens here](TOKENS.md), or keep reading for more information.
30
118
 
@@ -249,6 +337,55 @@ Typically, a host application should only utilize the SCSS and/or JavaScript var
249
337
  </style>
250
338
  ```
251
339
 
340
+ #### Kongponents
341
+
342
+ [Kongponents](https://kongponents.konghq.com) ships its own `defineKongponentsTheme` helper that validates a theme object against the full typed token surface at authoring time. To use a pre-built design-tokens theme in Kongponents, wrap it with `defineKongponentsTheme`:
343
+
344
+ ```ts
345
+ // my-app-theme.ts
346
+ import { konnectDay } from '@kong/design-tokens/themes'
347
+ import { defineKongponentsTheme } from '@kong/kongponents'
348
+
349
+ export const myTheme = defineKongponentsTheme({
350
+ ...konnectDay, // spread the base theme
351
+ '--kui-button-border-radius-medium': '999px', // then override specific tokens
352
+ })
353
+ ```
354
+
355
+ Register the theme at app startup via the Kongponents plugin:
356
+
357
+ ```ts
358
+ // main.ts
359
+ import { createApp } from 'vue'
360
+ import Kongponents from '@kong/kongponents'
361
+ import { myTheme } from './my-app-theme'
362
+ import App from './App.vue'
363
+
364
+ createApp(App)
365
+ .use(Kongponents, { theme: myTheme })
366
+ .mount('#app')
367
+ ```
368
+
369
+ Or apply a theme to a specific subtree at runtime using `KThemeProvider`:
370
+
371
+ ```vue
372
+ <template>
373
+ <KThemeProvider :theme="myTheme">
374
+ <!-- everything here renders with myTheme active -->
375
+ </KThemeProvider>
376
+ </template>
377
+ ```
378
+
379
+ For per-tenant runtime composition (e.g. theme values fetched from an API), use `applyTheme` from `@kong/kongponents`:
380
+
381
+ ```ts
382
+ import { applyTheme } from '@kong/kongponents'
383
+ import { konnectDay } from '@kong/design-tokens/themes'
384
+
385
+ // Merge the base theme with tenant-specific overrides, then apply to :root
386
+ applyTheme({ ...konnectDay, ...tenantOverrides })
387
+ ```
388
+
252
389
  #### Server-Side Rendering (SSR)
253
390
 
254
391
  If your host application utilizes SSR, you may need to resolve aliases to the package exports.
@@ -276,22 +413,26 @@ To get started, install the package dependencies from the repo root:
276
413
  pnpm install
277
414
  ```
278
415
 
279
- ### Token Requirements
416
+ ### Directory structure
280
417
 
281
- - Tokens **must** be defined in the corresponding JSON files within the `packages/design-tokens/tokens/` directory in one of two sub-directories:
418
+ The package is organized around four top-level source directories:
282
419
 
283
- Directory | Description
284
- ---------|----------
285
- `/tokens/alias` | The `alias` directory **must** only contain alias values that point directly to a raw CSS value. Any tokens defined within the `alias` directory **will not** be exposed in the package exports. Tokens defined in the `/tokens/alias/` directory can be utilized/referenced within the `/tokens/source/` files; however, these tokens will **NOT** be exported in the build files.
286
- `/tokens/source` | The `source` directory contains all tokens that **will be** available for consumption from the package exports.
420
+ | Directory | Purpose |
421
+ |-----------|---------|
422
+ | `tokens/alias/` | **Internal alias palette** raw CSS values (hex colors, base sizes) that semantic tokens reference via `{color.alias.*}`. Never exported in any build output; only used so Style Dictionary can resolve references at build time. |
423
+ | `tokens/source/` | **Semantic tokens** exported to `custom-properties.css`, SCSS, LESS, and JS. Each token family is its own subdirectory: `color/`, `space/`, `shadow/`, `font/`, `border/`, `animation/`, `breakpoint/`, `letter-spacing/`, `line-height/`, plus the concept-named families `method/`, `status/`, `navigation/`, and `icon/` (HTTP methods, status codes, navigation chrome, icons). |
424
+ | `tokens/components/` | **Component tokens** — name-only override slots for Kongponents components (`button/`, `card/`, `input/`, `badge/`, …). All `$value` fields must be `""`. Included in `KUI_THEMEABLE_TOKENS` — no CSS, no SCSS/LESS/JS values emitted. |
425
+ | `themes/` | **Named theme override sets** — each `{name}.json` lists the token values that activate for `[data-kui-theme="{name}"]`. Values may be raw hex or `{color.alias.*}` references resolved at build time. |
426
+
427
+ ### Token Requirements
287
428
 
288
429
  - Token keys **must** be lowercase, snake_case, and defined in normal alphabetical order (rules enforced by the eslint config)
289
- - The `category` of each token should be its own directory (e.g. `tokens/color/`)
290
- - Each `type` of token should be a file in the `category` directory, named `{type}.json` (e.g. `tokens/color/background.json`)
291
- - If there is only a single `type` of token within a `category`, you **should** name the file `index.json` (e.g. `tokens/line-height/index.json`)
292
- - Component tokens **must** be defined within the `/tokens/source/components/` directory. All tokens for a component should be defined in a single JSON file, `{component-name}.json`, with the name of the component as the top-level property in the file.
293
- - Token aliases (e.g. color aliases) **must not** be exposed/exported from the package exports
430
+ - The `category` of each token should be its own directory (e.g. `tokens/source/color/`)
431
+ - Each `type` of token should be a file in the `category` directory, named `{type}.json` (e.g. `tokens/source/color/background.json`)
432
+ - If there is only a single `type` of token within a `category`, you **should** name the file `index.json` (e.g. `tokens/source/line-height/index.json`)
433
+ - Alias tokens (`tokens/alias/`) **must not** be exposed/exported from the package exports
294
434
  - Tokens at the "root" of their structure **must** be defined with a key of `"_"` to allow for nested child tokens.
435
+ - Component tokens in `tokens/components/` **must always have `$value: ""`** — they are name-only slots with no CSS value. A non-empty `$value` is a build violation caught by the test suite.
295
436
 
296
437
  <details>
297
438
 
@@ -302,17 +443,17 @@ pnpm install
302
443
  "color": {
303
444
  "text": {
304
445
  "_": {
305
- "comment": "blue-100",
306
- "value": "{color.alias.blue.100}"
446
+ "$description": "Default text color.",
447
+ "$value": "{color.alias.blue.100}"
307
448
  },
308
449
  "neutral": {
309
450
  "_": {
310
- "comment": "gray-100",
311
- "value": "{color.alias.gray.60}"
451
+ "$description": "Neutral text color.",
452
+ "$value": "{color.alias.gray.60}"
312
453
  },
313
454
  "strong": {
314
- "comment": "gray-70",
315
- "value": "{color.alias.gray.70}"
455
+ "$description": "Strong neutral text color.",
456
+ "$value": "{color.alias.gray.70}"
316
457
  }
317
458
  }
318
459
  }
@@ -329,6 +470,61 @@ pnpm install
329
470
 
330
471
  </details>
331
472
 
473
+ ### Creating a new theme
474
+
475
+ A new theme is made by **copying an existing one** of the same class — it already carries the full token
476
+ set, descriptions, and a valid, building starting point. Pick the closest existing theme:
477
+
478
+ - **Exhaustive** (every themeable token, incl. component tokens — like `konnect-day`/`konnect-night`).
479
+ - **Semantic-only** (every semantic token, **zero** component tokens — like `classic-day`/`classic-night`;
480
+ components fall through to their semantic defaults).
481
+
482
+ ```sh
483
+ NEW=my-brand
484
+ FROM=konnect-day # or classic-day for a semantic-only theme
485
+
486
+ # 1. Copy the theme definition and (for alias-based themes) its companion color palette.
487
+ cp themes/$FROM.json themes/$NEW.json
488
+ cp tokens/alias/color/$FROM.json tokens/alias/color/$NEW.json # every alias-using theme MUST have one
489
+
490
+ # 2. Edit themes/$NEW.json (token $values) and tokens/alias/color/$NEW.json (palette values) to taste.
491
+ # 3. Classify $NEW in themes.spec.mjs (EXHAUSTIVE_THEMES / SEMANTIC_ONLY_THEMES / UNCHECKED_THEMES).
492
+ # 4. Build + verify — the drift, classification, and off-source guards confirm completeness.
493
+ pnpm build:tokens && pnpm test
494
+ ```
495
+
496
+ The build auto-discovers any `themes/*.json` — no code change needed. An alias-referencing theme with no
497
+ matching `tokens/alias/color/<name>.json` palette is a hard build error (no silent fallback), which is why
498
+ step 1 copies the palette too. See [`ALIAS-COLOR-MAPPING-GUIDE.md`](./ALIAS-COLOR-MAPPING-GUIDE.md) §6, "Adding a future theme".
499
+
500
+ ### Theme `$description` authoring rules
501
+
502
+ Every token entry in a theme JSON file may carry an optional `$description` field. When present, it must follow these rules:
503
+
504
+ - **Match the semantic token's description** — copy the text from the corresponding token in `tokens/source/`. Do not invent a different description for the same concept.
505
+ - **Never reference a CSS value** — descriptions must be value-agnostic. The description explains *what* the token controls, not *what value* it currently holds.
506
+
507
+ | ❌ Avoid | ✅ Use instead |
508
+ |---|---|
509
+ | `"2px border radius."` | _(omit — scale tokens are self-documenting by name)_ |
510
+ | `"Background color for containers (white)."` | `"Default background color for containers."` |
511
+ | `"Border color for danger actions or messages (red.60)."` | `"Border color for danger actions or messages."` |
512
+ | `"0px 0px 0px 1px blue.60 inset"` | `"Primary state inset border shadow."` |
513
+
514
+ **When to omit `$description` entirely:** pure scale tokens (`--kui-space-*`, `--kui-border-radius-0` through `-50`, `--kui-border-width-*`, `--kui-icon-size-*`, `--kui-line-height-*`, `--kui-letter-spacing-*`) are self-documenting — their token names carry all the meaning. Leave `$description` off these entries.
515
+
516
+ **Component tokens may appear in theme files with `$description`.** A theme may set any component token (`--kui-button-*`, `--kui-card-*`, etc.) to provide per-component customization that diverges from the semantic fallback. Use the same description as the component token's source definition in `tokens/components/`.
517
+
518
+ ```json
519
+ // ✅ Correct — description matches source definition
520
+ "kui-button-border-radius-medium": {
521
+ "$description": "Medium button border radius.",
522
+ "$value": "999px"
523
+ }
524
+ ```
525
+
526
+ **A theme only needs to define tokens it overrides.** Omit any token whose value should remain at its semantic default (from `custom-properties.css`) or at whatever value a base theme already sets. The `[data-kui-theme]` CSS cascade handles the rest — unset tokens fall back through `var()` to the semantic layer automatically.
527
+
332
528
  ### Development Sandbox
333
529
 
334
530
  This package includes a Vue sandbox (see the `sandbox/` directory) to allow you to experiment with consuming tokens.
@@ -345,7 +541,7 @@ Or from within this package directory:
345
541
  pnpm sandbox
346
542
  ```
347
543
 
348
- This command will simultaneously start the Vite dev server and initialize a watcher on the `tokens/` directory. If any files in the `tokens/` directory are modified, the sandbox will automatically run the build command to update the tokens and then restart the Vite dev server (simulating hot module reload).
544
+ This command simultaneously starts the Vite dev server and watches both the `tokens/` and `themes/` directories. Changes to either trigger a rebuild and restart the Vite dev server.
349
545
 
350
546
  Updating any files within the sandbox itself will also trigger hot module reload as expected.
351
547
 
@@ -399,7 +595,7 @@ For example, if I want to add a new `my-feature` folder, I'd update the `exports
399
595
 
400
596
  1. Ensure you are on the `main` branch, then pull down the latest code by running `git checkout main && git pull origin main`
401
597
  2. Checkout a new branch for your changes with `git checkout -b {type}/{jira-ticket}-{description}` — as an example, `git checkout feat/khcp-1234-add-color-tokens`
402
- 3. Add/edit the tokens in the `packages/design-tokens/tokens/` directory as needed, ensuring to adhere to the [Token Requirements](#token-requirements)
598
+ 3. Add/edit the tokens in the `tokens/` or `themes/` directory as needed, ensuring to adhere to the [Token Requirements](#token-requirements)
403
599
  4. Before committing your changes, locally run `pnpm lint` to ensure you do not have any linting errors. If you have errors, you can try running `pnpm lint:fix` to resolve
404
600
  5. Commit your changes, adhering to [Conventional Commits](#committing-changes). To make this easier, you're encouraged to run `pnpm commit` from the repo root to help build your commit message
405
601
  6. Push your branch up to the remote with `git push origin {branch-name}`