mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
NewTabStory utility component that prompts user to open story in new tab
This commit is contained in:
parent
9bc9805357
commit
0eebe373b0
@ -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/>)
|
||||
|
||||
@ -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
src/__stories__/util/NewTabStory.tsx
Normal file
15
src/__stories__/util/NewTabStory.tsx
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user