Skip to content

Commit 93ec5e7

Browse files
authored
Merge pull request #18 from achyutkneupane/feat/debug-mode-in-production
feat: Debug mode indicator if true in production
2 parents d228071 + 8099f70 commit 93ec5e7

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

readme.md

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

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

111125
If you want to contribute to this packages, you may want to test it in a real Filament project:

resources/css/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.environment-indicator {
1+
.environment-indicator, .debug-mode-indicator {
22
display: none;
33
height: 2.25rem;
44

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
@endphp
7+
<div
8+
class="
9+
debug-mode-indicator
10+
fi-badge fi-color fi-text-color-600
11+
dark:fi-text-color-400
12+
"
13+
style="{{ get_color_css_variables(Color::Red, [50, 300, 400, 600]) }}"
14+
>
15+
{{ generate_icon_html(Heroicon::OutlinedExclamationTriangle) }}
16+
Debug Mode
17+
</div>

src/EnvironmentIndicatorPlugin.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class EnvironmentIndicatorPlugin implements Plugin
2525

2626
public bool|Closure|null $showGitBranch = null;
2727

28+
public bool|Closure|null $showDebugModeWarning = null;
29+
2830
public static function make(): static
2931
{
3032
$plugin = app(static::class);
@@ -75,19 +77,30 @@ public function boot(Panel $panel): void
7577
public function register(Panel $panel): void
7678
{
7779
$panel->renderHook('panels::global-search.before', function () {
80+
$html = '';
81+
7882
if (! $this->evaluate($this->visible)) {
79-
return '';
83+
return $html;
8084
}
8185

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

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

93106
$panel->renderHook('panels::styles.after', function () {
@@ -142,6 +155,20 @@ public function showGitBranch(bool|Closure $showGitBranch = true): static
142155
return $this;
143156
}
144157

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

0 commit comments

Comments
 (0)