1. Understand the Goal: The user wants a "storybook documentation schema." This means a structured way to document UI components, specifically linking three distinct areas:
* Accessibility Notes (a11y): How to use the component accessibly.
* Responsive Behavior: How the component adapts to different screen sizes.
* Performance Budgets: Metrics to ensure the component doesn't slow down the app.
* Context: This is likely for a design system or component library using Storybook (or similar documentation tools).
2. Analyze the "Why": Why does the user want to link these?
* Usually, these are documented separately (a11y tab, responsive view, performance tab).
* Linking them implies a holistic view of component health. A component isn't "done" just because it looks right; it must be fast, responsive, and usable by everyone.
* The schema needs to be machine-readable (JSON/YAML) or human-readable (Markdown structure) but structured enough to be enforced.
3. Determine the Format:
* A JSON Schema is the most precise way to define "structure."
* I should also provide a "Conceptual Implementation" (how it looks in Storybook) and an "Example" to make it concrete.
4. Draft the Schema Structure (Mental Draft):
* Root: Component Name, Description.
* Section 1: Accessibility.
* ARIA roles, Keyboard interaction, Focus management, Screen Reader notes.
* Section 2: Responsive.
* Breakpoints, Fluid vs. Fixed, Layout shift notes.
* Section 3: Performance.
* Budget limits (KB, Time), Interaction metrics (INP, CLS).
* The "Link": How do they relate?
* Example: Responsive behavior (hiding content) affects accessibility (focus traps).
* Example: Performance (lazy loading images) affects layout shift (CLS) and accessibility (alt text).
* Strategy: I will create a "Cross-Cutting Concerns" or "Interdependency Matrix" section within the schema to explicitly link these.
5. Refining the Schema (JSON Structure):
* `meta`: version, author.
* `component`: name, path.
* `accessibility`:
* `wcagLevel`: AA.
* `keyboardNav`: [].
* `screenReader`: notes.
* `responsive`:
* `breakpoints`: [].
* `fluidBehavior`: description.
* `performance`:
* `budget`: {JS, CSS, Time}.
* `coreWebVitals`: {CLS, LCP, INP}.
* `holisticReview`: (This is the key part to link them)
* `dependency`: "Responsive hide triggers focus loss?" -> Mitigation.
6. Developing the Storybook Integration (The "How-to"):
* How would a developer actually use this?
* Storybook uses "Args," "Parameters," and "Docs Pages."
* I should suggest a custom DocsPage block or a parameters object in the story file.
7. Creating the Content - Step-by-Step:
* **Introduction:** Define what this schema is (a contract for component quality).
* **The JSON Schema:** Write valid JSON schema syntax for the structure defined above.
* **The Example Object:** Show what a filled-out instance looks like (e.g., for a "Modal" component, which touches all three areas heavily).
* **Implementation Guide:** How to put this into Storybook (CSF format).
* **Visualizing the Link:** Explain *why* specific fields link the concepts (e.g., `hideOnMobile` property impacts `aria-hidden`).
8. Self-Correction/Refinement during drafting:
* Initial thought: Just list the fields.
* Correction: The prompt asks to link them. I need to add fields like accessibilityImplications inside the responsive section, or a shared constraints object. Let's go with embedding context.
* Refined approach: Create a "Schema" object that accepts a configuration where specific behaviors in one domain mandate checks in another.
9. Final Polish:
* Use clear headings.
* Use code blocks for the schema and examples.
* Add a "Why this matters" section.
(Self-Correction during JSON creation): Make sure to include standard Core Web Vitals in the performance section, as that's the modern standard. For accessibility, referencing WCAG criteria is best.
10. Output Generation: (Proceeding to generate the response based on the above structure.)
* Schema Definition: JSON.
* Example Usage: Modal Component.
* Storybook Integration: CSF 3.0 code snippet.
This is a comprehensive schema definition designed to be used within a Design System’s Storybook. It utilizes Storybook Args (args) and Parameters (parameters) to create a structured "Quality Contract" for every component.
You can implement this by extending your .storybook/preview.js or creating a custom DocsPage component.
1. The Schema Definition (JSON Structure)
This structure represents the data object attached to a component story. It forces developers to define how Accessibility, Responsiveness, and Performance intersect.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Component Quality Contract",
"type": "object",
"properties": {
"componentMeta": {
"type": "object",
"properties": {
"name": { "type": "string" },
"status": { "enum": ["draft", "beta", "stable", "deprecated"] }
}
},
"accessibility": {
"type": "object",
"description": "A11y compliance and interaction notes",
"properties": {
"wcagLevel": { "enum": ["A", "AA", "AAA"] },
"keyboardInteraction": {
"type": "array",
"items": {
"type": "object",
"properties": {
"key": { "type": "string" },
"action": { "type": "string" },
"responsiveConstraint": {
"description": "Does this interaction change based on viewport?",
"type": "string"
}
}
}
},
"screenReaderBehavior": {
"type": "object",
"properties": {
"role": { "type": "string" },
"ariaLive": { "enum": ["off", "polite", "assertive"] },
"focusManagement": { "type": "string" }
}
}
}
},
"responsiveBehavior": {
"type": "object",
"description": "How layout changes impact logic and performance",
"properties": {
"breakpoints": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"width": { "type": "string" },
"layoutShiftRisk": {
"description": "Does this breakpoint trigger CLS?",
"type": "boolean"
},
"domMutation": {
"description": "Does the DOM structure change significantly here?",
"type": "boolean"
}
}
}
}
}
},
"performanceBudget": {
"type": "object",
"description": "Resource limits for this component in isolation",
"properties": {
"maxJSWeight": { "type": "string", "pattern": "^\\d+(kb|mb)$" },
"maxCSSWeight": { "type": "string", "pattern": "^\\d+(kb|mb)$" },
"interactionDelay": {
"type": "string",
"description": "Max time to interactive (e.g., 100ms)"
},
"clsScore": {
"type": "number",
"description": "Cumulative Layout Shift score limit (0 - 0.1)"
}
}
}
}
}
2. Implementation: The Storybook "Docs Page"
Here is how you would implement this schema in your Storybook configuration to automatically generate documentation tables.
Create a file named ComponentQualityDocBlock.js:
import React from 'react';
import { Title, Subtitle, Description, Primary, ArgsTable, Stories } from '@storybook/addon-docs';
import { useParameter } from '@storybook/addons';
// Custom Doc Block to visualize the schema
const QualityCheckTable = () => {
const qualityData = useParameter('qualityContract', {});
if (!qualityData) return <p>No quality contract defined.</p>;
const { accessibility, responsiveBehavior, performanceBudget } = qualityData;
return (
<div style={{ fontFamily: 'sans-serif', marginTop: '2rem' }}>
<h2>Quality Contract & Constraints</h2>
{/* Accessibility Section */}
<div style={{ border: '1px solid #eee', padding: '10px', marginBottom: '10px' }}>
<h3>♿ Accessibility ({accessibility?.wcagLevel || 'N/A'})</h3>
<p><strong>Focus Management:</strong> {accessibility?.screenReaderBehavior?.focusManagement}</p>
<ul>
{accessibility?.keyboardInteraction?.map((item, i) => (
<li key={i}>
<code>{item.key}</code>: {item.action}
{item.responsiveConstraint && <em style={{color: 'orange'}}> (Viewport Dependent)</em>}
</li>
))}
</ul>
</div>
{/* Responsive Section */}
<div style={{ border: '1px solid #eee', padding: '10px', marginBottom: '10px' }}>
<h3>📱 Responsive Behavior</h3>
<table style={{ width: '100%', textAlign: 'left' }}>
<thead>
<tr>
<th>Breakpoint</th>
<th>Layout Shift Risk?</th>
<th>DOM Mutation?</th>
</tr>
</thead>
<tbody>
{responsiveBehavior?.breakpoints?.map((bp, i) => (
<tr key={i} style={{color: bp.layoutShiftRisk ? 'red' : 'black'}}>
<td>{bp.name} ({bp.width})</td>
<td>{bp.layoutShiftRisk ? '⚠️ HIGH' : '✅ Low'}</td>
<td>{bp.domMutation ? 'Yes (A11y Re-check needed)' : 'No'}</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Performance Section */}
<div style={{ border: '1px solid #eee', padding: '10px' }}>
<h3>⚡ Performance Budget</h3>
<ul>
<li><strong>JS Bundle:</strong> {performanceBudget?.maxJSWeight}</li>
<li><strong>CSS Bundle:</strong> {performanceBudget?.maxCSSWeight}</li>
<li><strong>Max CLS:</strong> {performanceBudget?.clsScore}</li>
</ul>
</div>
</div>
);
};
export default QualityCheckTable;
3. Example Usage in a Component Story
Here is how a developer would write a Story for a Modal component using this schema.
Modal.stories.js:
import Modal from './Modal';
export default {
title: 'Components/Modal',
component: Modal,
parameters: {
// Define the data conforming to the schema
qualityContract: {
accessibility: {
wcagLevel: "AA",
keyboardInteraction: [
{ key: "Escape", action: "Closes Modal", responsiveConstraint: null },
{ key: "Tab", action: "Traps focus inside modal", responsiveConstraint: "Standard" }
],
screenReaderBehavior: {
role: "dialog",
ariaLive: "assertive",
focusManagement: "Focus moves to first interactive element on open"
}
},
responsiveBehavior: {
breakpoints: [
{
name: "Mobile",
width: "< 600px",
layoutShiftRisk: true, // High risk because modal might push content
domMutation: false
},
{
name: "Desktop",
width: "> 601px",
layoutShiftRisk: false,
domMutation: false
}
]
},
performanceBudget: {
maxJSWeight: "20kb",
maxCSSWeight: "5kb",
interactionDelay: "50ms",
clsScore: 0.05
}
}
}
};
const Template = (args) => <Modal {...args} />;
export const Default = Template.bind({});
Default.args = {
isOpen: true,
title: "Confirm Action"
};
4. Why This Schema Works: The Interdependencies
This schema does not just list requirements; it links them logically through specific fields:
-
Responsive + Accessibility (The responsiveConstraint field):
- The Link: Accessibility often breaks on mobile when touch targets shrink or when responsive designs change the DOM order.
- Schema Role: Explicitly asks developers to note if a keyboard interaction changes based on viewport size.
-
Responsive + Performance (The layoutShiftRisk field):
- The Link: When a component changes layout (responsive behavior), it often causes Cumulative Layout Shift (CLS), failing the Performance Budget.
- Schema Role: Forces the developer to flag breakpoints that might trigger visual instability.
-
Accessibility + Performance (The domMutation field):
- The Link: If a responsive breakpoint involves heavy DOM manipulation (Performance), screen readers often lose track of the element's state (Accessibility).
- Schema Role: If
domMutation is true, the documentation visually flags that an A11y re-test is required.