42 lines
No EOL
2.2 KiB
PHP
42 lines
No EOL
2.2 KiB
PHP
<?php
|
|
class Flash {
|
|
public static function set($message, $type = 'error') {
|
|
$_SESSION['flash_messages'][] = [
|
|
'message' => $message,
|
|
'type' => $type
|
|
];
|
|
}
|
|
public static function display() {
|
|
if (isset($_SESSION['flash_messages'])) {
|
|
foreach ($_SESSION['flash_messages'] as $flash) {
|
|
// Style-Mapping
|
|
$styles = [
|
|
'error' => ['class' => 'border-rose-500/50 text-rose-400 shadow-[0_0_20px_rgba(244,63,94,0.25)]', 'prefix' => '[ ERR ]'],
|
|
'success' => ['class' => 'border-emerald-500/50 text-emerald-400 shadow-[0_0_20px_rgba(16,185,129,0.25)]', 'prefix' => '[ OK ]'],
|
|
'warning' => ['class' => 'border-amber-500/50 text-amber-400 shadow-[0_0_20px_rgba(245,158,11,0.25)]', 'prefix' => '[ WARN ]'],
|
|
'info' => ['class' => 'border-cyan-500/50 text-cyan-400 shadow-[0_0_20px_rgba(6,182,212,0.25)]', 'prefix' => '[ INFO ]']
|
|
];
|
|
$currentStyle = $styles[$flash['type']] ?? $styles['error'];
|
|
$cssClasses = $currentStyle['class'];
|
|
$prefix = $currentStyle['prefix'];
|
|
// Output HUD Element
|
|
echo "<div class='flash-message fixed top-6 right-6 bg-slate-950/90 border {$cssClasses} px-6 py-4 rounded-xl backdrop-blur-md z-9999 font-mono text-sm uppercase tracking-wider flex items-center gap-4'>
|
|
<span class='font-bold animate-pulse'>{$prefix}</span>
|
|
<span class='text-slate-300'>" . htmlspecialchars($flash['message']) . "</span>
|
|
</div>";
|
|
}
|
|
unset($_SESSION['flash_messages']);
|
|
// Auto-Hide Script
|
|
echo "<script>
|
|
setTimeout(() => {
|
|
document.querySelectorAll('.flash-message').forEach(alert => {
|
|
alert.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
|
|
alert.style.opacity = '0';
|
|
alert.style.transform = 'translateY(-10px)';
|
|
setTimeout(() => alert.remove(), 500);
|
|
});
|
|
}, 4000);
|
|
</script>";
|
|
}
|
|
}
|
|
} |