From 5a8b40d6b3836d17d7b670c34e35ee881a2db5cf Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 1 May 2024 08:19:11 +0100 Subject: [PATCH] refactor: toast component changes (#620) --- resources/assets/css/_toasts.css | 30 +++++++++++--- resources/views/toast.blade.php | 68 ++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/resources/assets/css/_toasts.css b/resources/assets/css/_toasts.css index e81d2422..ff5c4454 100644 --- a/resources/assets/css/_toasts.css +++ b/resources/assets/css/_toasts.css @@ -3,12 +3,20 @@ @apply relative inline-flex flex-col sm:flex-row items-center max-w-4xl text-sm select-none text-theme-secondary-900 dark:text-theme-secondary-200 dark:bg-theme-secondary-800 rounded-xl overflow-hidden; } + .toast__titled { + @apply relative inline-flex flex-col items-center max-w-4xl text-sm select-none text-theme-secondary-900 dark:text-theme-secondary-200 dark:bg-theme-secondary-800 rounded-xl overflow-hidden; + } + .toast-body { @apply p-4 text-left mr-4 sm:mt-0; } .toast-icon { - @apply space-x-2 flex items-center px-4 sm:px-0 py-2 sm:py-0 sm:justify-center flex-shrink-0 text-white w-full sm:w-12 sm:h-14; + @apply space-x-2 flex items-center px-4 sm:px-0 py-2 sm:py-0 sm:justify-center flex-shrink-0 text-white w-full sm:w-12 sm:h-full; + } + + .toast-icon__titled { + @apply space-x-2 flex items-center px-4 py-2 flex-shrink-0 text-white w-full; } .toast-button, @@ -16,6 +24,11 @@ @apply absolute sm:relative top-0 sm:top-auto right-0 sm:right-auto m-2.5 sm:my-0 sm:ml-0 flex items-center justify-center flex-shrink-0 mr-4 rounded text-theme-secondary-900 dark:text-white sm:dark:text-theme-secondary-600; } + .toast-button__titled, + .toast-spinner__titled { + @apply absolute top-0 right-0 m-2.5 flex items-center justify-center flex-shrink-0 mr-4 rounded text-theme-secondary-900 dark:text-white sm:dark:text-theme-secondary-600; + } + .toast-info { @apply bg-theme-primary-50; } @@ -32,19 +45,24 @@ @apply bg-theme-success-50; } - .toast-info .toast-icon { + .toast-info .toast-icon, + .toast-info .toast-icon__titled { @apply bg-theme-primary-100 dark:bg-theme-primary-700 text-theme-primary-700 dark:text-white; } - .toast-warning .toast-icon { + .toast-warning .toast-icon, + .toast-warning .toast-icon__titled { @apply bg-theme-warning-100 dark:bg-theme-warning-700 text-theme-warning-900 dark:text-white; } - .toast-danger .toast-icon { + .toast-danger .toast-icon, + .toast-danger .toast-icon__titled { @apply bg-theme-danger-100 dark:bg-theme-danger-500 text-theme-danger-700 dark:text-white; } - .toast-hint .toast-icon { + .toast-hint .toast-icon, + .toast-hint .toast-icon__titled { @apply bg-theme-hint-100 dark:bg-theme-hint-700 text-theme-hint-700 dark:text-white; } - .toast-success .toast-icon { + .toast-success .toast-icon, + .toast-success .toast-icon__titled { @apply bg-theme-success-100 dark:bg-theme-success-700 text-theme-success-700 dark:text-white; } diff --git a/resources/views/toast.blade.php b/resources/views/toast.blade.php index edcad8bd..dd7f84fe 100644 --- a/resources/views/toast.blade.php +++ b/resources/views/toast.blade.php @@ -1,10 +1,12 @@ @props ([ 'type' => 'info', 'title' => null, - 'message' => '', + 'message' => null, 'wireClose' => false, 'alpineClose' => false, 'target' => null, + 'hideSpinner' => false, + 'alwaysShowTitle' => false, ]) @php @@ -27,19 +29,48 @@ ], $type); @endphp -
class('toast')->class($toastClass) }}> - - - {{ $title ?? trans('ui::toasts.'.$type) }} +
class([ + 'toast' => ! $alwaysShowTitle, + 'toast__titled' => $alwaysShowTitle, + $toastClass, + ]) }} +> + ! $alwaysShowTitle, + 'toast-icon__titled' => $alwaysShowTitle, + ])> + + + ! $alwaysShowTitle, + ])> + {{ $title ?? trans('ui::toasts.'.$type) }} + -
{{ $message }}
+
+ @if ($message) + {{ $message }} + @else + {!! $slot !!} + @endif +
-
- -
+ @unless ($hideSpinner) +
! $alwaysShowTitle, + 'toast-spinner__titled' => $alwaysShowTitle, + ]) + @if ($target) + wire:loading + wire:target="{{ $target }}" + @endif + > + +
+ @endunless