Skip to content

Commit 4f2cb47

Browse files
authored
Merge pull request #19 from pxlrbt/feat/debug-mode-v2
Debug Mode (v2)
2 parents e55bca2 + d82090a commit 4f2cb47

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"require": {
1717
"php": "^8.0",
18-
"filament/filament": "^3.0-stable"
18+
"filament/filament": "^3.0"
1919
},
2020
"require-dev": {
2121
"laravel/pint": "^1.10"

readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ $panel->plugins([
105105
]);
106106
```
107107

108+
### Debug Mode Warning
109+
110+
You can enable a debug mode warning for every environment or just for production by using `->showDebugModeWarning()`/`->showDebugModeWarningInProduction()`
111+
112+
```php
113+
use pxlrbt\FilamentEnvironmentIndicator\EnvironmentIndicatorPlugin;
114+
use Filament\Support\Colors\Color;
115+
116+
$panel->plugins([
117+
EnvironmentIndicatorPlugin::make()
118+
->showDebugModeWarningInProduction()
119+
]);
120+
```
121+
108122
## Contributing
109123

110124
If you want to contribute to this packages, you may want to test it in a real Filament project:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@php
2+
use Filament\Support\Colors\Color;
3+
use Filament\Support\Icons\Heroicon;
4+
use function Filament\Support\get_color_css_variables;
5+
use function Filament\Support\generate_icon_html;
6+
7+
$color = Color::Red;
8+
@endphp
9+
<div
10+
class="
11+
environment-indicator hidden sm:flex items-center h-9 px-3 text-sm font-medium
12+
rounded-lg shadow-sm ring-1
13+
ring-custom-600/20 bg-custom-50 text-custom-600
14+
dark:ring-custom-400/30 dark:bg-custom-400/10 dark:text-custom-400
15+
"
16+
style="
17+
--c-50: {{ $color[50] }};
18+
--c-300: {{ $color[300] }};
19+
--c-400: {{ $color[400] }};
20+
--c-600: {{ $color[600] }};
21+
"
22+
>
23+
@svg('heroicon-o-exclamation-triangle', ['style' => 'width: 20px; margin-right: 0.25rem'])
24+
Debug Mode
25+
</div>

src/EnvironmentIndicatorPlugin.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Filament\Panel;
88
use Filament\Support\Colors\Color;
99
use Filament\Support\Concerns\EvaluatesClosures;
10-
use Illuminate\Support\Facades\View;
1110
use Illuminate\Support\HtmlString;
1211
use Throwable;
1312

@@ -25,6 +24,8 @@ class EnvironmentIndicatorPlugin implements Plugin
2524

2625
public bool|Closure|null $showGitBranch = null;
2726

27+
public bool|Closure|null $showDebugModeWarning = null;
28+
2829
public static function make(): static
2930
{
3031
$plugin = app(static::class);
@@ -75,19 +76,29 @@ public function boot(Panel $panel): void
7576
public function register(Panel $panel): void
7677
{
7778
$panel->renderHook('panels::global-search.before', function () {
79+
$html = '';
80+
7881
if (! $this->evaluate($this->visible)) {
79-
return '';
82+
return $html;
8083
}
8184

82-
if (! $this->evaluate($this->showBadge)) {
83-
return '';
85+
if ($this->evaluate($this->showDebugModeWarning) && app()->hasDebugModeEnabled()) {
86+
$html .= view('filament-environment-indicator::debug-mode-warning', [
87+
'color' => $this->getColor(),
88+
'environment' => ucfirst(app()->environment()),
89+
'branch' => $this->getGitBranch(),
90+
])->render();
8491
}
8592

86-
return View::make('filament-environment-indicator::badge', [
87-
'color' => $this->getColor(),
88-
'environment' => ucfirst(app()->environment()),
89-
'branch' => $this->getGitBranch()
90-
]);
93+
if ($this->evaluate($this->showBadge)) {
94+
$html .= view('filament-environment-indicator::badge', [
95+
'color' => $this->getColor(),
96+
'environment' => ucfirst(app()->environment()),
97+
'branch' => $this->getGitBranch(),
98+
])->render();
99+
}
100+
101+
return $html;
91102
});
92103

93104
$panel->renderHook('panels::styles.after', function () {
@@ -142,6 +153,20 @@ public function showGitBranch(bool|Closure $showGitBranch = true): static
142153
return $this;
143154
}
144155

156+
public function showDebugModeWarning(bool|Closure $showWarning = true): static
157+
{
158+
$this->showDebugModeWarning = $showWarning;
159+
160+
return $this;
161+
}
162+
163+
public function showDebugModeWarningInProduction(): static
164+
{
165+
$this->showDebugModeWarning(fn () => app()->isProduction());
166+
167+
return $this;
168+
}
169+
145170
public function color(array|Closure $color = Color::Pink): static
146171
{
147172
$this->color = $color;

0 commit comments

Comments
 (0)