fix: Clean up types

Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
Tim Hårek Andreassen 2024-03-02 18:25:22 +01:00
parent cefaa6fa59
commit ee8956bc53
No known key found for this signature in database
GPG Key ID: E59C7734F0E10EB5
1 changed files with 10 additions and 6 deletions

View File

@ -2,9 +2,13 @@ import Preact from "preact";
import { useState } from "preact/hooks";
import { IS_BROWSER } from "$fresh/runtime.ts";
export default function CopyButton(
props: { textBefore: string; textAfter: string } & Preact.PropsWithChildren,
) {
type Props = {
text: string;
children: Preact.ComponentChildren;
disabled?: boolean;
};
export default function CopyButton({ text, disabled = false, children }: Props) {
const [clicked, setClicked] = useState(false);
const startReset = () => {
@ -16,14 +20,14 @@ export default function CopyButton(
return (
<button
onClick={() => {
navigator.clipboard.writeText(props.text.toString());
navigator.clipboard.writeText(text.toString());
setClicked(true);
startReset();
}}
disabled={!IS_BROWSER || props.disabled}
disabled={!IS_BROWSER || disabled}
class="px-2 py-1 border(gray-100 2) hover:bg-gray-200 mx-auto"
>
{clicked ? "Kopiert!" : props.children}
{clicked ? "Kopiert!" : children}
</button>
);
}