From 74379b76169733800c78b58cb199172872e9548a Mon Sep 17 00:00:00 2001 From: Rhiannon Journey Date: Fri, 12 Apr 2024 17:09:43 -0400 Subject: [PATCH] Add new Callout form component Introduces a new collapsible form component named Callout in the Filament Toolbox, with customizability options such as icon characteristics and content display methods. The component contains properties and methods to provision display options like Markdown or HTML content, icon color selection, and more. --- .../views/forms/components/callout.blade.php | 86 +++++++++++ src/Forms/Components/Callout.php | 140 ++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 resources/views/forms/components/callout.blade.php create mode 100644 src/Forms/Components/Callout.php diff --git a/resources/views/forms/components/callout.blade.php b/resources/views/forms/components/callout.blade.php new file mode 100644 index 0000000..0425fdf --- /dev/null +++ b/resources/views/forms/components/callout.blade.php @@ -0,0 +1,86 @@ +
merge($getExtraAttributes())->class([ + 'bg-gray-100 rounded-xl border-gray-300', + 'dark:bg-gray-900' => config('forms.dark_mode'), + ]) }} +> +
config('forms.dark_mode'), + ]) + @if ($isCollapsible()) + x-bind:class="{ 'rounded-b-xl': isCollapsed }" + @endif + > + @if($icon = $getIcon()) + @php + $iconColor = match ($getIconColor()) { + 'danger' => 'text-danger-500', + 'primary' => 'text-primary-500', + 'success' => 'text-success-500', + 'warning' => 'text-warning-500', + default => 'text-gray-700', + }; + @endphp + + @endif + +
+

+ {{ $getHeading() }} +

+
+ + @if ($isCollapsible()) + + @endif +
+ +
+
+
config('forms.dark_mode'), + ])> + {{ $getContent() }} +
+
+
+
diff --git a/src/Forms/Components/Callout.php b/src/Forms/Components/Callout.php new file mode 100644 index 0000000..6ca4274 --- /dev/null +++ b/src/Forms/Components/Callout.php @@ -0,0 +1,140 @@ +heading($heading); + } + + public static function make(string | Closure | null $heading = null): static + { + $static = app(static::class, ['heading' => $heading]); + $static->configure(); + + return $static; + } + + protected function setUp(): void + { + parent::setUp(); + + $this->columnSpan('full'); + } + + public function warning(): static + { + $this->iconColor('warning'); + $this->icon('heroicon-o-exclamation-triangle'); + + return $this; + } + + public function help(): static + { + $this->collapsed(true); + $this->icon('heroicon-o-question-mark-circle'); + $this->iconColor('primary'); + + return $this; + } + + public function heading(string | Closure | null $heading): static + { + $this->heading = $heading; + + return $this; + } + + public function content(string | Htmlable | Closure | null $content): static + { + $this->content = $content; + + return $this; + } + + public function getContent(): string | Htmlable | null + { + $content = $this->evaluate($this->content); + + if ($this->isHtml) { + return $content instanceof Htmlable + ? $content + : new HtmlString($content); + } + + if ($this->isMarkdown) { + return new HtmlString(Str::markdown($content)); + } + + return $content; + } + + public function getHeading(): ?string + { + return $this->evaluate($this->heading); + } + + public function markdown(bool $markdown = true): static + { + $this->isMarkdown = $markdown; + + return $this; + } + + public function html(bool $html = true): static + { + $this->isHtml = $html; + + return $this; + } + + public function icon(string | Closure | null $icon): static + { + $this->icon = $icon; + + return $this; + } + + public function getIcon(): ?string + { + return $this->evaluate($this->icon); + } + + public function iconColor(string | Closure | null $iconColor): static + { + $this->iconColor = $iconColor; + + return $this; + } + + public function getIconColor(): ?string + { + return $this->evaluate($this->iconColor); + } +}