Storybook
๐ ๏ธ ์์ด์ ํธ ์คํฌ
npx -y skills add DaleStudy/skills --skill storybookAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Storybook ์คํ ๋ฆฌ ์์ฑ ๋ฐ CSF 3.0 ๋ฒ ์คํธ ํ๋ํฐ์ค ์คํฌ. ๋ค์ ์ํฉ์์ ์ฌ์ฉ: (1) ์ ์คํ ๋ฆฌ ํ์ผ(.stories.tsx, .stories.ts) ์์ฑ ์, (2) ๊ธฐ์กด ์คํ ๋ฆฌ ์์ ์, (3) Args, Decorators, Parameters ์ค์ ์, (4) Storybook ์ค์ ํ์ผ(.storybook/) ์์ ์, (5) 'story', 'stories', 'storybook', 'CSF' ํค์๋๊ฐ ํฌํจ๋ ์์ ์
The file declares its own license as MIT. That is the authorโs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
10.1 KB, as published. Nobody here has run it
Storybook
๋ชจ๋ฒ ๊ด๋ก
1. CSF 3.0 ํ์ ์ฌ์ฉ
์ต์ Component Story Format 3.0 ์ฌ์ฉ. ๋ ๊ฐ๊ฒฐํ๊ณ ํ์ ์์ .
// โ CSF 2.0 (๊ตฌํ)
export default {
title: 'Components/Button',
component: Button,
};
export const Primary = () => <Button variant="primary">Click me</Button>;
// โ
CSF 3.0 (๊ถ์ฅ)
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';
const meta = {
component: Button,
tags: ['autodocs'], // ์๋ ๋ฌธ์ ์์ฑ
args: {
variant: 'primary',
children: 'Click me',
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Primary: Story = {};
export const Secondary: Story = {
args: {
variant: 'secondary',
},
};
2. Args ๊ธฐ๋ฐ ์คํ ๋ฆฌ ์์ฑ
์ปดํฌ๋ํธ Props๋ฅผ Args๋ก ์ ์ํ์ฌ Controls ํจ๋์์ ์ธํฐ๋ํฐ๋ธํ๊ฒ ์กฐ์ ๊ฐ๋ฅ.
- ๊ธฐ๋ณธ๊ฐ์
args์์ ์ ์ธ (โargTypes.defaultValue์ฌ์ฉ ๊ธ์ง). Meta์args์ ๊ธฐ๋ณธ๊ฐ์ ๋๋ฉด Controls ํจ๋์์ ์๋์ผ๋ก ํด๋น ๊ฐ์ด ์ ํ๋จ - ์ฌ๋ฌ ์คํ ๋ฆฌ์ ๊ณตํต์ผ๋ก ํ์ํ args๋ Meta(์ปดํฌ๋ํธ) ์์ค์์ ์ ์ธํ๊ณ , ๊ฐ๋ณ ์คํ ๋ฆฌ์์๋ ์ฐจ์ด์ ๋ง ์ค๋ฒ๋ผ์ด๋
// โ ํ๋์ฝ๋ฉ๋ Props
export const Disabled: Story = {
render: () => <Button disabled>Disabled</Button>,
};
// โ ์ฌ๋ฌ ์คํ ๋ฆฌ์์ ๊ฐ์ args ์ค๋ณต
export const Primary: Story = {
args: { children: 'Click me', variant: 'primary' },
};
export const Secondary: Story = {
args: { children: 'Click me', variant: 'secondary' },
};
// โ
Meta์์ ๊ณตํต args ์ ์ธ, ์คํ ๋ฆฌ์์ ์ฐจ์ด์ ๋ง ์ค๋ฒ๋ผ์ด๋
const meta = {
component: Button,
args: {
children: 'Click me',
variant: 'primary',
},
} satisfies Meta<typeof Button>;
export const Primary: Story = {};
export const Secondary: Story = {
args: { variant: 'secondary' },
};
export const Disabled: Story = {
args: { disabled: true },
};
3. title ์๋ต โ ํ์ผ ๊ฒฝ๋ก ๊ธฐ๋ฐ ์๋ ์ถ๋ก
title์ ๋ฌธ์์ด๋ก ์ง์ ๋ช
์ํ๋ฉด ํ์
์์ ํ์ง ์๊ณ , ์ปดํฌ๋ํธ ์ด๋ฆ/๊ฒฝ๋ก ๋ณ๊ฒฝ ์ ์ฑํฌ๊ฐ ๊นจ์ง๊ธฐ ์ฌ์. Storybook์ ํ์ผ ๊ฒฝ๋ก์์ ์ฌ์ด๋๋ฐ ๊ณ์ธต์ ์๋ ์ถ๋ก ํ๋ฏ๋ก title ์๋ต.
// โ title ์ง์ ๋ช
์ โ ํ์
์์ ํ์ง ์๊ณ ์ฑํฌ ๊นจ์ง ์ํ
const meta = {
title: 'Components/Button',
component: Button,
} satisfies Meta<typeof Button>;
// โ
title ์๋ต โ ํ์ผ ๊ฒฝ๋ก์์ ์๋ ์ถ๋ก
const meta = {
component: Button,
} satisfies Meta<typeof Button>;
4. ํ์ ์์ ํ Meta ์ ์
satisfies ํค์๋๋ก ํ์
์ฒดํฌ์ ํ์
์ถ๋ก ๋์ ํ์ฉ.
// โ ํ์
์ถ๋ก ๋ถ๊ฐ
const meta: Meta<typeof Button> = {
component: Button,
};
// โ
ํ์
์ฒดํฌ์ ์ถ๋ก ๋ชจ๋ ๊ฐ๋ฅ
const meta = {
component: Button,
args: {
size: 'md',
variant: 'primary',
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
5. Decorators๋ก ์ปจํ ์คํธ ์ ๊ณต
๊ณตํต ๋ํผ๋ Provider๋ฅผ Decorator๋ก ์ ์ฉ.
// ๊ฐ๋ณ ์คํ ๋ฆฌ์ Decorator ์ ์ฉ
export const WithTheme: Story = {
decorators: [
(Story) => (
<ThemeProvider theme="dark">
<Story />
</ThemeProvider>
),
],
};
// ๋ชจ๋ ์คํ ๋ฆฌ์ Decorator ์ ์ฉ
const meta = {
component: Button,
decorators: [
(Story) => (
<div style={{ padding: '3rem' }}>
<Story />
</div>
),
],
} satisfies Meta<typeof Button>;
6. Parameters๋ก ๋์ ์ปค์คํฐ๋ง์ด์ฆ
const meta = {
component: Button,
parameters: {
layout: 'centered', // ์คํ ๋ฆฌ๋ฅผ ์ค์ ์ ๋ ฌ
backgrounds: {
default: 'light',
values: [
{ name: 'light', value: '#ffffff' },
{ name: 'dark', value: '#000000' },
],
},
},
} satisfies Meta<typeof Button>;
// ๊ฐ๋ณ ์คํ ๋ฆฌ์์ ์ค๋ฒ๋ผ์ด๋
export const OnDark: Story = {
parameters: {
backgrounds: { default: 'dark' },
},
};
7. ArgTypes โ ์๋ ์ถ๋ก ์ฐ์ , ์๋ ์ง์ ์ต์ํ
Storybook์ ์ปดํฌ๋ํธ ํจ์์ TypeScript ํ์ ์์ ์ต์ ์ argType์ ์๋ ์ ์ฉํจ. ์๋์ผ๋ก ๋ฎ์ด์ฐ๋ฉด ์ปดํฌ๋ํธ ํ์ ๋ณ๊ฒฝ ์๋ง๋ค argType ์ฑํฌ๋ฅผ ๋ง์ถฐ์ผ ํ๋ฏ๋ก ํ๋นํ ์ด์ ์์ด argType์ ์ง์ ์ง์ ํ์ง ์์.
์๋ ์ง์ ์ด ํ๋นํ ๊ฒฝ์ฐ:
ReactNodeํ์ ์ธ๋ฐ Controls์์ ํ ์คํธ ์ ๋ ฅ์ด ํ์ํ ๋ โcontrol: 'text'- Compound pattern (์ปดํฌ๋ํธ๋ฅผ ์ฌ๋ฌ ๊ฐ export) โ argTypes๋ก ๋ช ์
- ํน์ ์คํ ๋ฆฌ์์ ํญ์ ๊ณ ์ ๋์ด์ผ ํ๋ prop โ
control: false
// โ ๋ถํ์ํ argType ์๋ ์ง์ โ ํ์
๋ณ๊ฒฝ ์ ์ฑํฌ ๊นจ์ง
const meta = {
component: Button,
argTypes: {
variant: {
control: 'select',
options: ['primary', 'secondary', 'tertiary'],
},
size: {
control: 'radio',
options: ['sm', 'md', 'lg'],
},
disabled: {
control: 'boolean',
},
},
} satisfies Meta<typeof Button>;
// โ
์๋ ์ถ๋ก ์ ๋งก๊ธฐ๊ณ , ํ์ํ ๊ฒฝ์ฐ๋ง ์๋ ์ง์
const meta = {
component: Button,
argTypes: {
// ReactNode ํ์
์ด์ง๋ง ํ
์คํธ ์
๋ ฅ์ด ํ์ํ ๊ฒฝ์ฐ
children: { control: 'text' },
},
} satisfies Meta<typeof Button>;
// โ
ํน์ ์คํ ๋ฆฌ์์ prop์ ๊ณ ์ ํ ๋ โ control: false
export const Horizontal: Story = {
args: { orientation: 'horizontal' },
argTypes: {
orientation: { control: false }, // ์ด ์คํ ๋ฆฌ์์๋ ํญ์ horizontal
},
};
๊ถ์ฅ ์คํ ๋ฆฌ ๊ตฌ์กฐ
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';
// 1. Meta ์ ์ โ title ์๋ต, ๊ณตํต args ์ ์ธ, argTypes๋ ์๋ ์ถ๋ก ์ ์์
const meta = {
component: Button,
tags: ['autodocs'],
parameters: {
layout: 'centered',
},
args: {
children: 'Button',
size: 'md',
variant: 'primary',
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
// 2. ๊ธฐ๋ณธ ์คํ ๋ฆฌ โ Meta args๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉ
export const Primary: Story = {};
// 3. ๋ณํ ์คํ ๋ฆฌ๋ค โ ์ฐจ์ด์ ๋ง ์ค๋ฒ๋ผ์ด๋
export const Secondary: Story = {
args: {
variant: 'secondary',
},
};
export const Disabled: Story = {
args: {
disabled: true,
},
};
// 4. prop ๊ณ ์ ์ด ํ์ํ ์คํ ๋ฆฌ โ control: false ์ฌ์ฉ
export const Horizontal: Story = {
args: { orientation: 'horizontal' },
argTypes: {
orientation: { control: false },
},
};
// 5. ๋ณต์กํ ์ํ๋ ์ปจํ
์คํธ๊ฐ ํ์ํ ๊ฒฝ์ฐ
export const WithCustomTheme: Story = {
decorators: [
(Story) => (
<ThemeProvider theme="custom">
<Story />
</ThemeProvider>
),
],
};
ArgTypes ์๋ ์ง์ ์ด ํ์ํ ๊ฒฝ์ฐ ์ฐธ๊ณ
์์น: ๋๋ถ๋ถ์ argType์ Storybook์ด ์ปดํฌ๋ํธ ํ์ ์์ ์๋ ์ถ๋ก . ์๋๋ ์๋ ์ถ๋ก ์ด ๋ถ์ ์ ํ ๋๋ง ์ฌ์ฉ.
๊ธฐ๋ณธ๊ฐ์
argTypes.defaultValue๊ฐ ์๋args์์ ์ ์ธ.
argTypes: {
// ReactNode ํ์
์ด์ง๋ง ํ
์คํธ ์
๋ ฅ์ด ํ์ํ ๋
children: { control: 'text' },
// Range slider (์๋ ์ถ๋ก ์ด ์ ์ ํ์ง ์์ ๋)
opacity: {
control: { type: 'range', min: 0, max: 1, step: 0.1 },
},
// Action logger (์ด๋ฒคํธ ํธ๋ค๋ฌ)
onClick: { action: 'clicked' },
// Control ๋นํ์ฑํ (ํน์ ์คํ ๋ฆฌ์์ prop ๊ณ ์ )
orientation: { control: false },
}
์์ฃผ ์ฌ์ฉ๋๋ Parameters
parameters: {
// ๋ ์ด์์ ์ค์
layout: 'centered' | 'fullscreen' | 'padded',
// ๋ฐฐ๊ฒฝ ์ค์
backgrounds: {
default: 'light',
values: [
{ name: 'light', value: '#ffffff' },
{ name: 'dark', value: '#333333' },
],
},
// Actions ํจ๋ ์ค์
actions: {
argTypesRegex: '^on[A-Z].*', // on์ผ๋ก ์์ํ๋ Props ์๋ ๊ฐ์ง
},
// Docs ์ค์
docs: {
description: {
component: '๋ฒํผ ์ปดํฌ๋ํธ ์์ธ ์ค๋ช
',
},
},
}
Decorators ํจํด
// 1. ์คํ์ผ ๋ํผ
(Story) => (
<div style={{ padding: '3rem' }}>
<Story />
</div>
)
// 2. Theme Provider
(Story) => (
<ThemeProvider theme="dark">
<Story />
</ThemeProvider>
)
// 3. Router Provider (React Router ์ฌ์ฉ ์)
(Story) => (
<MemoryRouter initialEntries={['/']}>
<Story />
</MemoryRouter>
)
// 4. ๋ค๊ตญ์ด Provider
(Story) => (
<I18nProvider locale="ko">
<Story />
</I18nProvider>
)
// 5. ์ ์ญ ์ํ Provider
(Story) => (
<Provider store={mockStore}>
<Story />
</Provider>
)
ํ์ผ ๋ช ๋ช ๊ท์น
Component.tsx # ์ปดํฌ๋ํธ ๊ตฌํ
Component.stories.tsx # ์คํ ๋ฆฌ ํ์ผ (๊ฐ์ ๋๋ ํ ๋ฆฌ)
Component.test.tsx # ํ
์คํธ ํ์ผ
Storybook ์ค์ ํ์ผ
// .storybook/main.ts
import type { StorybookConfig } from '@storybook/react-vite';
const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(ts|tsx)'],
addons: [
'@storybook/addon-essentials', // Controls, Actions, Docs ๋ฑ
'@storybook/addon-interactions', // Play functions
],
framework: {
name: '@storybook/react-vite',
options: {},
},
};
export default config;
// .storybook/preview.ts
import type { Preview } from '@storybook/react';
const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
// ๋ชจ๋ ์คํ ๋ฆฌ์ ์ ์ฉ๋ ์ ์ญ Decorators
decorators: [
(Story) => (
<div style={{ fontFamily: 'Arial, sans-serif' }}>
<Story />
</div>
),
],
};
export default preview;