@amboss/design-system 0.27.2 → 1.0.0-canary-1
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 +137 -174
- package/build/build-tokens/visualConfig.d.ts +714 -0
- package/build/index.js +10 -7
- package/build/index.js.map +1 -1
- package/build/src/components/Box/Box.d.ts +4 -4
- package/build/src/components/Card/Card.d.ts +2 -2
- package/build/src/components/Column/Columns.d.ts +22 -7
- package/build/src/components/Container/Container.d.ts +2 -1
- package/build/src/components/DropdownMenu/DropdownMenu.d.ts +3 -0
- package/build/src/components/Form/Input/Input.d.ts +1 -3
- package/build/src/components/Link/Link.d.ts +7 -6
- package/build/src/components/PictogramButton/PictogramButton.d.ts +1 -1
- package/build/src/components/Typography/Header/Header.d.ts +28 -8
- package/build/src/components/Typography/Text/Text.d.ts +4 -4
- package/build/src/index.d.ts +3 -2
- package/build/src/shared/mediaQueries.d.ts +10 -0
- package/build/src/shared/useAutoPosition.d.ts +1 -2
- package/build/src/types/index.d.ts +1 -1
- package/package.json +19 -20
- package/CHANGELOG.md +0 -1727
- package/build/src/components/Column/Column.d.ts +0 -17
- package/build/src/components/Typography/Header/CustomHeader.d.ts +0 -8
package/README.md
CHANGED
|
@@ -27,96 +27,88 @@ To build storybook run `npm run build-storybook`
|
|
|
27
27
|
- Add `skip-release` label to skip the release
|
|
28
28
|
- If you want your commit to skip ci, add "[skip ci]" to your commit message.
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
### Codebase Overview
|
|
31
31
|
|
|
32
|
-
1. [Tech stack](#tech-stack)
|
|
33
|
-
2. [
|
|
34
|
-
3. [
|
|
35
|
-
4. [
|
|
36
|
-
5. [Tokens, styles and theming](#tokens-styles-and-theming)
|
|
37
|
-
6. [Assets](#assets)
|
|
38
|
-
7. [Media queries](#media-queries)
|
|
32
|
+
**1. [Tech stack](#tech-stack)**<br/>
|
|
33
|
+
**2. [Linting](#linting)**<br/>
|
|
34
|
+
**3. [Folder structure](#folder-structure)**<br/>
|
|
35
|
+
**4. [Build](#build)**<br/>
|
|
36
|
+
**5. [Tokens, styles and theming](#tokens-styles-and-theming)**<br/>
|
|
37
|
+
**6. [Assets](#assets)**<br/>
|
|
38
|
+
**7. [Media queries](#media-queries)**<br/>
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
## Tech stack
|
|
41
41
|
|
|
42
|
-
Code: **typescript
|
|
42
|
+
- Code: **typescript**
|
|
43
|
+
- Styles: **emotion.js**
|
|
44
|
+
- Framework: **react**
|
|
45
|
+
- Bundler: **webpack**
|
|
46
|
+
- Environment: **storybook**
|
|
47
|
+
- Tokens: **[style-dictionary](https://github.com/amzn/style-dictionary)**
|
|
48
|
+
- Testing: **jest + react testing library**
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
## Linting
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
As for linting and formatting, you can configure your editor to automatically lint and format your code on save. For this purpose, we're using [Prettier](https://prettier.io/) and [ESLint](https://eslint.org/). If you need to do it manually, you can run:
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
```sh
|
|
55
|
+
npm run lint
|
|
56
|
+
```
|
|
51
57
|
|
|
52
|
-
|
|
58
|
+
> This command is also run as a **pre-push hook** and in the pipeline.
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
## Folder structure
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
```
|
|
57
63
|
|-- .storybook
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
|-- components
|
|
65
|
+
|-- ColorGrid.tsx
|
|
66
|
+
|-- SizeGrid.tsx
|
|
67
|
+
|-- main.js
|
|
68
|
+
|-- preview.js
|
|
63
69
|
|-- assets
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|-- build
|
|
67
|
-
|-- build-tokens
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
|-- fonts
|
|
71
|
+
|-- Lato.woff
|
|
72
|
+
|-- build (autogenerated)
|
|
73
|
+
|-- build-tokens (autogenerated)
|
|
74
|
+
|-- assets
|
|
75
|
+
|-- icons.json
|
|
76
|
+
|-- icons16.json
|
|
77
|
+
|-- _colors.json
|
|
78
|
+
|-- _sizes.json
|
|
79
|
+
|-- visualConfig.ts
|
|
73
80
|
|-- docs
|
|
74
|
-
|
|
81
|
+
|-- Design-principles.mdx
|
|
82
|
+
|-- static
|
|
83
|
+
|-- image-for-storybook.png
|
|
75
84
|
|-- tokens
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
|-- themes
|
|
86
|
+
|-- dark.json
|
|
87
|
+
|-- light.json
|
|
88
|
+
|-- assets.json
|
|
89
|
+
|-- colors.json
|
|
81
90
|
|-- src
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|-- index.ts
|
|
94
|
-
|
|
95
|
-
</pre>
|
|
96
|
-
|
|
97
|
-
### Build
|
|
98
|
-
|
|
99
|
-
There are 3 stages of a build.
|
|
100
|
-
|
|
101
|
-
1. Generate type definitions for styles
|
|
102
|
-
2. Generate variables and mixins for tokens
|
|
103
|
-
3. Bundle all exported components
|
|
104
|
-
|
|
105
|
-
#### Generate type definitions for styles
|
|
106
|
-
|
|
107
|
-
Files like `Button.scss.d.ts` are autogenerated, and they are added to .gitignore.
|
|
108
|
-
|
|
109
|
-
Type definitions are generating automatically:
|
|
91
|
+
|-- index.ts
|
|
92
|
+
|-- components
|
|
93
|
+
|-- Button
|
|
94
|
+
|-- Button.tsx
|
|
95
|
+
|-- Button.stories.tsx
|
|
96
|
+
|-- Button.test.tsx
|
|
97
|
+
|-- shared
|
|
98
|
+
-- mediaQueries.ts
|
|
99
|
+
|-- types
|
|
100
|
+
|-- index.ts
|
|
101
|
+
```
|
|
110
102
|
|
|
111
|
-
|
|
112
|
-
- after npm install
|
|
113
|
-
- before build
|
|
103
|
+
## Build
|
|
114
104
|
|
|
115
|
-
|
|
105
|
+
There are 3 stages of a build.
|
|
116
106
|
|
|
117
|
-
|
|
107
|
+
1. Generate variables, theme values and assets from tokens
|
|
108
|
+
2. Build all exported components with babel (preset-react, preset-typescript)
|
|
109
|
+
2. Bundle all built components with webpack
|
|
118
110
|
|
|
119
|
-
|
|
111
|
+
### Generate variables, theme values and assets from tokens
|
|
120
112
|
|
|
121
113
|
In order to structure our tokens we use **[style-dictionary](https://github.com/amzn/style-dictionary)**.
|
|
122
114
|
This tool is used for creation a content of `./build-tokens` folder where we keep all the scss variables and mixins.
|
|
@@ -130,155 +122,121 @@ New variables and mixins gets generated automaticaly:
|
|
|
130
122
|
You can generate tokens manually using `npm run tokens` and `npm run tokens:watch`
|
|
131
123
|
|
|
132
124
|
We use tokens to control the most atomic values in styles and themes.
|
|
125
|
+
|
|
133
126
|
How does it work?
|
|
127
|
+
|
|
134
128
|
We have a set of .json files that are located in `./tokens` folder, and we have a `style-dictionary` as a tool for converting .json in to various formats.
|
|
129
|
+
|
|
135
130
|
For example:
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
|
|
132
|
+
We have a file - `./tokens/colors.json` that gets converted into part of `./build-tokens/visualConfig.ts` and `./build-tokens/_colors.json`.
|
|
133
|
+
|
|
134
|
+
`visualConfig.ts` is used later as a source for emotion.js theme.
|
|
135
|
+
|
|
138
136
|
`_colors.json` is imported inside `./.storybook/components/ColorGrid.tsx` in order to present in storybook all the colors we currently have.
|
|
139
137
|
|
|
140
|
-
The configuration for `style-dictionary` is inside `./style-dictionary.config.json`. In this config we use
|
|
138
|
+
The configuration for `style-dictionary` is inside `./style-dictionary/style-dictionary.config.json`. In this config we use some custom transforms, filters and formatters, all of them defined in `./style-dictionary/style-dictionary.build.js`.
|
|
141
139
|
|
|
142
|
-
**custom/format/
|
|
143
|
-
|
|
144
|
-
**custom/filter/
|
|
140
|
+
**custom/format/emotion-visual-config** - a formatter that generates visualConfig.ts that contains all variables and themed values.
|
|
141
|
+
|
|
142
|
+
**custom/filter/emotion-build-tokens** - a filter for all token categories that should go to visutal config.
|
|
143
|
+
|
|
144
|
+
**custom/format/json** - a formatter for generation .json files per category. This formatter also add `isUsed` flag to according token.
|
|
145
|
+
|
|
146
|
+
**custom/format/sub-theme-types** - a formatter that generates type definitions for sub-themes.
|
|
147
|
+
|
|
148
|
+
**custom/assets/svg** - a transformer that adds a path name to dictionary of svg icons.
|
|
145
149
|
|
|
146
150
|
[More about tokens, themes and styles.](#tokens-styles-and-theming)
|
|
147
151
|
|
|
148
|
-
|
|
152
|
+
### Bundle all exported components
|
|
149
153
|
|
|
150
154
|
Before publish the design system for npm we run `npm run build` that bundles everything that is exported from `./src/index.ts`.
|
|
151
155
|
|
|
152
|
-
We use webpack +
|
|
156
|
+
We use webpack + babel for bundling. For all `/\.ts(x?)$/` files webpack uses a babel-loader as a rule which is implicitly using `tsconfig.json` and `.babelrc`.
|
|
153
157
|
|
|
154
|
-
For styles we use
|
|
158
|
+
For styles we use emotion.js.
|
|
155
159
|
|
|
156
160
|
What in the bundle?
|
|
157
161
|
|
|
158
|
-
- JS code that is compiled from
|
|
159
|
-
- css rules that are namespaced using css-loader
|
|
162
|
+
- JS code that is compiled from .tsx files (includes common components and emotion.js styled components)
|
|
160
163
|
- I svg icons that are inlined
|
|
161
164
|
|
|
162
165
|
fonts that are base64-ed currently taken off the build
|
|
163
166
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
We use type definitions for style in order to improve quality of a product overall. One example:
|
|
167
|
+
## Tokens, styles and theming
|
|
167
168
|
|
|
168
|
-
|
|
169
|
-
import styles from "./button.scss";
|
|
169
|
+
Currently, we have 4 types of tokens:
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
- atomic values, like colors, sizes, shadows.
|
|
172
|
+
- font assets, that are basically base64 of font files. (not used in production)
|
|
173
|
+
- theme values, that are referencing atomic different atomic values
|
|
174
|
+
- svg icon assets, that are inlined to a json file
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
<button className={styles[size]} />
|
|
177
|
-
);
|
|
178
|
-
```
|
|
176
|
+
As we use Emotion.js all tokenized values are accessible via theme provider. <br />
|
|
179
177
|
|
|
180
|
-
|
|
178
|
+
Basically during the build phase we generate big objects of variables and themed values for each theme (currently light and dark). <br />
|
|
181
179
|
|
|
182
|
-
|
|
180
|
+
We call this object `ambossVisualConfiguration`.
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
Particular themes from ambossVisualConfiguration has to be imported and passed to the theme provider at the consumer side.<br />
|
|
185
183
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
- theme values, that are referencing atomic different atomic values
|
|
189
|
-
- svg icon assets, that are inlined to a json file
|
|
184
|
+
<br />
|
|
185
|
+
Atomic values are straight forward and simply converted to `variables`.
|
|
190
186
|
|
|
191
|
-
|
|
192
|
-
After build all atomic values can't be imported as `@import "build-tokens/variables";`
|
|
193
|
-
Fonts are imported inside `./src/shared/_fonts` and never used directly (it doesn't make sense).
|
|
194
|
-
In the application simply `@import "src/shared/fonts";`.
|
|
187
|
+
After build all atomic values are passed to `theme.variables` by emotion.
|
|
195
188
|
|
|
196
|
-
|
|
189
|
+
Example:
|
|
190
|
+
```
|
|
191
|
+
const StyledContainer - styled.div(
|
|
192
|
+
({ theme }) => ({
|
|
193
|
+
marginTop: theme.variables.size.spacing.s
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
```
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
2. A `@theme` mixin, that include all themes.
|
|
200
|
-
3. A list of scss variables with the name of entries in the maps (see point 1). This is just for IDE auto-complition.
|
|
198
|
+
Theme tokens are little more complex. We generate separate VisualConfig for each theme, but together with that we generate type definition that describe any of the themes. This enables developers not care about current theme and how many themes are there.
|
|
201
199
|
|
|
202
|
-
|
|
200
|
+
After build all themes values are passed to `theme.values` by emotion.
|
|
203
201
|
|
|
204
202
|
Example:
|
|
205
203
|
|
|
206
|
-
```scss
|
|
207
|
-
@import "build-tokens/theme";
|
|
208
|
-
@import "build-tokens/variables";
|
|
209
|
-
@import "src/shared/fonts";
|
|
210
|
-
|
|
211
|
-
.primary {
|
|
212
|
-
@include theme("color", $theme-color-text-primary);
|
|
213
|
-
font-family: $Lato;
|
|
214
|
-
margin: 0;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
.secondary {
|
|
218
|
-
@include theme("color", $theme-color-text-secondary);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
.s {
|
|
222
|
-
font-size: $size-font-text-s;
|
|
223
|
-
line-height: $size-line-height-text-s;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
.m {
|
|
227
|
-
font-size: $size-font-text-m;
|
|
228
|
-
line-height: $size-line-height-text-m;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
.normal {
|
|
232
|
-
font-weight: $weight-normal;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
.bold {
|
|
236
|
-
font-weight: $weight-bold;
|
|
237
|
-
}
|
|
238
204
|
```
|
|
205
|
+
const StyledContainer - styled.div(
|
|
206
|
+
({ theme }) => ({
|
|
207
|
+
backgroundColor: theme.values.color.background.layer_2
|
|
208
|
+
})
|
|
209
|
+
);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Sub-themes are folowing the same concept as themes. Developer can fully rely on `theme.values` object. As long as component in runtime is wrapped in `SubThemeProvider` and it's tokens listed in "tokens/themes/sub-themes/...", all values will be set correctly and automaticaly.
|
|
213
|
+
|
|
214
|
+
> Note that not all tokens are enabled in sub-themes. Make sure to add missing ones to "tokens/themes/sub-themes/...".
|
|
215
|
+
|
|
216
|
+
> Components that has "Sub-themed" badge are already in.
|
|
239
217
|
|
|
240
|
-
|
|
218
|
+
## Assets
|
|
241
219
|
|
|
242
220
|
- assets are defined in `tokens/assets.json`
|
|
243
221
|
- with the help from style-dictionary we create a json file with tokens (`/build-tokens/assets/`)
|
|
244
222
|
- those json files supposed to be imported in the ts module (see Icons.tsx)
|
|
245
223
|
- in order to secure `d.ts` filed in the build we "manually" copy asset jsons on the `postbuild` phase (see package.json)
|
|
246
224
|
|
|
247
|
-
|
|
225
|
+
## Media queries
|
|
248
226
|
|
|
249
227
|
There is an API for media-query related props: an array of 3 elements [small, medium, large], for respective screen sizes.
|
|
250
|
-
|
|
228
|
+
|
|
229
|
+
For example `<Box space=["xs", "xl", "xxl"] />` will set `xs` for small screens, `xl` for medium screens and `xxl` for large.
|
|
251
230
|
|
|
252
231
|
Basically, if you see a type of `MQ<Whatever>` you can provide an array of 3 `Whatever`s.
|
|
253
232
|
|
|
254
233
|
In order to add a media query support to your components:
|
|
255
234
|
|
|
256
|
-
> mq mixin from media-queries module will create a set of media-query selectors.
|
|
257
|
-
|
|
258
|
-
```scss
|
|
259
|
-
@import "src/shared/media-queries";
|
|
260
|
-
|
|
261
|
-
@include mq(".align-left") {
|
|
262
|
-
text-align: left;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
@include mq(".align-right") {
|
|
266
|
-
text-align: right;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
@include mq(".align-center") {
|
|
270
|
-
text-align: center;
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
> import getMediaQueryClasses from mediaQueries module to create classnames compatible with mixin above.
|
|
275
|
-
> note that third parameter is a prefix to classname.
|
|
276
|
-
|
|
277
235
|
```ts
|
|
278
|
-
import
|
|
236
|
+
import React from "react";
|
|
279
237
|
|
|
280
|
-
import
|
|
281
|
-
import
|
|
238
|
+
import styled from "@emotion/styled";
|
|
239
|
+
import { mq } from "../../shared/mediaQueries";
|
|
282
240
|
|
|
283
241
|
type TextAlignment = "left" | "center" | "right";
|
|
284
242
|
|
|
@@ -286,9 +244,14 @@ type BoxProps = {
|
|
|
286
244
|
alignText: TextAlignment | MQ<TextAlignment>;
|
|
287
245
|
};
|
|
288
246
|
|
|
289
|
-
export const Box =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
247
|
+
export const Box = styled.div<BoxProps>(
|
|
248
|
+
({ alignText = "left" }) =>
|
|
249
|
+
mq({
|
|
250
|
+
textAlign: [
|
|
251
|
+
alignText,
|
|
252
|
+
{ left: "left", right: "right", center: "center" },
|
|
253
|
+
],
|
|
254
|
+
})
|
|
293
255
|
);
|
|
294
256
|
```
|
|
257
|
+
|