React Modular Themable Storybook
Overview
Create a reusable React UI package with a stable public API, theme tokens, part-based styling hooks, and Storybook coverage. Use this to modularize an existing widget without changing behavior, while enabling custom styling and composition.
Workflow (high-level)
- •
Inventory the existing UI.
- •Enumerate visual regions, variants, and states.
- •Identify "public" parts that should be themeable.
- •
Define the public API and theming contract.
- •Choose a
data-*part/role/state schema. - •Decide how styles are layered (base layout vs. token theme).
- •Define extension points (slots, renderers, component overrides).
- •See
references/parts-and-tokens.md.
- •Choose a
- •
Modularize and move code.
- •Extract components into a dedicated module folder.
- •Introduce a single top-level widget entrypoint + index exports.
- •Preserve behavior and accessibility attributes.
- •See
references/module-structure.md.
- •
Convert styles to tokens + parts.
- •Replace class selectors with
data-part+ CSS variables. - •Keep selectors low-specificity and scoped to a root attribute.
- •Provide
unstyledmode that omits base CSS. - •See
references/theming-css.md.
- •Replace class selectors with
- •
Wire Storybook.
- •Add stories for default, themed, unstyled, and custom renderers.
- •Use controls to expose key theme variables and slots.
- •See
references/storybook-patterns.md.
- •
Validate and document.
- •Run typecheck/lint/build.
- •Update diary/tasks, ensure migration notes are clear.
- •See
references/qa-checklist.md.
Decision cues
- •Prefer CSS variables for theme tokens and
data-partselectors for stability. - •Use component slots/renderers for structural customization; keep CSS for visuals.
- •Keep API additive and non-breaking; move legacy assets rather than deleting.
References
- •
references/parts-and-tokens.md - •
references/module-structure.md - •
references/theming-css.md - •
references/storybook-patterns.md - •
references/qa-checklist.md