stargaze-studio/utils/clipboard.ts

12 lines
370 B
TypeScript
Raw Normal View History

2022-12-13 19:21:05 +00:00
import type { Renderable } from 'react-hot-toast'
2022-07-13 13:56:36 +00:00
import { toast } from 'react-hot-toast'
export async function copy(text: string, message: Renderable = 'Copied to clipboard!') {
try {
await navigator.clipboard.writeText(text)
return toast.success(message)
} catch (err: unknown) {
2022-11-02 07:53:17 +00:00
return toast.error(String(err), { style: { maxWidth: 'none' } })
2022-07-13 13:56:36 +00:00
}
}