Détail du package

@kadira/storybook-ui

kadirahq11.5kMIT3.11.0

Core Storybook UI

readme

Storybook UI

This is the core UI of react-storybook and other similar projects. It's a React based UI where you can initialize with a simple function. You can configure it by providing a simple provider API.

Storybook UI Demo

Usage

First you need to install @kadira/storybook-ui into your app.

npm i --save @kadira/storybook-ui

Then you need to create a Provider class like this:

// provider.js
import { Provider } from '@kadira/storybook-ui';
import React from 'react';

export default class MyProvider extends Provider {
  getPanels() {
    return {};
  }

  renderPreview() {
    return (
      <p>This is the Preview</p>
    );
  }

  handleAPI(api) {
    // no need to do anything for now.
  }
}

Then you need to initialize the UI like this:

import Provider from './provider';
import renderStorybookUI from '@kadira/storybook-ui';

const roolEl = document.getElementById('root');
renderStorybookUI(roolEl, new Provider());

Then you'll get a UI like this:

Simplest Storybook UI

See the example app for a complete example.

API

.setOptions([option])

handleAPI(api) {
  api.setOptions({
    name: 'My Component', // change the name displayed in the left top portion
    url: 'https://github.com/user/my-component', // change its URL
    sortStoriesByKind: true // Sort the list of stories by their "kind"
  });
}

.setStories([stories])

This API is used to pass thekind and stories list to storybook-ui.

handleAPI(api) {
  api.setStories([
    {
      kind: 'Component 1',
      stories: ['State 1', 'State 2']
    },

    {
      kind: 'Component 2',
      stories: ['State a', 'State b']
    }
  ]);
}

.onStory()

You can use to listen to the story change and update the preview.

handleAPI(api) {
  api.onStory((kind, story) => {
      this.globalState.emit('change', kind, story);
  });
}

Hacking Guide

If you like to add features to the Storybook UI or fix bugs, this is the guide you need to follow.

First of all, you can need to start the example app to see your changes.

The App

This is a Redux app written based on the Mantra architecture. It's a set of modules. You can see those modules at src/modules directory.

Changing UI

If you like to change the appearance of the UI, you need to look at the ui module. Simply change components at the components directory for simple UI tweaks.

You can also change containers(which are written with react-komposer) to add more data from the redux state.

Redux

Each module has a it's own set of reducers at <module>/configs/reducers directory. These reducers are loaded in the src/index.js(inside the main api).

Mounting

The UI is mounted in the src/modules/ui/routes.js. Inside that, we have injected dependencies as well. Refer mantra-core for that.

We've injected the context and actions.

App Context

App context is the app which application context you initialize when creating the UI. It is initialized in the src/index.js file. It's a non serializable state. You can access the app context from containers and basically most of the place in the app.

So, that's the place to put app wide configurations and objects which won't changed after initialized. Our redux store is also stayed inside the app context.

Actions

Actions are the place we implement app logic in a Mantra app. Each module has a set of actions and they are globally accessible. These actions are located at <module>/actions directory.

They got injected into the app(when mounting) and you can access them via containers. If you are familiar with redux, this is exactly action creators. But they are not only limited to do redux stuff. Actions has the access to the app context, so literally it can do anything.

Core API

Core API (which is passed to the Provider with handleAPI method) is implemented in the api module. We put the provider passed by the user in the app context. Then api module access it and use it as needed.

Keyboard Shortcuts

Keyboard shortcuts are implemented in a bit different way. The final state of keyboard shortcuts is managed by the shortcuts module. But they are implemented in the ui module with src/modules/ui/configs/handle_routing.js

These shortcuts also can be called from main API using the handleShortcut method. Check the example app for the usage. That's implemented as an action in the shortcuts module.

The above action(or the handleShortcut method) accepts events as a constant defined by this module. They are defined in the src/libs/key_events.js. This is basically to serialize these events.

In react-storybook we need to pass these events from the preview iframe to the main app. That's the core reason for this.

URL Changes

We are not using any routing library. That's because, we don't want to do routing, but wanted to add some query params and use them.

Routing logic is implemented in the src/modules/ui/configs/handle_routing.js configuration.

changelog

Change Log

v3.11.0

12-Jan-2017

Add an option to sort stories by kind.

v3.10.1

07-Dec-2016

Fix a react warning about missing contentLabel property PR66

v3.10.0

05-Dec-2016

Storybook keyboard shortcuts are disabled when the user is focused into a textarea, input or similar elements. PR65

v3.9.0

30-Nov-2016

Some design tweaks to the UI. PR64

v3.8.0

16-Nov-2016

Replace the use of Redux with Podda. Now it's pretty easy to work with the system. PR61

v3.7.0

13-Nov-2016

Use the new React Komposer. It's a bit more lightweight and high performant. PR58

v3.6.4

12-Nov-2016

Avoid preview re-mounting when switching to the full screen mode. PR59

v3.6.3

17-Oct-2016

  • Improve shortcut help view for Windows users PR54

v3.6.2

04-Oct-2016

  • Fix a style regression introduced by the previous PR. See: PR47

v3.6.1

29-Sep-2016

  • Use links in story list for accessibility PR43

v3.6.0

27-Sep-2016

  • Dynamic Panel titles PR42

v3.5.0

26-Sep-2016

  • Set layout state with provider api PR41

v3.4.1

2-Sep-2016

  • Call the onStory callback as soon as it listens. PR38

v3.4.0

2-Sep-2016

  • Custom query params are not stored in a separate object. PR37

v3.3.4

30-Aug-2016

  • Add missing react-dom peerDependency PR35

v3.3.3

30-Aug-2016

  • Avoid re-rendering panel content PR36

v3.3.2

24-Aug-2016

  • When some url params are already present ui is displayed in the default way. PR33

v3.3.1

24-Aug-2016

  • Avoid adding custom query params to the state if its undefined. PR32
  • Prevent emit story event for every redux store change. PR31

v3.3.0

23-Aug-2016

  • Add 'setQueryParams' and 'getQueryParams' to api. PR30
  • Selected down panel in url. PR29

v3.2.0

09-Aug-2016

Support multiple callbacks for the provider's onStory callback.

v3.1.1

05-Aug-2016

Update react-fuzzy to version 0.3.3.

v3.1.0

05-Aug-2016

Add support for NPM2.

Basically, we remove the NPM3 from the package.json's engine. We also changed the example app to work with NPM2.

v3.0.0

  • Remove Action Logger and add support for custom panels PR22

v2.6.1

  • Remove some React warnings due to bad code.

v2.6.0

  • Remove logger name with the updated react-inspector. PR21

v2.5.0

  • API to set options added. PR20
  • Ability to dock action logger in right. PR18
  • Add transition to latest added log. PR16

v2.4.0

  • Show cross only if text present in the filter box. PR13
  • Update react-fuzzy. PR12
  • Improved logging with react-inspector. PR11

v2.3.0

  • Add support for Redux DevTools extension. See PR8.
  • Add fuzzy search support with a brand new search overlay. See PR7.

v2.2.0

  • Add fullscreen and other shortcut state to the URL. See PR5

v2.1.1

  • Add a hacking guide.
  • Refactored the module code base and removed provider code.

v2.1.0

  • When creating the provider, it's required to extend from the base Provider. See this example for more info.

v2.0.0

  • Expose the whole Manager UI from this module. See the usage in react-storybook.