ð Storybook for Vue tutorial æ¥æ¬èªèš³
ã¯ãããã
éçºç°å¢ã« Vue Storybook ãã»ããã¢ãããã
Storybook ã¯ãéçºã¢ãŒãã§ã¢ããªãšäžç·ã«å®è¡ãããŸããã¢ããªã®ããžãã¹ããžãã¯ãã³ã³ããã¹ãããåé¢ããã UI ã³ã³ããŒãã³ããæ§ç¯ããã®ã«åœ¹ç«ã¡ãŸãããã® Storybook å ¥éãã¥ãŒããªã¢ã« 㯠Vue çšã§ãä»ã«ã¯ ReactãReact NativeãAngularãSvelteãEmber çããããŸãã
Vue Storybook ãèšå®ãã
ç§ãã¡ã®ç°å¢ã§ãã«ãããã»ã¹ãèšå®ããããã«ã¯ãããã€ãã®ã¹ããããèžãå¿ èŠããããŸãããŸãå§ãã«ãdegit ã䜿ã£ãŠãã«ãã·ã¹ãã ãã»ããã¢ããããããšæããŸãããã®ããã±ãŒãžã䜿ããšã"ãã³ãã¬ãŒã"ïŒããã€ãã®ããã©ã«ãèšå®ãå«ããéšåçã«ãã«ããããã¢ããªã±ãŒã·ã§ã³ïŒãããŠã³ããŒãããŠãéçºã¯ãŒã¯ãããŒãé«éåããããšãã§ããŸãã
以äžã®ã³ãã³ããå®è¡ããŠã¿ãŸããã:
# ãã³ãã¬ãŒããã¯ããŒã³ãã
npx degit chromaui/intro-storybook-vue-template taskbox
cd taskbox
# äŸåé¢ä¿ãã€ã³ã¹ããŒã«ãã
yarn
ããã§ãã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªç°å¢ãæ£ããåäœããŠãããã©ãããããã«ç¢ºèªããããšãã§ããŸã:
# ã¿ãŒããã«ã§ãã¹ãã©ã³ããŒãèµ·åããïŒJestïŒ:
yarn test:unit
# ããŒã 6006 ã§ã³ã³ããŒãã³ãæ¢çŽ¢ãã¯ããã:
yarn storybook
# ããŒã 8080 ã§é©åã«ããã³ããšã³ãã¢ããªãå®è¡ãã:
yarn serve
åœç€Ÿã®ããã³ããšã³ãã¢ããªã®æ§åŒã¯ãèªåãã¹ãïŒJestïŒãã³ã³ããŒãã³ãéçºïŒStorybookïŒããããŠã¢ããªæ¬äœã® 3 ã€ã§ãã
ã¢ããªã®ã©ã®éšåã«åãçµãã§ãããã«ãã£ãŠããããã®ãã¡ã® 1 ã€ãŸãã¯è€æ°ãåæã«å®è¡ãããå ŽåããããŸããä»å㯠1 ã€ã® UI ã³ã³ããŒãã³ããäœæããããšã«ãã©ãŒã«ã¹ããŠããã®ã§ãStorybook ã®å®è¡ã«ãã ããããšã«ããŸãã
å€æŽãã³ããããã
ãã®æ®µéã§ãããŒã«ã«ãªããžããªã«ãã¡ã€ã«ãè¿œå ããŠã倧äžå€«ã§ãã以äžã®ã³ãã³ããå®è¡ããŠãããŒã«ã«ãªããžããªãåæåãããããŸã§ã«è¡ã£ãå€æŽãè¿œå ããŠã³ãããããŠãã ããã
$ git init
ç¶ããŠ:
$ git add .
ãããã:
$ git commit -m "first commit"
ãããŠæåŸã«:
$ git branch -M main
ããã§ã¯ãæåã®ã³ã³ããŒãã³ããäœã£ãŠã¿ãŸãããïŒ
ã·ã³ãã«ãªã³ã³ããŒãã³ã
è€åçãªã³ã³ããŒãã³ã
ããŒã¿
ã¹ã¯ãªãŒã³
ãããã€
ãã¹ã
æ¡åŒµæ©èœ
人æ°ã® Controls æ¡åŒµæ©èœãçµ±åããŠäœ¿çšããæ¹æ³ãåŠã¶
Storybook ã«ã¯ãããŒã å šå¡ã®éçºè äœéšãåäžãããããã«äœ¿çšã§ããæ¡åŒµæ©èœã®åŒ·åãªãšã³ã·ã¹ãã ããããŸããããã§ãã¹ãŠãèŠãããšãã§ããŸãã
ãã®ãã¥ãŒããªã¢ã«ã«æ²¿ã£ãŠããæ¹ã¯ããã§ã«è€æ°ã®æ¡åŒµæ©èœã«åºäŒãããã¹ãã®ç« 㧠1 ã€ã®æ¡åŒµæ©èœãã»ããã¢ããããããšã§ãããã
ãããã䜿çšäŸã«å¯Ÿå¿ããæ¡åŒµæ©èœããããããããã¹ãŠã«ã€ããŠæžããšæ°žé ã«æéããããã§ããããæã人æ°ã®ããæ¡åŒµæ©èœã® 1 ã€ãçµ±åããŠã¿ãŸããã: Controls ã§ãã
Controls ãšã¯ïŒ
Controlsã䜿ããšããã¶ã€ããŒãéçºè ã¯ãåŒæ°ãæäœããããšã§ãã³ã³ããŒãã³ãã®åäœãç°¡åã«èª¿ã¹ãããšãã§ããŸããã³ãŒãã¯å¿ èŠãããŸãããControls ã¯ãã¹ããŒãªãŒã®æšªã«æ¡åŒµæ©èœããã«ãäœæãããã®åŒæ°ãã©ã€ãã§ç·šéã§ããŸãã
Storybook ãæ°èŠã«ã€ã³ã¹ããŒã«ãããšãControls ãæåããå«ãŸããŠããŸããè¿œå ã®èšå®ã¯å¿ èŠãããŸããã
æ¡åŒµæ©èœã§æ°ãã Storybook ã®ã¯ãŒã¯ãããŒãéæŸ
Storybook ã¯çŽ æŽãããã³ã³ããŒãã³ãé§ååã®éçºç°å¢ã§ããControls ã¢ããªã³ã¯ãStorybook ãçžäºäœçšçãªããã¥ã¡ã³ãããŒã«ã«é²åãããŸãã
ãšããžã±ãŒã¹ãèŠã€ããããã« Controls ã䜿çšãã
Controls ã䜿ãã°ãQA ãšã³ãžãã¢ãUI ãšã³ãžãã¢ããã®ä»ã®é¢ä¿è ã¯ãã³ã³ããŒãã³ããéçãŸã§è¿œã蟌ãããšãã§ããŸãïŒæ¬¡ã®äŸã§ã¯ã巚倧㪠æååãè¿œå ããå ŽåãTask ã¯ã©ããªãã§ããããïŒ
ããããã§ãïŒããã¹ãã Task ã³ã³ããŒãã³ãã®å¢çãè¶ããŠãªãŒããŒãããŒããŠããããã«èŠããŸãã
ã³ã³ãããŒã«ã«ãã£ãŠãã³ã³ããŒãã³ããžã®ããŸããŸãªå ¥åïŒãã®å Žåã¯é·ãæååïŒããã°ãã確èªã§ããããã«ãªããUI ã®åé¡ãçºèŠããã®ã«å¿ èŠãªäœæ¥ã軜æžãããŸããã
ã§ã¯ãTask.vue ã«ã¹ã¿ã€ã«ãè¿œå ããŠãã¯ã¿åºãã®åé¡ã解決ããŸããã:
<input
type="text"
:value="task.title"
readonly
placeholder="Input title"
+ style="text-overflow: ellipsis;"
/>
åé¡ã¯è§£æ±ºããŸããïŒããã¹ããã¿ã¹ã¯ãšãªã¢ã®å¢çç·ã«éãããšãç«æŽŸãªçç¥èšå·ã䜿çšããŠåãæšãŠãããããã«ãªããŸããã
ãªã°ã¬ãã·ã§ã³ãåé¿ããããã®æ°èŠã¹ããŒãªãŒã®è¿œå
å°æ¥çã«ã¯ãControls çµç±ã§åãæååãå ¥åããããšã§ããã®åé¡ãæåã§åçŸããããšãã§ããŸãããããããã®ãšããžã±ãŒã¹ã玹ä»ããã¹ããŒãªãŒãæžãã»ããç°¡åã§ããããããããšã§ããªã°ã¬ãã·ã§ã³ãã¹ãã®ã«ããŒç¯å²ãåºãããããŒã ã®ä»ã®ã¡ã³ããŒã®ããã«ã³ã³ããŒãã³ãã®éçãæ確ã«èª¬æããããšãã§ããŸãã
Task.stories.js ã«ãé·ãããã¹ãã®å Žåã®æ°ããã¹ããŒãªãŒãè¿œå ããŠãã ãã:
const longTitleString = `This task's name is absurdly large. In face, I think if I keep going I might end up with content overflow. What will happen? The star that represents a pinned task could have text overlapping. The text could cut-off abruptly when it reaches the star. I hope not!`
export const LongTitle = Template.bind({})
LongTitle.args = {
task: {
...Default.args.task,
title: longTitleString,
},
}
ããã§ããã®ãšããžã±ãŒã¹ãç°¡åã«åçŸããäœæ¥ããããšãã§ããããã«ãªããŸããã
ããããžã¥ã¢ã«ãã¹ããããŠããã°ãåãæšãŠã®ãœãªã¥ãŒã·ã§ã³ãå£ããå Žåã«ãéç¥ãããŸãããšããžã±ãŒã¹ã¯ããã¹ãã«ãã¬ããžããªããšå¿ããããã¡ã§ãã
ãŸãšã
ç¥èãçµéããããã« Storybook ã®ãã¯ããã¯ãåŠã¶
ããã§ãšãããããŸãïŒããªã㯠Storybook ã§æåã® UI ãäœæããŸããããã®éçšã§ãUI ã³ã³ããŒãã³ãã®ãã«ããåæããã¹ãããããã€ã®æ¹æ³ãåŠã³ãŸããããããŸã§éãã§ããã°ãããªãã®ã¬ããšãããã€ããã Storybook ã¯ãã®ããã«ãªã£ãŠããã¯ãã§ã:
ð GitHub repo: chromaui/learnstorybook-code
ð Deployed Storybook
詳现ã¯ãã¡ã
ãã£ãšæ·±ãç¥ãããã§ããïŒããã«åœ¹ç«ã€è³æããããŸãã
- Storybook ã®å ¬åŒããã¥ã¡ã³ãã«ã¯ãAPI ããã¥ã¡ã³ããã³ãã¥ããã£ãªã³ã¯ãæ¡åŒµæ©èœã®ã£ã©ãªãŒããããŸãã
- 楜ãã Storybook ã¯ãŒã¯ãããŒã¯ãSquarespaceãMajor League SoccerãDiscovery NetworkãApollo GraphQL ã®é«éããŒã ã«ãã£ãŠäœ¿çšãããã¯ãŒã¯ãããŒã®ãã¹ããã©ã¯ãã£ã¹ã玹ä»ããŠããŸãã
- Visual Testing Handbook ã¯ãStorybook ã䜿çšããŠã³ã³ããŒãã³ããèŠèŠçã«ãã¹ãããããšãæ·±ãæãäžããŠããŸãã31 ããŒãžã®ç¡æã®é»åæžç±ã§ãã
- Storybook Discord ãã£ããã§ã¯ãStorybook ã®ã³ãã¥ããã£ãšé£çµ¡ãåãããšãã§ããŸããä»ã® Storybook ãŠãŒã¶ãŒã«å©ããæ±ããããäžãããããããšãã§ããŸãã
- Storybook ããã°ã§ã¯ãUI éçºã®ã¯ãŒã¯ãããŒãå¹çåããããã®ææ°ãªãªãŒã¹ãšæ©èœã玹ä»ããŠããŸãã
Storybook å ¥éãã¥ãŒããªã¢ã«ãäœã£ãã®ã¯èª°ã§ããïŒ
ããã¹ããã³ãŒããå¶äœã¯ Chromatic ããæäŸãããŸããããã®ãã¥ãŒããªã¢ã«ã¯ãChromatic ã®äººæ°ãã¥ãŒããªã¢ã«ã·ãªãŒãºãGraphQL + Reactãã«ã€ã³ã¹ãã€ã¢ããããã®ã§ãã
ãã®ãããªãã¥ãŒããªã¢ã«ãèšäºããã£ãšèªã¿ããã§ããïŒ Storybook ã¡ãŒãªã³ã°ãªã¹ãã«ç»é²ããŠãã ããã
è²¢ç®ãã
Storybook ãäžçãšå
±æããããã«
Storybook ã®ãã¥ãŒããªã¢ã«ã«è²¢ç®ããããšã奚å±ãããŠããŸããææ³ãå¥èªç¹ã®ãããªå°ããªããšã§ããã°ããã«ãªã¯ãšã¹ããéããŠãã ããã倧ããªå€æŽã§ããã°ãissue ãè¿œå ããŠè°è«ããŸãããã
Storybook ã®ãã¥ãŒããªã¢ã«ã¯äž»ã«ã³ãã¥ããã£ã«ãã£ãŠäœæãããç¶æãããŠããã®ã§ãææ°ã®ç¶æ ã«ä¿ã¡ãç²ãéšåãæéããããŠæ»ããã«ããããã«ã¯ãçããã®ååãå¿ èŠã§ããçæ§ã®ãååããããããé¡ãããããŸãïŒ
翻蚳
ç§ãã¡ã®ç®æšã¯ãStorybook ããã¹ãŠã®äººã«èŠªãã¿ããããã®ã«ããããšã§ãããã®ãã¥ãŒããªã¢ã«ãä»ã®èšèªã«ç¿»èš³ããã®ãæäŒã£ãŠãã ãããç¹ã«äžåœèªãšã¹ãã€ã³èªã®ç¿»èš³ããåŸ ã¡ããŠããŸãããã® issue ã«ã€ããŠã³ã¡ã³ãããŠãã ããã