aboutsummaryrefslogtreecommitdiff
path: root/src/composable/copy.ts
blob: 6c1eca09c8c30469dcbe363604cb31823ec5ac23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { type MaybeRef, get, useClipboard } from '@vueuse/core';
import { useMessage } from 'naive-ui';

export function useCopy({ source, text = 'Copied to the clipboard' }: { source: MaybeRef<unknown>; text?: string }) {
  const { copy } = useClipboard({ source: computed(() => String(get(source))) });
  const message = useMessage();

  return {
    async copy() {
      await copy();
      message.success(text);
    },
  };
}