From efb435eb9bdbb58d96a830d2fe5d76d69c4f87f3 Mon Sep 17 00:00:00 2001 From: "M. D." Date: Fri, 4 Oct 2024 15:58:45 +0200 Subject: [PATCH] Allow to pass an `Htmlable` to the view getting rid of unescaped output --- .../views/components/simple-alert.blade.php | 22 ++++++++++++------- src/Components/Concerns/HasDescription.php | 7 +++--- src/Components/Concerns/HasTitle.php | 7 +++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/resources/views/components/simple-alert.blade.php b/resources/views/components/simple-alert.blade.php index a81282e..fab1835 100644 --- a/resources/views/components/simple-alert.blade.php +++ b/resources/views/components/simple-alert.blade.php @@ -30,14 +30,20 @@ class="h-5 w-5 h-5 w-5 text-custom-400" @endif
-
-

- {!! $title !!} -

-

- {!! $description !!} -

-
+ @if($title || $description) +
+ @if($title) +

+ {{ $title }} +

+ @endif + @if($description) +

+ {{ $description }} +

+ @endif +
+ @endif @if($link)

diff --git a/src/Components/Concerns/HasDescription.php b/src/Components/Concerns/HasDescription.php index 961e4c6..a004c64 100644 --- a/src/Components/Concerns/HasDescription.php +++ b/src/Components/Concerns/HasDescription.php @@ -3,19 +3,20 @@ namespace CodeWithDennis\SimpleAlert\Components\Concerns; use Closure; +use Illuminate\Contracts\Support\Htmlable; trait HasDescription { - protected Closure|string|null $description = null; + protected string | Htmlable | Closure | null $description = null; - public function description(Closure|string|null $description): static + public function description(string | Htmlable | Closure | null $description): static { $this->description = $description; return $this; } - public function getDescription(): ?string + public function getDescription(): string | Htmlable | null { return $this->evaluate($this->description); } diff --git a/src/Components/Concerns/HasTitle.php b/src/Components/Concerns/HasTitle.php index 114a7fa..7b99b3a 100644 --- a/src/Components/Concerns/HasTitle.php +++ b/src/Components/Concerns/HasTitle.php @@ -3,19 +3,20 @@ namespace CodeWithDennis\SimpleAlert\Components\Concerns; use Closure; +use Illuminate\Contracts\Support\Htmlable; trait HasTitle { - protected Closure|string|null $title = null; + protected string | Htmlable | Closure | null $title = null; - public function title(Closure|string|null $title): static + public function title(string | Htmlable | Closure | null $title): static { $this->title = $title; return $this; } - public function getTitle(): ?string + public function getTitle(): string | Htmlable | null { return $this->evaluate($this->title); }