Skip to content

Commit

Permalink
add option to hide button
Browse files Browse the repository at this point in the history
  • Loading branch information
dododedodonl committed Nov 28, 2024
1 parent 0d4f985 commit aa62769
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
6 changes: 3 additions & 3 deletions resources/views/components/buttons.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@endforeach
@endif

@if (count($providers))
@if (count($visibleProviders))
@if($showDivider)
<div class="relative flex items-center justify-center text-center">
<div class="absolute border-t border-gray-200 w-full h-px"></div>
Expand All @@ -15,8 +15,8 @@
</div>
@endif

<div class="grid @if(count($providers) > 1) grid-cols-2 @endif gap-4">
@foreach($providers as $key => $provider)
<div class="grid @if(count($visibleProviders) > 1) grid-cols-2 @endif gap-4">
@foreach($visibleProviders as $key => $provider)
<x-filament::button
:color="$provider->getColor()"
:outlined="$provider->getOutlined()"
Expand Down
2 changes: 2 additions & 0 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace DutchCodingCompany\FilamentSocialite;

use Closure;
use DutchCodingCompany\FilamentSocialite\Traits\CanBeHidden;
use Filament\Support\Colors\Color;
use Filament\Support\Concerns\EvaluatesClosures;
use Illuminate\Support\Str;

class Provider
{
use EvaluatesClosures;
use CanBeHidden;

protected string $name;

Expand Down
40 changes: 40 additions & 0 deletions src/Traits/CanBeHidden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace DutchCodingCompany\FilamentSocialite\Traits;

use Closure;

trait CanBeHidden
{
protected bool | Closure $isHidden = false;

protected bool | Closure $isVisible = true;

public function hidden(bool | Closure $condition = true): static
{
$this->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();
}
}
4 changes: 3 additions & 1 deletion src/View/Components/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
]);
Expand Down

0 comments on commit aa62769

Please sign in to comment.