Angular 20 Storybook Tailwind Addons
Goal
Install, repair, or verify Storybook for Angular 20 + Tailwind projects. Ensure stories render with the app's global Tailwind styles and that themes, designs, and a11y addons are configured. Optionally set up Chromatic CLI when explicitly requested.
Inputs
projectRoot(string, default: current working directory)globalStylePath(string, default: auto-detect fromangular.jsonstyles list; fallbacksrc/styles.cssthensrc/styles.scss)installChromaticCli(boolean, default:false, install only on explicit request)runVerification(boolean, default:true)
Preconditions
angular.jsonexists inprojectRoot.- The project already has Tailwind configured in a global stylesheet. If not, use $angular-tailwind-setup to install and configure Tailwind CSS.
- Use the repo package manager; examples below use
npm.
Success Criteria
- Storybook is installed and
npm run storybookstarts. .storybook/preview.tsimports the global stylesheet used by the Angular app..storybook/main.tsincludes all required addons:@storybook/addon-a11y@storybook/addon-themes@storybook/addon-designs
- Theme switching works with class-based Tailwind dark mode.
- At least one story shows a
parameters.designexample. - If
installChromaticCli=true,chromaticcan be invoked fromnpm run chromatic.
Workflow
Validate workspace and detect versions
- Read
package.jsonand confirm Angular major version (@angular/core) is close to20. - Abort with an error if major is not exactly
20. - Detect Storybook version if already installed (for addon compatibility checks).
- Resolve the global style file from
angular.json > build.options.styles; fallback tosrc/styles.cssorsrc/styles.scss.
- Read
Install Storybook (Angular preset)
- Run from
projectRoot:
npx storybook@latest init- Keep Angular framework defaults from the installer.
- Ensure
.storybook/main.tsand.storybook/preview.tswere created. - Run once after installation:
npm run storybook- Run from
Install required addons
npm i -D @storybook/addon-themes @storybook/addon-designs @storybook/addon-a11y- Check
@storybook/addon-designscompatibility with the installed Storybook major. - If needed, pin
@storybook/addon-designsto the matching major range. - If
installChromaticCli=true, run:
npm i -D chromatic- Check
Configure
.storybook/main.ts- Ensure
framework.nameis@storybook/angular. - Ensure
storiesincludes both MDX and stories globs. - Ensure
addonsincludes all required addons exactly once. - Merge with existing config instead of destructive overwrite.
import type { StorybookConfig } from '@storybook/angular'; const config: StorybookConfig = { framework: { name: '@storybook/angular', options: {}, }, stories: ['../src/**/*.mdx', '../src/**/*.stories.@(ts|tsx)'], addons: [ '@storybook/addon-a11y', '@storybook/addon-themes', '@storybook/addon-designs', ], }; export default config;- Ensure
Configure
.storybook/preview.ts- Import the Angular global stylesheet used by Tailwind.
- Add themes decorator for class-based switching (
light-> empty class,dark->darkclass). - Keep existing parameters and decorators when present.
import '../src/styles.css'; import type { Preview } from '@storybook/angular'; import { withThemeByClassName } from '@storybook/addon-themes'; const preview: Preview = { decorators: [ withThemeByClassName({ themes: { light: '', dark: 'dark' }, defaultTheme: 'light', }), ], }; export default preview;- Use
styles.scssimport when the project global style file is SCSS.
Add a minimal design-panel example
- Add or update a story with
parameters.designso the Designs panel is visible.
export const Primary = { args: { label: 'Button' }, parameters: { design: { type: 'figma', url: 'https://www.figma.com/file/XXXX/YourFile?node-id=123-456', }, }, };- Add or update a story with
Verify
- Run
npm run storybookand confirm no startup errors. - Confirm Tailwind classes render in stories.
- Confirm A11y panel appears in Storybook UI.
- Confirm theme switcher toggles classes on the preview root.
- Confirm Design panel appears for stories with
parameters.design. - If
installChromaticCli=true, runnpm run chromatic -- --helpand confirm CLI is available.
- Run
Guardrails
- Do not replace existing Storybook config wholesale; merge settings safely.
- Do not assume
src/styles.css; detect and import the actual configured global style file. - Keep addon entries unique; avoid duplicate addon registrations.
- If Tailwind styles are not visible, check style import path first, then verify Tailwind directives in the imported file.
- Do not install Chromatic unless explicitly requested.