blob: b6fb345b22374a920843e2b53d326793a208919f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<!-- SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com> -->
<!-- SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1 -->
<!-- A sample with the name of its file and a button that copies it. -->
<script setup lang="ts">
import { chrome } from "~/content/chrome";
const props = defineProps<{ label: string; code: string }>();
const { locale } = useSiteLocale();
const copied = ref(false);
let timer: ReturnType<typeof setTimeout> | undefined;
async function copy() {
try {
await navigator.clipboard.writeText(props.code);
} catch {
return;
}
copied.value = true;
clearTimeout(timer);
timer = setTimeout(() => (copied.value = false), 1600);
}
</script>
<template>
<figure class="code">
<figcaption class="code-bar">
<span>{{ label }}</span>
<button type="button" @click="copy">
{{ copied ? chrome[locale].copied : chrome[locale].copy }}
</button>
</figcaption>
<pre><code>{{ code }}</code></pre>
</figure>
</template>
<style scoped>
figure {
margin: 0;
}
</style>
|