Skip to content

Commit

Permalink
Update banner styling and add warning banner functionality (#1486)
Browse files Browse the repository at this point in the history
* Update banner styling and add warning banner functionality

* Updated warning span color

* Update InteractsWithBanner.php

* Update JetstreamServiceProvider.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
gqrdev and taylorotwell authored May 6, 2024
1 parent 2776c50 commit 8bffd53
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/InteractsWithBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ protected function banner($message)
}

/**
* Update the banner message with an danger / error message.
* Update the banner message with a warning message.
*
* @param string $message
* @return void
*/
protected function warningBanner($message)
{
$this->dispatch('banner-message',
style: 'warning',
message: $message,
);
}

/**
* Update the banner message with a danger / error message.
*
* @param string $message
* @return void
Expand Down
8 changes: 8 additions & 0 deletions src/JetstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public function boot()
]);
});

RedirectResponse::macro('warningBanner', function ($message) {
/** @var \Illuminate\Http\RedirectResponse $this */
return $this->with('flash', [
'bannerStyle' => 'warning',
'banner' => $message,
]);
});

RedirectResponse::macro('dangerBanner', function ($message) {
/** @var \Illuminate\Http\RedirectResponse $this */
return $this->with('flash', [
Expand Down
10 changes: 7 additions & 3 deletions stubs/livewire/resources/views/components/banner.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@props(['style' => session('flash.bannerStyle', 'success'), 'message' => session('flash.banner')])

<div x-data="{{ json_encode(['show' => true, 'style' => $style, 'message' => $message]) }}"
:class="{ 'bg-indigo-500': style == 'success', 'bg-red-700': style == 'danger', 'bg-gray-500': style != 'success' && style != 'danger' }"
: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'}"
style="display: none;"
x-show="show && message"
x-on:banner-message.window="
Expand All @@ -12,7 +12,7 @@
<div class="max-w-screen-xl mx-auto py-2 px-3 sm:px-6 lg:px-8">
<div class="flex items-center justify-between flex-wrap">
<div class="w-0 flex-1 flex items-center min-w-0">
<span class="flex p-2 rounded-lg" :class="{ 'bg-indigo-600': style == 'success', 'bg-red-600': style == 'danger' }">
<span class="flex p-2 rounded-lg" :class="{ 'bg-indigo-600': style == 'success', 'bg-red-600': style == 'danger', 'bg-yellow-600': style == 'warning' }">
<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">
<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" />
</svg>
Expand All @@ -22,6 +22,10 @@
<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">
<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" />
</svg>
<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">
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="1.5" fill="none" />
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4v.01 0 0 " />
</svg>
</span>

<p class="ms-3 font-medium text-sm text-white truncate" x-text="message"></p>
Expand All @@ -31,7 +35,7 @@
<button
type="button"
class="-me-1 flex p-2 rounded-md focus:outline-none sm:-me-2 transition"
:class="{ 'hover:bg-indigo-600 focus:bg-indigo-600': style == 'success', 'hover:bg-red-600 focus:bg-red-600': style == 'danger' }"
: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'}"
aria-label="Dismiss"
x-on:click="show = false">
<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">
Expand Down

0 comments on commit 8bffd53

Please sign in to comment.