$ npx create-react-app example-story-book
$ cd example-story-book
$ npm install @storybook/react --save-dev
story book ์ค์ ์ ์ํด .storybook ํด๋ ์๋์ config ํ์ผ์ ์ถ๊ฐํฉ๋๋ค.
// .storybook/config.js
import { configure } from "@storybook/react";
configure(require.context("../docs", true, /\.stories\.js$/), module);
config ํ์ผ์ถ๊ฐ ํ story component ๋ค์ ๋์ docs ํด๋๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์
docs ํด๋์ story component ๋ค์ *.stories.js ์ด๋ผ๋ ํจํด์ ์ด๋ฆ์ ๊ฐ์ง๋๋ค.
storybook ์์ ์ ๊ณตํด์ฃผ๋ demo button ์ ์ถ๊ฐํด๋ณด๊ฒ ์ต๋๋ค.
// docs/button.stories.js
import React from "react";
import { storiesOf } from "@storybook/react";
import { Button } from "@storybook/react/demo";
export default { title: "Button" };
storiesOf("Button Component", module)
.add("withText", () => <Button>Hello Button</Button>)
.add("withEmoji", () => (
<Button>
<span role="img" aria-label="so cool">
๐ ๐ ๐ ๐ฏ
</span>
</Button>
));
storiesOf ๋ ์ปดํฌ๋ํธ๋ฅผ ์คํ ๋ฆฌ ๋จ์๋ก ๋
ธ์ถ ํ ์ ์๊ฒ ๋์์ค๋๋ค.
ํฌ๊ฒ Button Component ๋ผ๋ ์คํ ๋ฆฌ๋ก ๋ฌถ์ด ๋
ธ์ถํฉ๋๋ค.
์คํ์ ์ํด package.json ์ scripts ์ storybook ๋ช
๋ น์ด๋ฅผ ์ถ๊ฐํฉ๋๋ค.
์ฐ๋ฆฌ๊ฐ ์์ชฝ์์ story ์ ์ถ๊ฐํ๋ button ์ปดํฌ๋ํธ๋ฅผ ํ์ธ ํ ์ ์์ต๋๋ค.
์ด๋ฅผ ์ด์ฉํ๋ฉด ์ํ์ ๋ฐ๋ฅธ ์ปดํฌ๋ํธ ๋ณํ ๋๋ ๋์์ธ ์ ์ฉ์ฌ๋ถ๋ฅผ ๋ฏธ๋ฆฌ ํ์ธ ํ ์ ์์ต๋๋ค.
Component ์ถ๊ฐํด๋ณด๊ธฐ
styled-components ๋ฅผ ์ด์ฉํ์ฌ ์ง์ ๊ตฌ์ฑํด๋ณด๊ฒ ์ต๋๋ค.
src ํด๋ ์๋์ input.js ๋ผ๋ component ๋ฅผ ๋ง๋ค์ด์ฃผ์ธ์
input ์ focus props ์ ๋ฐ๋ผ border style ์ด ๋ณํฉ๋๋ค. ํด๋น component ๋ฅผ story book ์ ์ถ๊ฐํฉ๋๋ค.
addon ์ ์ถ๊ฐํ๋ฉด ๊ธฐ๋ณธ๋์ ์ธ ์ฌ๋ฌ๊ฐ์ง ์์
์ ํ ์ ์์ต๋๋ค.
.storybook ํด๋์ addons.js ํ์ผ์ ์ถ๊ฐํ์ฌ addons ๋ฅผ ๋ฑ๋กํฉ๋๋ค.
config ํ์ผ์๋ ์ถ๊ฐํด์ผํฉ๋๋ค.
addon ๊ธฐ๋ฅ์ผ๋ก input ์ focus ๋ฅผ ์กฐ์ ํ๋๋ก ์ถ๊ฐํด๋ณด๊ฒ ์ต๋๋ค.
Storybook ์ ๋ฐฐํฌํ Github Repo ๋ฅผ ๋ง๋ค์ด์ฃผ์ธ์
Github page ์ ๊ฐ๋จํ๊ฒ ๋ฐฐํฌํ ์ ์๊ฒ ๋์์ฃผ๋ ๋ชจ๋์ ์ค์นํด์ผํฉ๋๋ค.
์ค์นํ ๋ฐฐํฌ ๋ช
๋ น์ด๋ฅผ ๋ฑ๋กํฉ๋๋ค.
์์ฃผ ๊ฐ๋จํ๊ฒ ๋ฐฐํฌ๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
๋ฐฐํฌ ๊ฒฐ๊ณผ๋ฌผ์ <github name>.github.io/<repo name>
์ ์ ๊ฒฝ์ฐ https://appear.github.io/example-storybook ์
๋๋ค.