You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+92-31Lines changed: 92 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,7 @@
9
9
10
10
</h1>
11
11
12
-
Design System Utils is a micro framework that standardises your design-system tokens & provides helpful utility functions to access it’s information. It can be used with [styled-components](https://styled-components.com), [emotion](https://emotion.sh), [glamorous](https://glamorous.rocks/) or any other [CSS-in-JS framework](https://css-in-js-playground.com/).
13
-
14
-
<details>
15
-
<summary>Table of contents</summary>
16
-
17
-
-[Install](#install)
18
-
-[Usage](#usage)
19
-
-[Setting up your design system](#setting-up-your-design-system)
20
-
-[Initialise the design system framework](#initialise-the-design-system-framework)
21
-
-[Accessing the design system data in your app](#accessing-the-design-system-data-in-your-app)
22
-
-[Options](#options)
23
-
-[API methods](#api-methods)
24
-
-[`tokens.get()` - Get any value from the design tokens](#tokensget---get-any-value-from-the-design-tokens)
25
-
-[`tokens.fontSize()` or `tokens.fs()` - Get font-size values](#tokensfontsize-or-tokensfs---get-font-size-values)
26
-
-[Color palette](#color-palette)
27
-
-[`tokens.color()` - Get color palette values](#tokenscolor---get-color-palette-values)
28
-
-[`tokens.brand()` - Get brand palette values](#tokensbrand---get-brand-palette-values)
29
-
-[`tokens.bp()` - Get responsive breakpoint values](#tokensbp---get-responsive-breakpoint-values)
30
-
-[`tokens.z()` - Get `z-index` values](#tokensz---get-z-index-values)
31
-
-[`tokens.spacing()` or `tokens.space()` - Get spacing values](#tokensspacing-or-tokensspace---get-spacing-values)
32
-
-[Calculations](#calculations)
33
-
-[Usage with Typescript](#usage-with-typescript)
34
-
-[Demo & examples](#demo--examples)
35
-
36
-
</details>
12
+
Design System Utils is a micro framework that standardises your design-system tokens & provides helpful utility functions to access the information. It can be used with [styled-components](https://styled-components.com), [emotion](https://emotion.sh), [glamorous](https://glamorous.rocks/) or any other [CSS-in-JS framework](https://css-in-js-playground.com/).
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
44
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
45
+
46
+
47
+
-[Usage](#usage)
48
+
-[Setup](#setup)
49
+
-[Initialise the design system framework](#initialise-the-design-system-framework)
50
+
-[Accessing the design system data in your app](#accessing-the-design-system-data-in-your%C2%A0app)
51
+
-[Options](#options)
52
+
-[Basic API methods](#basic-api-methods)
53
+
-[`tokens.get()` - Get a token value](#tokensget---get-a-token-value)
54
+
-[`tokens.set()` - Set a token value](#tokensset---set-a-token-value)
55
+
-[API helper methods](#api-helper-methods)
56
+
-[`tokens.fontSize()` or `tokens.fs()` - Get font-size values](#tokensfontsize-or-tokensfs---get-font-size-values)
57
+
-[Modular scale](#modular-scale)
58
+
-[Color palette](#color-palette)
59
+
-[`tokens.color()` - Get color palette values](#tokenscolor---get-color-palette-values)
60
+
-[`tokens.brand()` - Get brand palette values](#tokensbrand---get-brand-palette-values)
61
+
-[`tokens.bp()` - Get responsive breakpoint values](#tokensbp---get-responsive-breakpoint-values)
62
+
-[`tokens.z()` - Get `z-index` values](#tokensz---get-z-index-values)
63
+
-[`tokens.spacing()` or `tokens.space()` - Get spacing values](#tokensspacing-or-tokensspace---get-spacing-values)
64
+
-[Array example:](#array-example)
65
+
-[Object example:](#object-example)
66
+
-[Calculations](#calculations)
67
+
-[`tokens.multiply()`](#tokensmultiply)
68
+
-[`pxTo()`](#pxto)
69
+
-[`toPx()`](#topx)
70
+
-[`parseUnit()`](#parseunit)
71
+
-[Usage with Typescript](#usage-with-typescript)
72
+
-[Demo & examples](#demo--examples)
73
+
-[Licence](#licence)
74
+
75
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
76
+
77
+
</details>
78
+
64
79
## Usage
65
80
66
81
First create your design system file, this contains all your design tokens that your app or site will use; things like font-sizes, color palette, spacing etc (kind of like a Sass/Less variables file).
@@ -84,7 +99,7 @@ const designTokens = {...}
84
99
exportdefaultnewDesignSystem(designTokens)
85
100
```
86
101
87
-
### Setting up your design system
102
+
### Setup
88
103
89
104
The "shape" and structure of your design tokens object **_can_** actually be anything you want, however, if you want to make use of the shortcut/helper methods like `tokens.fontSize|bp|z|color|brand|spacing` etc, there is a particular shape that your data will need to follow, see below:
90
105
@@ -230,18 +245,44 @@ export default new DesignSystem(myDesignSystem, {
230
245
})
231
246
```
232
247
233
-
## API methods
248
+
## Basic API methods
234
249
235
-
### `tokens.get()` - Get any value from the design tokens
250
+
### `tokens.get()` - Get a token value
236
251
237
252
The `tokens.get()` function can be used to get any value from the design-system. Use object dot notation to find the value you need from your design system object.
238
253
239
254
```js
240
255
// with the system setup, as above
241
256
tokens.get('lineHeight.headings') // 1.1
257
+
tokens.get('a.really.deeply.nested.value')
258
+
```
259
+
260
+
### `tokens.set()` - Set a token value
261
+
262
+
The `tokens.set()` function can be used to set tokens values. This means you can overwrite existing items, or create new items that are specific to your application.
263
+
264
+
Like the `.get()` method, use object dot notation to find the value you need from your design system object.
265
+
266
+
This method uses [dset](https://github.com/lukeed/dset#usage) under the hood, so please read the docs there for more info.
267
+
268
+
```js
269
+
// with the system setup, as above
270
+
tokens.set('forms.inputBackground', '#fff')
271
+
272
+
// then use it later like so:
273
+
tokens.get('forms.inputBackground')
242
274
```
243
275
244
-
There are a few more helper methods to make finding certain values more simple.
276
+
## API helper methods
277
+
278
+
The helper methods make getting values _much_ more simple.
279
+
280
+
-[`tokens.fontSize()` or `tokens.fs()`](#tokensfontsize-or-tokensfs---get-font-size-values) - Get font-size values
281
+
-[`tokens.color()`](#tokenscolor---get-color-palette-values) - Get color palette values
282
+
-[`tokens.brand()`](#tokensbrand---get-brand-palette-values) - Get brand palette values
283
+
-[`tokens.bp()`](#tokensbp---get-responsive-breakpoint-values) - Get responsive breakpoint values
284
+
-[`tokens.z()`](#tokensz---get-z-index-values) - Get `z-index` values
285
+
-[`tokens.spacing()` or `tokens.space()`](#tokensspacing-or-tokensspace---get-spacing-values) - Get spacing values
245
286
246
287
### `tokens.fontSize()` or `tokens.fs()` - Get font-size values
247
288
@@ -464,7 +505,27 @@ parseUnit('18px') // 'px'
464
505
465
506
## Usage with Typescript
466
507
467
-
Typescript types and interfaces should be imported as named imports. Below is an example where a new item (`baseline`) is added to the `spacing` object.
508
+
Typescript types and interfaces should be imported as named imports.
509
+
510
+
See all the type definitions in the [types.ts](https://github.com/mrmartineau/design-system-utils/blob/master/src/types.ts) file. Here are all the exported types that can be extended:
511
+
512
+
```
513
+
{
514
+
System,
515
+
SystemOptions,
516
+
SystemBreakpoints,
517
+
SystemZIndex,
518
+
SystemFontSizes,
519
+
SystemSpacing,
520
+
SystemScale,
521
+
SystemColorPalette,
522
+
SystemBrandPalette,
523
+
SystemType,
524
+
SystemOptionalKey,
525
+
}
526
+
```
527
+
528
+
Below is an example where a new item (`baseline`) is added to the `spacing` object.
0 commit comments