CopyButton.vue

 1<template>
 2  <button
 3    class="copyButton"
 4    @click="handleCopy"
 5    title="Copy to clipboard"
 6    type="button"
 7  >
 8    {{ copied ? 'Copied!' : 'Copy' }}
 9  </button>
10</template>
11
12<script setup>
13import { ref } from "vue";
14
15const props = defineProps({
16  text: {
17    type: String,
18    required: true,
19  },
20});
21
22const copied = ref(false);
23
24const handleCopy = () => {
25  navigator.clipboard.writeText(props.text);
26  copied.value = true;
27  setTimeout(() => (copied.value = false), 2000);
28};
29</script>
30
31<style scoped>
32.copyButton {
33  background: transparent;
34  color: var(--muted);
35  border: 1px solid var(--border);
36  border-radius: 6px;
37  padding: 0.4rem 0.75rem;
38  font-size: 0.7rem;
39  cursor: pointer;
40  white-space: nowrap;
41  flex-shrink: 0;
42  transition: color 0.2s, border-color 0.2s, background 0.2s;
43}
44
45.copyButton:hover {
46  color: var(--accent);
47  border-color: var(--accent);
48  background: var(--code-bg);
49}
50</style>