Skip to content

Commit 5a8b40d

Browse files
authored
refactor: toast component changes (#620)
1 parent fbfb4fa commit 5a8b40d

File tree

2 files changed

+76
-22
lines changed

2 files changed

+76
-22
lines changed

resources/assets/css/_toasts.css

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,32 @@
33
@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;
44
}
55

6+
.toast__titled {
7+
@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;
8+
}
9+
610
.toast-body {
711
@apply p-4 text-left mr-4 sm:mt-0;
812
}
913

1014
.toast-icon {
11-
@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;
15+
@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;
16+
}
17+
18+
.toast-icon__titled {
19+
@apply space-x-2 flex items-center px-4 py-2 flex-shrink-0 text-white w-full;
1220
}
1321

1422
.toast-button,
1523
.toast-spinner {
1624
@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;
1725
}
1826

27+
.toast-button__titled,
28+
.toast-spinner__titled {
29+
@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;
30+
}
31+
1932
.toast-info {
2033
@apply bg-theme-primary-50;
2134
}
@@ -32,19 +45,24 @@
3245
@apply bg-theme-success-50;
3346
}
3447

35-
.toast-info .toast-icon {
48+
.toast-info .toast-icon,
49+
.toast-info .toast-icon__titled {
3650
@apply bg-theme-primary-100 dark:bg-theme-primary-700 text-theme-primary-700 dark:text-white;
3751
}
38-
.toast-warning .toast-icon {
52+
.toast-warning .toast-icon,
53+
.toast-warning .toast-icon__titled {
3954
@apply bg-theme-warning-100 dark:bg-theme-warning-700 text-theme-warning-900 dark:text-white;
4055
}
41-
.toast-danger .toast-icon {
56+
.toast-danger .toast-icon,
57+
.toast-danger .toast-icon__titled {
4258
@apply bg-theme-danger-100 dark:bg-theme-danger-500 text-theme-danger-700 dark:text-white;
4359
}
44-
.toast-hint .toast-icon {
60+
.toast-hint .toast-icon,
61+
.toast-hint .toast-icon__titled {
4562
@apply bg-theme-hint-100 dark:bg-theme-hint-700 text-theme-hint-700 dark:text-white;
4663
}
47-
.toast-success .toast-icon {
64+
.toast-success .toast-icon,
65+
.toast-success .toast-icon__titled {
4866
@apply bg-theme-success-100 dark:bg-theme-success-700 text-theme-success-700 dark:text-white;
4967
}
5068

resources/views/toast.blade.php

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
@props ([
22
'type' => 'info',
33
'title' => null,
4-
'message' => '',
4+
'message' => null,
55
'wireClose' => false,
66
'alpineClose' => false,
77
'target' => null,
8+
'hideSpinner' => false,
9+
'alwaysShowTitle' => false,
810
])
911

1012
@php
@@ -27,19 +29,48 @@
2729
], $type);
2830
@endphp
2931

30-
<div role="alert" aria-live="polite" {{ $attributes->class('toast')->class($toastClass) }}>
31-
<span class="toast-icon">
32-
<x-ark-icon :name="$icon" size="sm" />
33-
<span class="text-sm font-semibold sm:hidden">{{ $title ?? trans('ui::toasts.'.$type) }}</span>
32+
<div
33+
role="alert"
34+
aria-live="polite"
35+
{{ $attributes->class([
36+
'toast' => ! $alwaysShowTitle,
37+
'toast__titled' => $alwaysShowTitle,
38+
$toastClass,
39+
]) }}
40+
>
41+
<span @class([
42+
'toast-icon' => ! $alwaysShowTitle,
43+
'toast-icon__titled' => $alwaysShowTitle,
44+
])>
45+
<x-ark-icon
46+
:name="$icon"
47+
size="sm"
48+
/>
49+
50+
<span @class([
51+
'text-sm font-semibold',
52+
'sm:hidden' => ! $alwaysShowTitle,
53+
])>
54+
{{ $title ?? trans('ui::toasts.'.$type) }}
55+
</span>
3456
</span>
3557

36-
<div class="toast-body">{{ $message }}</div>
58+
<div class="toast-body">
59+
@if ($message)
60+
{{ $message }}
61+
@else
62+
{!! $slot !!}
63+
@endif
64+
</div>
3765

3866
<button
3967
@if ($wireClose) wire:click="{{ $wireClose }}" @endif
4068
@if ($alpineClose) @click="{{ $alpineClose }}" @endif
4169
type="button"
42-
class="toast-button"
70+
@class([
71+
'toast-button' => ! $alwaysShowTitle,
72+
'toast-button__titled' => $alwaysShowTitle,
73+
])
4374
@if ($target)
4475
wire:loading.remove
4576
wire:target="{{ $target }}"
@@ -48,13 +79,18 @@ class="toast-button"
4879
<x-ark-icon name="cross" size="sm" />
4980
</button>
5081

51-
<div
52-
class="toast-spinner"
53-
@if ($target)
54-
wire:loading
55-
wire:target="{{ $target }}"
56-
@endif
57-
>
58-
<x-ark-spinner-icon circle-color="spinner" :stroke-width="3" />
59-
</div>
82+
@unless ($hideSpinner)
83+
<div
84+
@class([
85+
'toast-spinner' => ! $alwaysShowTitle,
86+
'toast-spinner__titled' => $alwaysShowTitle,
87+
])
88+
@if ($target)
89+
wire:loading
90+
wire:target="{{ $target }}"
91+
@endif
92+
>
93+
<x-ark-spinner-icon circle-color="spinner" :stroke-width="3" />
94+
</div>
95+
@endunless
6096
</div>

0 commit comments

Comments
 (0)