diff --git a/.storybook/CLAUDE.md b/.storybook/CLAUDE.md new file mode 100644 index 000000000..a8a937162 --- /dev/null +++ b/.storybook/CLAUDE.md @@ -0,0 +1,197 @@ +# Storybook Development Guidelines for Claude + +## Quick Commands + +- `npm run storybook`: Start Storybook development server +- `npm run build-storybook`: Build static Storybook +- `npm run test:component`: Run component tests (includes Storybook components) + +## Development Workflow for Storybook + +1. **Creating New Stories**: + - Place `*.stories.ts` files alongside components + - Follow the naming pattern: `ComponentName.stories.ts` + - Use realistic mock data that matches ComfyUI schemas + +2. **Testing Stories**: + - Verify stories render correctly in Storybook UI + - Test different component states and edge cases + - Ensure proper theming and styling + +3. **Code Quality**: + - Run `npm run typecheck` to verify TypeScript + - Run `npm run lint` to check for linting issues + - Follow existing story patterns and conventions + +## Story Creation Guidelines + +### Basic Story Structure + +```typescript +import type { Meta, StoryObj } from '@storybook/vue3' +import ComponentName from './ComponentName.vue' + +const meta: Meta = { + title: 'Category/ComponentName', + component: ComponentName, + parameters: { + layout: 'centered' // or 'fullscreen', 'padded' + } +} + +export default meta +type Story = StoryObj + +export const Default: Story = { + args: { + // Component props + } +} +``` + +### Mock Data Patterns + +For ComfyUI components, use realistic mock data: + +```typescript +// Node definition mock +const mockNodeDef = { + input: { + required: { + prompt: ["STRING", { multiline: true }] + } + }, + output: ["CONDITIONING"], + output_is_list: [false], + category: "conditioning" +} + +// Component instance mock +const mockComponent = { + id: "1", + type: "CLIPTextEncode", + // ... other properties +} +``` + +### Common Story Variants + +Always include these story variants when applicable: + +- **Default**: Basic component with minimal props +- **WithData**: Component with realistic data +- **Loading**: Component in loading state +- **Error**: Component with error state +- **LongContent**: Component with edge case content +- **Empty**: Component with no data + +### Storybook-Specific Code Patterns + +#### Store Access +```typescript +// In stories, access stores through the setup function +export const WithStore: Story = { + render: () => ({ + setup() { + const store = useMyStore() + return { store } + }, + template: '' + }) +} +``` + +#### Event Testing +```typescript +export const WithEvents: Story = { + args: { + onUpdate: fn() // Use Storybook's fn() for action logging + } +} +``` + +## Configuration Notes + +### Vue App Setup +The Storybook preview is configured with: +- Pinia stores initialized +- PrimeVue with ComfyUI theme +- i18n internationalization +- All necessary CSS imports + +### Build Configuration +- Vite integration with proper alias resolution +- Manual chunking for better performance +- TypeScript support with strict checking +- CSS processing for Vue components + +## Troubleshooting + +### Common Issues + +1. **Import Errors**: Verify `@/` alias is working correctly +2. **Missing Styles**: Ensure CSS imports are in `preview.ts` +3. **Store Errors**: Check store initialization in setup +4. **Type Errors**: Use proper TypeScript types for story args + +### Debug Commands + +```bash +# Check TypeScript issues +npm run typecheck + +# Lint Storybook files +npm run lint .storybook/ + +# Build to check for production issues +npm run build-storybook +``` + +## File Organization + +``` +.storybook/ +├── main.ts # Core configuration +├── preview.ts # Global setup and decorators +├── README.md # User documentation +└── CLAUDE.md # This file - Claude guidelines + +src/ +├── components/ +│ └── MyComponent/ +│ ├── MyComponent.vue +│ └── MyComponent.stories.ts +``` + +## Integration with ComfyUI + +### Available Context + +Stories have access to: +- All ComfyUI stores (widgetStore, colorPaletteStore, etc.) +- PrimeVue components with ComfyUI theming +- Internationalization system +- ComfyUI CSS variables and styling + +### Testing Components + +When testing ComfyUI-specific components: +1. Use realistic node definitions and data structures +2. Test with different node types (sampling, conditioning, etc.) +3. Verify proper CSS theming and dark/light modes +4. Check component behavior with various input combinations + +### Performance Considerations + +- Use manual chunking for large dependencies +- Minimize bundle size by avoiding unnecessary imports +- Leverage Storybook's lazy loading capabilities +- Profile build times and optimize as needed + +## Best Practices + +1. **Keep Stories Focused**: Each story should demonstrate one specific use case +2. **Use Descriptive Names**: Story names should clearly indicate what they show +3. **Document Complex Props**: Use JSDoc comments for complex prop types +4. **Test Edge Cases**: Create stories for unusual but valid use cases +5. **Maintain Consistency**: Follow established patterns in existing stories \ No newline at end of file diff --git a/.storybook/README.md b/.storybook/README.md new file mode 100644 index 000000000..26b615ead --- /dev/null +++ b/.storybook/README.md @@ -0,0 +1,148 @@ +# Storybook Configuration for ComfyUI Frontend + +## What is Storybook? + +Storybook is a frontend workshop for building UI components and pages in isolation. It allows developers to: + +- Build components independently from the main application +- Test components with different props and states +- Document component APIs and usage patterns +- Share components across teams and projects +- Catch visual regressions through visual testing + +## Storybook vs Other Testing Tools + +| Tool | Purpose | Use Case | +|------|---------|----------| +| **Storybook** | Component isolation & documentation | Developing, testing, and showcasing individual UI components | +| **Playwright** | End-to-end testing | Full user workflow testing across multiple pages | +| **Vitest** | Unit testing | Testing business logic, utilities, and component behavior | +| **Vue Testing Library** | Component testing | Testing component interactions and DOM output | + +### When to Use Storybook + +**✅ Use Storybook for:** +- Developing new UI components in isolation +- Creating component documentation and examples +- Testing different component states and props +- Sharing components with designers and stakeholders +- Visual regression testing +- Building a component library or design system + +**❌ Don't use Storybook for:** +- Testing complex user workflows (use Playwright) +- Testing business logic (use Vitest) +- Integration testing between components (use Vue Testing Library) + +## How to Use Storybook + +### Development Commands + +```bash +# Start Storybook development server +npm run storybook + +# Build static Storybook for deployment +npm run build-storybook +``` + +### Creating Stories + +Stories are located alongside components in `src/` directories with the pattern `*.stories.ts`: + +```typescript +// MyComponent.stories.ts +import type { Meta, StoryObj } from '@storybook/vue3' +import MyComponent from './MyComponent.vue' + +const meta: Meta = { + title: 'Components/MyComponent', + component: MyComponent, + parameters: { + layout: 'centered' + } +} + +export default meta +type Story = StoryObj + +export const Default: Story = { + args: { + title: 'Hello World' + } +} + +export const WithVariant: Story = { + args: { + title: 'Variant Example', + variant: 'secondary' + } +} +``` + +### Available Features + +- **Vue 3 Support**: Full Vue 3 composition API and reactivity +- **PrimeVue Integration**: All PrimeVue components and theming +- **ComfyUI Theming**: Custom ComfyUI theme preset applied +- **Pinia Stores**: Access to application stores for components that need state +- **TypeScript**: Full TypeScript support with proper type checking +- **CSS/SCSS**: Component styling support +- **Auto-documentation**: Automatic prop tables and component documentation + +## Development Tips + +### Best Practices + +1. **Keep Stories Simple**: Each story should demonstrate one specific use case +2. **Use Realistic Data**: Use data that resembles real application usage +3. **Document Edge Cases**: Create stories for loading states, errors, and edge cases +4. **Group Related Stories**: Use consistent naming and grouping for related components + +### Component Testing Strategy + +```typescript +// Example: Testing different component states +export const Loading: Story = { + args: { + isLoading: true + } +} + +export const Error: Story = { + args: { + error: 'Failed to load data' + } +} + +export const WithLongText: Story = { + args: { + description: 'Very long description that might cause layout issues...' + } +} +``` + +### Debugging Tips + +- Use browser DevTools to inspect component behavior +- Check the Storybook console for Vue warnings or errors +- Use the Controls addon to dynamically change props +- Leverage the Actions addon to test event handling + +## Configuration Files + +- **`main.ts`**: Core Storybook configuration and Vite integration +- **`preview.ts`**: Global decorators, parameters, and Vue app setup +- **`manager.ts`**: Storybook UI customization (if needed) + +## Integration with ComfyUI + +This Storybook setup includes: + +- ComfyUI-specific theming and styling +- Pre-configured Pinia stores for state management +- Internationalization (i18n) support +- PrimeVue component library integration +- Proper alias resolution for `@/` imports + +For component-specific examples, see the NodePreview stories in `src/components/node/`. \ No newline at end of file