Skip to content

Commit 7cbdb84

Browse files
authored
Merge pull request #28 from kc3hack/revert-27-revert-15-goto/storybook-introduction
Revert "Revert "storybook導入""
2 parents 274d639 + d1c20c0 commit 7cbdb84

31 files changed

+10090
-2610
lines changed

Diff for: package-lock.json

+9,143-2,609
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/akane-next/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
43+
*storybook.log

Diff for: packages/akane-next/.storybook/main.ts

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

Diff for: packages/akane-next/.storybook/preview.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Preview } from "@storybook/react";
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;

Diff for: packages/akane-next/package.json

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"typecheck": "tsc",
1212
"test": "vitest run",
1313
"codegen:graphql": "graphql-codegen",
14-
"codegen:graphql:watch": "graphql-codegen --watch"
14+
"codegen:graphql:watch": "graphql-codegen --watch",
15+
"storybook": "storybook dev -p 6006",
16+
"build-storybook": "storybook build"
1517
},
1618
"dependencies": {
1719
"@apollo/client": "^3.13.1",
@@ -28,16 +30,31 @@
2830
"react-icons": "^5.4.0"
2931
},
3032
"devDependencies": {
33+
"@chromatic-com/storybook": "^3.2.4",
3134
"@eslint/eslintrc": "^3",
3235
"@graphql-codegen/cli": "^5.0.5",
3336
"@graphql-codegen/client-preset": "^4.6.2",
3437
"@parcel/watcher": "^2.5.1",
38+
"@storybook/addon-essentials": "^8.5.6",
39+
"@storybook/addon-interactions": "^8.5.6",
40+
"@storybook/addon-onboarding": "^8.5.6",
41+
"@storybook/blocks": "^8.5.6",
42+
"@storybook/nextjs": "^8.5.6",
43+
"@storybook/react": "^8.5.6",
44+
"@storybook/test": "^8.5.6",
3545
"@types/node": "^20",
3646
"@types/react": "^19",
3747
"@types/react-dom": "^19",
3848
"eslint": "^9",
3949
"eslint-config-next": "15.1.7",
50+
"eslint-plugin-storybook": "^0.11.3",
51+
"storybook": "^8.5.6",
4052
"typescript": "^5",
4153
"vitest": "^3.0.5"
54+
},
55+
"eslintConfig": {
56+
"extends": [
57+
"plugin:storybook/recommended"
58+
]
4259
}
4360
}

Diff for: packages/akane-next/src/stories/Button.stories.ts

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

Diff for: packages/akane-next/src/stories/Button.tsx

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

0 commit comments

Comments
 (0)