Skip to content

Commit a0813ad

Browse files
authored
install storybook and add stories for Dropdown component (#207)
1 parent 4d318af commit a0813ad

File tree

9 files changed

+190
-2
lines changed

9 files changed

+190
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ package-lock.json
3131
/coverage/
3232

3333
/lib/
34-
tsconfig.tsbuildinfo
34+
tsconfig.tsbuildinfo
35+
*storybook.log

.storybook/global.css

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* From https://www.joshwcomeau.com/css/custom-css-reset/ */
2+
3+
/* 1. Use a more-intuitive box-sizing model */
4+
*,
5+
*::before,
6+
*::after {
7+
box-sizing: border-box;
8+
}
9+
10+
/* 2. Remove default margin */
11+
* {
12+
margin: 0;
13+
}
14+
15+
/* 3. Enable keyword animations */
16+
@media (prefers-reduced-motion: no-preference) {
17+
html {
18+
interpolate-size: allow-keywords;
19+
}
20+
}
21+
22+
body {
23+
/* 4. Add accessible line-height */
24+
line-height: 1.5;
25+
/* 5. Improve text rendering */
26+
-webkit-font-smoothing: antialiased;
27+
}
28+
29+
/* 6. Improve media defaults */
30+
img,
31+
picture,
32+
video,
33+
canvas,
34+
svg {
35+
display: block;
36+
max-width: 100%;
37+
}
38+
39+
/* 7. Inherit fonts for form controls */
40+
input,
41+
button,
42+
textarea,
43+
select {
44+
font: inherit;
45+
}
46+
47+
/* 8. Avoid text overflows */
48+
p,
49+
h1,
50+
h2,
51+
h3,
52+
h4,
53+
h5,
54+
h6 {
55+
overflow-wrap: break-word;
56+
}
57+
58+
/* 9. Improve line wrapping */
59+
p {
60+
text-wrap: pretty;
61+
}
62+
h1,
63+
h2,
64+
h3,
65+
h4,
66+
h5,
67+
h6 {
68+
text-wrap: balance;
69+
}
70+
71+
/*
72+
10. Create a root stacking context
73+
*/
74+
#root,
75+
#__next {
76+
isolation: isolate;
77+
}
78+
79+
/* Storybook */
80+
81+
* {
82+
font-family: "Mulish", "Helvetica Neue", Helvetica, Arial, sans-serif;
83+
}

.storybook/main.ts

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

.storybook/preview-head.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<link rel="preconnect" href="https://fonts.gstatic.com" />
2+
<link
3+
href="https://fonts.googleapis.com/css2?family=Mulish:wght@300;600&display=swap"
4+
rel="stylesheet"
5+
/>

.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+
import './global.css'
3+
4+
const preview: Preview = {
5+
parameters: {
6+
controls: {
7+
matchers: {
8+
color: /(background|color)$/i,
9+
date: /Date$/i,
10+
},
11+
},
12+
},
13+
}
14+
15+
export default preview

eslint.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import javascript from '@eslint/js'
22
import react from 'eslint-plugin-react'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import storybook from 'eslint-plugin-storybook'
56
import globals from 'globals'
67
import typescript from 'typescript-eslint'
78

@@ -105,5 +106,11 @@ export default typescript.config(
105106
...globals.node,
106107
},
107108
},
109+
},
110+
{
111+
extends: [
112+
...storybook.configs['flat/recommended'],
113+
],
114+
files: ['**/*.stories.tsx'],
108115
}
109116
)

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"prepublishOnly": "npm run build",
4141
"serve": "node bin/cli.js",
4242
"preserve": "npm run build",
43+
"storybook": "storybook dev -p 6006",
4344
"test": "vitest run",
4445
"typecheck": "tsc --noEmit",
4546
"url": "run-p -l watch:ts watch:vite watch:url",
@@ -59,6 +60,12 @@
5960
},
6061
"devDependencies": {
6162
"@eslint/js": "9.23.0",
63+
"@storybook/addon-essentials": "8.6.12",
64+
"@storybook/addon-interactions": "8.6.12",
65+
"@storybook/blocks": "8.6.12",
66+
"@storybook/react": "8.6.12",
67+
"@storybook/react-vite": "8.6.12",
68+
"@storybook/test": "8.6.12",
6269
"@testing-library/react": "16.3.0",
6370
"@types/node": "22.14.0",
6471
"@types/react": "19.0.12",
@@ -69,13 +76,20 @@
6976
"eslint-plugin-react": "7.37.5",
7077
"eslint-plugin-react-hooks": "5.2.0",
7178
"eslint-plugin-react-refresh": "0.4.19",
79+
"eslint-plugin-storybook": "0.12.0",
7280
"globals": "16.0.0",
7381
"jsdom": "26.0.0",
7482
"nodemon": "3.1.9",
7583
"npm-run-all": "4.1.5",
84+
"storybook": "8.6.12",
7685
"typescript": "5.8.3",
7786
"typescript-eslint": "8.29.0",
7887
"vite": "6.2.5",
7988
"vitest": "3.1.1"
89+
},
90+
"eslintConfig": {
91+
"extends": [
92+
"plugin:storybook/recommended"
93+
]
8094
}
8195
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
import Dropdown from './Dropdown.js'
3+
4+
const meta: Meta<typeof Dropdown> = {
5+
component: Dropdown,
6+
}
7+
export default meta
8+
type Story = StoryObj<typeof Dropdown>;
9+
export const Default: Story = {
10+
args: {
11+
children: <>
12+
<button>Item 1</button>
13+
<button>Item 2</button>
14+
</>,
15+
},
16+
}
17+
18+
export const LeftAlign: Story = {
19+
args: {
20+
label: 'Menu',
21+
align: 'left',
22+
children: <>
23+
<button>Item 1</button>
24+
<button>Item 2</button>
25+
</>,
26+
},
27+
}
28+
29+
export const RightAlign: Story = {
30+
args: {
31+
label: 'Very long label for the menu',
32+
align: 'right',
33+
children: <>
34+
<button>Item 1</button>
35+
<button>Item 2</button>
36+
</>,
37+
},
38+
}

tsconfig.eslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "./tsconfig.json",
3-
"include": ["src", "test", "bin", "**/*.js", "**/*.ts", "**/*.tsx"]
3+
"include": ["src", "test", "bin", "**/*.js", "**/*.ts", "**/*.tsx", "**/.storybook/*.ts"]
44
}

0 commit comments

Comments
 (0)