|
1 | 1 | <script setup> |
2 | | -import { computed } from 'vue' |
| 2 | +import { computed, ref } from 'vue' |
3 | 3 | import { apiVersion } from '../composables/useApiVersion' |
4 | 4 |
|
5 | | -const importCode = computed(() => { |
| 5 | +const copied = ref(false) |
| 6 | +
|
| 7 | +const command = computed(() => { |
6 | 8 | const base = |
7 | 9 | apiVersion.value === 'pjs' |
8 | 10 | ? '@paraspell/sdk-pjs' |
@@ -32,25 +34,75 @@ const importCode = computed(() => { |
32 | 34 | findAssetInfoOrThrow |
33 | 35 | } from '${base}'` |
34 | 36 | }) |
| 37 | +
|
| 38 | +const copy = async () => { |
| 39 | + await navigator.clipboard.writeText(command.value) |
| 40 | + copied.value = true |
| 41 | + setTimeout(() => (copied.value = false), 1500) |
| 42 | +} |
35 | 43 | </script> |
36 | 44 |
|
37 | 45 | <template> |
38 | 46 | <transition name="fade" mode="out-in"> |
39 | | - <div class="import-box" :key="importCode"> |
40 | | - <pre><code>{{ importCode }}</code></pre> |
| 47 | + <div class="install-box" :key="command"> |
| 48 | + <pre><code>{{ command }}</code></pre> |
| 49 | + |
| 50 | + <button class="copy-btn" @click="copy"> |
| 51 | + {{ copied ? 'Copied ✓' : 'Copy' }} |
| 52 | + </button> |
41 | 53 | </div> |
42 | 54 | </transition> |
43 | 55 | </template> |
44 | 56 |
|
45 | 57 | <style scoped> |
46 | | -.import-box { |
| 58 | +.install-box { |
| 59 | + position: relative; |
47 | 60 | background: var(--vp-code-block-bg); |
48 | 61 | border: 1px solid var(--vp-c-divider); |
49 | 62 | border-radius: 14px; |
50 | 63 | padding: 18px 20px; |
| 64 | + font-size: 0.95rem; |
51 | 65 | font-family: var(--vp-font-family-mono); |
| 66 | + transition: all 0.2s ease; |
| 67 | + user-select: text; |
| 68 | +} |
| 69 | +
|
| 70 | +.install-box:hover { |
| 71 | + border-color: var(--vp-c-brand-1); |
| 72 | + box-shadow: 0 0 0 1px var(--vp-c-brand-1) inset; |
| 73 | +} |
| 74 | +
|
| 75 | +pre { |
| 76 | + margin: 0; |
| 77 | + background: transparent; |
| 78 | + overflow-x: auto; |
| 79 | +} |
| 80 | +
|
| 81 | +code { |
| 82 | + background: transparent; |
| 83 | + user-select: text; |
| 84 | +} |
| 85 | +
|
| 86 | +/* Copy Button */ |
| 87 | +.copy-btn { |
| 88 | + position: absolute; |
| 89 | + top: 10px; |
| 90 | + right: 12px; |
| 91 | + border: none; |
| 92 | + background: var(--vp-c-bg-soft); |
| 93 | + border-radius: 8px; |
| 94 | + padding: 4px 10px; |
| 95 | + font-size: 0.75rem; |
| 96 | + cursor: pointer; |
| 97 | + transition: all 0.2s ease; |
| 98 | +} |
| 99 | +
|
| 100 | +.copy-btn:hover { |
| 101 | + background: var(--vp-c-brand-1); |
| 102 | + color: white; |
52 | 103 | } |
53 | 104 |
|
| 105 | +/* Fade animation */ |
54 | 106 | .fade-enter-active, |
55 | 107 | .fade-leave-active { |
56 | 108 | transition: opacity 0.2s ease, transform 0.2s ease; |
|
0 commit comments