-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a button which copies citation value to clipboard
- Loading branch information
orlinmalkja
committed
Nov 21, 2024
1 parent
ccf6e6d
commit 575f89d
Showing
3 changed files
with
155 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<template> | ||
<BaseButton | ||
display="mono" | ||
icon="copy" | ||
icon-position="right" | ||
text="Copy citation" | ||
class="t-mt-[10px] t-ml-[20px]" | ||
@click="copyContentToClipboard()" | ||
/> | ||
<Message | ||
v-if="copiedCitation" | ||
:pt="{ | ||
root: 't-bg-green-100 t-text-green-500 t-w-[200px] t-h-[25px] t-mt-[10px] t-ml-[20px] t-rounded', | ||
wrapper: 't-flex t-flex-row t-relative', | ||
icon: 't-hidden', | ||
text: 't-pl-[10px]', | ||
closebutton: { | ||
class: 't-absolute t-right-[10px]', | ||
onclick: onCloseClick, | ||
}, | ||
}" | ||
> | ||
Copied successfully! | ||
</Message> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Message from "primevue/message"; | ||
import BaseButton from "@/components/base/BaseButton.vue"; | ||
import { ref } from "vue"; | ||
const props = defineProps<{ | ||
value: string; | ||
}>(); | ||
let copiedCitation = ref(false); | ||
async function copyContentToClipboard() { | ||
try { | ||
await navigator.clipboard.writeText(props.value); | ||
copiedCitation.value = true; | ||
setTimeout(() => (this.copiedCitation = false), 1500); | ||
} catch (err) { | ||
console.error("Citation could not be copied in the keyboard"); | ||
} | ||
} | ||
function onCloseClick() { | ||
copiedCitation.value = false; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.