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: content/design-systems-for-developers/react/en/build.md
+17-3
Original file line number
Diff line number
Diff line change
@@ -55,16 +55,18 @@ Your Storybook should reload like this (notice that the font styles are a little
55
55
56
56
#### Add global styles
57
57
58
-
Our design system requires some global styles (a CSS reset) to be applied to the document for components to be rendered correctly. The styles can be added easily via a Styled Components global style tag. For reference here is how the code is exported from `src/shared/global.js`:
58
+
Our design system requires some global styles (a CSS reset) to be applied to the document for components to be rendered correctly. The styles can be added easily via a Styled Components global style tag. Adjust your global styles, located in `src/shared/global.js` to the following:
To use the `GlobalStyle` “component” in Storybook, we can make use of a decorator (a component wrapper). In an app we’d place that component in the top-level app layout, but in Storybook we wrap all stories in it using the preview config file `.storybook/preview.js`
@@ -116,6 +120,8 @@ The [actions addon](https://github.com/storybookjs/storybook/tree/next/addons/ac
116
120
Let’s see how to use it in our Button element, which optionally takes a wrapper component to respond to clicks. We have a story that passes an action to that wrapper:
@@ -219,6 +231,8 @@ We'll visit the Accessbility and Docs addons in later chapters.
219
231
220
232
## Learn how to automate maintenance
221
233
222
-
Now that our design system components are in Storybook, we need to set up the automated tooling that streamlines ongoing maintenance. A design system, like all software, should evolve. The challenge is to ensure UI components continue to look and feel as intended as the design system grows.
234
+
Now that our design system components are in Storybook, we've taken one more step to create a industry-standard design system. Now it's a good time to commit our work to our remote repository. Then we can start thinking about how we setup the automated tooling that streamlines ongoing maintenance.
235
+
236
+
A design system, like all software, should evolve. The challenge is to ensure UI components continue to look and feel as intended as the design system grows.
223
237
224
238
In chapter 4 we’ll learn how to set up continuous integration and auto-publish the design system online for collaboration.
Copy file name to clipboardExpand all lines: content/design-systems-for-developers/react/en/distribute.md
+83-19
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,8 @@ Learn more at [Learn Storybook](https://learnstorybook.com).
44
44
Then, let’s create a `src/index.js` file to create a common entry point for using our design system. From this file we’ll export all our design tokens and the components:
45
45
46
46
```javascript
47
+
//src/index.js
48
+
47
49
import*asstylesfrom'./shared/styles';
48
50
import*asglobalfrom'./shared/global';
49
51
import*asanimationfrom'./shared/animation';
@@ -71,7 +73,7 @@ To build the package, we’ll add a script to `package.json` that builds our sou
@@ -84,7 +86,6 @@ We can now run `yarn build` to build our code into the `dist` directory -- we sh
84
86
85
87
```
86
88
// ..
87
-
storybook-static
88
89
dist
89
90
```
90
91
@@ -154,7 +155,6 @@ NPM_TOKEN=<value you just got from npm>
154
155
By adding the file to `.gitignore` we’ll be sure that we don’t accidentally push this value to an open-source repository that all our users can see! This is crucial. If other maintainers need to publish the package from locally (later we’ll set things up to auto publish when PRs are merged to master) they should set up their own `.env` file following this process:
155
156
156
157
```
157
-
storybook-static
158
158
dist
159
159
.env
160
160
```
@@ -229,7 +229,7 @@ Yay! We’ve successfully published our package to npm and created a release on
229
229
230
230
(Note that although `auto` auto-generated the release notes for the first release, we've also modified them to make sense for a first version).
231
231
232
-
<h4>Set up scripts to use Auto</h4>
232
+
#### Set up scripts to use Auto
233
233
234
234
Let’s set up Auto to follow the same process when we want to publish the package in the future. We’ll add the following scripts to our `package.json`:
235
235
@@ -241,24 +241,80 @@ Let’s set up Auto to follow the same process when we want to publish the packa
241
241
}
242
242
```
243
243
244
-
Now, when we run `yarn release`, we’ll step through all the steps we ran above (except using the auto-generated changelog) in an automated fashion. We’ll ensure that all commits to master are published by adding a command to our circle config:
244
+
Now, when we run `yarn release`, we'll go through all the steps we ran above (except using the auto-generated changelog) in an automated fashion. All commits to `master` will be published.
245
245
246
-
```
247
-
# ...
248
-
- run: yarn test
249
-
- run: npx chromatic --project-token=2wix88i1ziu
250
-
- run: |
251
-
if [ $CIRCLE_BRANCH = "master" ]
252
-
then
253
-
yarn release
254
-
fi
255
-
```
246
+
Congratulations! You setup the infrastructure to manually publish your design system releases. Now learn how to automate releases with continuous integration.
247
+
248
+
## Publish releases automatically
249
+
250
+
We use GitHub Actions for continuous integration. But before proceeding, we need to securely store the GitHub and NPM tokens from earlier so that Actions can access them.
251
+
252
+
#### Add your tokens to GitHub Secrets
253
+
254
+
GitHub Secrets allow us to store sensitive information in our repository. In a browser window open your GitHub repository.
255
+
256
+
Click the ⚙️ Settings tab then the Secrets link in the sidebar. You'll see the following screen:
We’ll also need to add an npm+GitHub token to your project’s Circle environment on the CircleCI website (https://circleci.com/gh/<your-username>/learnstorybook-design-system/edit#env-vars):
264
+
When you add the npm secret to your repository, you'll be able to access it as `secrets.NPM_TOKEN`. You don't need to setup another secret for your GitHub token. All GitHub users automatically get a `secrets.GITHUB_TOKEN` associated with their account.
258
265
259
-

266
+
#### Automate releases with GitHub Actions
260
267
261
-
Now every time you merge a PR to master, it will automatically publish a new version, incrementing the version number as appropriate due to the labels you’ve added.
268
+
Every time a pull request is merged we want to publish the design system automatically. Create a new file called `push.yml` in the same folder we used earlier to <ahref="https://www.learnstorybook.com/design-systems-for-developers/react/en/review/#publish-storybook">publish Storybook</a> and add the following:
269
+
270
+
```yml
271
+
# .github/workflows/push.yml
272
+
273
+
## name of our action
274
+
name: Release
275
+
276
+
# the event that will trigger the action
277
+
on:
278
+
push:
279
+
branches: [master]
280
+
281
+
# what the action will do
282
+
jobs:
283
+
release:
284
+
# the operating system it will run on
285
+
runs-on: ubuntu-latest
286
+
# this check needs to be in place to prevent a publish loop with auto and github actions
# the list of steps that the action will go through
289
+
steps:
290
+
- uses: actions/checkout@v2
291
+
- name: Prepare repository
292
+
run: git fetch --unshallow --tags
293
+
- name: Use Node.js 12.x
294
+
uses: actions/setup-node@v1
295
+
with:
296
+
node-version: 12.x
297
+
- name: Cache node modules
298
+
uses: actions/cache@v1
299
+
with:
300
+
path: node_modules
301
+
key: yarn-deps-${{ hashFiles('yarn.lock') }}
302
+
restore-keys: |
303
+
yarn-deps-${{ hashFiles('yarn.lock') }}
304
+
305
+
- name: Create Release
306
+
env:
307
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
308
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
309
+
run: |
310
+
yarn install --frozen-lockfile
311
+
yarn build
312
+
yarn release
313
+
```
314
+
315
+
Save and commit your changes to the remote repository.
316
+
317
+
Success! Now every time you merge a PR to master, it will automatically publish a new version, incrementing the version number as appropriate due to the labels you’ve added.
262
318
263
319
<div class="aside">We didn’t cover all of Auto’s many features and integrations that might be useful for growing design systems. Read the docs <a href="https://github.com/intuit/auto">here</a>.</div>
Now, let’s update the example app’s `.storybook/main.js` to import the design system components:
305
361
306
362
```javascript
363
+
// .storybook/main.js
364
+
307
365
module.exports= {
308
366
stories: [
309
367
'../src/**/*.stories.js',
@@ -320,6 +378,8 @@ module.exports = {
320
378
Also we can add a global decorator to a new `.storybook/preview.js` config file use the global styles defined by the design system. Make the following change to the file:
You’ll now be able to browse the design system components and docs while developing the example app. Showcasing the design system during feature development increases the likelihood that developers will reuse existing components instead of wasting time inventing their own.
340
400
341
-
Alternatively, you can browse your design system’s Storybook online if you deployed it to a web host earlier (see chapter 4).
401
+
Alternatively, you can browse your design system’s Storybook online if you deployed it to <ahref="https://www.learnstorybook.com/design-systems-for-developers/react/en/review/#publish-storybook">Chromatic </a> earlier (see chapter 4).
342
402
343
403
We’ll use the Avatar component from our design system in the example app’s UserItem component. UserItem should render information about a user including a name and profile photo.
344
404
@@ -347,12 +407,16 @@ Navigate to the UserItem.js component in your editor. Also, find UserItem in the
We'll add it to our addons list in `.storybook/main.js`:
45
45
46
46
```javascript
47
+
// .storybook/main.js
48
+
47
49
module.exports= {
48
50
stories: ['../src/**/*.stories.js'],
49
51
addons: [
@@ -75,6 +77,8 @@ So far we’ve made lots of progress with little effort. Yet, the documentation
75
77
Start by adding more metadata that explains what the component does. In `src/Avatar.stories.js`, add a subtitle that describes what the Avatar is used for:
76
78
77
79
```javascript
80
+
// src/Avatar.stories.js
81
+
78
82
exportdefault {
79
83
title:'Design System|Avatar',
80
84
@@ -88,6 +92,8 @@ export default {
88
92
Next add JSdoc to the Avatar component (in `src/components/Avatar.js`) that provides a description to be read:
89
93
90
94
```javascript
95
+
// src/components/Avatar.js
96
+
91
97
/**
92
98
- Use an avatar for attributing actions or content to specific users.
93
99
- The user's name should always be present when using Avatar – either printed beside the avatar or in a tooltip.
@@ -103,6 +109,8 @@ You should now see this:
103
109
Storybook Docs automatically generated the prop table that shows types and default values. That’s convenient, but it doesn’t mean Avatar is dummy-proof – several props can be misused. Add comments in your proptypes to render them in the auto-generated prop table.
104
110
105
111
```javascript
112
+
// src/components/Avatar.js
113
+
106
114
Avatar.propTypes= {
107
115
/**
108
116
Use the loading state to indicate that the data Avatar needs is still loading.
@@ -127,6 +135,8 @@ Avatar.propTypes = {
127
135
By default, every Avatar story is rendered in the docs. We can’t assume other developers know what each story represents. Write some descriptive text for the stories in `src/Avatar.stories.js`:
128
136
129
137
```javascript
138
+
// src/Avatar.stories.js
139
+
130
140
exportconstsizes= () => (
131
141
<div>
132
142
<Avatar
@@ -167,6 +177,8 @@ Markdown is a straightforward format for writing text. MDX allows you to use int
167
177
First, let’s take control of the Avatar doc generation from the default. Register MDX files in `.storybook/main.js` like so.
168
178
169
179
```javascript
180
+
// .storybook/main.js
181
+
170
182
module.exports= {
171
183
// automatically import all files ending in *.stories.js|mdx
172
184
stories: ['../src/**/*.stories.(js|mdx)'],
@@ -185,6 +197,8 @@ module.exports = {
185
197
Create a new `src/Avatar.stories.mdx` file and supply some details. We’ll remove the `Avatar.stories.js` file and recreate the stories in the mdx file:
186
198
187
199
```javascript
200
+
// src/Avatar.stories.mdx
201
+
188
202
import { Meta, Story } from'@storybook/addon-docs/blocks';
@@ -284,6 +298,8 @@ Storybook Docs come with “Doc Blocks”, readymade components like interactive
284
298
Let’s add the `Props` doc block, and wrap our initial story in a `Preview`
285
299
286
300
```javascript
301
+
// src/Avatar.stories.mdx
302
+
287
303
import { Meta, Story, Props, Preview } from '@storybook/addon-docs/blocks';
288
304
289
305
# …
@@ -308,7 +324,9 @@ Nice! We’re back to where we started, but now with full control over ordering
308
324
Customize Avatar’s docs with a note about use cases. This gives developers context about how to take advantage of this component. We can just add markdown as we would in any other markdown document:
309
325
310
326
```javascript
311
-
// As before
327
+
// src/Avatar.stories.mdx
328
+
329
+
// Same content as before
312
330
313
331
<Props of={Avatar} />
314
332
@@ -318,7 +336,7 @@ Avatar is used to represent a person or an organization. By default the avatar s
318
336
319
337
### Sizes
320
338
321
-
// As before
339
+
// Same content as before
322
340
323
341
```
324
342
@@ -331,6 +349,8 @@ Every design system comes with a cover page. Storybook Docs allows you to create
331
349
Create a new file `src/components/Intro.stories.mdx`:
332
350
333
351
```javascript
352
+
// src/components/Intro.stories.mdx
353
+
334
354
import { Meta } from '@storybook/addon-docs/blocks';
335
355
336
356
<Meta title="Design System|Introduction" />
@@ -349,7 +369,10 @@ This generates a new documentation-only page that is independent of the automate
349
369
To get it to appear first, we have to tell Storybook to load the Introduction file in `.storybook/main.js`:
350
370
351
371
```javascript
372
+
// .storybook/main.js
373
+
352
374
module.exports = {
375
+
// changes the load order of our stories. First loads the Intro page
353
376
// automatically import all files ending in *.stories.js|mdx
@@ -385,16 +408,9 @@ In a previous chapter, we published Storybook online for visual review. It’s e
385
408
}
386
409
```
387
410
388
-
Save and commit. We could change our Netlify publication to deploy the docs site, or use a second deployment system (such as [now.sh](https://zeit.co/home)) to deploy the docs site on every commit.
389
-
390
-
<!--
391
-
Create a second Netlify integration to run the docs build script:
Great. Every time you commit, you’ll now see two PR checks. One takes you to the published Storybook. The other takes you to the published Storybook Docs.
Running `build-storybook-docs` in your command line or continuous integration tool will output a static site in the "docs" configuration. Set up a static site deployment tool [Netlify](https://www.netlify.com/) or [Vercel](https://vercel.com/) to deploy the docs site on every commit.
398
414
399
415
<div class="aside">As your design system grows you may encounter organization-specific requirements that warrant custom tooling or even building your own static site using tools like Gatsby or Next. It’s easy to port markdown and MDX to other solutions.</div>
0 commit comments