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-02-25 02:20:08 -06:00
2017-05-25 23:53:31 +02:00
2018-07-31 19:34:05 +03:00

Storybook Addon Events

This storybook (source) addon allows you to add events for your stories.

Framework Support

Storybook Addon Events Example Storybook Addon Events Live Demo

Getting Started

npm i --save-dev @storybook/addon-events

Then create a file called addons.js in your storybook config.

Add following content to it:

import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-events/register';

Then write your stories like this:

import { storiesOf } from '@storybook/react';
import withEvents from '@storybook/addon-events';
import EventEmiter from 'event-emiter';

import Logger from './Logger';
import * as EVENTS from './events';

const emiter = new EventEmiter();
const emit = emiter.emit.bind(emiter);


storiesOf('WithEvents', module)
  .addDecorator(
    withEvents({
      emit,
      events: [
        {
          name: EVENTS.TEST_EVENT_1,
          title: 'Test event 1',
          payload: 0,
        },
        {
          name: EVENTS.TEST_EVENT_2,
          title: 'Test event 2',
          payload: 'asdasdad asdasdasd',
        },
        {
          name: EVENTS.TEST_EVENT_3,
          title: 'Test event 3',
          payload: {
            string: 'value',
            number: 123,
            array: [1, 2, 3],
            object: {
              string: 'value',
              number: 123,
              array: [1, 2, 3],
            },
          },
        },
        {
          name: EVENTS.TEST_EVENT_4,
          title: 'Test event 4',
          payload: [
            {
              string: 'value',
              number: 123,
              array: [1, 2, 3],
            },
            {
              string: 'value',
              number: 123,
              array: [1, 2, 3],
            },
            {
              string: 'value',
              number: 123,
              array: [1, 2, 3],
            },
          ],
        },
      ]
    })
  )
  .add('Logger', () => <Logger emiter={emiter} />);