From 905474664750e0ec5b5c9df305b4798c88270352 Mon Sep 17 00:00:00 2001 From: francoism90 Date: Wed, 29 May 2024 13:10:21 +0200 Subject: [PATCH] Add has methods --- resources/views/actions/button.blade.php | 11 +++++++---- resources/views/actions/icon.blade.php | 2 +- src/Support/Components/Concerns/HasComponent.php | 5 +++++ src/Support/Components/Concerns/HasIcon.php | 10 ++++++++++ src/Support/Components/Concerns/HasLabel.php | 5 +++++ src/Support/Components/Concerns/HasLivewire.php | 5 +++++ src/Support/Components/Concerns/HasName.php | 5 +++++ src/Support/Components/Concerns/HasRequest.php | 5 +++++ src/Support/Components/Concerns/HasRouting.php | 5 +++++ src/Support/Components/Concerns/HasState.php | 5 +++++ src/Support/Components/Concerns/HasVisibility.php | 5 +++++ 11 files changed, 58 insertions(+), 5 deletions(-) diff --git a/resources/views/actions/button.blade.php b/resources/views/actions/button.blade.php index 03760f0b..9588801c 100644 --- a/resources/views/actions/button.blade.php +++ b/resources/views/actions/button.blade.php @@ -3,6 +3,7 @@ 'layer' => 'flex shrink-0 cursor-pointer items-center justify-center', 'label' => 'text-sm', 'primary' => 'py-1.5 px-3 bg-primary-500 rounded border border-primary-500', + 'icon' => 'size-6 text-secondary-400', ]) ->mergeAttributes($action->getComponentAttributes()) ->classMerge([ @@ -17,12 +18,14 @@ @if ($slot->isEmpty()) - - {{ $label() }} - + @if ($action->hasLabel()) + + {{ $label() }} + + @endif @else {{ $slot }} @endif diff --git a/resources/views/actions/icon.blade.php b/resources/views/actions/icon.blade.php index 9470b1d3..8abee8fa 100644 --- a/resources/views/actions/icon.blade.php +++ b/resources/views/actions/icon.blade.php @@ -7,7 +7,7 @@ 'layer', ]) }}> - @if ($iconName() && filled($action->getState())) + @if ($iconName() && $action->hasState()) value('component'); } + public function hasComponent(): bool + { + return $this->offsetExists('component'); + } + public function getComponentAttributes(): array { return $this->value('componentAttributes', []); diff --git a/src/Support/Components/Concerns/HasIcon.php b/src/Support/Components/Concerns/HasIcon.php index 78f45105..c183eaff 100644 --- a/src/Support/Components/Concerns/HasIcon.php +++ b/src/Support/Components/Concerns/HasIcon.php @@ -23,8 +23,18 @@ public function getIcon(): ?string return $this->value('icon'); } + public function hasIcon(): bool + { + return $this->offsetExists('icon'); + } + public function getActiveIcon(): ?string { return $this->value('iconActive', $this->getIcon()); } + + public function hasActiveIcon(): bool + { + return $this->offsetExists('iconActive'); + } } diff --git a/src/Support/Components/Concerns/HasLabel.php b/src/Support/Components/Concerns/HasLabel.php index 0cf11796..52c2fc19 100644 --- a/src/Support/Components/Concerns/HasLabel.php +++ b/src/Support/Components/Concerns/HasLabel.php @@ -15,4 +15,9 @@ public function getLabel(): ?string { return $this->value('label'); } + + public function hasLabel(): bool + { + return $this->offsetExists('label'); + } } diff --git a/src/Support/Components/Concerns/HasLivewire.php b/src/Support/Components/Concerns/HasLivewire.php index e562e418..84f8ab4e 100644 --- a/src/Support/Components/Concerns/HasLivewire.php +++ b/src/Support/Components/Concerns/HasLivewire.php @@ -25,6 +25,11 @@ public function getWireModel(): ?string return $this->value('wireModel'); } + public function hasWireModel(): bool + { + return $this->offsetExists('wireModel'); + } + public function getWireModifier(): ?string { return $this->value('wireModifier'); diff --git a/src/Support/Components/Concerns/HasName.php b/src/Support/Components/Concerns/HasName.php index a6c7505e..69898466 100644 --- a/src/Support/Components/Concerns/HasName.php +++ b/src/Support/Components/Concerns/HasName.php @@ -15,4 +15,9 @@ public function getName(): ?string { return $this->value('name'); } + + public function hasName(): bool + { + return $this->offsetExists('name'); + } } diff --git a/src/Support/Components/Concerns/HasRequest.php b/src/Support/Components/Concerns/HasRequest.php index 26285680..bd5a8d40 100644 --- a/src/Support/Components/Concerns/HasRequest.php +++ b/src/Support/Components/Concerns/HasRequest.php @@ -16,6 +16,11 @@ public function getUrl(): ?string return $this->value('url'); } + public function hasUrl(): bool + { + return $this->offsetExists('url'); + } + public function isAppUrl(): bool { $url = str($this->value('url', ''))->trim(); diff --git a/src/Support/Components/Concerns/HasRouting.php b/src/Support/Components/Concerns/HasRouting.php index 693859a9..e0e4fd94 100644 --- a/src/Support/Components/Concerns/HasRouting.php +++ b/src/Support/Components/Concerns/HasRouting.php @@ -30,6 +30,11 @@ public function getRoute(): ?string ); } + public function hasRoute(): bool + { + return $this->offsetExists('route'); + } + public function getRouteName(): ?string { return $this->value('route'); diff --git a/src/Support/Components/Concerns/HasState.php b/src/Support/Components/Concerns/HasState.php index 75875201..d509bcc4 100644 --- a/src/Support/Components/Concerns/HasState.php +++ b/src/Support/Components/Concerns/HasState.php @@ -23,6 +23,11 @@ public function getState(): mixed return $this->value('state'); } + public function hasState(): bool + { + return $this->offsetExists('state'); + } + public function getDefault(): mixed { return $this->value('default'); diff --git a/src/Support/Components/Concerns/HasVisibility.php b/src/Support/Components/Concerns/HasVisibility.php index 65724767..bbd9da24 100644 --- a/src/Support/Components/Concerns/HasVisibility.php +++ b/src/Support/Components/Concerns/HasVisibility.php @@ -23,6 +23,11 @@ public function getVisible(): ?bool return $this->value('visible'); } + public function hasVisible(): bool + { + return $this->offsetExists('visible'); + } + public function getHidden(): ?bool { return $this->value('hidden');