Skip to content

Commit 8bffd53

Browse files
gqrdevtaylorotwell
andauthored
Update banner styling and add warning banner functionality (#1486)
* Update banner styling and add warning banner functionality * Updated warning span color * Update InteractsWithBanner.php * Update JetstreamServiceProvider.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 2776c50 commit 8bffd53

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/InteractsWithBanner.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ protected function banner($message)
1919
}
2020

2121
/**
22-
* Update the banner message with an danger / error message.
22+
* Update the banner message with a warning message.
23+
*
24+
* @param string $message
25+
* @return void
26+
*/
27+
protected function warningBanner($message)
28+
{
29+
$this->dispatch('banner-message',
30+
style: 'warning',
31+
message: $message,
32+
);
33+
}
34+
35+
/**
36+
* Update the banner message with a danger / error message.
2337
*
2438
* @param string $message
2539
* @return void

src/JetstreamServiceProvider.php

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public function boot()
6161
]);
6262
});
6363

64+
RedirectResponse::macro('warningBanner', function ($message) {
65+
/** @var \Illuminate\Http\RedirectResponse $this */
66+
return $this->with('flash', [
67+
'bannerStyle' => 'warning',
68+
'banner' => $message,
69+
]);
70+
});
71+
6472
RedirectResponse::macro('dangerBanner', function ($message) {
6573
/** @var \Illuminate\Http\RedirectResponse $this */
6674
return $this->with('flash', [

stubs/livewire/resources/views/components/banner.blade.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@props(['style' => session('flash.bannerStyle', 'success'), 'message' => session('flash.banner')])
22

33
<div x-data="{{ json_encode(['show' => true, 'style' => $style, 'message' => $message]) }}"
4-
:class="{ 'bg-indigo-500': style == 'success', 'bg-red-700': style == 'danger', 'bg-gray-500': style != 'success' && style != 'danger' }"
4+
:class="{ 'bg-indigo-500': style == 'success', 'bg-red-700': style == 'danger', 'bg-yellow-500': style == 'warning', 'bg-gray-500': style != 'success' && style != 'danger' && style != 'warning'}"
55
style="display: none;"
66
x-show="show && message"
77
x-on:banner-message.window="
@@ -12,7 +12,7 @@
1212
<div class="max-w-screen-xl mx-auto py-2 px-3 sm:px-6 lg:px-8">
1313
<div class="flex items-center justify-between flex-wrap">
1414
<div class="w-0 flex-1 flex items-center min-w-0">
15-
<span class="flex p-2 rounded-lg" :class="{ 'bg-indigo-600': style == 'success', 'bg-red-600': style == 'danger' }">
15+
<span class="flex p-2 rounded-lg" :class="{ 'bg-indigo-600': style == 'success', 'bg-red-600': style == 'danger', 'bg-yellow-600': style == 'warning' }">
1616
<svg x-show="style == 'success'" class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
1717
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
1818
</svg>
@@ -22,6 +22,10 @@
2222
<svg x-show="style != 'success' && style != 'danger'" class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
2323
<path stroke-linecap="round" stroke-linejoin="round" d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z" />
2424
</svg>
25+
<svg x-show="style == 'warning'" class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
26+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="1.5" fill="none" />
27+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4v.01 0 0 " />
28+
</svg>
2529
</span>
2630

2731
<p class="ms-3 font-medium text-sm text-white truncate" x-text="message"></p>
@@ -31,7 +35,7 @@
3135
<button
3236
type="button"
3337
class="-me-1 flex p-2 rounded-md focus:outline-none sm:-me-2 transition"
34-
:class="{ 'hover:bg-indigo-600 focus:bg-indigo-600': style == 'success', 'hover:bg-red-600 focus:bg-red-600': style == 'danger' }"
38+
:class="{ 'hover:bg-indigo-600 focus:bg-indigo-600': style == 'success', 'hover:bg-red-600 focus:bg-red-600': style == 'danger', 'hover:bg-yellow-600 focus:bg-yellow-600': style == 'warning'}"
3539
aria-label="Dismiss"
3640
x-on:click="show = false">
3741
<svg class="h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">

0 commit comments

Comments
 (0)