Skip to content

๐Ÿ“šStorybook ์‚ฌ์šฉ ์˜ˆ์‹œ

Jiye Lee edited this page Dec 18, 2024 · 1 revision

storybook ์‚ฌ์šฉ๋ฒ• ์ฐธ๊ณ 

์ปดํฌ๋„ŒํŠธ ์ œ์ž‘

src/components/Sample.tsx

interface SampleProps {
  variant: "plain" | "text";
}

export default function Sample({ variant }: SampleProps) {
  if (variant === "plain") {
    return <div className="rounded-circle bg-light-accent-bold h-10 w-10" />;
  }
  return <div className="bg-light-accent-bold">hi</div>;
}

Story ํŒŒ์ผ ์ œ์ž‘

src/stories/Sample.stories.tsx

import Sample from "../components/Sample";

export default {
  component: Sample,
  title: "Sample",
  tags: ["autodocs"],
  excludeStories: /.*Data$/,
};

export const Default = {
  args: {
    variant: "plain",
  },
};

export const Text = {
  args: {
    variant: "text",
  },
};
  • componentย -- ์ปดํฌ๋„ŒํŠธ ์ž์ฒด
  • titleย -- ์Šคํ† ๋ฆฌ๋ถ ์‚ฌ์ด๋“œ๋ฐ”์—์„œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ทธ๋ฃนํ™”ํ•˜๊ฑฐ๋‚˜ ๋ถ„๋ฅ˜ํ•˜๋Š” ๋ฐฉ๋ฒ•
  • tagsย -- ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ๋ฌธ์„œ๋ฅผ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ํƒœ๊ทธ
  • excludeStoriesย -- ์Šคํ† ๋ฆฌ์— ํ•„์š”ํ•˜์ง€๋งŒ ์Šคํ† ๋ฆฌ๋ถ์—์„œ ๋ Œ๋”๋ง๋˜์ง€ ์•Š์•„์•ผ ํ•˜๋Š” ์ถ”๊ฐ€ ์ •๋ณด
  • argsย -- ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์‚ฌ์šฉ์ž ์ •์˜ ์ด๋ฒคํŠธ๋ฅผ ๋ชจํ‚นํ•˜๊ธฐ ์œ„ํ•ด ๊ธฐ๋Œ€ํ•˜๋Š” ์•ก์…˜ย [args](https://storybook.js.org/docs/essentials/actions#action-args)๋ฅผ ์ •์˜

    ๐Ÿ’กย [Actions](https://storybook.js.org/docs/essentials/actions)๋Š” UI ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋…๋ฆฝ์ ์œผ๋กœ ๋งŒ๋“ค ๋•Œ ์ƒํ˜ธ์ž‘์šฉ์„ ํ™•์ธํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค๋‹ˆ๋‹ค. ์ข…์ข… ์•ฑ์˜ ์ปจํ…์ŠคํŠธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜๋‚˜ ์ƒํƒœ์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†์„ ๋•Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œย fn()์„ ์‚ฌ์šฉํ•ด ํ•ด๋‹น ํ•จ์ˆ˜๋“ค์„ ์ž„์‹œ๋กœ ๋Œ€์ฒดํ•˜์„ธ์š”.