Goal
ใช้ Storybook สำหรับ develop, test, และ document UI components ใน isolated environment ด้วย CSF3, Autodocs, และ testing ecosystem
Scope
ใช้สำหรับ component development, testing, และ documentation ด้วย Storybook v10.4+ สำหรับ React, Vue, Angular, Svelte, Web Components, และ React Native
Execute
1. Installation
ติดตั้ง Storybook ด้วย bun create storybook@latest หรืออ่าน guide/installation.md
2. Quick Start
อ่าน guide/quick-start.md สำหรับเริ่มต้นใช้งาน
3. Key Concepts
อ่าน key-concepts/ สำหรับ CSF3, Manager/Preview architecture, และ addon system
4. Configuration
อ่าน guide/configuration.md สำหรับการตั้งค่า main.ts, preview.ts, และ manager.ts
5. Principles
อ่าน principles/ สำหรับ development, testing, และ documentation principles
6. Workflows
ใช้ workflows สำหรับ common tasks:
workflows/setup-storybook.md - Installation และ configuration
workflows/write-stories.md - Writing stories ด้วย CSF3
workflows/test-components.md - Testing ด้วย play function และ addons
workflows/deploy-storybook.md - Build และ deployment
7. References
อ่าน references/ สำหรับ CLI, configuration, และ API reference
Rules
Installation
- ใช้
bun create storybook@latest สำหรับ v8.3+ (recommended)
- ใช้
npx storybook@latest init สำหรับเวอร์ชันก่อน 8.3
- เลือก framework ที่เหมาะสม: React, Vue, Angular, Svelte, Web Components, React Native
- ใช้ Vite builder (@storybook/*-vite) เมื่อเป็นไปได้สำหรับ performance ที่ดีกว่า
- ตรวจสอบ project requirements: Node.js 20+, bun 10+, bun 9+, Yarn 4+
- ตรวจสอบ framework requirements: Angular 18+, React Native 0.72+, Svelte 5+, Vue 3+, Vite 5+
Story Writing (CSF3)
- เขียน stories สำหรับทุก components ด้วย Component Story Format 3 (CSF3)
- ใช้
Meta และ StoryObj types จาก @storybook/react หรือ framework-specific packages
- ใช้
tags: ['autodocs'] สำหรับ automatic documentation generation
- ใช้ UpperCamelCase สำหรับ story exports (e.g.,
Primary, Secondary)
- ใช้
args สำหรับ dynamic arguments และ component props
- ใช้
argTypes สำหรับ control types และ input validation
- วาง story files ไว้ข้างๆ component files:
Component.stories.ts หรือ Component.stories.tsx
Configuration Structure
.storybook/main.ts - Main configuration (stories, addons, framework, builder)
.storybook/preview.ts - Story rendering, decorators, parameters, global types
.storybook/manager.ts - UI behavior, theme, sidebar configuration
- ใช้
framework option สำหรับ framework-specific settings
- ใช้
addons array สำหรับ load addons (Essentials bundle recommended)
Testing
- ใช้
play function สำหรับ interaction testing ด้วย @storybook/testing-library
- ใช้ Vitest addon สำหรับ component testing (Vite projects)
- ใช้ Storybook Test runner สำหรับ testing (Webpack projects)
- ใช้ Accessibility addon สำหรับ a11y testing ด้วย axe-core
- ใช้ Visual testing ด้วย Chromatic สำหรับ snapshot testing
- Reuse stories สำหรับ testing ใน Jest, Vitest, Playwright, หรือ Cypress
Addons
- ใช้ Essentials Bundle (@storybook/addon-essentials) สำหรับ Controls, Actions, Docs, Backgrounds
- ติดตั้ง addons ผ่าน
npx storybook add <addon-name>
- ใช้ addon API สำหรับ custom addons (addDecorator, addParameters, addArgTypes)
- Configure addons ใน
.storybook/main.ts หรือ .storybook/preview.ts
Organization
- จัดระเบียบ stories ตาม component structure และ folder hierarchy
- ใช้ decorators สำหรับ wrapper components (theme providers, layouts)
- ใช้ parameters สำหรับ static metadata (layout, backgrounds, viewport)
- ใช้ proper naming conventions ตาม CSF3 standard
- ใช้
title ใน Meta สำหรับ organize stories ใน sidebar
Documentation
- ใช้ Autodocs สำหรับ automatic documentation generation
- เขียน MDX สำหรับ custom documentation pages
- ใช้ Doc Blocks สำหรับ structured documentation components
- Configure docs options ใน
.storybook/main.ts (defaultName, docsMode)
- Publish Storybook สำหรับ team collaboration และ design system
Expected Outcome
- Components ที่ well-documented ด้วย Autodocs และ MDX
- Development ใน isolated environment ด้วย Manager API และ Preview API architecture
- Testing ที่ comprehensive ด้วย interaction, accessibility, และ visual tests
- Stories ที่ well-organized ตาม CSF3 standard และ framework best practices
1---2name: storybook3description: Build, test, and document UI components in isolation with Storybook v10.4+4---5## Goal67ใช้ Storybook สำหรับ develop, test, และ document UI components ใน isolated environment ด้วย CSF3, Autodocs, และ testing ecosystem8910## Scope1112ใช้สำหรับ component development, testing, และ documentation ด้วย Storybook v10.4+ สำหรับ React, Vue, Angular, Svelte, Web Components, และ React Native131415## Execute1617### 1. Installation1819ติดตั้ง Storybook ด้วย `bun create storybook@latest` หรืออ่าน `guide/installation.md`2021### 2. Quick Start2223อ่าน `guide/quick-start.md` สำหรับเริ่มต้นใช้งาน2425### 3. Key Concepts2627อ่าน `key-concepts/` สำหรับ CSF3, Manager/Preview architecture, และ addon system2829### 4. Configuration3031อ่าน `guide/configuration.md` สำหรับการตั้งค่า main.ts, preview.ts, และ manager.ts3233### 5. Principles3435อ่าน `principles/` สำหรับ development, testing, และ documentation principles3637### 6. Workflows3839ใช้ workflows สำหรับ common tasks:40- `workflows/setup-storybook.md` - Installation และ configuration41- `workflows/write-stories.md` - Writing stories ด้วย CSF342- `workflows/test-components.md` - Testing ด้วย play function และ addons43- `workflows/deploy-storybook.md` - Build และ deployment4445### 7. References4647อ่าน `references/` สำหรับ CLI, configuration, และ API reference484950## Rules5152### Installation5354- ใช้ `bun create storybook@latest` สำหรับ v8.3+ (recommended)55- ใช้ `npx storybook@latest init` สำหรับเวอร์ชันก่อน 8.356- เลือก framework ที่เหมาะสม: React, Vue, Angular, Svelte, Web Components, React Native57- ใช้ Vite builder (@storybook/*-vite) เมื่อเป็นไปได้สำหรับ performance ที่ดีกว่า58- ตรวจสอบ project requirements: Node.js 20+, bun 10+, bun 9+, Yarn 4+59- ตรวจสอบ framework requirements: Angular 18+, React Native 0.72+, Svelte 5+, Vue 3+, Vite 5+6061### Story Writing (CSF3)6263- เขียน stories สำหรับทุก components ด้วย Component Story Format 3 (CSF3)64- ใช้ `Meta` และ `StoryObj` types จาก `@storybook/react` หรือ framework-specific packages65- ใช้ `tags: ['autodocs']` สำหรับ automatic documentation generation66- ใช้ UpperCamelCase สำหรับ story exports (e.g., `Primary`, `Secondary`)67- ใช้ `args` สำหรับ dynamic arguments และ component props68- ใช้ `argTypes` สำหรับ control types และ input validation69- วาง story files ไว้ข้างๆ component files: `Component.stories.ts` หรือ `Component.stories.tsx`7071### Configuration Structure7273- `.storybook/main.ts` - Main configuration (stories, addons, framework, builder)74- `.storybook/preview.ts` - Story rendering, decorators, parameters, global types75- `.storybook/manager.ts` - UI behavior, theme, sidebar configuration76- ใช้ `framework` option สำหรับ framework-specific settings77- ใช้ `addons` array สำหรับ load addons (Essentials bundle recommended)7879### Testing8081- ใช้ `play` function สำหรับ interaction testing ด้วย `@storybook/testing-library`82- ใช้ Vitest addon สำหรับ component testing (Vite projects)83- ใช้ Storybook Test runner สำหรับ testing (Webpack projects)84- ใช้ Accessibility addon สำหรับ a11y testing ด้วย axe-core85- ใช้ Visual testing ด้วย Chromatic สำหรับ snapshot testing86- Reuse stories สำหรับ testing ใน Jest, Vitest, Playwright, หรือ Cypress8788### Addons8990- ใช้ Essentials Bundle (@storybook/addon-essentials) สำหรับ Controls, Actions, Docs, Backgrounds91- ติดตั้ง addons ผ่าน `npx storybook add <addon-name>`92- ใช้ addon API สำหรับ custom addons (addDecorator, addParameters, addArgTypes)93- Configure addons ใน `.storybook/main.ts` หรือ `.storybook/preview.ts`9495### Organization9697- จัดระเบียบ stories ตาม component structure และ folder hierarchy98- ใช้ decorators สำหรับ wrapper components (theme providers, layouts)99- ใช้ parameters สำหรับ static metadata (layout, backgrounds, viewport)100- ใช้ proper naming conventions ตาม CSF3 standard101- ใช้ `title` ใน Meta สำหรับ organize stories ใน sidebar102103### Documentation104105- ใช้ Autodocs สำหรับ automatic documentation generation106- เขียน MDX สำหรับ custom documentation pages107- ใช้ Doc Blocks สำหรับ structured documentation components108- Configure docs options ใน `.storybook/main.ts` (defaultName, docsMode)109- Publish Storybook สำหรับ team collaboration และ design system110111112## Expected Outcome113114- Components ที่ well-documented ด้วย Autodocs และ MDX115- Development ใน isolated environment ด้วย Manager API และ Preview API architecture116- Testing ที่ comprehensive ด้วย interaction, accessibility, และ visual tests117- Stories ที่ well-organized ตาม CSF3 standard และ framework best practices