mirror of https://github.com/nocodb/nocodb
navi
2 years ago
committed by
GitHub
13 changed files with 46 additions and 19 deletions
@ -0,0 +1,26 @@
|
||||
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 } |
||||
} |
Loading…
Reference in new issue