Skip to content

Commit d3cd3fc

Browse files
committed
doc: better CopyButton doc
1 parent 9d1f95d commit d3cd3fc

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

client/src/components/copy-button.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,56 @@ export interface PreviewButtonProps extends ButtonProps {
3535
icon: React.ReactNode;
3636
}
3737

38+
/**
39+
* CopyButton Component
40+
*
41+
* A versatile React component that provides an easy way to copy text or images to the clipboard.
42+
* It supports both single and multiple values, with automatic visual feedback and error handling.
43+
*
44+
* Key Features:
45+
* - Supports copying text strings or arrays of text
46+
* - Supports copying single images or multiple images (automatically stacked vertically)
47+
* - Handles various image formats (PNG, JPEG, WebP, etc.) with automatic conversion
48+
* - Provides visual feedback with animated icons (copy → checkmark → error)
49+
* - Includes toast notifications for success/error states
50+
* - Fully accessible with proper ARIA labels and keyboard support
51+
* - Internationalization support with react-i18next
52+
*
53+
* Use Cases:
54+
* - Copy API keys, tokens, or configuration values
55+
* - Copy user-generated content or feedback
56+
* - Copy QR codes or other visual elements
57+
* - Copy multiple screenshots stacked vertically for documentation
58+
* - Any scenario where users need to copy content to clipboard
59+
*
60+
* Example Usage:
61+
*
62+
* // Copy text
63+
* <CopyButton value="Hello World" />
64+
*
65+
* // Copy multiple text values
66+
* <CopyButton value={["Item 1", "Item 2", "Item 3"]} />
67+
*
68+
* // Copy a single image (URL or data URL)
69+
* <CopyButton value="https://example.com/image.png" isImage />
70+
*
71+
* // Copy multiple images (stacked vertically)
72+
* <CopyButton
73+
* value={["image1.png", "image2.png", "image3.png"]}
74+
* isImage
75+
* showToast
76+
* toastText="Images copied!"
77+
* />
78+
*
79+
* // With custom styling and callbacks
80+
* <CopyButton
81+
* value="Secret API Key"
82+
* className="absolute top-2 right-2"
83+
* onCopySuccess={() => console.log("Copied successfully")}
84+
* onCopyError={(error) => console.error("Copy failed", error)}
85+
* />
86+
*/
87+
3888
export const PreviewButton = forwardRef<
3989
HTMLButtonElement | null,
4090
PreviewButtonProps

0 commit comments

Comments
 (0)