Skip to content

Commit

Permalink
Merge pull request #1 from peauty/feature/story-book
Browse files Browse the repository at this point in the history
Feat: 스토리북 추가
  • Loading branch information
myoungjinGo-FE authored Nov 18, 2024
2 parents 9174870 + 49669a1 commit d4a222a
Show file tree
Hide file tree
Showing 43 changed files with 3,845 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ dist-ssr

# yarn 관련 ignore 추가
tsconfig.tsbuildinfo
install-state.gz
install-state.gz

# storybook
*storybook.log
19 changes: 19 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
core: {
builder: '@storybook/builder-vite', // 👈 The builder enabled here.
},
};
export default config;
14 changes: 14 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
"svgr": "npx @svgr/cli -d src/assets/svg --ignore-existing --typescript --no-dimensions public/svg"
"svgr": "npx @svgr/cli -d src/assets/svg --ignore-existing --typescript --no-dimensions public/svg",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@types/react-router-dom": "^5.3.3",
Expand All @@ -21,10 +23,20 @@
"styled-normalize": "^8.1.1"
},
"devDependencies": {
"@chromatic-com/storybook": "^3.2.2",
"@eslint/compat": "^1.2.3",
"@eslint/js": "^9.13.0",
"@storybook/addon-essentials": "^8.4.4",
"@storybook/addon-interactions": "^8.4.4",
"@storybook/addon-onboarding": "^8.4.4",
"@storybook/blocks": "^8.4.4",
"@storybook/builder-vite": "^8.4.4",
"@storybook/react": "^8.4.4",
"@storybook/react-vite": "^8.4.4",
"@storybook/test": "^8.4.4",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/styled-components": "^5.1.34",
"@vitejs/plugin-react": "^4.3.3",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -34,11 +46,21 @@
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"eslint-plugin-storybook": "^0.11.0",
"globals": "^15.11.0",
"prettier": "^3.3.3",
"react-icons": "^5.3.0",
"recoil": "^0.7.7",
"storybook": "^8.4.4",
"styled-components": "^6.1.13",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10",
"vite-plugin-svgr": "^4.3.0"
},
"eslintConfig": {
"extends": [
"plugin:storybook/recommended"
]
}
}
144 changes: 144 additions & 0 deletions src/stories/components/CustomButton/CustomButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import type { Meta, StoryObj } from '@storybook/react';
import { CustomButton } from './CustomButton';

const meta = {
title: 'Components/CustomButton',
component: CustomButton,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
children: {
control: 'text',
description: '버튼 내부 텍스트',
},
size: {
control: 'select',
options: ['small', 'medium', 'large'],
description: '버튼 크기',
},
variant: {
control: 'select',
options: ['primary', 'secondary', 'outline'],
description: '버튼 스타일',
},
disabled: {
control: 'boolean',
description: '비활성화 여부',
},
fullWidth: {
control: 'boolean',
description: '너비 100% 설정',
defaultValue: false,
},
},
} satisfies Meta<typeof CustomButton>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Primary: Story = {
args: {
children: '시작하기',
variant: 'primary',
size: 'medium',
},
};

export const Secondary: Story = {
args: {
children: '취소',
variant: 'secondary',
size: 'medium',
},
};

export const Outline: Story = {
args: {
children: '더보기',
variant: 'outline',
size: 'medium',
},
};

export const Small: Story = {
args: {
children: '확인',
size: 'small',
variant: 'primary',
},
};

export const Large: Story = {
args: {
children: '계정 만들기',
size: 'large',
variant: 'primary',
},
};

export const Disabled: Story = {
args: {
children: '비활성화',
disabled: true,
variant: 'primary',
},
};

export const FullWidth: Story = {
args: {
children: '전체 너비 버튼',
fullWidth: true,
variant: 'primary',
},
parameters: {
layout: 'padded',
},
};

// Container를 활용한 FullWidth 버튼 예시
export const FullWidthContainer: Story = {
decorators: [
(Story) => (
<div style={{ width: '100%', maxWidth: '400px', padding: '16px' }}>
<Story />
</div>
),
],
args: {
children: '컨테이너 안의 전체 너비 버튼',
fullWidth: true,
variant: 'primary',
},
};

// 버튼 그룹 예시
export const ButtonGroup: Story = {
args: {
children: '버튼', // 기본 children 값 추가
},
render: () => (
<div style={{ display: 'flex', gap: '8px', alignItems: 'center' }}>
<CustomButton variant="primary" size="medium">확인</CustomButton>
<CustomButton variant="secondary" size="medium">취소</CustomButton>
<CustomButton variant="outline" size="medium">더보기</CustomButton>
</div>
),
};

// 다양한 너비의 버튼 예시
export const VariousWidths: Story = {
args: {
children: '버튼', // 기본 children 값 추가
},
render: () => (
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px', width: '100%', maxWidth: '600px' }}>
<CustomButton variant="primary">기본 버튼</CustomButton>
<CustomButton variant="primary" fullWidth>전체 너비 버튼</CustomButton>
<div style={{ width: '50%' }}>
<CustomButton variant="primary" fullWidth>50% 너비 버튼</CustomButton>
</div>
</div>
),
};
Loading

0 comments on commit d4a222a

Please sign in to comment.