52 lines
2.1 KiB
PHP
52 lines
2.1 KiB
PHP
{{--
|
|
Pesan dari sesi (status, error, warning, info, toast) + tempat toast klien.
|
|
Pasang satu kali per layout, tepat setelah tautan lewati (bukan di dalam <main>: toast memakai position fixed).
|
|
Tanpa JS pesan tampil sebagai daftar peringatan di atas cangkang; setelah Alpine siap, daftar itu disembunyikan dan toast mengambil alih.
|
|
Dari klien: window.toast('success', 'Tersimpan') atau $dispatch('toast', { tone: 'danger', message: '...' }).
|
|
--}}
|
|
@php
|
|
$tones = ['info', 'success', 'warning', 'danger'];
|
|
$messages = [];
|
|
|
|
if (request()->hasSession()) {
|
|
foreach (['status' => 'success', 'error' => 'danger', 'warning' => 'warning', 'info' => 'info'] as $key => $tone) {
|
|
$text = session($key);
|
|
if (is_string($text) && $text !== '') {
|
|
$messages[] = ['tone' => $tone, 'message' => $text];
|
|
}
|
|
}
|
|
|
|
foreach ((array) session('toast', []) as $item) {
|
|
if (is_array($item) && is_string($item['message'] ?? null) && $item['message'] !== '') {
|
|
$messages[] = [
|
|
'tone' => in_array($item['tone'] ?? 'info', $tones, true) ? $item['tone'] : 'info',
|
|
'message' => $item['message'],
|
|
];
|
|
}
|
|
}
|
|
}
|
|
@endphp
|
|
|
|
@if ($messages)
|
|
<div class="flash-static" data-flash-static>
|
|
@foreach ($messages as $item)
|
|
<x-ui.alert :tone="$item['tone']">{{ $item['message'] }}</x-ui.alert>
|
|
@endforeach
|
|
</div>
|
|
@endif
|
|
|
|
<div class="toasts" x-data x-init="$store.toasts.seed(@js($messages))">
|
|
<div class="toasts__stack" role="region" aria-label="Notifikasi">
|
|
<div aria-live="polite" aria-atomic="false">
|
|
<template x-for="item in $store.toasts.items.filter((i) => !i.assertive)" :key="item.id">
|
|
@include('ui.toast')
|
|
</template>
|
|
</div>
|
|
<div aria-live="assertive" aria-atomic="false">
|
|
<template x-for="item in $store.toasts.items.filter((i) => i.assertive)" :key="item.id">
|
|
@include('ui.toast')
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|