Upgrade Fresh and add a bunch of small QOL improvements #16
|
|
@ -2,9 +2,13 @@ import Preact from "preact";
|
||||||
import { useState } from "preact/hooks";
|
import { useState } from "preact/hooks";
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
export default function CopyButton(
|
type Props = {
|
||||||
props: { textBefore: string; textAfter: string } & Preact.PropsWithChildren,
|
text: string;
|
||||||
) {
|
children: Preact.ComponentChildren;
|
||||||
|
disabled?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function CopyButton({ text, disabled = false, children }: Props) {
|
||||||
const [clicked, setClicked] = useState(false);
|
const [clicked, setClicked] = useState(false);
|
||||||
|
|
||||||
const startReset = () => {
|
const startReset = () => {
|
||||||
|
|
@ -16,14 +20,14 @@ export default function CopyButton(
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigator.clipboard.writeText(props.text.toString());
|
navigator.clipboard.writeText(text.toString());
|
||||||
setClicked(true);
|
setClicked(true);
|
||||||
startReset();
|
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"
|
class="px-2 py-1 border(gray-100 2) hover:bg-gray-200 mx-auto"
|
||||||
>
|
>
|
||||||
{clicked ? "Kopiert!" : props.children}
|
{clicked ? "Kopiert!" : children}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue