JSPM

@storybook/addon-links

3.2.12
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6080864
  • Score
    100M100P100Q212925F
  • License MIT

Story Links addon for storybook

Package Exports

  • @storybook/addon-links
  • @storybook/addon-links/register
  • @storybook/addon-links/register.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@storybook/addon-links) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Story Links Addon

Greenkeeper badge Build Status CodeFactor Known Vulnerabilities BCH compliance codecov Storybook Slack

The Storybook Links addon can be used to create links between stories in Storybook.

This addon works with Storybook for: React and React Native.

Getting Started

Install this addon by adding the @storybook/addon-links dependency:

yarn add @storybook/addon-links

First configure it as an addon by adding it to your addons.js file (located in the Storybook config directory).

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

Then you can import linkTo in your stories and use like this:

import { storiesOf } from '@storybook/react'
import { linkTo } from '@storybook/addon-links'

storiesOf('Button', module)
  .add('First', () => (
    <button onClick={linkTo('Button', 'Second')}>Go to "Second"</button>
  ))
  .add('Second', () => (
    <button onClick={linkTo('Button', 'First')}>Go to "First"</button>
  ));

Have a look at the linkTo function:

import { linkTo } from '@storybook/addon-links'

linkTo('Toggle', 'off')
linkTo(() => 'Toggle', () => 'off')
linkTo('Toggle') // Links to the first story in the 'Toggle' kind

With that, you can link an event in a component to any story in the Storybook.

  • First parameter is the the story kind name (what you named with storiesOf).
  •   Second (optional) parameter is the story name (what you named with .add). If the second parameter is omitted, the link will point to the first story in the given kind.

You can also pass a function instead for any of above parameter. That function accepts arguments emitted by the event and it should return a string.
Have a look at PR86 for more information.