Skip to content

Commit

Permalink
NewTabStory utility component that prompts user to open story in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
wardoost committed Mar 31, 2019
1 parent 9bc9805 commit 0eebe37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/__stories__/useFavicon.story.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {storiesOf} from '@storybook/react';
import * as React from 'react';
import {useFavicon} from '..';
import NewTabStory from './util/NewTabStory';
import ShowDocs from '../util/ShowDocs';

const Demo = () => {
useFavicon('https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico');

return null;
return (
<NewTabStory>
Favicon should be the Stack Overflow logo
</NewTabStory>
);
};

storiesOf('Side effects|useFavicon', module)
.add('Docs', () => <ShowDocs md={require('../../docs/useFavicon.md')} />)
.add('Demo', () =>
<Demo/>
)
.add('Demo', () => <Demo/>)
11 changes: 7 additions & 4 deletions src/__stories__/useTitle.story.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {storiesOf} from '@storybook/react';
import * as React from 'react';
import {useTitle} from '..';
import NewTabStory from './util/NewTabStory';
import ShowDocs from '../util/ShowDocs';

const Demo = () => {
useTitle('Hello world!');

return null;
return (
<NewTabStory>
Title should be "Hello world!"
</NewTabStory>
);
};

storiesOf('Side effects|useTitle', module)
.add('Docs', () => <ShowDocs md={require('../../docs/useTitle.md')} />)
.add('Demo', () =>
<Demo/>
)
.add('Demo', () => <Demo/>)
15 changes: 15 additions & 0 deletions src/__stories__/util/NewTabStory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';

const NewTabStory = ({children}) => {
if (window.location === window.parent.location) {
return children
}

return (
<p>
This story should be <a href={window.location.href} target='_blank' title='Open in new tab'>opened in a new tab</a>.
</p>
);
}

export default NewTabStory

0 comments on commit 0eebe37

Please sign in to comment.