import { ComponentChildren, h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
export function CopyIcon(): VNode {
return (
)
};
export function CopiedIcon(): VNode {
return (
)
};
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) {
prompt("Clipboard is not available on insecure context (http).", getContent());
}
if (navigator.clipboard) {
navigator.clipboard.writeText(getContent() || "");
setCopied(true);
}
}
useEffect(() => {
if (copied) {
setTimeout(() => {
setCopied(false);
}, 1000);
}
}, [copied]);
if (!copied) {
return (
);
}
return (
);
}