Skip to content

Commit 33bf8eb

Browse files
authored
storybook introduction (#64)
1 parent bf39414 commit 33bf8eb

32 files changed

+1267
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ node_modules
99
# Build Output
1010
dist
1111
*.tsbuildinfo
12+
13+
*storybook.log
14+
storybook-static

bun.lock

Lines changed: 384 additions & 1 deletion
Large diffs are not rendered by default.

docs/developer_readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ Userのデータは`User`クラスを使用して扱います。Userのデータ
5959
"source.organizeImports.biome": "always"
6060
}
6161
}
62-
```
62+
```
63+
64+
## Storybookの使用
65+
```bash
66+
bun run storybook
67+
```
68+
- localhost:6006にStorybookが立ち上がるので、そこでUIを確認してください。

packages/web/.storybook/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { dirname, join } from "node:path";
2+
import type { StorybookConfig } from "@storybook/react-vite";
3+
4+
/**
5+
* This function is used to resolve the absolute path of a package.
6+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
7+
*/
8+
function getAbsolutePath(value: string): string {
9+
return dirname(require.resolve(join(value, "package.json")));
10+
}
11+
const config: StorybookConfig = {
12+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
13+
addons: [
14+
getAbsolutePath("@storybook/addon-links"),
15+
getAbsolutePath("@storybook/addon-essentials"),
16+
getAbsolutePath("@storybook/addon-onboarding"),
17+
getAbsolutePath("@storybook/addon-interactions"),
18+
],
19+
framework: {
20+
name: getAbsolutePath("@storybook/react-vite"),
21+
options: {},
22+
},
23+
};
24+
export default config;

packages/web/.storybook/preview.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Preview } from "@storybook/react-vite";
2+
3+
const preview: Preview = {
4+
parameters: {
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/i,
9+
},
10+
},
11+
},
12+
};
13+
14+
export default preview;

packages/web/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"dev": "vite",
88
"build": "tsc && vite build",
99
"preview": "vite preview",
10-
"check": "tsc --noEmit"
10+
"check": "tsc --noEmit",
11+
"storybook": "storybook dev -p 6006",
12+
"build-storybook": "storybook build"
1113
},
1214
"dependencies": {
1315
"@elysiajs/eden": "^1.3.2",
@@ -22,12 +24,21 @@
2224
"react-router-dom": "^7.1.1"
2325
},
2426
"devDependencies": {
27+
"@storybook/addon-essentials": "^8.6.14",
28+
"@storybook/addon-interactions": "^8.6.14",
29+
"@storybook/addon-links": "^8.6.14",
30+
"@storybook/addon-onboarding": "^8.6.14",
31+
"@storybook/blocks": "^8.6.14",
32+
"@storybook/react": "^8.6.14",
33+
"@storybook/react-vite": "^8.6.14",
34+
"@storybook/test": "^8.6.14",
2535
"@tailwindcss/postcss": "^4.1.11",
2636
"@types/react": "^19.0.5",
2737
"@types/react-dom": "^19.0.5",
2838
"@vitejs/plugin-react": "^4.3.4",
2939
"daisyui": "^5.0.46",
3040
"postcss": "^8.5.6",
41+
"storybook": "^8.0.9",
3142
"tailwindcss": "^4.1.11",
3243
"typescript": "^5.8.3",
3344
"vite": "^6.0.7"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { fn } from "@storybook/test";
4+
5+
import { Button } from "./Button.tsx";
6+
7+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
8+
const meta = {
9+
title: "Example/Button",
10+
component: Button,
11+
parameters: {
12+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
13+
layout: "centered",
14+
},
15+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16+
tags: ["autodocs"],
17+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
18+
argTypes: {
19+
backgroundColor: { control: "color" },
20+
},
21+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
22+
args: { onClick: fn() },
23+
} satisfies Meta<typeof Button>;
24+
25+
export default meta;
26+
type Story = StoryObj<typeof meta>;
27+
28+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
29+
export const Primary: Story = {
30+
args: {
31+
primary: true,
32+
label: "Button",
33+
},
34+
};
35+
36+
export const Secondary: Story = {
37+
args: {
38+
label: "Button",
39+
},
40+
};
41+
42+
export const Large: Story = {
43+
args: {
44+
size: "large",
45+
label: "Button",
46+
},
47+
};
48+
49+
export const Small: Story = {
50+
args: {
51+
size: "small",
52+
label: "Button",
53+
},
54+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import "./button.css";
2+
3+
export interface ButtonProps {
4+
/** Is this the principal call to action on the page? */
5+
primary?: boolean;
6+
/** What background color to use */
7+
backgroundColor?: string;
8+
/** How large should the button be? */
9+
size?: "small" | "medium" | "large";
10+
/** Button contents */
11+
label: string;
12+
/** Optional click handler */
13+
onClick?: () => void;
14+
}
15+
16+
/** Primary UI component for user interaction */
17+
export const Button = ({
18+
primary = false,
19+
size = "medium",
20+
backgroundColor,
21+
label,
22+
...props
23+
}: ButtonProps) => {
24+
const mode = primary
25+
? "storybook-button--primary"
26+
: "storybook-button--secondary";
27+
return (
28+
<button
29+
type="button"
30+
className={["storybook-button", `storybook-button--${size}`, mode].join(
31+
" ",
32+
)}
33+
style={{ backgroundColor }}
34+
{...props}
35+
>
36+
{label}
37+
</button>
38+
);
39+
};

0 commit comments

Comments
 (0)