Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move LinkTo component to a separate addon-links/react endpoint #2239

Merged
merged 3 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/links/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/react');
16 changes: 15 additions & 1 deletion addons/links/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,18 @@ export const RECEIVE_HREF_EVENT_ID = `${ADDON_ID}/receive-href-event`;

export { register } from './manager';
export { linkTo, hrefTo } from './preview';
export { default as LinkTo } from './components/link';

let hasWarned = false;

export function LinkTo() {
if (!hasWarned) {
// eslint-disable-next-line no-console
console.error(`
LinkTo has moved to addon-links/react:

import LinkTo from '@storybook/addon-links/react';
`);
hasWarned = true;
}
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';

import { RoutedLink } from '@storybook/components';
import { openLink, hrefTo } from '../preview';
import { openLink, hrefTo } from '../../preview';

export default class LinkTo extends PureComponent {
constructor(...args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { shallow } from 'enzyme';
import React from 'react';
import addons from '@storybook/addons';

import { EVENT_ID } from '..';
import { mockChannel } from '../preview.test';
import { EVENT_ID } from '../../index';
import { mockChannel } from '../../preview.test';
import LinkTo from './link';

jest.mock('@storybook/addons');
Expand Down
1 change: 1 addition & 0 deletions addons/links/src/react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from './components/link';
2 changes: 1 addition & 1 deletion app/react/src/demo/Welcome.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import glamorous from 'glamorous';
import { LinkTo } from '@storybook/addon-links';
import LinkTo from '@storybook/addon-links/react';

const Main = glamorous.article({
margin: 15,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Addon Links.Button First 1`] = `
<button
onClick={[Function]}
>
Go to "Second"
</button>
`;

exports[`Storyshots Addon Links.Button Second 1`] = `
<button
onClick={[Function]}
>
Go to "First"
</button>
`;

exports[`Storyshots Addon Links.Href log 1`] = `
<span>
See action logger
</span>
`;

exports[`Storyshots Addon Links.Link First 1`] = `
<a
href="/"
onClick={[Function]}
>
Go to Second
</a>
`;

exports[`Storyshots Addon Links.Link Second 1`] = `
<a
href="/"
onClick={[Function]}
>
Go to First
</a>
`;

exports[`Storyshots Addon Links.Select First 1`] = `
<a
href="/"
onClick={[Function]}
>
Go back
</a>
`;

exports[`Storyshots Addon Links.Select Index 1`] = `
<select
onChange={[Function]}
value="Index"
>
<option>
Index
</option>
<option>
First
</option>
<option>
Second
</option>
<option>
Third
</option>
</select>
`;

exports[`Storyshots Addon Links.Select Second 1`] = `
<a
href="/"
onClick={[Function]}
>
Go back
</a>
`;

exports[`Storyshots Addon Links.Select Third 1`] = `
<a
href="/"
onClick={[Function]}
>
Go back
</a>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ exports[`Storyshots Welcome to Storybook 1`] = `

<a
className="css-ca0824"
href="/"
onClick={[Function]}
role="button"
tabIndex="0"
>
stories
</a>
Expand Down
36 changes: 36 additions & 0 deletions examples/cra-kitchen-sink/src/stories/addon-links.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { linkTo, hrefTo } from '@storybook/addon-links';
import LinkTo from '@storybook/addon-links/react';
import { action } from '@storybook/addon-actions';

storiesOf('Addon Links.Link', module)
.add('First', () => <LinkTo story="Second">Go to Second</LinkTo>)
.add('Second', () => <LinkTo story="First">Go to First</LinkTo>);

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

storiesOf('Addon Links.Select', module)
.add('Index', () => (
<select value="Index" onChange={linkTo('Addon Links.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>);

storiesOf('Addon Links.Href', module).add('log', () => {
hrefTo('Addon Links.Href', 'log').then(href => action('URL of this story')({ href }));

return <span>See action logger</span>;
});
3 changes: 1 addition & 2 deletions examples/cra-kitchen-sink/src/stories/welcome.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { Welcome } from '@storybook/react/demo';
import { storiesOf } from '@storybook/react';
import { linkTo } from '@storybook/addon-links';

storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);
storiesOf('Welcome', module).add('to Storybook', () => <Welcome showKind="Button" />);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update these in the cli templates?

Copy link
Member Author

@Hypnosphi Hypnosphi Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already updated in #1829. Actually I just did some copy-pasting from commented code in stories/index.js to partially restore the release/3.3 changes.

If you feel like it, you can sync the rest of the changes in another PR

Copy link
Member

@ndelangen ndelangen Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has changed in #1829 not now. It’basically adding a usage of a new feature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, well I'm OK with this change.