Skip to content

Commit f8ce86b

Browse files
authored
chore(playground): support copying vue version (#11558)
1 parent 47cdf24 commit f8ce86b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/sfc-playground/src/VersionSelect.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import { onMounted, ref } from 'vue'
3+
import Copy from './icons/Copy.vue'
34
45
const expanded = ref(false)
56
const versions = ref<string[]>()
@@ -53,6 +54,12 @@ function setVersion(v: string) {
5354
expanded.value = false
5455
}
5556
57+
function copyVersion(v: string) {
58+
window.navigator.clipboard.writeText(v).then(() => {
59+
alert('Vue version has been copied to clipboard.')
60+
})
61+
}
62+
5663
onMounted(() => {
5764
window.addEventListener('click', () => {
5865
expanded.value = false
@@ -76,11 +83,19 @@ onMounted(() => {
7683
<li v-if="!versions"><a>loading versions...</a></li>
7784
<li
7885
v-for="(ver, index) of versions"
86+
class="versions-item"
7987
:class="{
8088
active: ver === version || (version === 'latest' && index === 0),
8189
}"
8290
>
8391
<a @click="setVersion(ver)">v{{ ver }}</a>
92+
<button
93+
title="Copy Version"
94+
class="version-copy"
95+
@click="copyVersion(`v${ver}`)"
96+
>
97+
<Copy />
98+
</button>
8499
</li>
85100
<div @click="expanded = false">
86101
<slot />
@@ -120,4 +135,17 @@ onMounted(() => {
120135
.versions .active a {
121136
color: var(--green);
122137
}
138+
139+
.versions .versions-item {
140+
display: flex;
141+
justify-content: space-between;
142+
}
143+
144+
.versions .versions-item .version-copy {
145+
display: none;
146+
}
147+
148+
.versions .versions-item:hover .version-copy {
149+
display: block;
150+
}
123151
</style>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<svg
3+
xmlns="http://www.w3.org/2000/svg"
4+
width="1.3em"
5+
height="1.3em"
6+
viewBox="0 0 24 24"
7+
>
8+
<path fill="currentColor" d="M8 7h11v14H8z" opacity=".3" />
9+
<path
10+
fill="currentColor"
11+
d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2m0 16H8V7h11z"
12+
/>
13+
</svg>
14+
</template>

0 commit comments

Comments
 (0)