Storybook Addon
The TailTrace Storybook Addon audits your component styles in real-time, flagging fuzzy matches as potential regressions.
Features
Section titled “Features”- Automatic Audits - Every story is analyzed on render
- Regression Detection - Fuzzy matches are flagged as warnings
- Token Suggestions - See which tokens to use instead
- Export Specs - Generate design token specifications
Installation
Section titled “Installation”-
Install the addon
Terminal window bun add -D @tailtrace/storybook-addon -
Add to your Storybook config
.storybook/main.ts import type { StorybookConfig } from '@storybook/react-vite';const config: StorybookConfig = {addons: ['@storybook/addon-essentials','@tailtrace/storybook-addon',],};export default config; -
Optionally configure the decorator
.storybook/preview.ts import { withTailtraceAudit } from '@tailtrace/storybook-addon';export const decorators = [withTailtraceAudit({deltaEThreshold: 2.3,}),];
Viewing Audits
Section titled “Viewing Audits”- Run Storybook:
bun run storybook - Navigate to any story
- Click the “TailTrace” tab in the addons panel
- See all computed styles with token translations
Understanding Results
Section titled “Understanding Results”The audit table shows:
| Column | Description |
|---|---|
| Element | HTML element and selector |
| Property | CSS property being audited |
| Value | Computed CSS value |
| Token | Matching Tailwind token |
| Status | Confidence indicator |
Regression Warnings
Section titled “Regression Warnings”When a style has a fuzzy match, it’s highlighted as a potential regression:
Configuration
Section titled “Configuration”Decorator Options
Section titled “Decorator Options”withTailtraceAudit({ // Color matching threshold deltaEThreshold: 2.3,
// Spacing matching threshold (px) spacingThreshold: 2,
// Properties to audit properties: [ 'color', 'background-color', 'border-color', 'padding', 'margin', 'font-size', ],
// Elements to skip skipSelectors: ['.ignore-audit', '[data-no-audit]'],})Config File
Section titled “Config File”Create tailtrace.json in your Storybook root:
{ "colors": { "brand-primary": "#3b82f6" }, "deltaEThreshold": 2.3}Exporting Specs
Section titled “Exporting Specs”Generate a design token specification from your stories:
- Open the TailTrace panel
- Click “Export Spec”
- Choose JSON or CSS custom properties format
Example output:
{ "usedTokens": { "colors": ["blue-500", "slate-900", "white"], "spacing": ["p-4", "m-2", "gap-4"], "typography": ["text-sm", "font-semibold"] }, "unknownValues": [ { "property": "color", "value": "#custom123" } ]}CI Integration
Section titled “CI Integration”Run TailTrace audits in CI to catch regressions:
# Install dependenciesbun install
# Run Storybook in CI mode with TailTracebun run build-storybookbunx @tailtrace/storybook-addon audit ./storybook-staticThe audit command exits with code 1 if fuzzy matches exceed your threshold.
Troubleshooting
Section titled “Troubleshooting”Panel Not Showing
Section titled “Panel Not Showing”- Verify the addon is in your
main.tsconfig - Restart Storybook
- Check browser console for errors
Styles Not Detected
Section titled “Styles Not Detected”- Ensure components render actual DOM elements
- Check that styles aren’t in Shadow DOM
- The addon reads
getComputedStyle()- inline styles work fine
Performance
Section titled “Performance”For stories with many elements:
- Use
skipSelectorsto exclude non-essential elements - Limit audited properties
- Consider auditing only in development, not production builds