118 lines
3.7 KiB
Markdown
Raw Normal View History

2017-05-17 00:21:36 +02:00
# Storybook Options Addon
2017-05-26 11:21:46 +02:00
2017-10-23 16:01:20 +02:00
[![Build Status on CircleCI](https://circleci.com/gh/storybooks/storybook.svg?style=shield)](https://circleci.com/gh/storybooks/storybook)
2017-05-17 00:21:36 +02:00
[![CodeFactor](https://www.codefactor.io/repository/github/storybooks/storybook/badge)](https://www.codefactor.io/repository/github/storybooks/storybook)
[![Known Vulnerabilities](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847/badge.svg)](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847)
2017-10-23 16:01:20 +02:00
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook)
2017-12-22 18:06:27 +01:00
[![Storybook Slack](https://now-examples-slackin-rrirkqohko.now.sh/badge.svg)](https://now-examples-slackin-rrirkqohko.now.sh/)
2017-10-23 16:01:20 +02:00
[![Backers on Open Collective](https://opencollective.com/storybook/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/storybook/sponsors/badge.svg)](#sponsors)
2017-10-23 16:01:20 +02:00
* * *
The Options addon can be used to (re-)configure the [Storybook](https://storybook.js.org) UI at runtime.
2018-02-21 16:17:02 +02:00
[Framework Support](https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md)
2017-05-17 00:21:36 +02:00
![Screenshot](docs/screenshot.png)
## Getting Started
First, install the addon
2017-05-17 00:21:36 +02:00
```sh
npm install -D @storybook/addon-options
```
Add this line to your `addons.js` file (create this file inside your storybook config directory if needed).
```js
import '@storybook/addon-options/register';
```
Import and use the `setOptions` function in your config.js file.
```js
import * as storybook from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
// Option defaults:
setOptions({
/**
2017-08-01 13:24:59 -04:00
* name to display in the top left corner
* @type {String}
*/
name: 'Storybook',
/**
2017-08-01 13:24:59 -04:00
* URL for name in top left corner to link to
* @type {String}
*/
url: '#',
/**
* show story component as full screen
* @type {Boolean}
*/
goFullScreen: false,
/**
2017-08-31 02:08:32 +03:00
* display panel that shows a list of stories
* @type {Boolean}
*/
2017-08-31 02:08:32 +03:00
showStoriesPanel: true,
/**
2017-08-31 02:08:32 +03:00
* display panel that shows addon configurations
* @type {Boolean}
*/
2017-08-31 02:08:32 +03:00
showAddonPanel: true,
/**
2017-08-01 13:24:59 -04:00
* display floating search box to search through stories
* @type {Boolean}
*/
2017-08-01 13:24:59 -04:00
showSearchBox: false,
/**
2017-08-31 02:08:32 +03:00
* show addon panel as a vertical panel on the right
* @type {Boolean}
*/
2017-08-31 02:08:32 +03:00
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 mulitple hierarchy roots
* /\|/ - split by `|`
* @type {Regex}
*/
hierarchyRootSeparator: null,
2017-08-04 19:54:08 +02:00
/**
* sidebar tree animations
* @type {Boolean}
*/
sidebarAnimations: true,
2017-08-11 22:21:59 +03:00
/**
* id to select an addon panel
* @type {String}
*/
2017-08-31 02:08:32 +03:00
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
2018-03-19 20:50:58 +05:30
/**
* enable/disable shortcuts
* @type {Boolean}
*/
2018-03-19 20:55:01 +05:30
enableShortcuts: false, // true by default
});
storybook.configure(() => require('./stories'), module);
```
2017-10-29 18:56:52 -04:00
It is also possible to call `setOptions()` inside individual stories. Note that this will bring impact story render performance significantly.