@storybook/addon-console
Version:
Show console output like logs, errors, and warnings in the Storybook
81 lines (75 loc) • 2.67 kB
TypeScript
/**
* It handles `console.log`, `console.warn`, `console.dir`, and `console.error` methods and not catched errors. By default, it just reflects all console messages in the Action Logger Panel (should be installed as a peerDependency) except [HMR] logs.
* @module @storybook/addon-console
*
*
*/
/**
* This callback could be passed to {@link setConsoleOptions} or {@link withConsole}
*
* @example
* import { withConsole } from `@storybook/addon-console`;
*
* const optionsCallback = (options) => ({panelExclude: [...options.panelExclude, /Warning/]});
* export default {
* title: 'Button',
* decorators: [withConsole(optionsCallback)],
* };
*
* @callback optionsCallback
* @param {addonOptions} currentOptions - the current {@link addonOptions}
* @return {addonOptions} - new {@link addonOptions}
*/
/**
* Set addon options and returns a new one
* @param {addonOptions|optionsCallback} optionsOrFn
* @return {addonOptions}
* @see addonOptions
* @see optionsCallback
*
* @example
import { setConsoleOptions } from '@storybook/addon-console';
const panelExclude = setConsoleOptions({}).panelExclude;
setConsoleOptions({
panelExclude: [...panelExclude, /deprecated/],
});
*/
declare function setConsoleOptions(optionsOrFn: any): {
panelExclude: RegExp[];
panelInclude: never[];
consoleExclude: never[];
consoleInclude: never[];
log: string;
warn: string;
error: string;
dir: string;
};
/**
* Wraps your stories with specified addon options.
* If you don't pass {`log`, `warn`, `error`, `dir`} in options argument it'll create them from context for each story individually. Hence you'll see from what exact story you got a log or error. You can log from component's lifecycle methods or within your story.
* @param {addonOptions|optionsCallback} [optionsOrFn]
* @see [addonOptions]{@link #storybookaddon-consolesetconsoleoptionsoptionsorfn--addonoptions}
* @see [optionsCallback]{@link #storybookaddon-consoleoptionscallback--addonoptions}
* @return {function} wrappedStoryFn
*
* @example
import type { Meta, StoryObj } from '@storybook/react';
import { withConsole } from '@storybook/addon-console';
const meta: Meta<typeof Button> = {
title: 'Example/Button',
component: Button,
};
export default meta;
type Story = StoryObj<typeof Button>;
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
onClick: () => console.log(['Data:', 1, 3, 4]),
},
};
// Action Logger Panel:
// withConsole/with Log: ["Data:", 1, 3, 4]
*/
declare function withConsole(optionsOrFn?: any): (storyFn: any) => (context: any) => any;
export { setConsoleOptions, withConsole };