Skip to content

Latest commit

 

History

History
 
 

links

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Story Links Addon

Build Status on CircleCI CodeFactor Known Vulnerabilities BCH compliance codecov
Storybook Slack Backers on Open Collective Sponsors on Open Collective


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

This addon works with Storybook for:

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.