@kong/design-tokens 2.0.0 → 2.0.1-pr.666.034b8ef.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.
- package/README.md +205 -21
- package/dist/themeable-tokens.cjs +918 -0
- package/dist/themeable-tokens.d.ts +926 -0
- package/dist/themeable-tokens.mjs +921 -0
- package/dist/themes/brand-a.css +169 -0
- package/dist/themes/brand-a.d.ts +5 -0
- package/dist/themes/brand-a.mjs +167 -0
- package/dist/themes/brand-b.css +161 -0
- package/dist/themes/brand-b.d.ts +5 -0
- package/dist/themes/brand-b.mjs +159 -0
- package/dist/themes/classic.css +340 -0
- package/dist/themes/classic.d.ts +5 -0
- package/dist/themes/classic.mjs +338 -0
- package/dist/themes/index.d.ts +9 -0
- package/dist/themes/index.mjs +9 -0
- package/dist/themes/konnect-day.css +918 -0
- package/dist/themes/konnect-day.d.ts +5 -0
- package/dist/themes/konnect-day.mjs +916 -0
- package/dist/themes/konnect-night.css +918 -0
- package/dist/themes/konnect-night.d.ts +5 -0
- package/dist/themes/konnect-night.mjs +916 -0
- package/dist/tokens/css/custom-properties.css +1 -1
- package/dist/tokens/js/cjs/index.d.ts +1 -1
- package/dist/tokens/js/cjs/index.js +1 -1
- package/dist/tokens/js/index.d.ts +1 -1
- package/dist/tokens/js/index.mjs +1 -1
- package/dist/tokens/less/variables.less +1 -1
- package/dist/tokens/scss/_map.scss +1 -1
- package/dist/tokens/scss/_variables.scss +1 -1
- package/package.json +52 -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,87 @@ 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
|
-
##
|
|
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
|
+
- **Domain tokens** (`tokens/source/domain/`) — `--kui-method-*`, `--kui-status-*`, `--kui-navigation-*`, `--kui-icon-*`. Named after a cross-cutting UI concept (HTTP methods, status codes, navigation chrome). 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
|
-
|
|
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-light">
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// Load the theme CSS — webpack/Vite will bundle it
|
|
87
|
+
import '@kong/design-tokens/themes/konnect-light.css'
|
|
88
|
+
|
|
89
|
+
// Switch the active theme at runtime
|
|
90
|
+
document.documentElement.setAttribute('data-kui-theme', 'konnect-dark')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Available themes: `konnect-light`, `konnect-dark`, `brand-a`, `brand-b`.
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
To respond to the system dark-mode preference, listen to the `prefers-color-scheme` media query in JS:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const mq = window.matchMedia('(prefers-color-scheme: dark)')
|
|
101
|
+
const applyColorScheme = (dark: boolean) =>
|
|
102
|
+
document.documentElement.setAttribute('data-kui-theme', dark ? 'konnect-dark' : 'konnect-light')
|
|
103
|
+
|
|
104
|
+
applyColorScheme(mq.matches)
|
|
105
|
+
mq.addEventListener('change', e => applyColorScheme(e.matches))
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
You can also import the theme objects as JavaScript for runtime composition or for use with Kongponents' `applyTheme` / `defineKongponentsTheme`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { konnectDay, konnectNight, brandA, brandB } from '@kong/design-tokens/themes'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Tokens
|
|
28
115
|
|
|
29
116
|
[View the lists of available tokens here](TOKENS.md), or keep reading for more information.
|
|
30
117
|
|
|
@@ -249,6 +336,55 @@ Typically, a host application should only utilize the SCSS and/or JavaScript var
|
|
|
249
336
|
</style>
|
|
250
337
|
```
|
|
251
338
|
|
|
339
|
+
#### Kongponents
|
|
340
|
+
|
|
341
|
+
[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`:
|
|
342
|
+
|
|
343
|
+
```ts
|
|
344
|
+
// my-app-theme.ts
|
|
345
|
+
import { konnectDay } from '@kong/design-tokens/themes'
|
|
346
|
+
import { defineKongponentsTheme } from '@kong/kongponents'
|
|
347
|
+
|
|
348
|
+
export const myTheme = defineKongponentsTheme({
|
|
349
|
+
...konnectDay, // spread the base theme
|
|
350
|
+
'--kui-button-border-radius-medium': '999px', // then override specific tokens
|
|
351
|
+
})
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Register the theme at app startup via the Kongponents plugin:
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
// main.ts
|
|
358
|
+
import { createApp } from 'vue'
|
|
359
|
+
import Kongponents from '@kong/kongponents'
|
|
360
|
+
import { myTheme } from './my-app-theme'
|
|
361
|
+
import App from './App.vue'
|
|
362
|
+
|
|
363
|
+
createApp(App)
|
|
364
|
+
.use(Kongponents, { theme: myTheme })
|
|
365
|
+
.mount('#app')
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Or apply a theme to a specific subtree at runtime using `KThemeProvider`:
|
|
369
|
+
|
|
370
|
+
```vue
|
|
371
|
+
<template>
|
|
372
|
+
<KThemeProvider :theme="myTheme">
|
|
373
|
+
<!-- everything here renders with myTheme active -->
|
|
374
|
+
</KThemeProvider>
|
|
375
|
+
</template>
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
For per-tenant runtime composition (e.g. theme values fetched from an API), use `applyTheme` from `@kong/kongponents`:
|
|
379
|
+
|
|
380
|
+
```ts
|
|
381
|
+
import { applyTheme } from '@kong/kongponents'
|
|
382
|
+
import { konnectDay } from '@kong/design-tokens/themes'
|
|
383
|
+
|
|
384
|
+
// Merge the base theme with tenant-specific overrides, then apply to :root
|
|
385
|
+
applyTheme({ ...konnectDay, ...tenantOverrides })
|
|
386
|
+
```
|
|
387
|
+
|
|
252
388
|
#### Server-Side Rendering (SSR)
|
|
253
389
|
|
|
254
390
|
If your host application utilizes SSR, you may need to resolve aliases to the package exports.
|
|
@@ -276,22 +412,26 @@ To get started, install the package dependencies from the repo root:
|
|
|
276
412
|
pnpm install
|
|
277
413
|
```
|
|
278
414
|
|
|
279
|
-
###
|
|
415
|
+
### Directory structure
|
|
280
416
|
|
|
281
|
-
|
|
417
|
+
The package is organized around four top-level source directories:
|
|
282
418
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
419
|
+
| Directory | Purpose |
|
|
420
|
+
|-----------|---------|
|
|
421
|
+
| `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. |
|
|
422
|
+
| `tokens/source/` | **Semantic tokens** — scale and domain tokens that are exported to `custom-properties.css`, SCSS, LESS, and JS. Subdirectories: `color/`, `space/`, `shadow/`, `font/`, `border/`, `animation/`, `breakpoint/`, `letter-spacing/`, `line-height/`, plus `domain/` for HTTP-method, status, navigation, and icon token families. |
|
|
423
|
+
| `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. |
|
|
424
|
+
| `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. |
|
|
425
|
+
|
|
426
|
+
### Token Requirements
|
|
287
427
|
|
|
288
428
|
- 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
|
-
-
|
|
293
|
-
- Token aliases (e.g. color aliases) **must not** be exposed/exported from the package exports
|
|
429
|
+
- The `category` of each token should be its own directory (e.g. `tokens/source/color/`)
|
|
430
|
+
- Each `type` of token should be a file in the `category` directory, named `{type}.json` (e.g. `tokens/source/color/background.json`)
|
|
431
|
+
- 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`)
|
|
432
|
+
- Alias tokens (`tokens/alias/`) **must not** be exposed/exported from the package exports
|
|
294
433
|
- Tokens at the "root" of their structure **must** be defined with a key of `"_"` to allow for nested child tokens.
|
|
434
|
+
- 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
435
|
|
|
296
436
|
<details>
|
|
297
437
|
|
|
@@ -302,17 +442,17 @@ pnpm install
|
|
|
302
442
|
"color": {
|
|
303
443
|
"text": {
|
|
304
444
|
"_": {
|
|
305
|
-
"
|
|
306
|
-
"value": "{color.alias.blue.100}"
|
|
445
|
+
"$description": "Default text color.",
|
|
446
|
+
"$value": "{color.alias.blue.100}"
|
|
307
447
|
},
|
|
308
448
|
"neutral": {
|
|
309
449
|
"_": {
|
|
310
|
-
"
|
|
311
|
-
"value": "{color.alias.gray.60}"
|
|
450
|
+
"$description": "Neutral text color.",
|
|
451
|
+
"$value": "{color.alias.gray.60}"
|
|
312
452
|
},
|
|
313
453
|
"strong": {
|
|
314
|
-
"
|
|
315
|
-
"value": "{color.alias.gray.70}"
|
|
454
|
+
"$description": "Strong neutral text color.",
|
|
455
|
+
"$value": "{color.alias.gray.70}"
|
|
316
456
|
}
|
|
317
457
|
}
|
|
318
458
|
}
|
|
@@ -329,6 +469,50 @@ pnpm install
|
|
|
329
469
|
|
|
330
470
|
</details>
|
|
331
471
|
|
|
472
|
+
### Creating a new theme
|
|
473
|
+
|
|
474
|
+
Use the `create-theme` script to scaffold a new theme file from the current `KUI_THEMEABLE_TOKENS` list. The script reads the built `dist/themeable-tokens.mjs` to get the canonical token list, and sources `$description` text from the actual token metadata.
|
|
475
|
+
|
|
476
|
+
```sh
|
|
477
|
+
# Scaffold an empty theme (all $value fields are "")
|
|
478
|
+
pnpm create-theme my-brand
|
|
479
|
+
|
|
480
|
+
# Start from a copy of an existing theme's values
|
|
481
|
+
pnpm create-theme my-brand --from konnect-light
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
This creates `themes/my-brand.json`. The next build picks it up automatically — no code change is required.
|
|
485
|
+
|
|
486
|
+
> **Prerequisites:** Run `pnpm build` at least once before running `create-theme` so `dist/themeable-tokens.mjs` exists.
|
|
487
|
+
|
|
488
|
+
### Theme `$description` authoring rules
|
|
489
|
+
|
|
490
|
+
Every token entry in a theme JSON file may carry an optional `$description` field. When present, it must follow these rules:
|
|
491
|
+
|
|
492
|
+
- **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.
|
|
493
|
+
- **Never reference a CSS value** — descriptions must be value-agnostic. The description explains *what* the token controls, not *what value* it currently holds.
|
|
494
|
+
|
|
495
|
+
| ❌ Avoid | ✅ Use instead |
|
|
496
|
+
|---|---|
|
|
497
|
+
| `"2px border radius."` | _(omit — scale tokens are self-documenting by name)_ |
|
|
498
|
+
| `"Background color for containers (white)."` | `"Default background color for containers."` |
|
|
499
|
+
| `"Border color for danger actions or messages (red.60)."` | `"Border color for danger actions or messages."` |
|
|
500
|
+
| `"0px 0px 0px 1px blue.60 inset"` | `"Primary state inset border shadow."` |
|
|
501
|
+
|
|
502
|
+
**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.
|
|
503
|
+
|
|
504
|
+
**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/`.
|
|
505
|
+
|
|
506
|
+
```json
|
|
507
|
+
// ✅ Correct — description matches source definition
|
|
508
|
+
"kui-button-border-radius-medium": {
|
|
509
|
+
"$description": "Medium button border radius.",
|
|
510
|
+
"$value": "999px"
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**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.
|
|
515
|
+
|
|
332
516
|
### Development Sandbox
|
|
333
517
|
|
|
334
518
|
This package includes a Vue sandbox (see the `sandbox/` directory) to allow you to experiment with consuming tokens.
|
|
@@ -345,7 +529,7 @@ Or from within this package directory:
|
|
|
345
529
|
pnpm sandbox
|
|
346
530
|
```
|
|
347
531
|
|
|
348
|
-
This command
|
|
532
|
+
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
533
|
|
|
350
534
|
Updating any files within the sandbox itself will also trigger hot module reload as expected.
|
|
351
535
|
|
|
@@ -399,7 +583,7 @@ For example, if I want to add a new `my-feature` folder, I'd update the `exports
|
|
|
399
583
|
|
|
400
584
|
1. Ensure you are on the `main` branch, then pull down the latest code by running `git checkout main && git pull origin main`
|
|
401
585
|
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 `
|
|
586
|
+
3. Add/edit the tokens in the `tokens/` or `themes/` directory as needed, ensuring to adhere to the [Token Requirements](#token-requirements)
|
|
403
587
|
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
588
|
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
589
|
6. Push your branch up to the remote with `git push origin {branch-name}`
|