Storybook story modes
Capture separate Storybook snapshots for each mode, combining theme, viewport, and locale globals in Argos.
Argos can capture multiple versions of your stories by applying different “modes,” which are essentially combinations of global Storybook settings (such as theme, viewport, locale, etc.). With modes, you can automatically generate a separate snapshot for each unique configuration.
What are modes?
A mode is a preset that configures various Storybook globals. For instance, you can have a “dark” mode for your UI theme, a “mobile” mode for smaller screens, or a combined “dark-mobile-spanish” mode that configures multiple globals at once.
Key features of modes:
Each mode is named (e.g., "dark desktop" or "mobile").
Each mode sets specific values for the Storybook globals (e.g., viewport size, background color, locale).
Argos creates a separate visual baseline for each mode name.
Setting up globals & addons
Before you define any modes, make sure you’ve configured the relevant Storybook features and addons in your .storybook/preview.ts (or .js) file. Examples include:
Viewports and backgrounds, built into Storybook 9 and later (on Storybook 8, install
@storybook/addon-viewportand@storybook/addon-backgrounds)@storybook/addon-themesfor light/dark themesstorybook-i18nfor locales
These features rely on Storybook “globals” and “decorators” under the hood. Argos modes simply set those globals at test time to generate multiple snapshots of the same story.
import { withThemeByClassName } from "@storybook/addon-themes";
import "../src/styles.css";
const preview = {
parameters: {
viewport: {
options: {
compact: {
name: "Compact",
styles: { width: "600px", height: "900px" },
},
widescreen: {
name: "Widescreen",
styles: { width: "1440px", height: "900px" },
},
},
},
backgrounds: {
options: {
light: { name: "Light", value: "#ffffff" },
dark: { name: "Dark", value: "#1A1A1A" },
},
},
},
decorators: [
withThemeByClassName({
themes: {
light: "light",
dark: "dark",
},
defaultTheme: "light",
}),
],
};
export default preview;Defining modes
Create a .storybook/modes.ts (or .js) file that exports an object where each key is a mode name and each value is a set of overrides for the Storybook globals. For example:
Each object can include as many or as few globals as you need. If a mode doesn’t specify a particular global, that global simply won’t be changed in that mode.
A mode’s viewport is a key of your viewport.options map: Argos resizes the browser to that viewport before capturing the story. Storybook’s own global format works too, so viewport: { value: "compact", isRotated: true } captures the viewport in landscape orientation. Likewise, backgrounds.value is a key of backgrounds.options, and theme is the global read by withThemeByClassName.
Applying modes
Attach modes to any level of your Storybook: globally in .storybook/preview.ts (or .js), at the component (default export) level, or in an individual story’s parameters. Argos merges all modes defined up the chain.
Basic usage in a story file
In this example, Argos will generate two snapshots for each story (DefaultView and SoldOutView): one in “mobile” mode and another in “dark” mode.
Combining modes from multiple levels
You can add modes in your .storybook/preview.ts (or .js) at the project level, then define additional modes in a story file. Argos merges the modes defined at every level and captures one snapshot per mode name.
Project-level modes
Component-level modes
When Argos runs, it will generate snapshots for each mode defined at the project level and the component level. So for Basic, you get “light mobile” (from preview.ts) plus “dark widescreen” (from the component’s parameter).
Excluding or disabling modes
Sometimes you want to turn off a certain higher-level mode for a specific story. You can do this by passing a disable property:
That story will now ignore light mobile mode but still apply any other inherited modes.
Working with baselines
Each mode name corresponds to a separate baseline in Argos. If you rename a mode, it’s treated as entirely new. If you alter the internals of a mode (like changing the viewport from “compact” to “ultra-compact”) without renaming it, Argos still compares the new screenshot against the old baselines for that mode name.
FAQ
By setting up modes for dark vs. light, mobile vs. desktop, and everything in between, you verify all key variants of your UI without writing extra stories.
Last updated
Was this helpful?