|
| 1 | +# Why Storybook? |
| 2 | + |
| 3 | +Storybook is a development environment for UI components that helps catch UI changes and provides integrations for various testing types. For testing, Storybook offers: |
| 4 | + |
| 5 | +- **Accessibility tests** - Built-in a11y checks |
| 6 | +- **Visual tests** - Compare JPG screenshots |
| 7 | +- **Vitest tests** - Use stories directly in your unit tests |
| 8 | + |
| 9 | +## Component Categories |
| 10 | + |
| 11 | +The plan is to organize components into 3 categories. |
| 12 | + |
| 13 | +### UI Library Components |
| 14 | + |
| 15 | +Generic and reusable components used throughout your application. |
| 16 | + |
| 17 | +- Examples: Button, Input, Modal, Card |
| 18 | +- **Testing focus:** Props, variants, accessibility |
| 19 | +- **Coverage:** All variants and states |
| 20 | + |
| 21 | +### Composite Components |
| 22 | + |
| 23 | +Single-use components that encapsulate one feature. |
| 24 | + |
| 25 | +- Examples: UserProfile, WeeklyDownloadStats |
| 26 | +- **Testing focus:** Integration patterns, user interactions |
| 27 | +- **Coverage:** Common usage scenarios |
| 28 | + |
| 29 | +### Page Components |
| 30 | + |
| 31 | +**Full-page layouts** should match what the users see. |
| 32 | + |
| 33 | +- Examples: HomePage, Dashboard, CheckoutPage |
| 34 | +- **Testing focus:** Layout, responsive behavior, integration testing |
| 35 | +- **Coverage:** Critical user flows and breakpoints |
| 36 | + |
| 37 | +## Coverage Guidelines |
| 38 | + |
| 39 | +### Which Components Need Stories? |
| 40 | + |
| 41 | +TBD |
| 42 | + |
| 43 | +## Project Conventions |
| 44 | + |
| 45 | +### Place a `.stories.ts` file next to your component |
| 46 | + |
| 47 | +``` |
| 48 | +components/ |
| 49 | +├── Button.vue |
| 50 | +└── Button.stories.ts |
| 51 | +``` |
| 52 | + |
| 53 | +### Story Template |
| 54 | + |
| 55 | +```ts |
| 56 | +// *.stories.ts |
| 57 | +import type { Meta, StoryObj } from '@nuxtjs/storybook' |
| 58 | +import Component from './Button.vue' |
| 59 | + |
| 60 | +const meta = { |
| 61 | + component: Component, |
| 62 | + // component scope configuration goes here |
| 63 | +} satisfies Meta<typeof Component> |
| 64 | + |
| 65 | +export default meta |
| 66 | +type Story = StoryObj<typeof meta> |
| 67 | + |
| 68 | +export const Default: Story = { |
| 69 | + // story scope configuration goes here |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +## Configuration |
| 74 | + |
| 75 | +Stories can be configured at three levels: |
| 76 | + |
| 77 | +- **Global scope** (`.storybook/preview.ts`) - Applies to all stories |
| 78 | +- **Component scope** - Applies to all stories for a specific component |
| 79 | +- **Story scope** - Applies to individual stories only |
| 80 | + |
| 81 | +## Global App Settings |
| 82 | + |
| 83 | +Global application settings are added to the Storybook toolbar for easy testing and viewing. Configure these in `.storybook/preview.ts` under the `globalTypes` and `decorators` properties. |
| 84 | + |
| 85 | +## Known Limitations |
| 86 | + |
| 87 | +- `autodocs` usage is discouraged as it is buggy. |
| 88 | +- Changing `i18n` in the toolbar doesn't update the language. A manual story reload is required. |
0 commit comments