From aa6276942b2cb30b19af2c0b9bf22ca847a7cb52 Mon Sep 17 00:00:00 2001 From: Tom Janssen Date: Thu, 28 Nov 2024 11:42:03 +0100 Subject: [PATCH] add option to hide button --- resources/views/components/buttons.blade.php | 6 +-- src/Provider.php | 2 + src/Traits/CanBeHidden.php | 40 ++++++++++++++++++++ src/View/Components/Buttons.php | 4 +- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/Traits/CanBeHidden.php diff --git a/resources/views/components/buttons.blade.php b/resources/views/components/buttons.blade.php index 50aef85..de84c73 100644 --- a/resources/views/components/buttons.blade.php +++ b/resources/views/components/buttons.blade.php @@ -5,7 +5,7 @@ @endforeach @endif - @if (count($providers)) + @if (count($visibleProviders)) @if($showDivider)
@@ -15,8 +15,8 @@
@endif -
- @foreach($providers as $key => $provider) +
+ @foreach($visibleProviders as $key => $provider) isHidden = $condition; + + return $this; + } + + public function visible(bool | Closure $condition = true): static + { + $this->isVisible = $condition; + + return $this; + } + + public function isHidden(): bool + { + if ($this->evaluate($this->isHidden)) { + return true; + } + + return ! $this->evaluate($this->isVisible); + } + + public function isVisible(): bool + { + return ! $this->isHidden(); + } +} diff --git a/src/View/Components/Buttons.php b/src/View/Components/Buttons.php index 1c61df2..0ef81e7 100644 --- a/src/View/Components/Buttons.php +++ b/src/View/Components/Buttons.php @@ -3,6 +3,7 @@ namespace DutchCodingCompany\FilamentSocialite\View\Components; use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; +use DutchCodingCompany\FilamentSocialite\Provider; use Illuminate\Support\MessageBag; use Illuminate\View\Component; @@ -28,7 +29,8 @@ public function render() } return view('filament-socialite::components.buttons', [ - 'providers' => $this->plugin->getProviders(), + 'providers' => $providers = $this->plugin->getProviders(), + 'visibleProviders' => array_filter($providers, fn (Provider $provider) => $provider->isVisible()), 'socialiteRoute' => $this->plugin->getRoute(), 'messageBag' => $messageBag, ]);