summaryrefslogtreecommitdiff
path: root/packages/web-util/src/components/CopyButton.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web-util/src/components/CopyButton.tsx')
-rw-r--r--packages/web-util/src/components/CopyButton.tsx11
1 files changed, 8 insertions, 3 deletions
diff --git a/packages/web-util/src/components/CopyButton.tsx b/packages/web-util/src/components/CopyButton.tsx
index e76447291..dbb38b474 100644
--- a/packages/web-util/src/components/CopyButton.tsx
+++ b/packages/web-util/src/components/CopyButton.tsx
@@ -1,4 +1,4 @@
-import { h, VNode } from "preact";
+import { ComponentChildren, h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
export function CopyIcon(): VNode {
@@ -17,7 +17,7 @@ export function CopiedIcon(): VNode {
)
};
-export function CopyButton({ class: clazz, getContent }: { class: string, getContent: () => string }): VNode {
+export function CopyButton({ class: clazz, children, getContent }: { children?: ComponentChildren, class: string, getContent: () => string }): VNode {
const [copied, setCopied] = useState(false);
function copyText(): void {
if (!navigator.clipboard && !window.isSecureContext) {
@@ -38,14 +38,19 @@ export function CopyButton({ class: clazz, getContent }: { class: string, getCon
if (!copied) {
return (
- <button class={clazz} onClick={copyText} >
+ <button class={clazz} onClick={e => {
+ e.preventDefault()
+ copyText()
+ }} >
<CopyIcon />
+ {children}
</button>
);
}
return (
<button class={clazz} disabled>
<CopiedIcon />
+ {children}
</button>
);
}