|
| 1 | +# Component Documentation Guidelines |
| 2 | + |
| 3 | +This guide outlines the standards and structure for documenting components in the Cube UI Kit. Following these guidelines ensures consistency, clarity, and comprehensive coverage of component features. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Our component documentation serves multiple purposes: |
| 8 | +- Provides clear usage instructions for developers |
| 9 | +- Ensures accessibility best practices are communicated |
| 10 | +- Documents styling capabilities through the `tasty` style system |
| 11 | +- Maintains consistency across all component documentation |
| 12 | + |
| 13 | +## Key Principles |
| 14 | + |
| 15 | +1. **Accessibility First**: Components use React Aria Hooks and documentation should emphasize accessibility features |
| 16 | +2. **Style System Integration**: Document `tasty` styling capabilities thoroughly |
| 17 | +3. **Practical Examples**: Include real-world usage examples, not just API references |
| 18 | +4. **Clear Structure**: Follow the prescribed documentation structure for consistency |
| 19 | + |
| 20 | +## Documentation Structure |
| 21 | + |
| 22 | +Every component documentation file should follow this structure: |
| 23 | + |
| 24 | +```mdx |
| 25 | +import { Meta, Canvas, Story, Controls } from '@storybook/blocks'; |
| 26 | +import { ComponentName } from './ComponentName'; |
| 27 | +import * as ComponentStories from './ComponentName.stories'; |
| 28 | + |
| 29 | +<Meta of={ComponentStories} /> |
| 30 | + |
| 31 | +# ComponentName |
| 32 | + |
| 33 | +Brief description of what the component is and its primary purpose. |
| 34 | + |
| 35 | +## When to Use |
| 36 | + |
| 37 | +- Scenario 1 where this component is appropriate |
| 38 | +- Scenario 2 where this component is appropriate |
| 39 | +- Scenario 3 where this component is appropriate |
| 40 | + |
| 41 | +## Component |
| 42 | + |
| 43 | +<Story of={ComponentStories.Default} /> |
| 44 | + |
| 45 | +### Properties |
| 46 | + |
| 47 | +<Controls of={componentStories.Default} /> |
| 48 | + |
| 49 | +### Base Properties |
| 50 | + |
| 51 | +Supports [Base properties](/BaseProperties) |
| 52 | + |
| 53 | +### Styling Properties |
| 54 | + |
| 55 | +#### styles |
| 56 | + |
| 57 | +Customizes the root element of the component. |
| 58 | + |
| 59 | +**Sub-elements:** |
| 60 | +- `ElementName` - Description of what this element represents |
| 61 | + |
| 62 | +#### [additionalStyles] (if applicable) |
| 63 | + |
| 64 | +Customizes the [specific part] of the component. |
| 65 | + |
| 66 | +**Sub-elements:** |
| 67 | +- `SubElementName` - Description of what this sub-element represents |
| 68 | + |
| 69 | +### Style Properties |
| 70 | + |
| 71 | +These properties allow direct style application without using the `styles` prop: `width`, `height`. |
| 72 | + |
| 73 | +### Modifiers |
| 74 | + |
| 75 | +The `mods` property accepts the following modifiers you can override: |
| 76 | + |
| 77 | +| Modifier | Type | Description | |
| 78 | +|----------|------|-------------| |
| 79 | +| modifierName | `boolean` | Description of what this modifier does | |
| 80 | + |
| 81 | +## Variants |
| 82 | + |
| 83 | +### Types |
| 84 | + |
| 85 | +- `primary` - Description of primary type |
| 86 | +- `secondary` - Description of secondary type |
| 87 | + |
| 88 | +### Themes |
| 89 | + |
| 90 | +- `default` - Standard appearance |
| 91 | +- `danger` - Used for destructive actions |
| 92 | + |
| 93 | +### Sizes |
| 94 | + |
| 95 | +- `small` - Compact size for dense interfaces |
| 96 | +- `medium` - Default size |
| 97 | +- `large` - Emphasized size for important actions |
| 98 | + |
| 99 | +## Examples |
| 100 | + |
| 101 | +### Basic Usage |
| 102 | + |
| 103 | +```jsx |
| 104 | +<ComponentName arg="something" /> |
| 105 | +``` |
| 106 | + |
| 107 | +### [Additional Examples as needed] |
| 108 | + |
| 109 | +## Accessibility |
| 110 | + |
| 111 | +### Keyboard Navigation |
| 112 | + |
| 113 | +- `Tab` - Moves focus to the component |
| 114 | +- `Space/Enter` - Activates the component |
| 115 | +- [Additional keyboard shortcuts] |
| 116 | + |
| 117 | +### Screen Reader Support |
| 118 | + |
| 119 | +- Component announces as "[role]" to screen readers |
| 120 | +- State changes are announced (e.g., "pressed", "expanded") |
| 121 | +- [Additional screen reader considerations] |
| 122 | + |
| 123 | +### ARIA Properties |
| 124 | + |
| 125 | +- `aria-label` - Provides accessible label when no visible label exists |
| 126 | +- [Additional ARIA properties] |
| 127 | + |
| 128 | +## Best Practices |
| 129 | + |
| 130 | +1. **Do**: Best practice example |
| 131 | + ```jsx |
| 132 | + <ComponentName label="Clear Label">Content</ComponentName> |
| 133 | + ``` |
| 134 | + |
| 135 | +2. **Don't**: Anti-pattern example |
| 136 | + ```jsx |
| 137 | + <ComponentName>Unclear usage</ComponentName> |
| 138 | + ``` |
| 139 | + |
| 140 | +3. **Accessibility**: Always provide meaningful labels |
| 141 | +4. **Performance**: Consider performance implications for specific use cases |
| 142 | + |
| 143 | +## Integration with Forms |
| 144 | + |
| 145 | +[For input components only] |
| 146 | +This component supports all [Field properties](/field-properties.md) when used within a Form. |
| 147 | + |
| 148 | +## Suggested Improvements |
| 149 | + |
| 150 | +- Improvement 1: Description of potential enhancement |
| 151 | +- Improvement 2: Description of potential enhancement |
| 152 | +- Improvement 3: Description of potential enhancement |
| 153 | + |
| 154 | +## Related Components |
| 155 | + |
| 156 | +- [RelatedComponent1](/components/RelatedComponent1) - When to use instead |
| 157 | +- [RelatedComponent2](/components/RelatedComponent2) - Complementary component |
| 158 | +``` |
| 159 | + |
| 160 | +## Specific Guidelines |
| 161 | + |
| 162 | +### 1. Component Description |
| 163 | + |
| 164 | +- Start with a clear, concise description of what the component is |
| 165 | +- Follow with scenarios where the component should be used |
| 166 | +- Avoid technical implementation details in the introduction |
| 167 | + |
| 168 | +### 2. Properties Documentation |
| 169 | + |
| 170 | +#### Base Properties |
| 171 | +- If the component uses `filterBaseProps`, don't list base properties individually |
| 172 | +- Instead, include the link: `Supports [Base properties](/base-properties.md)` |
| 173 | +- Exception: Always document the `qa` property if it has special behavior |
| 174 | + |
| 175 | +#### Styling Properties |
| 176 | +- Document each `styles` or `*Styles` property separately |
| 177 | +- For each styling property, list all available tasty sub-elements with descriptions. Count only those sub-elements that are mentioned in tasty styles in the root element inside component and can be overrided by passing an object with a specific key (sub-element name) to `styles` property |
| 178 | +- Format: `ElementName` - Description of what this element represents |
| 179 | + |
| 180 | +#### Style Properties |
| 181 | +- List all properties that can be used for direct styling (e.g., `width`, `height`, `padding`) |
| 182 | +- These are properties that map to `tasty` styles without using the `styles` prop |
| 183 | +- Use `src/tasty/styles/list.ts` file to understand how it works. |
| 184 | + |
| 185 | +#### React Aria Properties |
| 186 | +- Document all React Aria properties with clear descriptions |
| 187 | +- It's acceptable to rewrite React Aria descriptions for clarity |
| 188 | +- Focus on practical usage rather than technical implementation |
| 189 | + |
| 190 | +### 3. Examples |
| 191 | + |
| 192 | +- Provide practical, real-world examples written in `jsx` code |
| 193 | +- Avoid styling examples unless it demonstrates essential capabilities |
| 194 | +- Each example should have a clear purpose and title |
| 195 | +- Do not use Storybook's Canvas and Story components for interactive examples |
| 196 | +- Each story should describe a usage case |
| 197 | +- The more sophisticated component, the more stories we need to cover all cases |
| 198 | + |
| 199 | +### 4. Modifiers |
| 200 | + |
| 201 | +- Document all available modifiers that can be passed via the `mods` property |
| 202 | +- Explain how each modifier affects the component's appearance or behavior |
| 203 | +- Include any modifier combinations that have special behavior |
| 204 | + |
| 205 | +### 5. Accessibility Section |
| 206 | + |
| 207 | +- Include keyboard navigation patterns |
| 208 | +- Document screen reader behavior |
| 209 | +- List relevant ARIA properties and their usage |
| 210 | +- Provide guidance on ensuring accessible implementations |
| 211 | + |
| 212 | +### 6. Form Integration |
| 213 | + |
| 214 | +For input components (TextInput, Select, DatePicker, etc.): |
| 215 | +- Don't duplicate field property documentation |
| 216 | +- Include: "This component supports all [Field properties](/field-properties.md) when used within a Form." |
| 217 | + |
| 218 | +### 7. File Naming and Location |
| 219 | + |
| 220 | +- Documentation files use `.docs.mdx` extension |
| 221 | +- Place in the same directory as the component |
| 222 | +- Naming convention: `ComponentName.tsx` → `ComponentName.docs.mdx` |
| 223 | + |
| 224 | +## Review Checklist |
| 225 | + |
| 226 | +Before submitting component documentation, ensure: |
| 227 | + |
| 228 | +- [ ] Follows the prescribed structure |
| 229 | +- [ ] Includes practical examples with Storybook Stories |
| 230 | +- [ ] Documents all styling properties and sub-elements |
| 231 | +- [ ] Lists all modifiers with descriptions |
| 232 | +- [ ] Includes accessibility information |
| 233 | +- [ ] Contains best practices section |
| 234 | +- [ ] Has "Suggested Improvements" section |
| 235 | +- [ ] Uses correct file naming and location |
| 236 | +- [ ] All links use provided placeholder format |
| 237 | +- [ ] Style properties are documented separately from styling properties |
| 238 | +- [ ] Form integration mentioned for input components |
| 239 | +- [ ] Base properties linked, not listed (except `qa`) |
| 240 | +- [ ] Tabler (`@tabler/icons-react`) or UI Kit icons are used in examples |
0 commit comments