-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathLandingCopyCommand.vue
More file actions
102 lines (93 loc) · 2.67 KB
/
Copy pathLandingCopyCommand.vue
File metadata and controls
102 lines (93 loc) · 2.67 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script setup lang="ts">
import { useClipboard } from "@vueuse/core";
const props = defineProps<{
command: string;
}>();
const { copy, isSupported } = useClipboard();
// Optimistic feedback: morph the icon immediately; the clipboard write (which
// can stall when the document isn't focused) fires alongside.
const copied = ref(false);
let resetTimer: ReturnType<typeof setTimeout> | undefined;
function onCopy() {
copy(props.command);
copied.value = true;
clearTimeout(resetTimer);
resetTimer = setTimeout(() => (copied.value = false), 2000);
}
onBeforeUnmount(() => clearTimeout(resetTimer));
</script>
<template>
<div
class="copy-cmd flex items-center gap-3 rounded-2xl border border-default bg-default py-2.5 pr-2.5 pl-4"
>
<span aria-hidden="true" class="font-mono text-sm text-dimmed select-none"
>$</span
>
<code
class="min-w-0 flex-1 overflow-x-auto font-mono text-sm whitespace-nowrap text-highlighted"
>
{{ command }}
</code>
<!-- Client-only: `isSupported` differs between server and client
(hydration mismatch); the command text stays in the SSR HTML. -->
<ClientOnly>
<button
v-if="isSupported"
type="button"
class="copy-btn relative inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-xl border border-default bg-default text-muted transition-colors hover:text-highlighted"
:aria-label="copied ? 'Copied' : 'Copy install command'"
@click="onCopy"
>
<!-- Icon morphs copy -> check on success (state feedback). -->
<UIcon
name="i-lucide-copy"
class="copy-icon absolute size-4"
:class="copied ? 'is-hidden' : ''"
/>
<UIcon
name="i-lucide-check"
class="copy-icon absolute size-4 text-success"
:class="copied ? '' : 'is-hidden'"
/>
</button>
</ClientOnly>
</div>
</template>
<style scoped>
.copy-cmd {
/* Shared landing elevation (defined on .landing), matching the other cards. */
box-shadow: var(--landing-elev);
}
.copy-btn {
transition:
color 0.15s ease,
transform 0.14s var(--ease-out);
}
.copy-btn:active {
transform: scale(0.94);
}
/* Cross-fade the two glyphs so the swap reads as one morph, not a pop. */
.copy-icon {
transition:
opacity 0.18s ease,
transform 0.18s var(--ease-out),
filter 0.18s ease;
}
.copy-icon.is-hidden {
opacity: 0;
transform: scale(0.6);
filter: blur(2px);
}
@media (prefers-reduced-motion: reduce) {
.copy-btn:active {
transform: none;
}
.copy-icon {
transition: opacity 0.12s ease;
}
.copy-icon.is-hidden {
transform: none;
filter: none;
}
}
</style>