|
| 1 | +# Storybook HTML5 Element Stories |
| 2 | + |
| 3 | +**Compatible with Storybook v8+ (tested with v10)** |
| 4 | + |
| 5 | +A comprehensive collection of auto-generated Storybook stories for all HTML5 elements, providing interactive documentation and testing capabilities for web components and HTML elements. |
| 6 | + |
| 7 | +## 🚀 Quick Start - Drop-in Solution |
| 8 | + |
| 9 | +Getting started is incredibly simple: |
| 10 | + |
| 11 | +1. **Create or open your Storybook project** |
| 12 | + ```bash |
| 13 | + npx storybook@latest init |
| 14 | + ``` |
| 15 | + |
| 16 | +2. **Drop in the templates** |
| 17 | + - Copy the `storybook` folder to your storybook folder |
| 18 | + - Rename it to `stories` (or your configured stories directory) |
| 19 | + |
| 20 | +3. **Done!** |
| 21 | + - Start Storybook: `npm run storybook` |
| 22 | + - All HTML5 elements are now available in your Storybook |
| 23 | + |
| 24 | +That's it! No configuration needed. All stories are ready to use immediately. |
| 25 | + |
| 26 | +## 📁 Structure |
| 27 | + |
| 28 | +``` |
| 29 | +storybook/ |
| 30 | +├── inline/ # Inline elements (a, span, strong, etc.) |
| 31 | +│ ├── a.stories.js |
| 32 | +│ ├── abbr.stories.js |
| 33 | +│ └── ... |
| 34 | +├── block/ # Block elements (div, section, article, etc.) |
| 35 | +│ ├── article.stories.js |
| 36 | +│ ├── aside.stories.js |
| 37 | +│ └── ... |
| 38 | +├── void/ # Void/self-closing elements (img, input, meta, etc.) |
| 39 | +│ ├── img.stories.js |
| 40 | +│ ├── input.stories.js |
| 41 | +│ └── ... |
| 42 | +└── composed/ # Composed examples showing valid parent-child relationships |
| 43 | + ├── form.composed.stories.js |
| 44 | + ├── table.composed.stories.js |
| 45 | + └── ... |
| 46 | +``` |
| 47 | + |
| 48 | +## ✨ Features |
| 49 | + |
| 50 | +### Complete HTML5 Coverage |
| 51 | +- **113 HTML5 elements** with full documentation |
| 52 | +- All **global attributes** (id, class, data-*, aria-*, etc.) |
| 53 | +- **Element-specific attributes** with proper types and validation |
| 54 | +- **Enum attributes** with dropdown selectors showing all valid values |
| 55 | +- **ARIA support** with all applicable ARIA attributes |
| 56 | + |
| 57 | +### Interactive Controls |
| 58 | +Every story includes Storybook controls for: |
| 59 | +- **Text inputs** for string attributes |
| 60 | +- **Number inputs** for numeric attributes |
| 61 | +- **Boolean toggles** for true/false attributes |
| 62 | +- **Select dropdowns** for enum values (with empty option) |
| 63 | +- **Object editors** for data-* attributes |
| 64 | + |
| 65 | +### Composed Examples |
| 66 | +The `composed/` folder contains **17 sophisticated examples** demonstrating: |
| 67 | +- **Valid parent-child relationships** based on HTML5 content model |
| 68 | +- **Realistic usage patterns** (forms with inputs, tables with rows, lists with items) |
| 69 | +- **Priority elements** showing the most common children |
| 70 | +- **Proper nesting** respecting uniqueness constraints (`uniquePerParent`) |
| 71 | + |
| 72 | +Examples include: |
| 73 | +- `form.composed.stories.js` - Forms with fieldsets, inputs, buttons |
| 74 | +- `table.composed.stories.js` - Tables with caption, colgroups, tbody, rows |
| 75 | +- `head.composed.stories.js` - Head with title, meta, link, script elements |
| 76 | +- `figure.composed.stories.js` - Figures with images and captions |
| 77 | +- `ul.composed.stories.js`, `ol.composed.stories.js` - Lists with items |
| 78 | +- And more... |
| 79 | + |
| 80 | +## 🎯 Advantages |
| 81 | + |
| 82 | +### For Developers |
| 83 | +- **Zero Configuration** - Drop in and start using immediately |
| 84 | +- **Type Safety** - All attributes properly typed and validated |
| 85 | +- **Autocomplete** - Full IDE support through JSDoc comments |
| 86 | +- **Reusable Components** - Import and use Default stories in your own components |
| 87 | +- **Learning Tool** - Explore HTML5 elements and their attributes interactively |
| 88 | + |
| 89 | +### For Teams |
| 90 | +- **Single Source of Truth** - One place to see all HTML5 capabilities |
| 91 | +- **Consistency** - Standardized documentation across all elements |
| 92 | +- **Accessibility** - All ARIA attributes included and documented |
| 93 | +- **Quality Assurance** - Test elements with different attribute combinations |
| 94 | +- **Onboarding** - New team members can learn HTML5 quickly |
| 95 | + |
| 96 | +### For Design Systems |
| 97 | +- **Foundation** - Build your design system on top of semantic HTML |
| 98 | +- **Customization** - Extend stories with your own variants |
| 99 | +- **Documentation** - Use as base documentation for your components |
| 100 | +- **Testing** - Validate your CSS against all HTML5 elements |
| 101 | +- **Visual Regression** - Test styling across all element types |
| 102 | + |
| 103 | +## 🔧 Customization |
| 104 | + |
| 105 | +### Using Stories in Your Components |
| 106 | + |
| 107 | +Import and use the Default stories to compose your own: |
| 108 | + |
| 109 | +```javascript |
| 110 | +import * as ButtonStories from './inline/button.stories.js'; |
| 111 | +import * as InputStories from './void/input.stories.js'; |
| 112 | + |
| 113 | +export const MyForm = { |
| 114 | + render: () => { |
| 115 | + const form = document.createElement('form'); |
| 116 | + |
| 117 | + const input = InputStories.Default.render(InputStories.Default.args); |
| 118 | + const button = ButtonStories.Default.render(ButtonStories.Default.args); |
| 119 | + |
| 120 | + form.appendChild(input); |
| 121 | + form.appendChild(button); |
| 122 | + |
| 123 | + return form; |
| 124 | + } |
| 125 | +}; |
| 126 | +``` |
| 127 | + |
| 128 | +### Extending Stories |
| 129 | + |
| 130 | +Add your own variants by importing the element stories: |
| 131 | + |
| 132 | +```javascript |
| 133 | +import Anchor from './inline/a.stories.js'; |
| 134 | + |
| 135 | +export const InlineButton = { |
| 136 | + ...Anchor, |
| 137 | + args: { |
| 138 | + ...Anchor.args, |
| 139 | + role: 'button', |
| 140 | + } |
| 141 | +}; |
| 142 | +``` |
| 143 | + |
| 144 | +## 🎨 Styling |
| 145 | + |
| 146 | +All stories use semantic HTML without inline styles, making them perfect for: |
| 147 | +- **CSS framework testing** (Bootstrap, Tailwind, PicoCSS, etc.) |
| 148 | +- **Custom design systems** |
| 149 | +- **Accessibility testing** |
| 150 | +They are intended to form the basis of your own design system. You make them your own by creating organisms and molecules on top of these atomic elements - including custom styles as needed. |
| 151 | + |
| 152 | +## 🔍 Content Model Validation |
| 153 | + |
| 154 | +Some HTML elements need to be seen in their content model context to be meaningful. The `composed/` folder provides stories that demonstrate valid parent-child relationships according to HTML5 specifications. |
| 155 | +Composed stories follow HTML5 content model rules: |
| 156 | +- Only **valid children** are included (based on `$parentOf` metadata) |
| 157 | +- **Unique elements** appear only once (title, base, etc.) |
| 158 | + |
| 159 | +## 🚦 Compatibility |
| 160 | + |
| 161 | +- **Storybook**: v8, v9, v10+ |
| 162 | +- **Browsers**: All modern browsers (ES6+) |
| 163 | +- **Frameworks**: Framework-agnostic (vanilla JavaScript) |
| 164 | +- **Build Tools**: Works with Webpack, Vite, etc. |
| 165 | + |
| 166 | +## 📝 Generated Code |
| 167 | + |
| 168 | +All stories are **auto-generated** from: |
| 169 | +- HTML5 schema YAML files |
| 170 | +- PHP Element classes with metadata |
| 171 | +- Content model relationships (`$childOf`, `$parentOf`) |
| 172 | +- Global and element-specific attributes |
| 173 | + |
| 174 | +**Do not edit the generated files manually** - they will be overwritten. Instead: |
| 175 | +1. Modify the source specifications |
| 176 | +2. Regenerate using: `php bin/ext-html generate:composed storybook templates/storybook` |
| 177 | + |
| 178 | +To regenerate stories: |
| 179 | +```bash |
| 180 | +# Generate all element stories |
| 181 | +php bin/ext-html generate:all storybook templates/storybook |
| 182 | + |
| 183 | +# Generate only composed examples |
| 184 | +php bin/ext-html generate:composed storybook templates/storybook --overwrite-existing=true |
| 185 | +``` |
0 commit comments