Skip to content

Commit

Permalink
add disableCloseButton
Browse files Browse the repository at this point in the history
  • Loading branch information
rupadana committed Jan 24, 2024
1 parent a7c80f3 commit 0d83d9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
19 changes: 8 additions & 11 deletions resources/views/announcement.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
@php
$data = $notification->data;
$color = $data['color'] ?? $data['iconColor'] ?? $data['status'];
$color = $data['color'] ?? ($data['iconColor'] ?? $data['status']);
$icon = $data['icon'];
$title = $data['title'];
$body = $data['body'];
$closeButton = $data['closeButton'] ?? true;
$colorClasses = \Illuminate\Support\Arr::toCssClasses([
'flex items-center border border-transparent px-6 py-2 gap-4',
'bg-white text-gray-950 dark:bg-white/5 dark:text-white' => $color === 'gray',
'bg-custom-600 text-white dark:bg-custom-500' => $color !== 'gray',
]);
$colorClasses = \Illuminate\Support\Arr::toCssClasses(['flex items-center border border-transparent px-6 py-2 gap-4', 'bg-white text-gray-950 dark:bg-white/5 dark:text-white' => $color === 'gray', 'bg-custom-600 text-white dark:bg-custom-500' => $color !== 'gray']);
$colorStyles = \Illuminate\Support\Arr::toCssStyles([
\Filament\Support\get_color_css_variables(
$color,
shades: [400, 500, 600],
) => $color !== 'gray',
\Filament\Support\get_color_css_variables($color, shades: [400, 500, 600]) => $color !== 'gray',
]);
@endphp

Expand All @@ -40,6 +34,9 @@


<div class="flex items-center">
<x-filament::icon-button icon="heroicon-o-x-mark" color="white" x-on:click="$dispatch('markedAnnouncementAsRead', {id: '{{ $notification->id }}'})"/>
@if ($closeButton)
<x-filament::icon-button icon="heroicon-o-x-mark" color="white"
x-on:click="$dispatch('markedAnnouncementAsRead', {id: '{{ $notification->id }}'})" />
@endif
</div>
</div>
22 changes: 22 additions & 0 deletions src/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class Announce extends Notification
{

protected bool $closeButton = true;

public function announceTo(Model | Authenticatable | Collection | array $users): void
{
if (! $this->getColor()) {
Expand All @@ -26,4 +29,23 @@ public function announceTo(Model | Authenticatable | Collection | array $users):
$user->notify($notification);
}
}

public function disableCloseButton(bool $condition = true) : static
{
$this->closeButton = !$condition;
return $this;
}

public function isCloseButton() : bool
{
return $this->closeButton;
}

public function toArray(): array
{
return [
...parent::toArray(),
'closeButton' => $this->isCloseButton()
];
}
}

0 comments on commit 0d83d9b

Please sign in to comment.