-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathuseCopyToClipboard.story.tsx
34 lines (31 loc) · 1.01 KB
/
useCopyToClipboard.story.tsx
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
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 />);