Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94f71fe

Browse files
authored
refactor: Add storybook + initial story (#118)
This hooks up `storybook`, which the front-end team has enjoyed using in the v1 codebase - it makes it quick and easy to view and test components in isolation. The `<LoadingButton />` has a simple story added now, so if you run `yarn storybook`, you can preview it in various states: ![2022-01-31 19 24 24](https://user-images.githubusercontent.com/88213859/151908656-27dac0a8-9c6e-4353-ad25-3eafee979bd4.gif) This will be helpful as we bring more front-end devs to help build v2 out.
1 parent c65850b commit 94f71fe

File tree

10 files changed

+8146
-193
lines changed

10 files changed

+8146
-193
lines changed

.github/workflows/coder.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ jobs:
198198
- run: yarn build
199199
working-directory: site
200200

201+
- run: yarn storybook:build
202+
working-directory: site
203+
201204
- run: yarn test:coverage
202205
working-directory: site
203206

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log
1919
site/.eslintcache
2020
site/.next/
2121
site/node_modules/
22+
site/storybook-static/
2223
site/yarn-error.log
2324
coverage/
2425

site/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ node_modules
55
vendor
66
out
77
coverage
8-
.next
8+
.next
9+
storybook-static

site/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ yarn-error.log
1414
.next/
1515
coverage/
1616
out/
17+
storybook-static/

site/.storybook/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require("path")
2+
3+
module.exports = {
4+
stories: ["../**/*.stories.mdx", "../**/*.stories.@(js|jsx|ts|tsx)"],
5+
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
6+
babel: async (options) => ({
7+
...options,
8+
plugins: ["@babel/plugin-proposal-class-properties"],
9+
// any extra options you want to set
10+
}),
11+
webpackFinal: async (config) => {
12+
config.resolve.modules = [path.resolve(__dirname, ".."), "node_modules"]
13+
14+
return config
15+
},
16+
}

site/.storybook/preview.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import ThemeProvider from "@material-ui/styles/ThemeProvider"
2+
import { withThemes } from "@react-theming/storybook-addon"
3+
import { light, dark } from "../theme"
4+
import { addDecorator } from "node_modules/@storybook/react"
5+
6+
addDecorator(withThemes(ThemeProvider, [light, dark]))
7+
8+
export const parameters = {
9+
actions: {
10+
argTypesRegex: "^on[A-Z].*",
11+
argTypesRegex: "^handle[A-Z].*",
12+
},
13+
controls: {
14+
expanded: true,
15+
matchers: {
16+
color: /(background|color)$/i,
17+
date: /Date$/,
18+
},
19+
},
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Story } from "@storybook/react"
2+
import React from "react"
3+
import { LoadingButton, LoadingButtonProps } from "./LoadingButton"
4+
5+
export default {
6+
title: "Button/LoadingButton",
7+
component: LoadingButton,
8+
argTypes: {
9+
loading: { control: { type: "boolean" } },
10+
children: { control: "text", defaultValue: "Create workspace" },
11+
},
12+
}
13+
14+
const Template: Story<LoadingButtonProps> = (args) => <LoadingButton {...args} />
15+
16+
export const Loading = Template.bind({})
17+
Loading.args = {
18+
variant: "contained",
19+
loading: true,
20+
}
21+
22+
export const NotLoading = Template.bind({})
23+
NotLoading.args = {
24+
variant: "contained",
25+
loading: false,
26+
}

site/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ module.exports = {
4141
"!<rootDir>/next-env.d.ts",
4242
"!<rootDir>/next.config.js",
4343
"!<rootDir>/out/**/*.*",
44+
"!<rootDir>/storybook-static/**/*.*",
4445
],
4546
}

site/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
"format:write": "prettier --write '**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}' && sql-formatter -l postgresql ./database/query.sql -o ./database/query.sql",
1313
"lint": "jest --selectProjects lint",
1414
"lint:fix": "FIX=true yarn lint",
15+
"storybook": "start-storybook -p 6006 -s ./static",
16+
"storybook:build": "build-storybook",
1517
"test": "jest --selectProjects test",
1618
"test:coverage": "jest --selectProjects test --collectCoverage"
1719
},
1820
"devDependencies": {
1921
"@material-ui/core": "4.9.4",
2022
"@material-ui/icons": "4.5.1",
2123
"@material-ui/lab": "4.0.0-alpha.42",
24+
"@react-theming/storybook-addon": "1.1.3",
25+
"@storybook/addon-actions": "6.3.12",
26+
"@storybook/addon-essentials": "6.3.12",
27+
"@storybook/addon-links": "6.3.12",
28+
"@storybook/react": "6.3.12",
2229
"@testing-library/react": "12.1.2",
2330
"@types/express": "4.17.13",
2431
"@types/jest": "27.4.0",

0 commit comments

Comments
 (0)