From 20a27de0b45757a22f7a06ec39505570ecc2c11a Mon Sep 17 00:00:00 2001 From: "M. D." <dissto@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:23:10 +0200 Subject: [PATCH 1/4] Add ability to set a border --- README.md | 10 +++++++++ .../components/simple-alert-entry.blade.php | 1 + .../components/simple-alert-field.blade.php | 1 + .../views/components/simple-alert.blade.php | 8 +++++-- src/Components/Concerns/HasBorder.php | 22 +++++++++++++++++++ src/Components/Forms/SimpleAlert.php | 2 ++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/Components/Concerns/HasBorder.php diff --git a/README.md b/README.md index 0cb3fe3..306ebb0 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,16 @@ SimpleAlert::make('example') ->description('This is the description') ``` +### Border + +You can add a border to the alert by using the `border` method. + +```php +use CodeWithDennis\SimpleAlert\Components\Infolists\SimpleAlert; + +SimpleAlert::make('example') + ->border(true) +``` ### Actions You can also add actions to the alert by using the `actions` method. All regular action features are supported. diff --git a/resources/views/components/simple-alert-entry.blade.php b/resources/views/components/simple-alert-entry.blade.php index 9ad2419..4ce2d24 100644 --- a/resources/views/components/simple-alert-entry.blade.php +++ b/resources/views/components/simple-alert-entry.blade.php @@ -7,5 +7,6 @@ :link="$getLink()" :link-label="$getLinkLabel()" :link-blank="$getLinkBlank()" + :border="$getBorder()" /> </x-dynamic-component> \ No newline at end of file diff --git a/resources/views/components/simple-alert-field.blade.php b/resources/views/components/simple-alert-field.blade.php index ab3142d..27396fb 100644 --- a/resources/views/components/simple-alert-field.blade.php +++ b/resources/views/components/simple-alert-field.blade.php @@ -8,5 +8,6 @@ :link-label="$getLinkLabel()" :link-blank="$getLinkBlank()" :actions="$getActions()" + :border="$getBorder()" /> </x-dynamic-component> \ No newline at end of file diff --git a/resources/views/components/simple-alert.blade.php b/resources/views/components/simple-alert.blade.php index ef7fc40..f7bcb5c 100644 --- a/resources/views/components/simple-alert.blade.php +++ b/resources/views/components/simple-alert.blade.php @@ -1,5 +1,6 @@ @props([ 'actions' => null, + 'border' => false, 'color' => null, 'description' => null, 'icon' => null, @@ -13,13 +14,16 @@ use function Filament\Support\get_color_css_variables; $colors = \Illuminate\Support\Arr::toCssStyles([ - get_color_css_variables($color, shades: [50, 400, 500, 600, 700, 800]), + get_color_css_variables($color, shades: [50, 100, 400, 500, 600, 700, 800]), ]); @endphp <div x-data="{}" - class="filament-simple-alert rounded-md bg-custom-50 p-4 dark:bg-gray-900 dark:ring-white/10" + @class([ + 'filament-simple-alert rounded-md bg-custom-50 p-4 dark:bg-gray-900 ', + 'ring-1 ring-custom-100 dark:ring-white/10' => $border, + ]) style="{{ $colors }}"> <div class="flex"> @if($icon) diff --git a/src/Components/Concerns/HasBorder.php b/src/Components/Concerns/HasBorder.php new file mode 100644 index 0000000..68f03af --- /dev/null +++ b/src/Components/Concerns/HasBorder.php @@ -0,0 +1,22 @@ +<?php + +namespace CodeWithDennis\SimpleAlert\Components\Concerns; + +use Closure; + +trait HasBorder +{ + protected Closure|bool|null $border; + + public function border(Closure|bool $condition = false): static + { + $this->border = $condition; + + return $this; + } + + public function getBorder(): bool + { + return $this->evaluate($this->border); + } +} diff --git a/src/Components/Forms/SimpleAlert.php b/src/Components/Forms/SimpleAlert.php index 2069538..5b8508f 100644 --- a/src/Components/Forms/SimpleAlert.php +++ b/src/Components/Forms/SimpleAlert.php @@ -3,6 +3,7 @@ namespace CodeWithDennis\SimpleAlert\Components\Forms; use Closure; +use CodeWithDennis\SimpleAlert\Components\Concerns\HasBorder; use CodeWithDennis\SimpleAlert\Components\Concerns\HasColor; use CodeWithDennis\SimpleAlert\Components\Concerns\HasDescription; use CodeWithDennis\SimpleAlert\Components\Concerns\HasIcon; @@ -19,6 +20,7 @@ class SimpleAlert extends Field use HasLink; use HasSimple; use HasTitle; + use HasBorder; protected string $view = 'filament-simple-alert::components.simple-alert-field'; From 4f69e96ee4c28a33537be0315326659e871bec3a Mon Sep 17 00:00:00 2001 From: dissto <dissto@users.noreply.github.com> Date: Sat, 5 Oct 2024 21:23:33 +0000 Subject: [PATCH 2/4] PHP Linting (Pint) --- src/Components/Forms/SimpleAlert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Forms/SimpleAlert.php b/src/Components/Forms/SimpleAlert.php index 5b8508f..833a314 100644 --- a/src/Components/Forms/SimpleAlert.php +++ b/src/Components/Forms/SimpleAlert.php @@ -14,13 +14,13 @@ class SimpleAlert extends Field { + use HasBorder; use HasColor; use HasDescription; use HasIcon; use HasLink; use HasSimple; use HasTitle; - use HasBorder; protected string $view = 'filament-simple-alert::components.simple-alert-field'; From 9530fbd1672a89fb11a14e2753b6bc76fb76a183 Mon Sep 17 00:00:00 2001 From: "M. D." <dissto@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:58:38 +0200 Subject: [PATCH 3/4] Fix text wrapping for action labels with a space --- resources/views/components/simple-alert.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/simple-alert.blade.php b/resources/views/components/simple-alert.blade.php index ef7fc40..1ceedc7 100644 --- a/resources/views/components/simple-alert.blade.php +++ b/resources/views/components/simple-alert.blade.php @@ -46,7 +46,7 @@ class="h-5 w-5 text-custom-400" </div> @endif @if($link || $actions) - <div class="flex gap-x-3 items-center"> + <div class="flex gap-x-3 items-center whitespace-nowrap"> @if($link) <p class="text-sm md:ml-6 md:mt-0 self-center"> <a href="{{ $link }}" {{ $linkBlank ? 'target="_blank"' : '' }} class="whitespace-nowrap font-medium text-custom-400 hover:text-custom-500"> From 7d9d3f6a3b0f3dcedb8f8b5c3440991de8cb11e0 Mon Sep 17 00:00:00 2001 From: "M. D." <dissto@users.noreply.github.com> Date: Sun, 6 Oct 2024 00:06:33 +0200 Subject: [PATCH 4/4] Fix initialization issue --- src/Components/Concerns/HasBorder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Concerns/HasBorder.php b/src/Components/Concerns/HasBorder.php index 68f03af..748e5b9 100644 --- a/src/Components/Concerns/HasBorder.php +++ b/src/Components/Concerns/HasBorder.php @@ -6,7 +6,7 @@ trait HasBorder { - protected Closure|bool|null $border; + protected Closure|bool $border = false; public function border(Closure|bool $condition = false): static {