Skip to content

Commit 809ea9c

Browse files
authored
Merge pull request #343 from chromaui/chore_reword_design_systems
2 parents 15b882a + d74f6d5 commit 809ea9c

File tree

83 files changed

+275
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+275
-182
lines changed

content/design-systems-for-developers/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ twitterShareText: "I’m learning about building design systems! They're great f
7979
Prettier
8080
</div>
8181
<div class="badge">
82-
CircleCI
82+
GitHub Actions
8383
</div>
8484
<div class="badge">
8585
ESLint

content/design-systems-for-developers/react/en/build.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,18 @@ Your Storybook should reload like this (notice that the font styles are a little
5555

5656
#### Add global styles
5757

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:
5959

6060
```javascript
61+
// src/shared/global.js
62+
6163
import { createGlobalStyle, css } from 'styled-components';
6264
import { color, typography } from './styles';
6365

6466
export const fontUrl = 'https://fonts.googleapis.com/css?family=Nunito+Sans:400,700,800,900';
6567

6668
export const bodyStyles = css`
67-
/* global styles */
69+
/* same as before */
6870
`;
6971

7072
export const GlobalStyle = createGlobalStyle`
@@ -77,6 +79,8 @@ export const GlobalStyle = createGlobalStyle`
7779
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`
7880

7981
```javascript
82+
// .storybook/preview.js
83+
8084
import React from 'react';
8185
import { addDecorator } from '@storybook/react';
8286
import { GlobalStyle } from '../src/shared/global';
@@ -116,6 +120,8 @@ The [actions addon](https://github.com/storybookjs/storybook/tree/next/addons/ac
116120
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:
117121

118122
```javascript
123+
// src/Button.js
124+
119125
import React from 'react';
120126
import styled from 'styled-components';
121127
import { action } from '@storybook/addon-actions';
@@ -145,6 +151,8 @@ yarn add --dev @storybook/addon-storysource
145151
Add the addon in `.storybook/main.js`:
146152

147153
```javascript
154+
//.storybook/main.js
155+
148156
module.exports = {
149157
stories: ['../src/**/*.stories.js'],
150158
addons: [
@@ -173,6 +181,8 @@ yarn add --dev @storybook/addon-knobs
173181
Add the addon in `.storybook/main.js`:
174182

175183
```javascript
184+
//.storybook/main.js
185+
176186
module.exports = {
177187
stories: ['../src/**/*.stories.js'],
178188
addons: [
@@ -188,6 +198,8 @@ module.exports = {
188198
Add a story that uses knobs in `src/Avatar.stories.js`:
189199

190200
```javascript
201+
//src/Avatar.stories.js
202+
191203
import React from 'react';
192204
import { withKnobs, select, boolean } from '@storybook/addon-knobs';
193205

@@ -219,6 +231,8 @@ We'll visit the Accessbility and Docs addons in later chapters.
219231
220232
## Learn how to automate maintenance
221233

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.
223237

224238
In chapter 4 we’ll learn how to set up continuous integration and auto-publish the design system online for collaboration.

content/design-systems-for-developers/react/en/distribute.md

+83-19
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Learn more at [Learn Storybook](https://learnstorybook.com).
4444
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:
4545

4646
```javascript
47+
//src/index.js
48+
4749
import * as styles from './shared/styles';
4850
import * as global from './shared/global';
4951
import * as animation from './shared/animation';
@@ -71,7 +73,7 @@ To build the package, we’ll add a script to `package.json` that builds our sou
7173
"scripts": {
7274
"build": "cross-env BABEL_ENV=production babel src -d dist",
7375
...
74-
}
76+
},
7577
"babel": {
7678
"presets": [
7779
"react-app"
@@ -84,7 +86,6 @@ We can now run `yarn build` to build our code into the `dist` directory -- we sh
8486

8587
```
8688
// ..
87-
storybook-static
8889
dist
8990
```
9091

@@ -154,7 +155,6 @@ NPM_TOKEN=<value you just got from npm>
154155
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:
155156

156157
```
157-
storybook-static
158158
dist
159159
.env
160160
```
@@ -229,7 +229,7 @@ Yay! We’ve successfully published our package to npm and created a release on
229229

230230
(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).
231231

232-
<h4>Set up scripts to use Auto</h4>
232+
#### Set up scripts to use Auto
233233

234234
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`:
235235

@@ -241,24 +241,80 @@ Let’s set up Auto to follow the same process when we want to publish the packa
241241
}
242242
```
243243

244-
Now, when we run `yarn release`, well 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.
245245

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:
257+
258+
![Empty GitHub secrets page](/design-systems-for-developers/github-empty-secrets-page.png)
259+
260+
Click the **New secret** button. Use `NPM_TOKEN` for the name and paste the token you got from npm earlier in this chapter.
261+
262+
![Filled GitHub secrets form](/design-systems-for-developers/github-secrets-form-filled.png)
256263

257-
We’ll also need to add an npm+GitHub token to your project’s Circle environment on the CircleCI website (https://circleci.com/gh/&lt;your-username&gt;/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.
258265

259-
![Setting environment variables on CircleCI](/design-systems-for-developers/circleci-set-env-vars.png)
266+
#### Automate releases with GitHub Actions
260267

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 <a href="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
287+
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
288+
# 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.
262318
263319
<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>
264320
@@ -304,6 +360,8 @@ yarn add <your-username>-learnstorybook-design-system
304360
Now, let’s update the example app’s `.storybook/main.js` to import the design system components:
305361

306362
```javascript
363+
// .storybook/main.js
364+
307365
module.exports = {
308366
stories: [
309367
'../src/**/*.stories.js',
@@ -320,6 +378,8 @@ module.exports = {
320378
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:
321379

322380
```javascript
381+
// .storybook/preview.js
382+
323383
import React from 'react';
324384
import { addDecorator } from '@storybook/react';
325385
import { global as designSystemGlobal } from '<your-username>-learnstorybook-design-system';
@@ -338,7 +398,7 @@ addDecorator(story => (
338398

339399
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.
340400

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 <a href="https://www.learnstorybook.com/design-systems-for-developers/react/en/review/#publish-storybook">Chromatic </a> earlier (see chapter 4).
342402

343403
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.
344404

@@ -347,12 +407,16 @@ Navigate to the UserItem.js component in your editor. Also, find UserItem in the
347407
Import the Avatar component.
348408

349409
```javascript
410+
// src/components/UserItem.js
411+
350412
import { Avatar } from '<your-username>-learnstorybook-design-system';
351413
```
352414

353415
We want to render the Avatar beside the username.
354416

355417
```javascript
418+
//src/components/UserItem.js
419+
356420
import React from 'react';
357421
import styled from 'styled-components';
358422
import { Avatar } from 'learnstorybook-design-system';

content/design-systems-for-developers/react/en/document.md

+27-11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ yarn add --dev @storybook/addon-docs
4444
We'll add it to our addons list in `.storybook/main.js`:
4545

4646
```javascript
47+
// .storybook/main.js
48+
4749
module.exports = {
4850
stories: ['../src/**/*.stories.js'],
4951
addons: [
@@ -75,6 +77,8 @@ So far we’ve made lots of progress with little effort. Yet, the documentation
7577
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:
7678

7779
```javascript
80+
// src/Avatar.stories.js
81+
7882
export default {
7983
title: 'Design System|Avatar',
8084

@@ -88,6 +92,8 @@ export default {
8892
Next add JSdoc to the Avatar component (in `src/components/Avatar.js`) that provides a description to be read:
8993

9094
```javascript
95+
// src/components/Avatar.js
96+
9197
/**
9298
- Use an avatar for attributing actions or content to specific users.
9399
- 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:
103109
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.
104110
105111
```javascript
112+
// src/components/Avatar.js
113+
106114
Avatar.propTypes = {
107115
/**
108116
Use the loading state to indicate that the data Avatar needs is still loading.
@@ -127,6 +135,8 @@ Avatar.propTypes = {
127135
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`:
128136
129137
```javascript
138+
// src/Avatar.stories.js
139+
130140
export const sizes = () => (
131141
<div>
132142
<Avatar
@@ -167,6 +177,8 @@ Markdown is a straightforward format for writing text. MDX allows you to use int
167177
First, let’s take control of the Avatar doc generation from the default. Register MDX files in `.storybook/main.js` like so.
168178
169179
```javascript
180+
// .storybook/main.js
181+
170182
module.exports = {
171183
// automatically import all files ending in *.stories.js|mdx
172184
stories: ['../src/**/*.stories.(js|mdx)'],
@@ -185,6 +197,8 @@ module.exports = {
185197
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:
186198
187199
```javascript
200+
// src/Avatar.stories.mdx
201+
188202
import { Meta, Story } from '@storybook/addon-docs/blocks';
189203
import { withKnobs, select, boolean } from '@storybook/addon-knobs';
190204

@@ -284,6 +298,8 @@ Storybook Docs come with “Doc Blocks”, readymade components like interactive
284298
Let’s add the `Props` doc block, and wrap our initial story in a `Preview`
285299
286300
```javascript
301+
// src/Avatar.stories.mdx
302+
287303
import { Meta, Story, Props, Preview } from '@storybook/addon-docs/blocks';
288304
289305
# …
@@ -308,7 +324,9 @@ Nice! We’re back to where we started, but now with full control over ordering
308324
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:
309325
310326
```javascript
311-
// As before
327+
// src/Avatar.stories.mdx
328+
329+
// Same content as before
312330
313331
<Props of={Avatar} />
314332
@@ -318,7 +336,7 @@ Avatar is used to represent a person or an organization. By default the avatar s
318336
319337
### Sizes
320338
321-
// As before
339+
// Same content as before
322340
323341
```
324342
@@ -331,6 +349,8 @@ Every design system comes with a cover page. Storybook Docs allows you to create
331349
Create a new file `src/components/Intro.stories.mdx`:
332350
333351
```javascript
352+
// src/components/Intro.stories.mdx
353+
334354
import { Meta } from '@storybook/addon-docs/blocks';
335355
336356
<Meta title="Design System|Introduction" />
@@ -349,7 +369,10 @@ This generates a new documentation-only page that is independent of the automate
349369
To get it to appear first, we have to tell Storybook to load the Introduction file in `.storybook/main.js`:
350370
351371
```javascript
372+
// .storybook/main.js
373+
352374
module.exports = {
375+
// changes the load order of our stories. First loads the Intro page
353376
// automatically import all files ending in *.stories.js|mdx
354377
stories: ['../src/components/Intro.stories.mdx', '../src/**/*.stories.(js|mdx)'],
355378
addons: [
@@ -385,16 +408,9 @@ In a previous chapter, we published Storybook online for visual review. It’s e
385408
}
386409
```
387410
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:
392-
393-
![alt_text](/design-systems-for-developers/Feedback-wanted55.png)
394-
395-
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.
411+
Save and commit.
396412
397-
![alt_text](/design-systems-for-developers/Feedback-wanted56.png) -->
413+
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.
398414
399415
<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>
400416

0 commit comments

Comments
 (0)