Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae7b652

Browse files
authoredAug 17, 2021
Create a storybook with callout component (github#20902)
* Create a storybook with callout component * Add to dist/storybook * Remove references to dist dir, storybook takes place * Update Callout.stories.tsx * Update Dockerfile * Update Dockerfile
1 parent 8ded5d9 commit ae7b652

File tree

15 files changed

+38868
-17100
lines changed

15 files changed

+38868
-17100
lines changed
 

‎.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dist/
1+
storybook/

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ coverage/
1010
/data/early-access
1111
.next
1212
.eslintcache
13+
/storybook/
1314

1415
# blc: broken link checker
1516
blc_output.log

‎.storybook/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
stories: [
5+
'../components/stories/**/*.stories.mdx',
6+
'../components/stories/**/*.stories.@(js|jsx|ts|tsx)',
7+
],
8+
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/preset-scss'],
9+
}

‎.storybook/preview.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../stylesheets/index.scss'
2+
3+
export const parameters = {
4+
actions: { argTypesRegex: '^on[A-Z].*' },
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/,
9+
},
10+
},
11+
}

‎Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ COPY content/index.md ./content/index.md
4848
COPY next.config.js ./next.config.js
4949
COPY tsconfig.json ./tsconfig.json
5050
COPY next-env.d.ts ./next-env.d.ts
51+
COPY .storybook ./.storybook
5152

5253
RUN npx tsc --noEmit
5354

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { ComponentStory, ComponentMeta } from '@storybook/react'
3+
4+
// @ts-ignore
5+
import { Callout } from '../ui/Callout.tsx'
6+
7+
export default {
8+
title: 'UI/Callout',
9+
component: Callout,
10+
} as ComponentMeta<typeof Callout>
11+
12+
const Template: ComponentStory<typeof Callout> = (args) => <Callout {...args} />
13+
14+
export const Success = Template.bind({})
15+
Success.args = {
16+
variant: 'success',
17+
children: <p>Hello!</p>,
18+
}
19+
20+
export const Info = Template.bind({})
21+
Info.args = {
22+
variant: 'info',
23+
children: <p>Hello!</p>,
24+
}
25+
26+
export const Warning = Template.bind({})
27+
Warning.args = {
28+
variant: 'warning',
29+
children: <p>Hello!</p>,
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Meta } from '@storybook/addon-docs';
2+
3+
<Meta title="Example/Introduction" />
4+
5+
# Welcome to Storybook
6+
7+
Storybook helps you build UI components in isolation from your app's business logic, data, and context.
8+
That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA.
9+
10+
Browse example stories now by navigating to them in the sidebar.
11+
View their code in the `src/stories` directory to learn how they work.
12+
We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages.

‎contributing/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ When you're ready to stop your local server, type <kbd>CTRL</kbd><kbd>c</kbd> in
2828

2929
Note that `npm ci` and `npm run build` are steps that should typically only need to be run once each time you pull the latest for a branch.
3030
- `npm ci` does a clean install of dependencies, without updating the `package-lock.json` file
31-
- `npm run build` creates static assets, such as the `dist/index.js` and `dist/index.css` files
31+
- `npm run build` creates static assets, such as JavaScript and CSS files
3232

3333
### Using GitHub Codespaces
3434

‎middleware/csp.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,10 @@ export default function csp(req, res, next) {
7070
csp.directives.scriptSrc.push("'unsafe-inline'")
7171
}
7272

73+
if (req.path.startsWith('/storybook')) {
74+
csp.directives.scriptSrc.push("'unsafe-eval'", "'unsafe-inline'")
75+
csp.directives.frameSrc.push("'self'")
76+
}
77+
7378
return contentSecurityPolicy(csp)(req, res, next)
7479
}

‎middleware/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,20 @@ export default function (app) {
137137

138138
// *** Rendering, 2xx responses ***
139139
// I largely ordered these by use frequency
140+
// archivedEnterpriseVersionsAssets must come before static/assets
140141
app.use(
141142
asyncMiddleware(
142143
instrument(archivedEnterpriseVersionsAssets, './archived-enterprise-versions-assets')
143144
)
144-
) // Must come before static/assets
145+
)
145146
app.use(
146-
'/dist',
147-
express.static('dist', {
147+
'/storybook',
148+
express.static('storybook', {
148149
index: false,
149150
etag: false,
150151
immutable: true,
151152
lastModified: false,
152-
maxAge: '28 days', // Could be infinite given our fingerprinting
153+
maxAge: '1 day', // Relatively short in case we update index.html
153154
})
154155
)
155156
app.use(

‎nodemon.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"ext": "js,json,yml,md,html,scss",
33
"ignore": [
44
"assets",
5-
"scripts",
5+
"script",
66
"translations",
7-
"dist",
8-
"javascripts",
97
"stylesheets",
108
"tests"
119
]

‎package-lock.json

Lines changed: 38779 additions & 17082 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
"@graphql-tools/load": "^7.0.1",
104104
"@jest/globals": "^27.0.6",
105105
"@octokit/rest": "^18.7.1",
106+
"@storybook/addon-actions": "^6.3.7",
107+
"@storybook/addon-essentials": "^6.3.7",
108+
"@storybook/addon-links": "^6.3.7",
109+
"@storybook/preset-scss": "^1.0.3",
110+
"@storybook/react": "^6.3.7",
106111
"@types/github-slugger": "^1.3.0",
107112
"@types/imurmurhash": "^0.1.1",
108113
"@types/js-cookie": "^2.2.7",
@@ -114,6 +119,7 @@
114119
"@typescript-eslint/parser": "^4.28.5",
115120
"async": "^3.2.0",
116121
"await-sleep": "0.0.1",
122+
"babel-loader": "^8.2.2",
117123
"babel-plugin-styled-components": "^1.13.2",
118124
"babel-preset-env": "^1.7.0",
119125
"chalk": "^4.1.1",
@@ -160,6 +166,7 @@
160166
"rimraf": "^3.0.2",
161167
"robots-parser": "^2.3.0",
162168
"sass": "^1.36.0",
169+
"sass-loader": "^10.2.0",
163170
"start-server-and-test": "^1.13.1",
164171
"strip-ansi": "^7.0.0",
165172
"supertest": "^6.1.4",
@@ -186,7 +193,8 @@
186193
"browser-test": "start-server-and-test browser-test-server 4001 browser-test-tests",
187194
"browser-test-server": "cross-env NODE_ENV=production WEB_CONCURRENCY=1 PORT=4001 node server.mjs",
188195
"browser-test-tests": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules jest tests/browser/browser.js",
189-
"build": "next build",
196+
"build": "next build && npm run build-storybook",
197+
"build-storybook": "build-storybook -o ./storybook",
190198
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon --inspect server.mjs",
191199
"dev": "npm start",
192200
"heroku-postbuild": "node script/early-access/clone-for-build.js && npm run build",
@@ -204,6 +212,7 @@
204212
"rest-dev": "script/rest/update-files.js && npm run dev",
205213
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs",
206214
"start-all-languages": "cross-env NODE_ENV=development nodemon server.mjs",
215+
"storybook": "start-storybook -p 6006",
207216
"sync-search": "start-server-and-test sync-search-server 4002 sync-search-indices",
208217
"sync-search-dry-run": "cross-env DRY_RUN=1 npm run sync-search",
209218
"sync-search-ghes-release": "cross-env GHES_RELEASE=1 start-server-and-test sync-search-server 4002 sync-search-indices",

‎stylesheets/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
This website uses a Sass preprocessor, and gets most of its styles from GitHub's
44
[Primer](https://primer.style) design system.
55

6-
All styles come from:
7-
8-
```html
9-
<link rel="stylesheet" href="/dist/index.css">
10-
```
11-
12-
`index.css` is a compiled version of `index.scss`, where all imported scss files are declared.
6+
All styles come from imports in our Next.js compnents (pages, components).
137

148
In general, we use Primer's [utility classes](https://styleguide.github.com/primer/utilities/)
159
as much as we can, and avoid writing custom styles whenever possible.

‎tests/meta/repository-references.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('check if a GitHub-owned private repository is referenced', () => {
5353
'.github/workflows/sync-search-indices.yml',
5454
'.next',
5555
'contributing/search.md',
56-
'dist',
5756
'node_modules',
5857
'translations',
5958
'lib/rest/**/*.json',
@@ -72,6 +71,7 @@ describe('check if a GitHub-owned private repository is referenced', () => {
7271
'**/*.woff',
7372
'script/deploy',
7473
'script/README.md',
74+
'storybook',
7575
],
7676
})
7777

0 commit comments

Comments
 (0)
Please sign in to comment.