mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-25 06:05:33 +00:00
27 lines
657 B
TypeScript
27 lines
657 B
TypeScript
import { useClipboard } from '#imports'
|
|
|
|
export const useCopy = () => {
|
|
/** fallback for copy if clipboard api is not supported */
|
|
const copyFallback = (text: string) => {
|
|
const textAreaEl = document.createElement('textarea')
|
|
textAreaEl.innerHTML = text
|
|
document.body.appendChild(textAreaEl)
|
|
textAreaEl.select()
|
|
const result = document.execCommand('copy')
|
|
document.body.removeChild(textAreaEl)
|
|
return result
|
|
}
|
|
|
|
const { copy: _copy, isSupported } = useClipboard()
|
|
|
|
const copy = async (text: string) => {
|
|
if (isSupported) {
|
|
await _copy(text)
|
|
} else {
|
|
copyFallback(text)
|
|
}
|
|
}
|
|
|
|
return { copy }
|
|
}
|