Skip to content

feat: add copy link button #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ const ssr = useRouteQuery<string, boolean>('ssr', 'false', {
const prod = useRouteQuery<string, boolean>('prod', 'false', {
transform: stringToBooleanTransformer,
})

const toast = useToast()
const { copy } = useClipboard()

function resetVueVersion() {
vueVersion.value = null
}

function resetVueUseVersion() {
vueUseVersion.value = 'latest'
}

async function copyLink(e: MouseEvent) {
if (e.metaKey) {
resetVueVersion()
resetVueUseVersion()
// hidden logic for going to local debug from playground.vueuse.org
window.location.href = `http://localhost:3000/${window.location.hash}`
return
}
copy(location.href)
toast.add({
title: 'Sharable URL has been copied to clipboard.',
icon: 'i-heroicons-check-circle',
color: 'success',
})
}
</script>

<template>
Expand All @@ -71,6 +98,15 @@ const prod = useRouteQuery<string, boolean>('prod', 'false', {
@click="toggleColorMode"
/>

<UTooltip text="Copy sharable URL">
<UButton
color="neutral"
variant="ghost"
icon="i-carbon-share"
@click="copyLink"
/>
</UTooltip>

<UTooltip text="Open on GitHub">
<UButton
color="neutral"
Expand Down