![[Storybook] ์์ํ๊ธฐ](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FngdMR%2FbtsMwsnSSzn%2FxTnGFrrvQd9wnWBpLr7fnk%2Fimg.png)
๐ฆฉ์งํ ํ๊ฒฝ
storybook v8.x ๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
React with Vite ํ๊ฒฝ์์ ์งํํ์ต๋๋ค.
tailwindcss v4.x ์ ํ๋ก์ ํธ์์ ์ฌ์ฉํฉ๋๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก ์๋์ ๋งํฌ์ Get Started๋ฅผ ํตํด ํ๊ฒฝ ๊ตฌ์ฑ์ ํ์์ต๋๋ค.
๊ณต์๋ฌธ์๋ฅผ ๋ฐ๋ผํ๊ณ ํ์ตํ ํ ๊ฐ๋จํ๊ฒ ๊ฐ๋ ์ ์ ๋ฆฌํ ํฌ์คํธ์ ๋๋ค.
Storybook: Frontend workshop for UI development
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and documentation. It's open source and free.
storybook.js.org
1๏ธโฃ์ด๋ฏธ ๋ง๋ค์ด์ง Button ์ปดํฌ๋ํธ์ Story ๊น๋ณด๊ธฐ
npm run storybook
์์ ๋ช ๋ น์ด๋ฅผ ํตํด storybook์ ์ผ๊ณ ๋๋ฉด ์ผ์ชฝ๊ณผ ๊ฐ์ ํ๋ก์ ํธ ํด๋๊ตฌ์กฐ๊ฐ ๋์ต๋๋ค.
(๋ค๋ง ๊ตฌ๋ถ์ ํธ์์ ์ถํ์ npm ํจํค์ง ๋ฐฐํฌ๋ฅผ ์ํด components ๋๋ ํ ๋ฆฌ๋ฅผ ์์๋ก ๋ง๋ค์ด button.css์ Button.tsx๋ฅผ ๋ฃ์์ต๋๋ค. ์๋๋ stories ๋๋ ํฐ๋ฆฌ ์์ ์กด์ฌํฉ๋๋ค)
๊ทธ๋ฆฌ๊ณ ์ด์ ๊ฐ์ ๋ก์ปฌ์ด ์ด๋ฆฌ๊ฒ ๋ฉ๋๋ค.
๊ทธ๋ผ ์ด์ ์ฝ๋๋ฅผ ํตํด ์ด๋ค ์ฝ๋๊ฐ ๋ฌด์์ ํด๋นํ๋์ง ์ ์ด๋ณด๋๋ก ํ ๊ฒ์.
ํ์ฌ ๋ณด๊ณ ์๋ ๊ฒ์ด Button ์ปดํฌ๋ํธ์ด๊ธฐ์ Button.stories.ts ์ Button.tsx ๋ ๊ฐ์ง๋ง ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
๋จผ์ Button.stories.ts์ ์ฝ๋์ metadata๋ฅผ ๋ณด๋ฉด...
์ด๋ฐ ๋ชจ์ต์ ๋๋ค.
๊ฐ๊ฐ์ ์ฃผ์์ ์ ํ ๋๋ก์ ์ญํ ์ ํ๊ณ ์์ต๋๋ค.
title์ ํตํด ๊ฒฝ๋ก๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
๋ง์ฝ 'Basic/Button'์ผ๋ก ๋ฐ๊พผ๋ค๋ฉด ์๋์ ๊ฐ์ด ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
๋ํ, parameters๋ ๋ ๋ง์ ์์ฑ๋ค์ด ์กด์ฌํฉ๋๋ค. ์๋์ ๋งํฌ์์ ํ์ธํด ๋ณผ ์ ์์ด์.
Storybook: Frontend workshop for UI development
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and documentation. It's open source and free.
storybook.js.org
์ด ์คํ ๋ฆฌ๋ฅผ ์ด์ด๋ณด๋ฉฐ ์ค์ํ๊ฒ ์๊ฐํ๋ ๊ฑด argsType์ ๋๋ค. ์์ ์ฝ๋์์๋ backgroundColor๋ง ์ ํ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ { control : 'color' } ๋ผ๊ณ ์ ํ์๋๋ฐ ์ด๊ฑด ์๋์ ์ฌ์ง์ฒ๋ผ ํ๋์ ๋ฐ์ค๋ก ํ์๋ color picker๋ฅผ ์๋ฏธํฉ๋๋ค.
๊ทธ๋ผ ์ด์ ๋ ธ๋์์ผ๋ก ํ์๋ ๊ฒ๋ค์ ๋ฌด์์ธ์ง ์์๋ณด๊ฒ ์ต๋๋ค.
์์๋ณด๊ธฐ ์ํด Button.tsx์ ์ผ๋ณด๋ฉด ์ด๋ฐ ์ฝ๋๋ค์ด ๋ณด์ ๋๋ค.
๋ ธ๋์์ผ๋ก ํ์๋ ๊ฒ๋ค์ Button.tsx์์ ์ฃผ์์ฒ๋ฆฌ๊ฐ ๋ ๊ฒ๋ค์ ๊ทธ๋๋ก ์ฐ๊ณ ์์ต๋๋ค.
๐ค์ฌ๊ธฐ์ ์๊ธด ์๋ฌธ์
์ฌ๊ธฐ์ ํ๋ ์๋ฌธ์ ์ด ์๊ฒผ์ต๋๋คโ
"์ปดํฌ๋ํธ"์ ์ธํฐํ์ด์ค์ ์ ํ ์ฃผ์๋ค์ด storybook์ ๋ฐ์๋๊ณ ์๋ ๊ฑด๋ฐ์.
์คํ ๋ฆฌ์ argType ์ค๋ช ์ ์ปดํฌ๋ํธ์ ์์ฑํ๋ ๊ฒ์ ์ปดํฌ๋ํธ์ ์ฑ ์ ๋ฐ ์์ญ์ด ์๋์ง ์๋?
๊ทธ๋์ ํน์ ์คํ ๋ฆฌํ์ผ์์ ์ค๋ช ์ ์์ฑํ๋ ๊ฒ์ด ์์๊น? ํ๊ณ argsType → ArgTypes → InputType์ผ๋ก ํ๊ณ ๋ค์ด๊ฐ ๋ดค์ต๋๋ค. ์ด๋ค ์์ฑ์ ๊ฐ์ง๊ณ ์๋์ง ๋ณด๊ธฐ ์ํจ์ด์์ด์.
description์ด๋ผ๋ ๊ฒ ๋ณด์๊ณ ๊ณต์๋ฌธ์๋ก ํ๊ณ ๋ค์ด๊ฐ๋ ์๋์ ๊ฐ์ ์ค๋ช ์ด ๋์๊ณ ์ ๋ง์ ๋๋ ์ค๋ช ์ด์์ต๋๋ค.
2๏ธโฃ Label ์ปดํฌ๋ํธ ์ค์ค๋ก ๋ง๋ค์ด๋ณด๊ธฐ
์ปดํฌ๋ํธ์ ์คํ ๋ฆฌ๋ฅผ ๋ง๋ค์๋ ์ ์ฐจ์ ๋ํด ๊ฐ๋ตํ๊ฒ ์ ์ด๋ณด์๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
- ์ปดํฌ๋ํธ๊ฐ ๊ฐ์ง props์ ๋ํ interface๋ฅผ ์ ์ํฉ๋๋ค.
- ์คํ ๋ฆฌ์ meta data๋ฅผ ์์ฑํฉ๋๋ค.
- ์ปดํฌ๋ํธ์ ๋ทฐ ๋ก์ง์ ์์ฑํฉ๋๋ค.
- ์คํ ๋ฆฌ ๋ณ case๋ฅผ ์์ฑํฉ๋๋ค.
์ฐธ๊ณ ๋ก tailwindcss๋ฅผ ์ฌ์ฉํ ๋ preview.ts๋ฅผ ๋ฐ๋ก ์ปค์คํ ํด์ฃผ์ด์ผ ํฉ๋๋ค.
'FrontEnd > storybook' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Storybook] About Crash : Storybook-Tailwindcss (0) | 2025.02.26 |
---|
์๋ ํ์ธ์? ๊ฐ๋ฐ์์ ๋๋ค.