| 1 | "use client"; |
| 2 | |
| 3 | import { Check, Copy |
| 4 | |
| 5 | import { Button } |
| 6 | import { Field, FieldDescription |
| 7 | import { Input } |
| 8 | import { useCopy } |
| 9 | |
| 10 | /** A read-only value, such as a client ID, with a button that copies it. */ |
| 11 | export function CopyField({ |
| 12 | id, |
| 13 | label, |
| 14 | value, |
| 15 | description, |
| 16 | }: { |
| 17 | id: string |
| 18 | label: string |
| 19 | value: string |
| 20 | description?: string |
| 21 | }) { |
| 22 | const { copied, |
| 23 | value, |
| 24 | `Could not copy the ${label.toLowerCase |
| 25 | ); |
| 26 | |
| 27 | return ( |
| 28 | <Field> |
| 29 | <FieldLabel htmlFor={ |
| 30 | <div className="flex gap-2 |
| 31 | <Input id={ |
| 32 | <Button |
| 33 | type="button" |
| 34 | variant="outline" |
| 35 | onClick={copy} |
| 36 | aria-label={`Copy ${label |
| 37 | > |
| 38 | {copied ? <Check |
| 39 | {copied ? "Copied |
| 40 | </Button> |
| 41 | </div> |
| 42 | {description && <FieldDescription |
| 43 | </Field> |
| 44 | ); |
| 45 | } |