diff --git a/addons/links/react.js b/addons/links/react.js new file mode 100644 index 000000000000..70e1111ae070 --- /dev/null +++ b/addons/links/react.js @@ -0,0 +1 @@ +module.exports = require('./dist/react'); diff --git a/addons/links/src/index.js b/addons/links/src/index.js index eb82507d26d6..3093e7027095 100644 --- a/addons/links/src/index.js +++ b/addons/links/src/index.js @@ -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; +} diff --git a/addons/links/src/components/__snapshots__/link.test.js.snap b/addons/links/src/react/components/__snapshots__/link.test.js.snap similarity index 100% rename from addons/links/src/components/__snapshots__/link.test.js.snap rename to addons/links/src/react/components/__snapshots__/link.test.js.snap diff --git a/addons/links/src/components/link.js b/addons/links/src/react/components/link.js similarity index 95% rename from addons/links/src/components/link.js rename to addons/links/src/react/components/link.js index 43d023139445..5a5d93310e82 100644 --- a/addons/links/src/components/link.js +++ b/addons/links/src/react/components/link.js @@ -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) { diff --git a/addons/links/src/components/link.test.js b/addons/links/src/react/components/link.test.js similarity index 91% rename from addons/links/src/components/link.test.js rename to addons/links/src/react/components/link.test.js index edff7730c723..3db7fdd472ee 100644 --- a/addons/links/src/components/link.test.js +++ b/addons/links/src/react/components/link.test.js @@ -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'); diff --git a/addons/links/src/react/index.js b/addons/links/src/react/index.js new file mode 100644 index 000000000000..cb1f5b43c5d0 --- /dev/null +++ b/addons/links/src/react/index.js @@ -0,0 +1 @@ +export default from './components/link'; diff --git a/app/react/src/demo/Welcome.js b/app/react/src/demo/Welcome.js index a5a49b797dcb..fcde670c95fb 100644 --- a/app/react/src/demo/Welcome.js +++ b/app/react/src/demo/Welcome.js @@ -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, diff --git a/examples/cra-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot b/examples/cra-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot new file mode 100644 index 000000000000..927a05de6e75 --- /dev/null +++ b/examples/cra-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon Links.Button First 1`] = ` + +`; + +exports[`Storyshots Addon Links.Button Second 1`] = ` + +`; + +exports[`Storyshots Addon Links.Href log 1`] = ` + + See action logger + +`; + +exports[`Storyshots Addon Links.Link First 1`] = ` + + Go to Second + +`; + +exports[`Storyshots Addon Links.Link Second 1`] = ` + + Go to First + +`; + +exports[`Storyshots Addon Links.Select First 1`] = ` + + Go back + +`; + +exports[`Storyshots Addon Links.Select Index 1`] = ` + +`; + +exports[`Storyshots Addon Links.Select Second 1`] = ` + + Go back + +`; + +exports[`Storyshots Addon Links.Select Third 1`] = ` + + Go back + +`; diff --git a/examples/cra-kitchen-sink/src/stories/__snapshots__/welcome.storyshot b/examples/cra-kitchen-sink/src/stories/__snapshots__/welcome.storyshot index bc6abe86a6e7..1b541e647cb9 100644 --- a/examples/cra-kitchen-sink/src/stories/__snapshots__/welcome.storyshot +++ b/examples/cra-kitchen-sink/src/stories/__snapshots__/welcome.storyshot @@ -32,9 +32,8 @@ exports[`Storyshots Welcome to Storybook 1`] = ` stories diff --git a/examples/cra-kitchen-sink/src/stories/addon-links.stories.js b/examples/cra-kitchen-sink/src/stories/addon-links.stories.js new file mode 100644 index 000000000000..fada321e6a72 --- /dev/null +++ b/examples/cra-kitchen-sink/src/stories/addon-links.stories.js @@ -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', () => Go to Second) + .add('Second', () => Go to First); + +storiesOf('Addon Links.Button', module) + .add('First', () => ( + + )) + .add('Second', () => ( + + )); + +storiesOf('Addon Links.Select', module) + .add('Index', () => ( + + )) + .add('First', () => Go back) + .add('Second', () => Go back) + .add('Third', () => Go back); + +storiesOf('Addon Links.Href', module).add('log', () => { + hrefTo('Addon Links.Href', 'log').then(href => action('URL of this story')({ href })); + + return See action logger; +}); diff --git a/examples/cra-kitchen-sink/src/stories/welcome.js b/examples/cra-kitchen-sink/src/stories/welcome.js index 9610f12d04e9..d55211af5d41 100644 --- a/examples/cra-kitchen-sink/src/stories/welcome.js +++ b/examples/cra-kitchen-sink/src/stories/welcome.js @@ -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', () => ); +storiesOf('Welcome', module).add('to Storybook', () => );