Outline all elements with CSS to help with layout placement and alignment
npx @tessl/cli install tessl/npm-storybook--addon-outline@8.6.0@storybook/addon-outline provides visual debugging capabilities for Storybook by drawing colored outlines around HTML elements. Based on the Pesticide CSS library, it helps developers identify layout issues, understand element boundaries, and debug complex UI components through an integrated toolbar toggle and keyboard shortcut.
npm install -D @storybook/addon-outlineMain entry point:
import addonOutline from "@storybook/addon-outline";
import type { OutlineParameters } from "@storybook/addon-outline";Preview-specific imports:
import { decorators, initialGlobals } from "@storybook/addon-outline/preview";Add to your .storybook/main.js (if not using essentials):
export default {
addons: ['@storybook/addon-outline'],
};Alt+O (Windows/Linux) or Option+O (Mac)outline: true// .storybook/preview.js
export default {
globals: {
outline: false, // Default state
},
};Configure the outline addon for preview integration.
/**
* Default export factory function that configures the addon for preview
* Returns a preview configuration with decorator and global annotations
*/
declare function addonOutline(): PreviewAnnotations;Usage Example:
// .storybook/preview.js
import addonOutline from '@storybook/addon-outline';
export default addonOutline();Configuration interface for addon parameters.
/**
* Addon configuration parameters interface
*/
interface OutlineParameters {
/**
* Outline configuration
* @see https://storybook.js.org/docs/essentials/measure-and-outline#parameters
*/
outline: {
/** Remove the addon panel and disable the addon's behavior */
disable?: boolean;
};
}Usage Example:
// In a story file
export default {
title: 'Example/Button',
component: Button,
parameters: {
outline: {
disable: true, // Disable outline for this story
},
},
};Core decorator and global configuration exported from preview entry point.
/**
* Array of decorators including the outline decorator
*/
declare const decorators: DecoratorFunction[];
/**
* Initial global state configuration
* Sets the outline parameter to false by default
*/
declare const initialGlobals: {
outline: boolean;
};Usage Example:
// .storybook/preview.js
import { decorators, initialGlobals } from '@storybook/addon-outline/preview';
export default {
decorators,
initialGlobals,
};The addon is built around several key components:
Alt+O/Option+O) via Storybook's manager API.sb-show-main selector) vs docs view ([data-story-block="true"] selector)outline key) for state management// In a story file
export const MyStory = {
parameters: {
outline: {
disable: true, // Disable for this specific story
},
},
};// .storybook/preview.js
export default {
globals: {
outline: true, // Enable by default for all stories
},
};For custom preview configurations:
// .storybook/preview.js
import { decorators, initialGlobals } from '@storybook/addon-outline/preview';
export default {
decorators: [...decorators, /* your other decorators */],
initialGlobals: {
...initialGlobals,
// your other globals
},
};