File size: 1,039 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useCopyToClipboard } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [text, setText] = React.useState('');
const [state, copyToClipboard] = useCopyToClipboard();
return (
<div>
<input value={text} onChange={(e) => setText(e.target.value)} />
<button type="button" onClick={() => copyToClipboard(text)}>
copy text
</button>
{state.error ? (
<p>Unable to copy value: {state.error.message}</p>
) : (
state.value && (
<>
<p>
Copied {state.value} {state.noUserInteraction ? 'without' : 'with'} user interaction
</p>
<input type="text" placeholder="Paste it in here to check" />
</>
)
)}
</div>
);
};
storiesOf('Side-effects/useCopyToClipboard', module)
.add('Docs', () => <ShowDocs md={require('../docs/useCopyToClipboard.md')} />)
.add('Demo', () => <Demo />);
|