Skip to content

Commit

Permalink
Create a storybook with callout component (github#20902)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
heiskr authored Aug 17, 2021
1 parent 8ded5d9 commit ae7b652
Show file tree
Hide file tree
Showing 15 changed files with 38,868 additions and 17,100 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dist/
storybook/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coverage/
/data/early-access
.next
.eslintcache
/storybook/

# blc: broken link checker
blc_output.log
Expand Down
9 changes: 9 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('path')

module.exports = {
stories: [
'../components/stories/**/*.stories.mdx',
'../components/stories/**/*.stories.@(js|jsx|ts|tsx)',
],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/preset-scss'],
}
11 changes: 11 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../stylesheets/index.scss'

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ COPY content/index.md ./content/index.md
COPY next.config.js ./next.config.js
COPY tsconfig.json ./tsconfig.json
COPY next-env.d.ts ./next-env.d.ts
COPY .storybook ./.storybook

RUN npx tsc --noEmit

Expand Down
30 changes: 30 additions & 0 deletions components/stories/Callout.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { ComponentStory, ComponentMeta } from '@storybook/react'

// @ts-ignore
import { Callout } from '../ui/Callout.tsx'

export default {
title: 'UI/Callout',
component: Callout,
} as ComponentMeta<typeof Callout>

const Template: ComponentStory<typeof Callout> = (args) => <Callout {...args} />

export const Success = Template.bind({})
Success.args = {
variant: 'success',
children: <p>Hello!</p>,
}

export const Info = Template.bind({})
Info.args = {
variant: 'info',
children: <p>Hello!</p>,
}

export const Warning = Template.bind({})
Warning.args = {
variant: 'warning',
children: <p>Hello!</p>,
}
12 changes: 12 additions & 0 deletions components/stories/Introduction.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Meta } from '@storybook/addon-docs';

<Meta title="Example/Introduction" />

# Welcome to Storybook

Storybook helps you build UI components in isolation from your app's business logic, data, and context.
That makes it easy to develop hard-to-reach states. Save these UI states as **stories** to revisit during development, testing, or QA.

Browse example stories now by navigating to them in the sidebar.
View their code in the `src/stories` directory to learn how they work.
We recommend building UIs with a [**component-driven**](https://componentdriven.org) process starting with atomic components and ending with pages.
2 changes: 1 addition & 1 deletion contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ When you're ready to stop your local server, type <kbd>CTRL</kbd><kbd>c</kbd> in

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.
- `npm ci` does a clean install of dependencies, without updating the `package-lock.json` file
- `npm run build` creates static assets, such as the `dist/index.js` and `dist/index.css` files
- `npm run build` creates static assets, such as JavaScript and CSS files

### Using GitHub Codespaces

Expand Down
5 changes: 5 additions & 0 deletions middleware/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,10 @@ export default function csp(req, res, next) {
csp.directives.scriptSrc.push("'unsafe-inline'")
}

if (req.path.startsWith('/storybook')) {
csp.directives.scriptSrc.push("'unsafe-eval'", "'unsafe-inline'")
csp.directives.frameSrc.push("'self'")
}

return contentSecurityPolicy(csp)(req, res, next)
}
9 changes: 5 additions & 4 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,20 @@ export default function (app) {

// *** Rendering, 2xx responses ***
// I largely ordered these by use frequency
// archivedEnterpriseVersionsAssets must come before static/assets
app.use(
asyncMiddleware(
instrument(archivedEnterpriseVersionsAssets, './archived-enterprise-versions-assets')
)
) // Must come before static/assets
)
app.use(
'/dist',
express.static('dist', {
'/storybook',
express.static('storybook', {
index: false,
etag: false,
immutable: true,
lastModified: false,
maxAge: '28 days', // Could be infinite given our fingerprinting
maxAge: '1 day', // Relatively short in case we update index.html
})
)
app.use(
Expand Down
4 changes: 1 addition & 3 deletions nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"ext": "js,json,yml,md,html,scss",
"ignore": [
"assets",
"scripts",
"script",
"translations",
"dist",
"javascripts",
"stylesheets",
"tests"
]
Expand Down
Loading

0 comments on commit ae7b652

Please sign in to comment.