|
1 | | -import { useClipboard, useField } from '@siberiacancode/reactuse'; |
| 1 | +import { useClipboard } from '@siberiacancode/reactuse'; |
| 2 | +import { CheckIcon, CopyIcon } from 'lucide-react'; |
| 3 | +import { useState } from 'react'; |
| 4 | + |
| 5 | +const SHARE_URL = 'https://reactuse.org'; |
2 | 6 |
|
3 | 7 | const Demo = () => { |
4 | 8 | const clipboard = useClipboard(); |
5 | | - const textField = useField(); |
| 9 | + const [copied, setCopied] = useState(false); |
| 10 | + |
| 11 | + const onShare = () => { |
| 12 | + clipboard.copy(SHARE_URL); |
| 13 | + setCopied(true); |
| 14 | + setTimeout(() => { |
| 15 | + setCopied(false); |
| 16 | + }, 1500); |
| 17 | + }; |
6 | 18 |
|
7 | 19 | return ( |
8 | | - <> |
9 | | - <p> |
10 | | - Copied value: <code>{clipboard.value || 'Nothing is copied yet!'}</code> |
11 | | - </p> |
12 | | - <input {...textField.register()} /> |
| 20 | + <section className='flex max-w-sm flex-col gap-5'> |
| 21 | + <div className='flex flex-col items-center gap-2'> |
| 22 | + <h3>Share with friends</h3> |
| 23 | + <p className='text-muted-foreground text-center text-sm'> |
| 24 | + Spread the word about reactuse. Click the button below to copy the link to your clipboard |
| 25 | + and share it with anyone. |
| 26 | + </p> |
| 27 | + </div> |
13 | 28 |
|
14 | | - <button type='button' onClick={() => clipboard.copy(textField.getValue())}> |
15 | | - Copy |
16 | | - </button> |
17 | | - </> |
| 29 | + <div className='relative mt-2 flex items-center gap-2'> |
| 30 | + <input readOnly className='text-md! h-12! rounded-full! px-3!' value={SHARE_URL} /> |
| 31 | + |
| 32 | + <button className='absolute top-2 right-2 h-8!' type='button' onClick={onShare}> |
| 33 | + {copied ? ( |
| 34 | + <> |
| 35 | + <CheckIcon className='size-4' /> Copied |
| 36 | + </> |
| 37 | + ) : ( |
| 38 | + <> |
| 39 | + <CopyIcon className='size-4' /> Share |
| 40 | + </> |
| 41 | + )} |
| 42 | + </button> |
| 43 | + </div> |
| 44 | + |
| 45 | + <p className='text-muted-foreground text-center text-xs'> |
| 46 | + Star us on{' '} |
| 47 | + <a |
| 48 | + className='underline' |
| 49 | + href='https://github.com/siberiacancode/reactuse' |
| 50 | + rel='noreferrer' |
| 51 | + target='_blank' |
| 52 | + > |
| 53 | + GitHub |
| 54 | + </a> |
| 55 | + </p> |
| 56 | + </section> |
18 | 57 | ); |
19 | 58 | }; |
20 | 59 |
|
|
0 commit comments