Norbert de Langen a039c96426
Merge branch 'master' into babel-7
# Conflicts:
#	MIGRATION.md
#	addons/backgrounds/package.json
#	addons/events/package.json
#	addons/info/package.json
#	addons/info/src/__snapshots__/index.test.js.snap
#	addons/jest/package.json
#	addons/knobs/package.json
#	addons/links/package.json
#	addons/notes/package.json
#	addons/options/package.json
#	addons/storyshots/storyshots-core/package.json
#	addons/storyshots/storyshots-puppeteer/package.json
#	addons/storysource/package.json
#	addons/viewport/package.json
#	app/angular/package.json
#	app/html/package.json
#	app/marko/package.json
#	app/mithril/package.json
#	app/polymer/package.json
#	app/react/package.json
#	app/vue/package.json
#	examples/angular-cli/package.json
#	examples/cra-kitchen-sink/package.json
#	examples/html-kitchen-sink/package.json
#	examples/marko-cli/package.json
#	examples/mithril-kitchen-sink/package.json
#	examples/official-storybook/package.json
#	examples/official-storybook/stories/__snapshots__/addon-info.stories.storyshot
#	examples/official-storybook/stories/__snapshots__/other-dirname.stories.storyshot
#	examples/polymer-cli/package.json
#	examples/vue-kitchen-sink/package.json
#	jest.config.js
#	lib/cli/package.json
#	lib/cli/test/snapshots/angular-cli/package.json
#	lib/cli/test/snapshots/marko/package.json
#	lib/cli/test/snapshots/meteor/package.json
#	lib/cli/test/snapshots/mithril/package.json
#	lib/cli/test/snapshots/polymer/package.json
#	lib/cli/test/snapshots/react/package.json
#	lib/cli/test/snapshots/react_project/package.json
#	lib/cli/test/snapshots/react_scripts/package.json
#	lib/cli/test/snapshots/sfc_vue/package.json
#	lib/cli/test/snapshots/update_package_organisations/package.json
#	lib/cli/test/snapshots/vue/package.json
#	lib/cli/test/snapshots/webpack_react/package.json
#	lib/codemod/package.json
#	lib/components/src/layout/__snapshots__/index.stories.storyshot
#	lib/core/package.json
#	lib/core/src/server/config/webpack.config.prod.js
#	package.json
#	yarn.lock
2018-08-15 00:01:36 +02:00
..
2018-08-04 14:53:52 -07:00
2018-08-04 14:53:52 -07:00
2018-08-04 15:36:38 -07:00

Storybook Options Addon

The Options addon can be used to (re-)configure the Storybook UI at runtime.

Framework Support

Screenshot

Getting Started

First, install the addon

npm install -D @storybook/addon-options

Add this line to your addons.js file (create this file inside your storybook config directory if needed).

import '@storybook/addon-options/register';

Import and use the setOptions function in your config.js file.

import * as storybook from '@storybook/react';
import { setOptions } from '@storybook/addon-options';

// Option defaults:
setOptions({
  /**
   * name to display in the top left corner
   * @type {String}
   */
  name: 'Storybook',
  /**
   * URL for name in top left corner to link to
   * @type {String}
   */
  url: '#',
  /**
   * show story component as full screen
   * @type {Boolean}
   */
  goFullScreen: false,
  /**
   * display panel that shows a list of stories
   * @type {Boolean}
   */
  showStoriesPanel: true,
  /**
   * display panel that shows addon configurations
   * @type {Boolean}
   */
  showAddonPanel: true,
  /**
   * display floating search box to search through stories
   * @type {Boolean}
   */
  showSearchBox: false,
  /**
   * show addon panel as a vertical panel on the right
   * @type {Boolean}
   */
  addonPanelInRight: false,
  /**
   * sorts stories
   * @type {Boolean}
   */
  sortStoriesByKind: false,
  /**
   * regex for finding the hierarchy separator
   * @example:
   *   null - turn off hierarchy
   *   /\// - split by `/`
   *   /\./ - split by `.`
   *   /\/|\./ - split by `/` or `.`
   * @type {Regex}
   */
  hierarchySeparator: null,
  /**
   * regex for finding the hierarchy root separator
   * @example:
   *   null - turn off multiple hierarchy roots
   *   /\|/ - split by `|`
   * @type {Regex}
   */
  hierarchyRootSeparator: null,
  /**
   * sidebar tree animations
   * @type {Boolean}
   */
  sidebarAnimations: true,
  /**
   * id to select an addon panel
   * @type {String}
   */
  selectedAddonPanel: undefined, // The order of addons in the "Addon panel" is the same as you import them in 'addons.js'. The first panel will be opened by default as you run Storybook
  /**
   * enable/disable shortcuts
   * @type {Boolean}
   */
  enableShortcuts: false, // true by default
});

storybook.configure(() => require('./stories'), module);

using withOptions options or parameters

The options-addon accepts story paramters to set options (as shown below).

import { storiesOf } from '@storybook/marko';
import { withKnobs, text, number } from '@storybook/addon-knobs';
import { withOptions } from '@storybook/addon-options';
import Hello from '../components/hello/index.marko';

storiesOf('Addons|Knobs/Hello', module)
  .addDecorator(withOptions)
  .addDecorator(withKnobs)
  .addParameters({ options: { addonPanelInRight: true } })
  .add('Simple', () => {
    const name = text('Name', 'John Doe');
    const age = number('Age', 44);
    return Hello.renderSync({
      name,
      age,
    });
  });

It is also possible to call setOptions() inside individual stories. Note that this will bring impact story render performance significantly.