From 336bb7cf4dbcd88bec85ee8f0ad99260b0e1295c Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 5 May 2026 18:04:25 +0200 Subject: [PATCH] feat: add toast notification system --- static/toast.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ templates/base.gohtml | 17 +++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 static/toast.ts diff --git a/static/toast.ts b/static/toast.ts new file mode 100644 index 0000000..b3b3bfd --- /dev/null +++ b/static/toast.ts @@ -0,0 +1,43 @@ +interface ToastOptions { + message: string; + duration?: number; +} + +const toastContainer = () => { + let container = document.getElementById('toast-container'); + if (!container) { + container = document.createElement('div'); + container.id = 'toast-container'; + container.className = 'fixed bottom-4 right-4 z-[100] flex flex-col gap-2'; + document.body.appendChild(container); + } + return container; +}; + +const showToast = ({ message, duration = 3000 }: ToastOptions) => { + const container = toastContainer(); + const toast = document.createElement('div'); + + toast.className = 'bg-white/10 border border-white/20 flex items-center gap-3 px-4 py-3 shadow-lg transform transition-all duration-300 translate-y-2 opacity-0'; + toast.innerHTML = ` + ${message} + + `; + + container.appendChild(toast); + + requestAnimationFrame(() => { + toast.classList.remove('translate-y-2', 'opacity-0'); + }); + + setTimeout(() => { + toast.classList.add('translate-y-2', 'opacity-0'); + setTimeout(() => toast.remove(), 300); + }, duration); +}; + +(window as unknown as Record).showToast = showToast; + +export { showToast }; \ No newline at end of file diff --git a/templates/base.gohtml b/templates/base.gohtml index 7b20dd6..d67e8c0 100644 --- a/templates/base.gohtml +++ b/templates/base.gohtml @@ -34,7 +34,18 @@ + +