| name | enhance-component-docs |
| description | Enhance React component documentation with JSDoc, improved Storybook stories, and autodoc configuration. |
| argument-hint | <component-files...> |
| model | sonnet |
| disable-model-invocation | true |
Enhance Component Documentation
Automatically enhance React component documentation with JSDoc comments, improved Storybook stories, and autodoc configuration.
Usage
/enhance-component-docs <component-files...>
What this command does
This command replicates the comprehensive documentation enhancement process:
- Analyze Component Structure: Read and understand component interfaces, props, and functionality
- Add Comprehensive JSDoc: Add detailed documentation comments to all interfaces, types, and functions
- Configure Storybook Autodocs: Enable automatic documentation generation with proper version compatibility handling
- Create Enhanced Stories: Improve existing stories or create new ones with detailed descriptions
- Add Interactive Examples: Create stories demonstrating real-world usage patterns
Implementation
Step 1: Add JSDoc to Component Files
For each component file, add documentation following these patterns:
Interfaces and Types
export interface ComponentProps extends BaseProps {
visible?: boolean;
onStateChange?: (newState: State) => void;
config?: ComponentConfig;
}
export type ComponentItems<T = any> = ComponentItem<T>[];
Utility Functions
export const isItemVisible = (
item: ComponentItem,
key: string,
overrides?: OverrideSettings,
): boolean => {
};
Main Component
const ComponentName = (props: ComponentProps): React.ReactElement => {
};
ComponentName.displayName = 'ComponentName';
Step 2: Configure Storybook Autodocs
Important: Due to version compatibility issues, use this simplified approach:
Update .storybook/main.ts:
import type { StorybookConfig } from '@storybook/react-vite';
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
'@storybook/addon-docs',
'@storybook/addon-onboarding',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
docs: {
defaultName: 'Documentation',
},
typescript: {
reactDocgen: false,
},
};
export default config;
Update .storybook/preview.tsx (note .tsx extension):
import type { Preview } from '@storybook/react-vite';
import { ConfigProvider } from 'antd';
import React from 'react';
const preview: Preview = {
tags: ['autodocs'],
decorators: [
(Story) => (
<ConfigProvider>
<div style={{ padding: '16px' }}>
<Story />
</div>
</ConfigProvider>
),
],
parameters: {
docs: {
extractComponentDescription: (_component: any, { notes }: any) => {
return notes?.markdown || notes?.text || null;
},
},
layout: 'padded',
},
};
export default preview;
Step 3: Enhance Story Files
Create comprehensive stories with this template:
import type { Meta, StoryObj } from '@storybook/react-vite';
import { ComponentName, ComponentProps } from './ComponentName';
const meta: Meta<typeof ComponentName> = {
title: 'Components/ComponentName',
component: ComponentName,
tags: ['autodocs'],
parameters: {
layout: 'padded',
docs: {
description: {
component: `
ComponentName provides [brief description].
## Key Features
### Feature 1
Detailed explanation of the feature and its benefits.
### Feature 2
How this feature works and when to use it.
### Integration
How to integrate with other components or systems.
## Usage Patterns
### Basic Usage
Simple examples for common use cases.
### Advanced Configuration
Examples of complex configurations and edge cases.
`,
},
},
},
argTypes: {
visible: {
control: { type: 'boolean' },
description: 'Control component visibility',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'true' },
},
},
config: {
control: { type: 'object' },
description: 'Advanced configuration options',
table: {
type: { summary: 'ComponentConfig' },
},
},
onStateChange: {
action: 'stateChanged',
description: 'Called when component state changes',
table: {
type: { summary: '(newState: State) => void' },
},
},
children: {
control: false,
description: 'Component children content',
table: {
type: { summary: 'ReactNode' },
},
},
},
};
export default meta;
type Story = StoryObj<typeof ComponentName>;
export const Default: Story = {
parameters: {
docs: {
description: {
story: 'Basic usage with default settings. Shows the component in its simplest form.',
},
},
},
args: {
visible: true,
config: {
},
},
};
export const Interactive: Story = {
parameters: {
docs: {
description: {
story: 'Interactive example with state management. Demonstrates callbacks and dynamic behavior.',
},
},
},
render: () => {
const [state, setState] = useState(initialState);
return (
<ComponentName
visible={state.visible}
config={state.config}
onStateChange={(newState) => {
setState(newState);
console.log('State changed:', newState);
}}
/>
);
},
};
export const ConfigurationVariants: Story = {
parameters: {
docs: {
description: {
story: 'Different configuration options showing component flexibility.',
},
},
},
args: {
visible: true,
config: {
},
},
};
Step 4: Create Sub-component Stories
For complex components with sub-components, create dedicated story files:
const meta: Meta<typeof SubComponent> = {
title: 'Components/ComponentName/SubComponent',
component: SubComponent,
tags: ['autodocs'],
parameters: {
docs: {
description: {
component: 'SubComponent documentation focusing on its specific functionality.',
},
},
},
};
Step 5: Validation Steps
After enhancement:
- TypeScript Check: Ensure no type errors
- Build Stories: Verify Storybook builds successfully
- Review Documentation: Check auto-generated docs are complete
- Test Interactivity: Validate all controls and actions work
- Cross-reference: Ensure examples match actual component behavior
File Checklist
For each component, ensure these files are created/updated:
Best Practices
- Documentation First: Write docs that explain the "why" not just the "what"
- Real Examples: Use practical examples that developers will actually use
- Interactive Stories: Create stories that let users experiment
- Comprehensive Coverage: Cover edge cases and error states
- Consistent Style: Maintain consistent documentation patterns across components
- Manual ArgTypes: Since TypeScript docgen is disabled, manually define all argTypes with complete information
- Version Compatibility: Always check Storybook addon versions for compatibility
- Component DisplayName: Add displayName to improve debugging and documentation clarity
- JSX Support: Use .tsx extension for preview files when using JSX syntax
Troubleshooting
"Cannot convert a symbol to a string" Error
- Disable TypeScript docgen:
reactDocgen: false
- Use manual argTypes definition instead of automatic extraction
- Ensure all Storybook addons are compatible versions
Version Compatibility Issues
- Check all
@storybook/* packages are the same version
- Avoid mixing different major versions of Storybook addons
- Use simplified addon configuration to reduce conflicts
JSX Syntax Errors in Preview
- Use
.tsx extension for preview files
- Import React properly:
import React from 'react'
- Ensure JSX transforms are configured correctly