89 lines
3.8 KiB
HTML
89 lines
3.8 KiB
HTML
{{ define "notifications" }}
|
|
{{ if .Notification }}
|
|
<div id="notification-container" class="fixed top-4 right-4 max-w-md z-50">
|
|
<div id="notification-toast" class="rounded-lg shadow-lg p-4 flex items-start gap-3 {{ if eq .NotificationType "error" }}bg-red-900 border-l-4 border-red-500{{ else if eq .NotificationType "success" }}bg-green-900 border-l-4 border-green-500{{ else }}bg-blue-900 border-l-4 border-blue-500{{ end }}" onmouseenter="pauseNotification()" onmouseleave="resumeNotification()">
|
|
<div class="flex-shrink-0">
|
|
{{ if eq .NotificationType "error" }}
|
|
<svg class="h-5 w-5 text-red-400" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
|
|
</svg>
|
|
{{ else if eq .NotificationType "success" }}
|
|
<svg class="h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
|
|
</svg>
|
|
{{ else }}
|
|
<svg class="h-5 w-5 text-blue-400" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
|
|
</svg>
|
|
{{ end }}
|
|
</div>
|
|
<div class="flex-1">
|
|
<p class="font-medium {{ if eq .NotificationType "error" }}text-red-200{{ else if eq .NotificationType "success" }}text-green-200{{ else }}text-blue-200{{ end }}">
|
|
{{ .Notification }}
|
|
</p>
|
|
</div>
|
|
<button onclick="closeNotification()" class="flex-shrink-0 text-gray-400 hover:text-white transition">
|
|
<svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
<div id="notification-progress" class="mt-2 h-1 bg-gray-700 rounded" style="animation: shrink 5s linear forwards;"></div>
|
|
</div>
|
|
|
|
<style>
|
|
@keyframes shrink {
|
|
from {
|
|
width: 100%;
|
|
}
|
|
to {
|
|
width: 0%;
|
|
}
|
|
}
|
|
|
|
#notification-progress.paused {
|
|
animation-play-state: paused;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
var notificationTimeout;
|
|
var isNotificationPaused = false;
|
|
|
|
function closeNotification() {
|
|
var container = document.getElementById('notification-container');
|
|
if (container) {
|
|
container.style.transition = 'opacity 0.3s ease-out';
|
|
container.style.opacity = '0';
|
|
setTimeout(function() {
|
|
container.remove();
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
function pauseNotification() {
|
|
isNotificationPaused = true;
|
|
clearTimeout(notificationTimeout);
|
|
var progress = document.getElementById('notification-progress');
|
|
if (progress) {
|
|
progress.classList.add('paused');
|
|
}
|
|
}
|
|
|
|
function resumeNotification() {
|
|
if (isNotificationPaused) {
|
|
isNotificationPaused = false;
|
|
var progress = document.getElementById('notification-progress');
|
|
if (progress) {
|
|
progress.classList.remove('paused');
|
|
}
|
|
notificationTimeout = setTimeout(closeNotification, 5000);
|
|
}
|
|
}
|
|
|
|
// Auto-close after 5 seconds
|
|
notificationTimeout = setTimeout(closeNotification, 5000);
|
|
</script>
|
|
{{ end }}
|
|
{{ end }}
|