Skip to content

Commit 73fd725

Browse files
committed
Initialize storybook
1 parent 6a7f736 commit 73fd725

30 files changed

+982
-8
lines changed

.eslintrc.json

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@
55
"jest": true,
66
"es6": true
77
},
8-
"extends": ["eslint:recommended", "next", "prettier"],
9-
"plugins": ["eslint-plugin-prettier", "unused-imports"],
10-
"ignorePatterns": ["node_modules/", ".next/"],
8+
"extends": [
9+
"eslint:recommended",
10+
"next",
11+
"prettier",
12+
"plugin:storybook/recommended"
13+
],
14+
"plugins": [
15+
"eslint-plugin-prettier",
16+
"unused-imports"
17+
],
18+
"ignorePatterns": [
19+
"node_modules/",
20+
".next/"
21+
],
1122
"settings": {
1223
"react": {
1324
"pragma": "React",
@@ -34,7 +45,10 @@
3445
"flatTernaryExpressions": true
3546
}
3647
],
37-
"linebreak-style": ["error", "unix"],
48+
"linebreak-style": [
49+
"error",
50+
"unix"
51+
],
3852
"quotes": [
3953
"error",
4054
"single",
@@ -43,7 +57,10 @@
4357
"allowTemplateLiterals": false
4458
}
4559
],
46-
"semi": ["error", "never"],
60+
"semi": [
61+
"error",
62+
"never"
63+
],
4764
"react/prop-types": 0,
4865
"react/no-unknown-property": 0,
4966
"no-mixed-spaces-and-tabs": 0,

.storybook/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { StorybookConfig } from '@storybook/nextjs'
2+
3+
const config: StorybookConfig = {
4+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5+
addons: [
6+
'@storybook/addon-links',
7+
'@storybook/addon-essentials',
8+
'@storybook/addon-onboarding',
9+
'@storybook/addon-interactions',
10+
],
11+
framework: {
12+
name: '@storybook/nextjs',
13+
options: {},
14+
},
15+
docs: {
16+
autodocs: 'tag',
17+
},
18+
}
19+
export default config

.storybook/preview.ts

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ Add your mongoDB uri in env file.
160160

161161
## Show support
162162

163-
Give a ⭐️ if this project helped you!
163+
Give a ⭐️ if you like this project!

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-typescript-redux-starter",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"bin": "./bin/cli.js",
55
"scripts": {
66
"dev": "next dev -p 3050",
@@ -22,7 +22,9 @@
2222
"e2e": "start-server-and-test dev http://localhost:3050 \"cypress open --e2e\"",
2323
"e2e:headless": "start-server-and-test dev http://localhost:3050 \"cypress run --e2e\"",
2424
"e2e:component": "cypress open --component",
25-
"e2e:component:headless": "cypress run --component"
25+
"e2e:component:headless": "cypress run --component",
26+
"storybook": "storybook dev -p 6006",
27+
"build-storybook": "storybook build"
2628
},
2729
"dependencies": {
2830
"@hookform/resolvers": "^3.3.2",
@@ -45,6 +47,14 @@
4547
"@emotion/react": "^11.11.1",
4648
"@emotion/styled": "^11.11.0",
4749
"@next/bundle-analyzer": "^13.5.4",
50+
"@storybook/addon-essentials": "^7.5.3",
51+
"@storybook/addon-interactions": "^7.5.3",
52+
"@storybook/addon-links": "^7.5.3",
53+
"@storybook/addon-onboarding": "^1.0.8",
54+
"@storybook/blocks": "^7.5.3",
55+
"@storybook/nextjs": "^7.5.3",
56+
"@storybook/react": "^7.5.3",
57+
"@storybook/testing-library": "^0.2.2",
4858
"@tailwindcss/typography": "^0.5.10",
4959
"@testing-library/jest-dom": "^6.1.4",
5060
"@testing-library/react": "^14.0.0",
@@ -63,6 +73,7 @@
6373
"eslint-config-next": "13.5.4",
6474
"eslint-config-prettier": "^9.0.0",
6575
"eslint-plugin-prettier": "^5.0.1",
76+
"eslint-plugin-storybook": "^0.6.15",
6677
"eslint-plugin-unused-imports": "^3.0.0",
6778
"husky": "^8.0.3",
6879
"jest": "^29.7.0",
@@ -72,6 +83,7 @@
7283
"prettier": "^3.0.3",
7384
"redux-logger": "^3.0.6",
7485
"start-server-and-test": "^2.0.2",
86+
"storybook": "^7.5.3",
7587
"tailwindcss": "^3.3.3",
7688
"typescript": "^5"
7789
},

src/stories/Button.stories.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { Button } from './Button';
4+
5+
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
6+
const meta = {
7+
title: 'Example/Button',
8+
component: Button,
9+
parameters: {
10+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
11+
layout: 'centered',
12+
},
13+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
14+
tags: ['autodocs'],
15+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
16+
argTypes: {
17+
backgroundColor: { control: 'color' },
18+
},
19+
} satisfies Meta<typeof Button>;
20+
21+
export default meta;
22+
type Story = StoryObj<typeof meta>;
23+
24+
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
25+
export const Primary: Story = {
26+
args: {
27+
primary: true,
28+
label: 'Button',
29+
},
30+
};
31+
32+
export const Secondary: Story = {
33+
args: {
34+
label: 'Button',
35+
},
36+
};
37+
38+
export const Large: Story = {
39+
args: {
40+
size: 'large',
41+
label: 'Button',
42+
},
43+
};
44+
45+
export const Small: Story = {
46+
args: {
47+
size: 'small',
48+
label: 'Button',
49+
},
50+
};
51+
52+
53+
export const Warning: Story = {
54+
args: {
55+
primary: true,
56+
label: 'Delete now',
57+
backgroundColor: 'red',
58+
}
59+
};

src/stories/Button.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import './button.css';
3+
4+
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 = ({
31+
primary = false,
32+
size = 'medium',
33+
backgroundColor,
34+
label,
35+
...props
36+
}: ButtonProps) => {
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+
{...props}
43+
>
44+
{label}
45+
<style jsx>{`
46+
button {
47+
background-color: ${backgroundColor};
48+
}
49+
`}</style>
50+
</button>
51+
);
52+
};

0 commit comments

Comments
 (0)