|
| 1 | +# Storybook |
| 2 | + |
| 3 | +This project uses [Storybook](https://storybook.js.org/) for component development and documentation. |
| 4 | + |
| 5 | +## Running Storybook |
| 6 | + |
| 7 | +To start Storybook in development mode: |
| 8 | + |
| 9 | +```bash |
| 10 | +bun run storybook |
| 11 | +``` |
| 12 | + |
| 13 | +This will start Storybook on http://localhost:6006 |
| 14 | + |
| 15 | +## Building Storybook |
| 16 | + |
| 17 | +To build a static version of Storybook: |
| 18 | + |
| 19 | +```bash |
| 20 | +bun run build-storybook |
| 21 | +``` |
| 22 | + |
| 23 | +The output will be in the `storybook-static` directory. |
| 24 | + |
| 25 | +## Creating Stories |
| 26 | + |
| 27 | +Stories are located next to their components with the `.stories.tsx` extension. |
| 28 | + |
| 29 | +Example structure: |
| 30 | +``` |
| 31 | +src/components/Messages/ |
| 32 | +├── AssistantMessage.tsx |
| 33 | +└── AssistantMessage.stories.tsx |
| 34 | +``` |
| 35 | + |
| 36 | +### Example Story |
| 37 | + |
| 38 | +```typescript |
| 39 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 40 | +import { MyComponent } from "./MyComponent"; |
| 41 | + |
| 42 | +const meta = { |
| 43 | + title: "Category/MyComponent", |
| 44 | + component: MyComponent, |
| 45 | + parameters: { |
| 46 | + layout: "padded", |
| 47 | + }, |
| 48 | + tags: ["autodocs"], |
| 49 | +} satisfies Meta<typeof MyComponent>; |
| 50 | + |
| 51 | +export default meta; |
| 52 | +type Story = StoryObj<typeof meta>; |
| 53 | + |
| 54 | +export const Default: Story = { |
| 55 | + args: { |
| 56 | + // component props |
| 57 | + }, |
| 58 | +}; |
| 59 | +``` |
| 60 | + |
| 61 | +## Current Stories |
| 62 | + |
| 63 | +- **Messages/AssistantMessage**: Various states of assistant messages including streaming, partial, with models, etc. |
| 64 | + |
| 65 | +## Configuration |
| 66 | + |
| 67 | +- `.storybook/main.ts` - Main Storybook configuration |
| 68 | +- `.storybook/preview.tsx` - Preview configuration with global styles and dark theme for docs |
| 69 | +- `.storybook/manager.ts` - Manager (UI chrome) configuration with dark theme |
| 70 | + |
| 71 | +## Theme |
| 72 | + |
| 73 | +Storybook is configured with a dark theme to match the application: |
| 74 | +- Dark UI chrome (sidebar, toolbar, etc.) |
| 75 | +- Dark documentation pages |
| 76 | +- Dark canvas background (`hsl(0 0% 12%)`) matching the app's `--color-background` |
| 77 | + |
| 78 | +## Visual Regression Testing with Chromatic |
| 79 | + |
| 80 | +This project uses [Chromatic](https://www.chromatic.com/) for automated visual regression testing. |
| 81 | + |
| 82 | +### How it works |
| 83 | + |
| 84 | +- **On PRs**: Chromatic captures snapshots of all stories and compares them to the baseline |
| 85 | +- **On main**: Changes are automatically accepted as the new baseline |
| 86 | +- **TurboSnap**: Only changed stories are tested, making builds fast (~30s typical) |
| 87 | + |
| 88 | +### Running Chromatic locally |
| 89 | + |
| 90 | +```bash |
| 91 | +bun run chromatic |
| 92 | +``` |
| 93 | + |
| 94 | +You'll need a `CHROMATIC_PROJECT_TOKEN` environment variable set. |
| 95 | + |
| 96 | +### CI Integration |
| 97 | + |
| 98 | +Chromatic runs automatically in CI via `.github/workflows/chromatic.yml`: |
| 99 | +- Runs on all PRs and pushes to main |
| 100 | +- Visual diffs are shown inline in PR comments |
| 101 | +- Won't fail the build on visual changes (for review) |
| 102 | + |
| 103 | +### Configuration |
| 104 | + |
| 105 | +- `chromatic.config.json` - Chromatic settings (TurboSnap, skip patterns, etc.) |
| 106 | +- See [Chromatic docs](https://www.chromatic.com/docs/) for more options |
0 commit comments