Skip to content

Commit 82c22f1

Browse files
committed
feat: 버튼 storybook 추가
1 parent 2c3b7ae commit 82c22f1

File tree

8 files changed

+113
-26
lines changed

8 files changed

+113
-26
lines changed

.storybook/preview.module.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@
1010
.Story {
1111
height: 100%;
1212
padding: 2.5rem;
13-
background-color: gray;
13+
background-color: white;
14+
color: black;
15+
}
16+
17+
.InverseStory {
18+
height: 100%;
19+
padding: 2.5rem;
20+
background-color: black;
21+
color: white;
1422
}

.storybook/preview.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const preview: Preview = {
1818
<div className={styles.Story}>
1919
<Story />
2020
</div>
21+
22+
<div className={styles.InverseStory}>
23+
<Story />
24+
</div>
2125
</div>
2226
),
2327
],

src/components/ui/Button/Button.module.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@
1919
@include buttonSecondary;
2020
}
2121
}
22+
23+
.ButtonStory {
24+
display: flex;
25+
flex-direction: column;
26+
gap: 1rem;
27+
28+
.Wrapper {
29+
display: flex;
30+
gap: 1rem;
31+
justify-content: center;
32+
width: 300px;
33+
}
34+
35+
.Text {
36+
font-size: 1.125rem;
37+
width: 120px;
38+
}
39+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Button from "@/components/ui/Button/Button";
2+
import styles from "@/components/ui/Button/Button.module.scss";
3+
import type { ButtonProps } from "@/components/ui/Button/Button.types";
4+
5+
import type { Meta, StoryObj } from "@storybook/react";
6+
7+
const meta: Meta<typeof Button> = {
8+
title: "Example/Button",
9+
component: Button,
10+
parameters: {
11+
layout: "centered",
12+
},
13+
tags: ["!autodocs"],
14+
};
15+
16+
export default meta;
17+
18+
export const Primary: StoryObj<ButtonProps> = {
19+
args: {
20+
text: "정보가 맞아요",
21+
disabled: false,
22+
variant: "primary",
23+
},
24+
};
25+
26+
export const VariantProps: StoryObj<typeof Button> = {
27+
render: () => (
28+
<div className={styles.ButtonStory}>
29+
<div className={styles.Wrapper}>
30+
<p className={styles.Text}>primary</p>
31+
<Button variant="primary" text="정보가 맞아요" />
32+
</div>
33+
<div className={styles.Wrapper}>
34+
<p className={styles.Text}>secondary</p>
35+
<Button variant="secondary" text="정보가 맞아요" />
36+
</div>
37+
<div className={styles.Wrapper}>
38+
<p className={styles.Text}>disabled</p>
39+
<Button variant="disabled" text="정보가 맞아요" />
40+
</div>
41+
</div>
42+
),
43+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.IconStory {
2+
display: flex;
3+
align-items: center;
4+
gap: 4rem;
5+
6+
.Wrapper {
7+
display: flex;
8+
flex-direction: column;
9+
align-items: center;
10+
gap: 1rem;
11+
12+
.InnerWrapper {
13+
width: 1.5rem;
14+
height: 1.5rem;
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
}
19+
}
20+
}

src/components/ui/Icon/Icon.stories.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Icon from "@/components/ui/Icon/Icon";
22
import { ICONS } from "@/components/ui/Icon/Icon";
3-
import type { IconNameType } from "@/components/ui/Icon/Icon";
3+
import type { IconNameType, IconProps } from "@/components/ui/Icon/Icon";
4+
import styles from "@/components/ui/Icon/Icon.module.scss";
45

56
import type { Meta, StoryObj } from "@storybook/react";
67

@@ -10,34 +11,23 @@ const meta: Meta<typeof Icon> = {
1011
parameters: {
1112
layout: "centered",
1213
},
13-
argTypes: {
14-
name: {
15-
control: {
16-
type: "select",
17-
options: ["camera", "close", "gallery", "leftArrow", "paste", "plus"],
18-
},
19-
},
20-
},
14+
tags: ["!autodocs"],
2115
};
2216

2317
export default meta;
2418

25-
export const AllIcons: StoryObj<typeof Icon> = {
19+
export const Primary: StoryObj<IconProps> = {
20+
args: {
21+
name: "camera",
22+
},
23+
};
24+
25+
export const AllIcons: StoryObj<IconProps> = {
2626
render: () => (
27-
<div style={{ display: "flex", alignItems: "center", gap: "4rem" }}>
27+
<div className={styles.IconStory}>
2828
{(Object.keys(ICONS) as IconNameType[]).map((iconName) => (
29-
<div
30-
style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: "1rem" }}
31-
>
32-
<div
33-
style={{
34-
width: "1.5rem",
35-
height: "1.5rem",
36-
display: "flex",
37-
justifyContent: "center",
38-
alignItems: "center",
39-
}}
40-
>
29+
<div className={styles.Wrapper}>
30+
<div className={styles.InnerWrapper}>
4131
<Icon name={iconName} />
4232
</div>
4333
<p>{iconName}</p>

src/components/ui/Icon/Icon.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import PlusIcon from "@/assets/svg/ic-plus.svg?react";
77

88
export type IconNameType = "camera" | "close" | "gallery" | "leftArrow" | "paste" | "plus";
99

10+
export interface IconProps {
11+
name: IconNameType;
12+
}
13+
1014
export const ICONS = {
1115
camera: CameraIcon,
1216
close: CloseIcon,
@@ -17,7 +21,7 @@ export const ICONS = {
1721
};
1822

1923
// 추후 사이즈, 컬러등 추가 가능
20-
const Icon = ({ name }: { name: IconNameType }) => {
24+
const Icon = ({ name }: IconProps) => {
2125
const SvgIcon = ICONS[name];
2226

2327
return <SvgIcon />;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
"plugins": [{ "name": "typescript-plugin-css-modules" }],
2828
"types": ["@testing-library/jest-dom", "vite-plugin-svgr/client", "vite/client"]
2929
},
30-
"include": ["src", "src/types"]
30+
"include": ["src", "src/types", ".storybook/**/*"]
3131
}

0 commit comments

Comments
 (0)