Banners/ Alerts #1000
Replies: 5 comments 8 replies
-
@ibalat thanks for the request! We already have Toasts that do that, will that do what you want? See https://fluxui.dev/components/toast |
Beta Was this translation helpful? Give feedback.
-
@ibalat I use the e.g.
If you want to make it even easier to use you can create your own component to 'wrap' the badge usage. |
Beta Was this translation helpful? Give feedback.
-
A real Alert/Message/Banner component would be useful, especially with a close button but for exemple, or a slot for actions Almost all UI libraries have that |
Beta Was this translation helpful? Give feedback.
-
I created my own implementation using the badge component. It also has a dismissable (close button) and persistable (keep the message hidden after it was dismissed using Alpines $persist) and an autohide (in milliseconds). PreviewUsage <flux:alert variant="success" dismissable persistable>Good job!</flux:alert>
<flux:alert variant="error" dismissable>Oops, something went wrong</flux:alert>
<flux:alert variant="warning">You're not allowed to do this. And you know it. Therefore you can't dismiss this warning. </flux:alert>
<flux:alert variant="info" dismissable autohide="2000">A message was sent.</flux:alert> Component{{-- /resources/views/flux/alert.blade.php --}}
@props([
'color' => 'blue',
'class' => null,
'icon' => null,
'dismissable' => null,
'variant' => null,
'iconVariant' => null,
'iconClasses' => null,
'uniqueId' => null,
'autohide' => null,
'persistable' => null,
])
@php
$classes = Flux::classes()
->add('w-full px-3 py-2 !whitespace-normal !items-start');
$iconClasses = Flux::classes()
->add('mr-2 size-5');
if($dismissable || $autohide) {
$uniqueId = $uniqueId ?? 'alert'.hash('murmur3f',$slot);
}
if($variant){
$color = match($variant){
'success' => 'green',
'error' => 'red',
'warning' => 'yellow',
'info' => 'blue',
default => $color,
};
$icon = match($variant){
'success' => 'check-circle',
'error' => 'exclamation-circle',
'warning' => 'exclamation-triangle',
'info' => 'information-circle',
default => $icon,
};
}
@endphp
<?php if (isset($dismissable) || isset($autohide)): ?>
<div
<?php if (isset($persistable)): ?>
x-data="{ {{ $uniqueId }} : $persist(true).using(sessionStorage) }"
<?php else: ?>
x-data="{ {{ $uniqueId }} : true }"
<?php endif; ?>
x-show="{{ $uniqueId }} " x-transition x-cloak
@isset($autohide) x-init="setTimeout(() => { {{ $uniqueId }} = false }, {{ $autohide }});" @endisset
>
<?php endif; ?>
<flux:badge :$color :class="$classes">
<?php if (is_string($icon) && $icon !== ''): ?>
<flux:icon :icon="$icon" :variant="$iconVariant" :class="$iconClasses"/>
<?php elseif ($icon): ?>
{{ $icon }}
<?php endif; ?>
<div>
{{ $slot }}
</div>
<?php if (isset($dismissable)): ?>
<flux:spacer />
<flux:button icon="x-mark" x-on:click="{{ $uniqueId }} = ! {{ $uniqueId }}" size="xs" inset="top bottom" variant="subtle"></flux:button>
<?php endif; ?>
</flux:badge>
<?php if (isset($dismissable) || isset$autohide)): ?>
</div>
<?php endif; ?> |
Beta Was this translation helpful? Give feedback.
-
Another typo: -<?php if (isset($dismissable) || isset$autohide)): ?>
+<?php if (isset($dismissable) || isset($autohide)): ?> |
Beta Was this translation helpful? Give feedback.
-
Hi, please can you add
alerts
component with variations like with icon, without icon, color etc..Beta Was this translation helpful? Give feedback.
All reactions