@equinor/eds-tokens 1.1.2 → 1.1.3

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 CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  [Design tokens] used in the <abbr title="Equinor Design System">EDS</abbr>, including colors, spacing, typography, and more. These tokens are synchronized with Figma variables and provide a single source of truth for design decisions across the design system.
4
4
 
5
+
6
+ > For <abbr title="Large Language Model">LLM</abbr> instructions on using colors, see the [instructions/colors.md](./instructions/colors.md), or jump directly to the [static](./instructions/colors-static.md) or [dynamic](./instructions/colors-dynamic.md) instructions.
7
+
5
8
  ## Installation
6
9
 
7
10
  ```sh
@@ -91,6 +94,41 @@ const padding = comfortableSpacing.SPACING_INLINE_MD
91
94
  const borderRadius = comfortableSpacing.SPACING_BORDER_RADIUS_ROUNDED
92
95
  ```
93
96
 
97
+ ### Importing variables as JSON
98
+
99
+ The variables are available in two formats:
100
+
101
+ * **Flat format** (`/flat/`) -- Simple key-value pairs for easy access
102
+ * **Nested format** (`/nested/`) -- Hierarchical structure matching the token naming
103
+
104
+ * The semantic color tokens are available for light and dark color schemes.
105
+
106
+ * `light-semantic.json` / `dark-semantic.json` -- Semantic color tokens for each color scheme
107
+
108
+ #### Flat Format
109
+
110
+ ```typescript
111
+ // Import flat format tokens
112
+ import lightSemanticFlat from '@equinor/eds-tokens/json/color/color-scheme/flat/light-semantic.json'
113
+ import darkSemanticFlat from '@equinor/eds-tokens/json/color/color-scheme/flat/dark-semantic.json'
114
+
115
+ // Access values directly
116
+ const lightSurface = lightSemanticFlat['bg-neutral-surface'] // "#ffffff"
117
+ const darkSurface = darkSemanticFlat['bg-neutral-surface'] // "#262626"
118
+ ```
119
+
120
+ #### Nested Format
121
+
122
+ ```typescript
123
+ // Import nested format tokens
124
+ import lightSemanticNested from '@equinor/eds-tokens/json/color/color-scheme/nested/light-semantic.json'
125
+ import darkSemanticNested from '@equinor/eds-tokens/json/color/color-scheme/nested/dark-semantic.json'
126
+
127
+ // Access values via hierarchical structure
128
+ const lightSurface = lightSemanticNested.bg.neutral.surface // "#ffffff"
129
+ const darkSurface = darkSemanticNested.bg.neutral.surface // "#262626"
130
+ ```
131
+
94
132
  ### Available Token Categories
95
133
 
96
134
  * **Colors** -- Semantic color tokens for backgrounds, text, borders, and states
@@ -0,0 +1,114 @@
1
+ ---
2
+ applyTo: '**'
3
+ ---
4
+
5
+ # Dynamic Color Approach
6
+
7
+ The dynamic approach uses abstraction with variable modes in Figma and data attributes in code to define the semantic category at runtime. The same component can work with different semantic meanings without changing code.
8
+
9
+ :::tip
10
+
11
+ See [colors.md](./colors.md) for core color system concepts.
12
+
13
+ :::
14
+
15
+ ## Concept
16
+
17
+ Variables use abstract role names (background, text, border) without specifying the semantic category. The semantic category is applied using the `data-color-appearance` attribute.
18
+
19
+ ## Naming Pattern
20
+
21
+ Dynamic variable names follow this pattern:
22
+
23
+ ```
24
+ --eds-color-[role]-[priority]-[state]
25
+ ```
26
+
27
+ **Examples:**
28
+
29
+ - `--eds-color-bg-fill-emphasis-default`
30
+ - `--eds-color-text-strong-on-emphasis`
31
+ - `--eds-color-border-subtle`
32
+
33
+ Note: No semantic category (accent, neutral, etc.) in the variable name itself.
34
+
35
+ ## CSS Variables
36
+
37
+ ### Import
38
+
39
+ ```css
40
+ @import '@equinor/eds-tokens/css/variables';
41
+ ```
42
+
43
+ ### Setting Appearance
44
+
45
+ Use the `data-color-appearance` attribute to set the semantic category:
46
+
47
+ ```html
48
+ <!-- Accent appearance -->
49
+ <button data-color-appearance="accent">Primary</button>
50
+
51
+ <!-- Neutral appearance (default) -->
52
+ <button data-color-appearance="neutral">Secondary</button>
53
+
54
+ <!-- Success appearance -->
55
+ <button data-color-appearance="success">Confirm</button>
56
+
57
+ <!-- Warning appearance -->
58
+ <button data-color-appearance="warning">Caution</button>
59
+
60
+ <!-- Danger appearance -->
61
+ <button data-color-appearance="danger">Delete</button>
62
+
63
+ <!-- Info appearance -->
64
+ <button data-color-appearance="info">Info</button>
65
+ ```
66
+
67
+ ### Usage
68
+
69
+ Use abstract role variables in your CSS:
70
+
71
+ ```css
72
+ .button {
73
+ background-color: var(--eds-color-bg-fill-emphasis-default);
74
+ color: var(--eds-color-text-strong-on-emphasis);
75
+ border: 1px solid var(--eds-color-border-strong);
76
+ }
77
+
78
+ .button:hover {
79
+ background-color: var(--eds-color-bg-fill-emphasis-hover);
80
+ }
81
+
82
+ .button:active {
83
+ background-color: var(--eds-color-bg-fill-emphasis-active);
84
+ }
85
+ ```
86
+
87
+ Now the same component works with any appearance:
88
+
89
+ ```html
90
+ <!-- All use the same CSS class but different appearances -->
91
+ <button class="button" data-color-appearance="accent">Primary</button>
92
+ <button class="button" data-color-appearance="neutral">Secondary</button>
93
+ <button class="button" data-color-appearance="success">Success</button>
94
+ ```
95
+
96
+ ## Appearance Values
97
+
98
+ Use one of these values for the `data-color-appearance` attribute:
99
+
100
+ - `neutral` (default) -- Base and supporting colors
101
+ - `accent` -- Brand and highlight colors
102
+ - `success` -- Positive or confirming feedback
103
+ - `info` -- Communication and neutral messages
104
+ - `warning` -- Cautionary states
105
+ - `danger` -- Destructive or error states
106
+
107
+ ## Best Practices
108
+
109
+ - **Use abstraction** -- Write CSS once, reuse with different appearances
110
+ - **Set appearance semantically** -- Use the attribute based on context, not styling needs
111
+ - **Keep appearance stable** -- Don't change appearances based on hover/active states
112
+ - **Test all appearances** -- Verify your component works with all appearance values
113
+ - **Document requirements** -- Make clear which appearances work with your component
114
+ - **Never mix approaches** -- Use dynamic consistently, don't mix with static
@@ -0,0 +1,80 @@
1
+ ---
2
+ applyTo: '**'
3
+ ---
4
+
5
+ # Static Color Approach
6
+
7
+ The static approach uses a complete set of variables for each semantic category. Each variable explicitly specifies the semantic category in its name.
8
+
9
+ > See [colors.md](./colors.md) for the core color system concepts.
10
+
11
+ ## Concept
12
+
13
+ In the static approach, each semantic category (accent, neutral, info, success, warning, danger) has its own variables. You choose the specific variable you need based on the semantic meaning required.
14
+
15
+ ## Naming Pattern
16
+
17
+ Static variable names follow this pattern:
18
+
19
+ ```
20
+ --eds-color-[role]-[semantic category]-[priority]-[state]
21
+ ```
22
+
23
+ > **Note:** The `[state]` suffix (e.g., `-default`, `-hover`, `-active`) is only present for certain roles, such as background fill. For text and border variables, the state is typically omitted.
24
+
25
+ - `--eds-color-bg-accent-fill-emphasis-default` -- Accent semantic category (background fill, with default state)
26
+ - `--eds-color-bg-neutral-fill-muted-default` -- Neutral semantic category (background fill, with default state)
27
+ - `--eds-color-border-danger-medium` -- Danger semantic category (border, no state)
28
+ - `--eds-color-text-success-strong` -- Success semantic category (text, no state)
29
+
30
+ ## CSS Variables
31
+
32
+ ### Import
33
+
34
+ ```css
35
+ @import '@equinor/eds-tokens/css/variables';
36
+ ```
37
+
38
+ ### Usage
39
+
40
+ Use specific semantic variables in your styles:
41
+
42
+ ```css
43
+ .button-primary {
44
+ background-color: var(--eds-color-bg-accent-fill-emphasis-default);
45
+ color: var(--eds-color-text-accent-strong-on-emphasis);
46
+ border: 1px solid var(--eds-color-border-accent-strong);
47
+ }
48
+
49
+ .alert-warning {
50
+ background-color: var(--eds-color-bg-warning-fill-emphasis);
51
+ color: var(--eds-color-text-warning-strong-on-emphasis);
52
+ border-left: 4px solid var(--eds-color-border-warning-strong);
53
+ }
54
+ ```
55
+
56
+ ### Interactive States
57
+
58
+ Background fill-muted and fill-emphasis include state variants for hover and active:
59
+
60
+ ```css
61
+ .button {
62
+ background-color: var(--eds-color-bg-accent-fill-emphasis-default);
63
+ transition: background-color 0.2s;
64
+ }
65
+
66
+ .button:hover {
67
+ background-color: var(--eds-color-bg-accent-fill-emphasis-hover);
68
+ }
69
+
70
+ .button:active {
71
+ background-color: var(--eds-color-bg-accent-fill-emphasis-active);
72
+ }
73
+ ```
74
+
75
+ ## Best Practices
76
+
77
+ - **Be explicit** -- Choose the specific semantic category your element needs
78
+ - **Pair carefully** -- Always use matching text and background variables for contrast
79
+ - **Never mix approaches** -- Use static consistently, don't mix with dynamic
80
+ - **Test contrast** -- Verify all color combinations meet accessibility standards
@@ -0,0 +1,123 @@
1
+ ---
2
+ applyTo: '**'
3
+ ---
4
+
5
+ # Color System Introduction
6
+
7
+ This guide introduces the <abbr title="Equinor Design System">EDS</abbr> color system -- semantic meaning, token categories, and how to choose the right approach for your project.
8
+
9
+ ## Core Concepts
10
+
11
+ The <abbr title="Equinor Design System">EDS</abbr> color system is built on **semantic meaning**, not visual appearance. You choose colors based on **function and role** in the interface, not on how they look.
12
+
13
+ ### Semantic Categories
14
+
15
+ All colors belong to one of six semantic categories that reflect their purpose:
16
+
17
+ - **Accent** -- Brand and highlight colors
18
+ - **Neutral** -- Base and supporting colors
19
+ - **Info** -- Communication and neutral messages
20
+ - **Success** -- Positive or confirming feedback
21
+ - **Warning** -- Cautionary states
22
+ - **Danger** -- Destructive or error states
23
+
24
+ ### Color Roles
25
+
26
+ Within each semantic category, colors serve specific roles:
27
+
28
+ - **Background (`bg`)** -- Surface and canvas layers
29
+ - `surface` -- Placed on canvas to create depth in layouts
30
+ - `canvas` -- Main application background
31
+ - `fill-muted` -- Subtle backgrounds for interactive elements
32
+ - `fill-emphasis` -- Bold backgrounds for prominent interactive elements
33
+
34
+ - **Border** -- Separators and outlines
35
+ - `subtle` -- Light separators and dividers
36
+ - `medium` -- Standard borders and controls
37
+ - `strong` -- Emphasis or interactive elements
38
+
39
+ - **Text** -- Content and readability
40
+ - `strong` -- Primary text in the application
41
+ - `subtle` -- Secondary text and less important content
42
+ - `strong-on-emphasis` -- Text on emphasis backgrounds
43
+ - `subtle-on-emphasis` -- Secondary text on emphasis backgrounds
44
+
45
+ ### Concept Colors
46
+
47
+ Global colors that sit outside the semantic scales for special cases:
48
+
49
+ - `bg-floating` -- Floating elements like tooltips and menus
50
+ - `bg-backdrop` -- Overlay layer behind modals
51
+ - `bg-input` -- Input fields and forms
52
+ - `border-focus` -- Focus rings for accessibility
53
+ - `text-link` -- Default link color
54
+
55
+ ## Two Approaches: Static vs. Dynamic
56
+
57
+ The <abbr title="Equinor Design System">EDS</abbr> color system offers two approaches. Both use the same color values and accessibility logic but differ in how you apply and manage them.
58
+
59
+ :::warning
60
+
61
+ **Choose one approach and use it consistently** across design and development. Mixing approaches causes design and code to drift apart, making development harder. Each Figma variable has a matching code variable -- keep them aligned.
62
+
63
+ :::
64
+
65
+ ### Static Approach
66
+
67
+ Each semantic category has its own complete set of variables.
68
+
69
+ - **When to use:** Fixed semantic meanings throughout your interface
70
+ - **Example:** All primary buttons always use `accent` colors
71
+ - **More info:** See [colors-static.md](./colors-static.md)
72
+
73
+ ### Dynamic Approach
74
+
75
+ Uses abstraction with variable modes in Figma and data attributes in code to define semantic category at runtime.
76
+
77
+ - **When to use:** Need to change semantic meaning without updating components
78
+ - **Example:** Same button component can switch from `accent` to `neutral` context
79
+ - **More info:** See [colors-dynamic.md](./colors-dynamic.md)
80
+
81
+ ## Accessibility
82
+
83
+ All color combinations have been evaluated using the **<abbr title="Accessible Perceptual Contrast Algorithm">APCA</abbr>** contrast algorithm:
84
+
85
+ **Key principle:** Always pair text colors with their intended background tokens. They have been carefully tested together.
86
+
87
+ ## Color Schemes
88
+
89
+ The color system automatically adapts to light and dark color schemes using the `data-color-scheme` attribute:
90
+
91
+ ```html
92
+ <!-- Light theme (default) -->
93
+ <html data-color-scheme="light"></html>
94
+
95
+ <!-- Dark theme -->
96
+ <html data-color-scheme="dark"></html>
97
+ ```
98
+
99
+ Or with custom selectors:
100
+
101
+ ```css
102
+ .light {
103
+ color-scheme: light;
104
+ }
105
+ .dark {
106
+ color-scheme: dark;
107
+ }
108
+ ```
109
+
110
+ Both the static and dynamic libraries support light and dark modes automatically.
111
+
112
+ ## Installation
113
+
114
+ ```bash
115
+ pnpm add @equinor/eds-tokens
116
+ ```
117
+
118
+ ## Next Steps
119
+
120
+ Choose your approach and refer to the specific guide:
121
+
122
+ - **Static Approach:** See [colors-static.md](./colors-static.md)
123
+ - **Dynamic Approach:** See [colors-dynamic.md](./colors-dynamic.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-tokens",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Design tokens for the Equinor Design System",
5
5
  "type": "module",
6
6
  "exports": {
@@ -41,6 +41,7 @@
41
41
  "dist/*",
42
42
  "build/*",
43
43
  "commonjs/*",
44
+ "instructions/*",
44
45
  "tokens.css",
45
46
  "elements.css"
46
47
  ],