@balena/design-tokens 0.1.1 → 0.1.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.
package/README.md CHANGED
@@ -1,3 +1,124 @@
1
- # design-tokens
1
+ # Balena Design Tokens
2
2
 
3
- Design Tokens for balena
3
+ ## What's this?
4
+
5
+ Design tokens are small bits of design decisions that can be used across different platforms and projects.
6
+ They define the visual language of a product, and help create a consistent experience across different platforms.
7
+
8
+ Practically, this package will serve two purposes:
9
+ * Be the source of truth for design decisions: instead of using absolute values in your project, you can import this package and reference tokens in a variety of ways (currently with an ES module and CSS custom properties).
10
+ * Add a layer of semantics: tokens are more descriptive and convey meaning. For example, instead of relying on abstract naming such as `primary.main` or `quartenary.lightest`, tokens convey meaning and context. Examples: `color.text.accent` or `color.bg.success.strong`.
11
+
12
+ ## Usage
13
+
14
+ ### Install the package in your project
15
+
16
+ `npm install @balena/design-tokens`
17
+
18
+ ### TypeScript
19
+
20
+ ```tsx
21
+ import tokens from '@balena/design-tokens';
22
+
23
+ console.log(tokens.color.text.accent.value); // outputs '#1496e1'
24
+ ```
25
+
26
+ You can also import categories directly:
27
+
28
+ ```tsx
29
+ import { color } from '@balena/design-tokens';
30
+
31
+ console.log(color.text.accent.value); // outputs '#1496e1'
32
+ ```
33
+
34
+ ### CSS
35
+
36
+ The file `@balena/design-tokens/build/css/tokens.css` contains all the tokens as CSS custom properties.
37
+
38
+ The way you would import this file depends on the project. In a typical `create-react-app` project (or similar)
39
+ you should be able to import it in a tsx file:
40
+
41
+ ```tsx
42
+ import '@balena/design-tokens/build/css/tokens.css';
43
+ ```
44
+
45
+ The custom properties will be added to the `:root` element, and you can use them anywhere like so:
46
+
47
+ ```css
48
+ .alert.success {
49
+ border: solid 1px var(--color-border-success);
50
+ background-color: var(--color-bg-success);
51
+ color: var(--color-text-success);
52
+ }
53
+ ```
54
+
55
+ ## Update tokens
56
+
57
+ The tokens are exported from our Figma Design System library: https://www.figma.com/file/P7wVVPymUK4ekV6QOa3i0s/Design-System?type=design&t=hi4n82bo8vGO8noO-6
58
+
59
+ The export is a 3 steps process:
60
+ 1. Download a JSON file using the [Design Tokens plugin](https://github.com/lukasoppermann/design-tokens) to export the tokens from Figma.
61
+ 2. Replace the existing file in `tokens/design-tokens.json` with the one you downloaded
62
+ 3. (Optional) Run `npm run build` to generate the new tokens in the `build` folder
63
+ 4. Create a new branch and open a PR with the changes
64
+
65
+ TODO: this process can be greatly improved by using the "Send Design Tokens to URL" feature of the plugin, which would
66
+ allow for a more streamlined process.
67
+
68
+ ### Plugin settings
69
+
70
+ Please replicate the settings exactly as shown in the screenshots below:
71
+
72
+ ![plugin_settings.png](docs/plugin_settings.png)
73
+ ![plugin_export_settings.png](docs/plugin_export_settings.png)
74
+
75
+ ## Contribute
76
+
77
+ ### How it works
78
+
79
+ This package uses [Style Dictionary](https://amzn.github.io/style-dictionary/#/) to generate the tokens. The tokens are defined in `tokens/design-tokens.json`, and the build process will generate the tokens in the `build` folder.
80
+
81
+ #### Install dependencies
82
+
83
+ ```bash
84
+ npm install
85
+ ```
86
+
87
+ #### Develop (watch the tokens folder)
88
+
89
+ ```bash
90
+ npm start
91
+ ```
92
+
93
+ #### Build the tokens
94
+
95
+ ```bash
96
+ npm run build
97
+ ```
98
+
99
+ #### Run the tests
100
+
101
+ ```bash
102
+ npm run test
103
+ ```
104
+
105
+ ### Custom formats
106
+
107
+ See `scripts/transform.ts`.
108
+
109
+ Custom formats were created to generate the ES module and its typescript declarations, as standard formats didn't meet our
110
+ requirements:
111
+ * ES module export
112
+ * default exports to single categories for easier imports (`import { color } from '@balena/design-tokens'`)
113
+ * Path simplification (see below)
114
+
115
+ #### Path simplification
116
+
117
+ The goal of this package is to offer engineers the easiest way possible to implement design
118
+ decisions into their own projects. In this respect, we decided to shorten the path of the tokens as much as possible. So we don't use a "default" modifier, instead we
119
+ reduce the path to the minimum:
120
+
121
+ ❌ `color.bg.accent.default` \
122
+ ✅ `color.bg.accent`
123
+
124
+ By using a `_` prefix, we can also easily filter out the default tokens from the Figma plugin in Style Dictionary CSS transform. But this is not available for JS objects, and that's the point of the `flattenDefaultTokens`.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 20 Nov 2023 12:00:40 GMT
3
+ * Generated on Wed, 22 Nov 2023 16:01:35 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 20 Nov 2023 12:00:40 GMT
3
+ * Generated on Wed, 22 Nov 2023 16:01:35 GMT
4
4
  */
5
5
 
6
6
  export const color: {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 20 Nov 2023 12:00:40 GMT
3
+ * Generated on Wed, 22 Nov 2023 16:01:35 GMT
4
4
  */
5
5
 
6
6
  export const color = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/design-tokens",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "build/js/tokens.js",
5
5
  "module": "build/js/tokens.js",
6
6
  "types": "build/js/tokens.d.ts",
@@ -36,6 +36,6 @@
36
36
  "vitest": "^0.34.6"
37
37
  },
38
38
  "versionist": {
39
- "publishedAt": "2023-11-20T11:59:38.174Z"
39
+ "publishedAt": "2023-11-22T16:00:32.855Z"
40
40
  }
41
41
  }