Skip to content

Commit

Permalink
chore(playground): support copying vue version (#11558)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuseen-l authored Aug 8, 2024
1 parent 47cdf24 commit f8ce86b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/sfc-playground/src/VersionSelect.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import Copy from './icons/Copy.vue'
const expanded = ref(false)
const versions = ref<string[]>()
Expand Down Expand Up @@ -53,6 +54,12 @@ function setVersion(v: string) {
expanded.value = false
}
function copyVersion(v: string) {
window.navigator.clipboard.writeText(v).then(() => {
alert('Vue version has been copied to clipboard.')
})
}
onMounted(() => {
window.addEventListener('click', () => {
expanded.value = false
Expand All @@ -76,11 +83,19 @@ onMounted(() => {
<li v-if="!versions"><a>loading versions...</a></li>
<li
v-for="(ver, index) of versions"
class="versions-item"
:class="{
active: ver === version || (version === 'latest' && index === 0),
}"
>
<a @click="setVersion(ver)">v{{ ver }}</a>
<button
title="Copy Version"
class="version-copy"
@click="copyVersion(`v${ver}`)"
>
<Copy />
</button>
</li>
<div @click="expanded = false">
<slot />
Expand Down Expand Up @@ -120,4 +135,17 @@ onMounted(() => {
.versions .active a {
color: var(--green);
}
.versions .versions-item {
display: flex;
justify-content: space-between;
}
.versions .versions-item .version-copy {
display: none;
}
.versions .versions-item:hover .version-copy {
display: block;
}
</style>
14 changes: 14 additions & 0 deletions packages/sfc-playground/src/icons/Copy.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
width="1.3em"
height="1.3em"
viewBox="0 0 24 24"
>
<path fill="currentColor" d="M8 7h11v14H8z" opacity=".3" />
<path
fill="currentColor"
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"
/>
</svg>
</template>

0 comments on commit f8ce86b

Please sign in to comment.