Skip to content

Commit 0efeaa0

Browse files
committed
updated storybook
1 parent 669046a commit 0efeaa0

26 files changed

+1411
-36
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
BROWSER=none
2+
SKIP_PREFLIGHT_CHECK=true

.storybook/main.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
module.exports = {
2-
stories: ['../stories/*.js'],
3-
addons: ['@storybook/preset-create-react-app']
4-
}
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/preset-create-react-app"
10+
]
11+
}

.storybook/preview.js

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

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,31 @@
1212
},
1313
"scripts": {
1414
"analyze": "source-map-explorer 'build/static/js/*.js'",
15-
"storybook": "start-storybook -p 9001 -c .storybook",
15+
"storybook": "start-storybook -p 6006 -s public",
1616
"start": "concurrently \"yarn react-start\" \"wait-on http://localhost:3000/ && cross-env NODE_ENV=development yarn electron-start\"",
1717
"build": "yarn react-build && yarn build-main && copyfiles package.json build/ && yarn electron-build",
1818
"electron-start": "electron .",
1919
"electron-build": "electron-packager ./build --out=dist",
2020
"react-start": "craco start",
2121
"react-build": "craco build",
2222
"build-main": "webpack --config electron/webpack.config.js",
23-
"test": "craco test"
23+
"test": "craco test",
24+
"build-storybook": "build-storybook -s public"
2425
},
2526
"eslintConfig": {
2627
"extends": [
2728
"react-app",
2829
"react-app/jest"
30+
],
31+
"overrides": [
32+
{
33+
"files": [
34+
"**/*.stories.*"
35+
],
36+
"rules": {
37+
"import/no-anonymous-default-export": "off"
38+
}
39+
}
2940
]
3041
},
3142
"browserslist": [
@@ -38,6 +49,10 @@
3849
},
3950
"devDependencies": {
4051
"@babel/core": "^7.14.0",
52+
"@storybook/addon-actions": "^6.2.9",
53+
"@storybook/addon-essentials": "^6.2.9",
54+
"@storybook/addon-links": "^6.2.9",
55+
"@storybook/node-logger": "^6.2.9",
4156
"@storybook/preset-create-react-app": "^3.1.7",
4257
"@storybook/react": "^6.2.9",
4358
"@types/jest": "^26.0.23",

src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

src/stories/Button.stories.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { Story, Meta } from '@storybook/react';
3+
4+
import { Button, ButtonProps } from './Button';
5+
6+
export default {
7+
title: 'Example/Button',
8+
component: Button,
9+
argTypes: {
10+
backgroundColor: { control: 'color' },
11+
},
12+
} as Meta;
13+
14+
const Template: Story<ButtonProps> = (args) => <Button {...args} />;
15+
16+
export const Primary = Template.bind({});
17+
Primary.args = {
18+
primary: true,
19+
label: 'Button',
20+
};
21+
22+
export const Secondary = Template.bind({});
23+
Secondary.args = {
24+
label: 'Button',
25+
};
26+
27+
export const Large = Template.bind({});
28+
Large.args = {
29+
size: 'large',
30+
label: 'Button',
31+
};
32+
33+
export const Small = Template.bind({});
34+
Small.args = {
35+
size: 'small',
36+
label: 'Button',
37+
};

src/stories/Button.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import './button.css';
3+
4+
export interface ButtonProps {
5+
/**
6+
* Is this the principal call to action on the page?
7+
*/
8+
primary?: boolean;
9+
/**
10+
* What background color to use
11+
*/
12+
backgroundColor?: string;
13+
/**
14+
* How large should the button be?
15+
*/
16+
size?: 'small' | 'medium' | 'large';
17+
/**
18+
* Button contents
19+
*/
20+
label: string;
21+
/**
22+
* Optional click handler
23+
*/
24+
onClick?: () => void;
25+
}
26+
27+
/**
28+
* Primary UI component for user interaction
29+
*/
30+
export const Button: React.FC<ButtonProps> = ({
31+
primary = false,
32+
size = 'medium',
33+
backgroundColor,
34+
label,
35+
...props
36+
}) => {
37+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
38+
return (
39+
<button
40+
type="button"
41+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
42+
style={{ backgroundColor }}
43+
{...props}
44+
>
45+
{label}
46+
</button>
47+
);
48+
};

src/stories/Header.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import { Story, Meta } from '@storybook/react';
3+
4+
import { Header, HeaderProps } from './Header';
5+
6+
export default {
7+
title: 'Example/Header',
8+
component: Header,
9+
} as Meta;
10+
11+
const Template: Story<HeaderProps> = (args) => <Header {...args} />;
12+
13+
export const LoggedIn = Template.bind({});
14+
LoggedIn.args = {
15+
user: {},
16+
};
17+
18+
export const LoggedOut = Template.bind({});
19+
LoggedOut.args = {};

src/stories/Header.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
3+
import { Button } from './Button';
4+
import './header.css';
5+
6+
export interface HeaderProps {
7+
user?: {};
8+
onLogin: () => void;
9+
onLogout: () => void;
10+
onCreateAccount: () => void;
11+
}
12+
13+
export const Header: React.FC<HeaderProps> = ({ user, onLogin, onLogout, onCreateAccount }) => (
14+
<header>
15+
<div className="wrapper">
16+
<div>
17+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
18+
<g fill="none" fillRule="evenodd">
19+
<path
20+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
21+
fill="#FFF"
22+
/>
23+
<path
24+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
25+
fill="#555AB9"
26+
/>
27+
<path
28+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
29+
fill="#91BAF8"
30+
/>
31+
</g>
32+
</svg>
33+
<h1>Acme</h1>
34+
</div>
35+
<div>
36+
{user ? (
37+
<Button size="small" onClick={onLogout} label="Log out" />
38+
) : (
39+
<>
40+
<Button size="small" onClick={onLogin} label="Log in" />
41+
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
42+
</>
43+
)}
44+
</div>
45+
</div>
46+
</header>
47+
);

0 commit comments

Comments
 (0)