136 lines
6.4 KiB
PHP
136 lines
6.4 KiB
PHP
<!-- Toast Notifications -->
|
|||
|
|
<div x-data="{
|
||
|
|
notices: [],
|
||
|
|
visible: [],
|
||
|
|
add(notice) {
|
||
|
|
const id = Date.now();
|
||
|
|
notice.id = id;
|
||
|
|
this.notices.push(notice);
|
||
|
|
this.visible.push(id);
|
||
|
|
setTimeout(() => {
|
||
|
|
this.remove(id);
|
||
|
|
}, notice.duration || 5000);
|
||
|
|
},
|
||
|
|
remove(id) {
|
||
|
|
const index = this.visible.indexOf(id);
|
||
|
|
if (index > -1) {
|
||
|
|
this.visible.splice(index, 1);
|
||
|
|
}
|
||
|
|
setTimeout(() => {
|
||
|
|
const noticeIndex = this.notices.findIndex(n => n.id === id);
|
||
|
|
if (noticeIndex > -1) {
|
||
|
|
this.notices.splice(noticeIndex, 1);
|
||
|
|
}
|
||
|
|
}, 300);
|
||
|
|
}
|
||
|
|
}"
|
||
|
|
@notify.window="add($event.detail)"
|
||
|
|
class="fixed top-4 right-4 z-50 space-y-2"
|
||
|
|
aria-live="assertive">
|
||
|
|
<template x-for="notice in notices" :key="notice.id">
|
||
|
|
<div x-show="visible.includes(notice.id)"
|
||
|
|
x-transition:enter="transition ease-out duration-300"
|
||
|
|
x-transition:enter-start="transform translate-x-full opacity-0"
|
||
|
|
x-transition:enter-end="transform translate-x-0 opacity-100"
|
||
|
|
x-transition:leave="transition ease-in duration-200"
|
||
|
|
x-transition:leave-start="transform translate-x-0 opacity-100"
|
||
|
|
x-transition:leave-end="transform translate-x-full opacity-0"
|
||
|
|
class="max-w-sm w-full bg-white shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 overflow-hidden">
|
||
|
|
<div class="p-4">
|
||
|
|
<div class="flex items-start">
|
||
|
|
<div class="flex-shrink-0">
|
||
|
|
<!-- Success Icon -->
|
||
|
|
<template x-if="notice.type === 'success'">
|
||
|
|
<svg class="h-6 w-6 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
|
|
</svg>
|
||
|
|
</template>
|
||
|
|
<!-- Error Icon -->
|
||
|
|
<template x-if="notice.type === 'error'">
|
||
|
|
<svg class="h-6 w-6 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
|
|
</svg>
|
||
|
|
</template>
|
||
|
|
<!-- Info Icon -->
|
||
|
|
<template x-if="notice.type === 'info'">
|
||
|
|
<svg class="h-6 w-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||
|
|
</svg>
|
||
|
|
</template>
|
||
|
|
<!-- Warning Icon -->
|
||
|
|
<template x-if="notice.type === 'warning'">
|
||
|
|
<svg class="h-6 w-6 text-yellow-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
|
||
|
|
</svg>
|
||
|
|
</template>
|
||
|
|
</div>
|
||
|
|
<div class="ml-3 w-0 flex-1 pt-0.5">
|
||
|
|
<p class="text-sm font-medium text-gray-900" x-text="notice.title"></p>
|
||
|
|
<p class="mt-1 text-sm text-gray-500" x-text="notice.message"></p>
|
||
|
|
</div>
|
||
|
|
<div class="ml-4 flex-shrink-0 flex">
|
||
|
|
<button @click="remove(notice.id)"
|
||
|
|
class="bg-white rounded-md inline-flex text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500">
|
||
|
|
<span class="sr-only">Close</span>
|
||
|
|
<svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
|
||
|
|
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
|
||
|
|
</svg>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Session Messages (Laravel Flash Messages) -->
|
||
|
|
@if(session('success') || session('error') || session('info') || session('warning'))
|
||
|
|
<script>
|
||
|
|
document.addEventListener('DOMContentLoaded', function() {
|
||
|
|
@if(session('success'))
|
||
|
|
window.dispatchEvent(new CustomEvent('notify', {
|
||
|
|
detail: {
|
||
|
|
type: 'success',
|
||
|
|
title: 'Success!',
|
||
|
|
message: '{{ session('success') }}',
|
||
|
|
duration: 5000
|
||
|
|
}
|
||
|
|
}));
|
||
|
|
@endif
|
||
|
|
|
||
|
|
@if(session('error'))
|
||
|
|
window.dispatchEvent(new CustomEvent('notify', {
|
||
|
|
detail: {
|
||
|
|
type: 'error',
|
||
|
|
title: 'Error!',
|
||
|
|
message: '{{ session('error') }}',
|
||
|
|
duration: 5000
|
||
|
|
}
|
||
|
|
}));
|
||
|
|
@endif
|
||
|
|
|
||
|
|
@if(session('info'))
|
||
|
|
window.dispatchEvent(new CustomEvent('notify', {
|
||
|
|
detail: {
|
||
|
|
type: 'info',
|
||
|
|
title: 'Info',
|
||
|
|
message: '{{ session('info') }}',
|
||
|
|
duration: 5000
|
||
|
|
}
|
||
|
|
}));
|
||
|
|
@endif
|
||
|
|
|
||
|
|
@if(session('warning'))
|
||
|
|
window.dispatchEvent(new CustomEvent('notify', {
|
||
|
|
detail: {
|
||
|
|
type: 'warning',
|
||
|
|
title: 'Warning!',
|
||
|
|
message: '{{ session('warning') }}',
|
||
|
|
duration: 5000
|
||
|
|
}
|
||
|
|
}));
|
||
|
|
@endif
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
@endif
|