-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from DanielvdSpoel/feature/filament-3x-support
Migrate to filament v3
- Loading branch information
Showing
6 changed files
with
202 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
<div | ||
class="environment-indicator hidden sm:flex items-center h-10 rounded-lg px-3 text-white text-sm font-medium" | ||
style="background-color: {{ $color }}; margin-right: 1rem;" | ||
class=" | ||
environment-indicator hidden sm:flex items-center h-9 mr-4 px-3 text-sm font-medium | ||
rounded-lg shadow-sm ring-1 | ||
ring-custom-600/20 bg-custom-50 text-custom-600 | ||
dark:ring-custom-400/30 dark:bg-custom-400/10 dark:text-custom-400 | ||
" | ||
style=" | ||
--c-50: {{ $color[50] }}; | ||
--c-300: {{ $color[300] }}; | ||
--c-400: {{ $color[400] }}; | ||
--c-600: {{ $color[600] }}; | ||
margin-right: 1rem; | ||
" | ||
> | ||
{{ $environment }} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
namespace pxlrbt\FilamentEnvironmentIndicator; | ||
|
||
use Closure; | ||
use Filament\Contracts\Plugin; | ||
use Filament\Panel; | ||
use Filament\Support\Colors\Color; | ||
use Filament\Support\Concerns\EvaluatesClosures; | ||
use Illuminate\Support\Facades\View; | ||
use Illuminate\Support\HtmlString; | ||
|
||
class EnvironmentIndicatorPlugin implements Plugin | ||
{ | ||
use EvaluatesClosures; | ||
|
||
public bool | Closure | null $visible = null; | ||
public bool | Closure | null $showBadge = null; | ||
public bool | Closure | null $showBorder = null; | ||
|
||
public array | Closure | null $color = null; | ||
|
||
public static function make(): static | ||
{ | ||
$plugin = app(static::class); | ||
|
||
// Defaults | ||
$plugin->visible(function () { | ||
if (($user = auth()->user()) === null) { | ||
return false; | ||
} | ||
|
||
if (method_exists($user, 'hasRole')) { | ||
return $user->hasRole('super_admin'); | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
$plugin->color(fn () => match (app()->environment()) { | ||
'production' => Color::Red, | ||
'staging' => Color::Orange, | ||
'development' => Color::Blue, | ||
default => Color::Pink, | ||
}); | ||
|
||
$plugin->showBadge(fn () => match (app()->environment()) { | ||
'production', 'prod' => false, | ||
default => true, | ||
}); | ||
|
||
$plugin->showBorder(fn () => match (app()->environment()) { | ||
'production', 'prod' => false, | ||
default => true, | ||
}); | ||
|
||
return $plugin; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return 'environment-indicator'; | ||
} | ||
|
||
public function boot(Panel $panel): void | ||
{ | ||
// | ||
} | ||
|
||
public function register(Panel $panel): void | ||
{ | ||
$panel->renderHook('panels::global-search.start', function () { | ||
if (! $this->evaluate($this->visible)) { | ||
return ''; | ||
} | ||
|
||
if (! $this->evaluate($this->showBadge)) { | ||
return ''; | ||
} | ||
|
||
return View::make('filament-environment-indicator::badge', [ | ||
'color' => $this->getColor(), | ||
'environment' => ucfirst(app()->environment()), | ||
]); | ||
}); | ||
|
||
$panel->renderHook('panels::styles.after', function () { | ||
if (! $this->evaluate($this->visible)) { | ||
return ''; | ||
} | ||
|
||
if (! $this->evaluate($this->showBorder)) { | ||
return ''; | ||
} | ||
|
||
return new HtmlString(" | ||
<style> | ||
.fi-topbar, | ||
.fi-sidebar { | ||
border-top: 5px solid rgb({$this->getColor()['500']}) !important; | ||
} | ||
.fi-topbar { | ||
height: calc(4rem + 5px) !important; | ||
} | ||
</style> | ||
"); | ||
}); | ||
} | ||
|
||
public function visible(bool|Closure $visible): static | ||
{ | ||
$this->visible = $visible; | ||
|
||
return $this; | ||
} | ||
|
||
public function showBadge(bool|Closure $showBadge = true): static | ||
{ | ||
$this->showBadge = $showBadge; | ||
|
||
return $this; | ||
} | ||
|
||
public function showBorder(bool|Closure $showBorder = true): static | ||
{ | ||
$this->showBorder = $showBorder; | ||
|
||
return $this; | ||
} | ||
|
||
public function color(array|Closure $color = Color::Pink): static | ||
{ | ||
$this->color = $color; | ||
|
||
return $this; | ||
} | ||
|
||
protected function getColor(): array | ||
{ | ||
return $this->evaluate($this->color); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.