Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@storybook/addon-links
Advanced tools
The @storybook/addon-links package allows you to create links between your stories in Storybook. This can be used to navigate from one story to another, simulating user flows and providing a more connected and interactive experience when showcasing components.
Link to another story
This feature allows you to create a link that navigates to a different story within Storybook. The 'linkTo' function takes two arguments: the first is the name of the component (or 'kind' in Storybook terminology), and the second is the specific story name. When the element is clicked, Storybook will navigate to the specified story.
{"<MyButton onClick={linkTo('Button', 'secondary')}>Next Story</MyButton>"}
Link with parameters
This feature extends the basic linking functionality by allowing you to pass additional parameters to the target story. These parameters can be used within the target story to modify its state or display certain data, making it a powerful tool for creating interactive and dynamic story flows.
{"<MyButton onClick={linkTo('Button', 'secondary', { userId: '12345' })}>User Profile</MyButton>"}
The @storybook/addon-actions package can be used to log actions performed on UI components within Storybook. While it doesn't provide direct linking between stories like @storybook/addon-links, it is often used in conjunction with links to provide a more interactive storytelling experience.
The @storybook/addon-knobs package allows you to add dynamic variables to your stories in Storybook. Similar to @storybook/addon-links, it enhances the interactivity of stories by allowing users to manipulate props in real-time. However, it does not provide functionality for linking between stories.
The Storybook Links addon can be used to create links that navigate between stories in Storybook.
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.
storiesOf
)..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:
import { storiesOf } from '@storybook/react';
import { LinkTo, linkTo } from '@storybook/addon-links';
storiesOf('Select', module)
.add('Index', () => (
<select value="Index" onChange={linkTo('Select', e => e.currentTarget.value)}>
<option>Index</option>
<option>First</option>
<option>Second</option>
<option>Third</option>
</select>
))
.add('First', () => <LinkTo story="Index">Go back</LinkTo>)
.add('Second', () => <LinkTo story="Index">Go back</LinkTo>)
.add('Third', () => <LinkTo story="Index">Go back</LinkTo>);
If you want to get an URL for a particular story, you may use hrefTo
function. It returns a promise, which resolves to string containing a relative URL:
import { storiesOf } from '@storybook/react';
import { hrefTo } from '@storybook/addon-links';
import { action } from '@storybook/addon-actions';
storiesOf('Href', module)
.add('log', () => {
hrefTo('Href', 'log').then(action('URL of this story'));
return <span>See action logger</span>;
});
withLinks
decorator enables a declarative way of defining story links, using data attributes.
Here is an example in React, but it works with any framework:
import { storiesOf } from '@storybook/react'
import { withLinks } from '@storybook/addon-links'
storiesOf('Button', module)
.addDecorator(withLinks)
.add('First', () => (
<button data-sb-kind="OtherKind" data-sb-story="OtherStory">Go to "OtherStory"</button>
))
One possible way of using hrefTo
is to create a component that uses native a
element, but prevents page reloads on plain left click, so that one can still use default browser methods to open link in new tab.
A React implementation of such a component can be imported from @storybook/addon-links
package:
import { storiesOf } from '@storybook/react';
import LinkTo from '@storybook/addon-links/react';
storiesOf('Link', module)
.add('First', () => (
<LinkTo story="Second">Go to Second</LinkTo>
))
.add('Second', () => (
<LinkTo story="First">Go to First</LinkTo>
));
It accepts all the props the a
element does, plus story
and kind
. It the kind
prop is omitted, the current kind will be preserved.
<LinkTo
kind="Toggle"
story="off"
target="_blank"
title="link to second story"
style={{color: '#1474f3'}}
>Go to Second</LinkTo>
To implement such a component for another framework, you need to add special handling for click
event on native a
element. See RoutedLink
sources for reference.
FAQs
Link stories together to build demos and prototypes with your UI components
The npm package @storybook/addon-links receives a total of 1,715,381 weekly downloads. As such, @storybook/addon-links popularity was classified as popular.
We found that @storybook/addon-links demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.