import { h, VNode } from "preact";
import { useTransition } from "preact/compat";
import { useEffect, useState } from "preact/hooks";
import { useTranslationContext } from "../index.browser.js";
export function CopyIcon(): VNode {
return (
)
};
export function CopiedIcon(): VNode {
return (
)
};
export function CopyButton({ class: clazz, getContent }: { class: string, getContent: () => string }): VNode {
const [copied, setCopied] = useState(false);
const {i18n} = useTranslationContext()
function copyText(): void {
if (!navigator.clipboard && !window.isSecureContext) {
alert('clipboard is not available on insecure context (http)')
}
if (navigator.clipboard) {
navigator.clipboard.writeText(getContent() || "");
setCopied(true);
}
}
useEffect(() => {
if (copied) {
setTimeout(() => {
setCopied(false);
}, 1000);
}
}, [copied]);
if (!copied) {
return (
);
}
return (
);
}