mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 12:03:25 -04:00
(refactor) replace clipboard dependency by useClipboard
This commit is contained in:
parent
01703e86be
commit
d0d017126b
@ -1,31 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
|
||||
const props = defineProps<{
|
||||
link: string;
|
||||
}>();
|
||||
|
||||
const { copy, copied } = useClipboard({ source: props.link });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button ref="clipboard" :class="['btn', clipboardFeedback ? 'btn-success' : 'btn-outline-primary', 'm-1']" :data-clipboard-text="link">
|
||||
<Icon :v="clipboardFeedback ? 'clipboard-check' : 'clipboard'" />
|
||||
<button type="button" :class="['btn', copied ? 'btn-success' : 'btn-outline-primary', 'm-1']" @click="copy()">
|
||||
<Icon :v="copied ? 'clipboard-check' : 'clipboard'" />
|
||||
<T>crud.copy</T>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ClipboardJS from 'clipboard';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
link: { required: true },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
clipboardFeedback: false,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
if (!this.$refs.clipboard) {
|
||||
return;
|
||||
}
|
||||
const clipboard = new ClipboardJS(this.$refs.clipboard);
|
||||
clipboard.on('success', () => {
|
||||
this.clipboardFeedback = true;
|
||||
setTimeout(() => this.clipboardFeedback = false, 3000);
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -1,37 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
|
||||
const props = defineProps<{
|
||||
link: string;
|
||||
}>();
|
||||
|
||||
const value = computed(() => props.link.replace('https://', '').replace('http://', ''));
|
||||
|
||||
const { copy, copied } = useClipboard({ source: value });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="input-group my-2">
|
||||
<input id="link" ref="link" class="form-control" readonly :value="link.replace('https://', '').replace('http://', '')">
|
||||
<input ref="linkInput" class="form-control" readonly :value>
|
||||
<button
|
||||
ref="clipboard"
|
||||
class="btn btn-outline-secondary"
|
||||
data-clipboard-target="#link"
|
||||
:data-clipboard-text="link"
|
||||
type="button"
|
||||
:class="['btn', copied ? 'btn-success' : 'btn-outline-secondary']"
|
||||
:aria-label="$t('crud.copy')"
|
||||
:title="$t('crud.copy')"
|
||||
@click="focusLink"
|
||||
@click="copy()"
|
||||
>
|
||||
<Icon v="clipboard" />
|
||||
<Icon :v="copied ? 'clipboard-check' : 'clipboard'" />
|
||||
</button>
|
||||
<a :href="link" target="_blank" rel="noopener" class="btn btn-outline-secondary">
|
||||
<Icon v="external-link" />
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ClipboardJS from 'clipboard';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
link: { required: true },
|
||||
},
|
||||
mounted() {
|
||||
new ClipboardJS(this.$refs.clipboard);
|
||||
},
|
||||
methods: {
|
||||
focusLink() {
|
||||
setTimeout((_) => this.$refs.link.select(), 100);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
@ -42,8 +42,8 @@ const link = computed((): string | null => {
|
||||
<div class="card-body">
|
||||
<slot></slot>
|
||||
</div>
|
||||
<div v-if="path" class="card-footer">
|
||||
<LinkInput v-if="addPronoun === undefined" :link="link" />
|
||||
<div v-if="path && link" class="card-footer">
|
||||
<LinkInput v-if="addPronoun === undefined" :link />
|
||||
<div v-else class="input-group my-2">
|
||||
<input class="form-control" readonly :value="path">
|
||||
<button
|
||||
|
@ -94,7 +94,6 @@
|
||||
"avris-vue-share": "^1.0.1",
|
||||
"bootstrap": "^5.3.1",
|
||||
"chart.js": "4.4.8",
|
||||
"clipboard": "^2.0.6",
|
||||
"eslint": "^9.22.0",
|
||||
"eslint-formatter-gitlab": "^5.1.0",
|
||||
"eslint-plugin-json-schema-validator": "^5.1.3",
|
||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -237,9 +237,6 @@ importers:
|
||||
chart.js:
|
||||
specifier: 4.4.8
|
||||
version: 4.4.8
|
||||
clipboard:
|
||||
specifier: ^2.0.6
|
||||
version: 2.0.11
|
||||
eslint:
|
||||
specifier: ^9.22.0
|
||||
version: 9.22.0(jiti@2.4.2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user