mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-17 21:18:26 +03:00
feat: implement show toast
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { showToast } from './showToast';
|
||||
|
||||
export function copyToClipboard(text: string) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
@@ -5,7 +7,9 @@ export function copyToClipboard(text: string) {
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
showToast(_('Successfully copied!'), 'success');
|
||||
} catch (_err) {
|
||||
showToast(_('Failed to copy!'), 'error');
|
||||
console.error('copyToClipboard - e', _err);
|
||||
}
|
||||
document.body.removeChild(textarea);
|
||||
|
||||
24
fe-app-podkop/src/helpers/showToast.ts
Normal file
24
fe-app-podkop/src/helpers/showToast.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export function showToast(
|
||||
message: string,
|
||||
type: 'success' | 'error',
|
||||
duration: number = 3000,
|
||||
) {
|
||||
let container = document.querySelector('.toast-container');
|
||||
if (!container) {
|
||||
container = document.createElement('div');
|
||||
container.className = 'toast-container';
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
toast.textContent = message;
|
||||
|
||||
container.appendChild(toast);
|
||||
setTimeout(() => toast.classList.add('visible'), 100);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('visible');
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, duration);
|
||||
}
|
||||
Reference in New Issue
Block a user