Skip to content

Commit 01d7c27

Browse files
committed
chore: add clipboard hooks
1 parent 6b14d50 commit 01d7c27

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/hooks/useClipboard.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ref } from 'vue';
2+
3+
export type UseClipboardOptions = {
4+
source: string;
5+
};
6+
7+
export function useClipboard({ source }: UseClipboardOptions) {
8+
const copied = ref(false);
9+
10+
const copy = async () => {
11+
try {
12+
await navigator.clipboard.writeText(source);
13+
copied.value = true;
14+
setTimeout(() => {
15+
copied.value = false;
16+
}, 300);
17+
} catch (err) {
18+
console.error('[vue-json-pretty] Copy failed: ', err);
19+
}
20+
};
21+
22+
return {
23+
copy,
24+
};
25+
};

src/hooks/useError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type UseErrorOptions = {
44
emitListener: boolean;
55
};
66

7-
export default function useError(message: string, { emitListener }: UseErrorOptions) {
7+
export function useError(message: string, { emitListener }: UseErrorOptions) {
88
const emit = () => {
99
throw new Error(`[VueJsonPretty] ${message}`);
1010
};

0 commit comments

Comments
 (0)