CoolFace
Datasetpublic

gradio/frontend

sourceHugging Faceupdated 14h agoView on Hugging Face
1likes403kdownloads
Copy.svelte31 linesDownload Raw Back to shared
1<script lang="ts">2	import { onDestroy } from "svelte";3	import { Copy, Check } from "@gradio/icons";4	import { IconButton } from "@gradio/atoms";5 6	let copied = false;7	export let value: string;8	let timer: NodeJS.Timeout;9 10	function copy_feedback(): void {11		copied = true;12		if (timer) clearTimeout(timer);13		timer = setTimeout(() => {14			copied = false;15		}, 2000);16	}17 18	async function handle_copy(): Promise<void> {19		if ("clipboard" in navigator) {20			await navigator.clipboard.writeText(value);21			copy_feedback();22		}23	}24 25	onDestroy(() => {26		if (timer) clearTimeout(timer);27	});28</script>29 30<IconButton Icon={copied ? Check : Copy} on:click={handle_copy} />31 
gradio/frontend · CoolFace