mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-17 21:18:26 +03:00
feat: add copy & download actions for modal
This commit is contained in:
12
fe-app-podkop/src/helpers/copyToClipboard.ts
Normal file
12
fe-app-podkop/src/helpers/copyToClipboard.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function copyToClipboard(text: string) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
} catch (_err) {
|
||||
console.error('copyToClipboard - e', _err);
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
15
fe-app-podkop/src/helpers/downloadAsTxt.ts
Normal file
15
fe-app-podkop/src/helpers/downloadAsTxt.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function downloadAsTxt(text: string, filename: string) {
|
||||
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
|
||||
const safeName = filename.endsWith('.txt') ? filename : `${filename}.txt`;
|
||||
link.download = safeName;
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(link.href);
|
||||
}
|
||||
Reference in New Issue
Block a user