@fluentui/react-storybook-addon v0.0.0-nightly-20250416-0406.1
@fluentui/react-storybook-addon
Storybook addon for Fluent UI React
✨ Features
Toolbar/Tools
- Adds a Fluent theme switcher:
Theme Management in Storybook Globals
Exports types and utilities to set and consume the correct Fluent theme in Storybook globals. Here's an example picker that sets the Fluent theme in Storybook globals.
import * as React from 'react';
import { themes, setGlobalTheme, FluentStoryContext, THEME_ID } from '@fluentui/react-storybook-addon';
// Storybook context which can be accessed, for example, in decorators
// https://storybook.js.org/docs/react/writing-stories/decorators#context-for-mocking
export const ThemePicker: React.FC<{ context: FluentStoryContext }> = ({ context }) => {
  const handleChange = e => {
    setGlobalTheme(e.target.value);
  };
  const selectedTheme = themes.find(theme => theme.id === context.globals[THEME_ID]);
  return (
    <select onChange={handleChange}>
      {themes.map(theme => (
        <option selected={selectedTheme.id === theme.id} value={theme.id}>
          {theme.label}
        </option>
      ))}
    </select>
  );
};Getting Started
Installation
To install the addon, run:
yarn add -D @fluentui/react-storybook-addonConfiguration
Add the following content to .storybook/main.js:
module.exports = {
  addons: ['@fluentui/react-storybook-addon'],
};Development
- Run the inner loop from the monorepo root with - yarn workspace @fluentui/react-storybook-addon storybook.- 💡 This will run the prestorybookscript that compiles the addon implementation with all of its direct dependencies within the monorepo, so it can be consumed by the local Storybook.
 
- 💡 This will run the 
- After making any changes to the implementation, manually run - yarn workspace @fluentui/react-storybook-addon buildto reflect those changes in your local Storybook.
Parameter Configuration
Three custom optional parameters can be set to alter the behavior of the addon:
- dir- Determines whether to render the story in- ltror- rtlmode. Default is- undefined.
- fluentTheme- Determines whether to render the story theme in- web-light,- web-dark,- teams-high-contrast,- teams-dark, or- teams-light. Setting this parameter will disable the ability to dynamically change the theme within the story canvas or doc.
- mode- When set to- vr-test, this removes the injected padding and background theme that's automatically applied from the rendered story. Default is- default.
import { FluentParameters, parameters } from '@fluentui/react-storybook-addon';
import { Button } from '@fluentui/react-components';
export const Button = () => <Button>Hello World</Button>;
export const ButtonDarkMode = {
  render: Button,
  parameters: { fluentTheme: 'web-dark' } as FluentParameters, // Story renders in Dark mode.
};
export const ButtonHighContrast = {
  render: Button,
  parameters: { fluentTheme: 'teams-high-contrast', mode: 'vr-test' } as FluentParameters, // Story renders in High Contrast mode without injected padding and background style.
};
export const ButtonRTL = {
  render: Button,
  // Parameters identity function will have all TS type annotations built in for intellisense.
  parameters: parameters({ fluentTheme: 'web-light', dir: 'rtl', mode: 'vr-test' }), // Story renders in RTL, Web light mode and without injected padding and background style.
};5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
