Skip to content

Commit b899040

Browse files
authored
Merge pull request #45 from awcodes/feat/disable-on-list-pages
Feat: support disable on list pages
2 parents 307ca6d + 1dc499b commit b899040

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ public function panel(Panel $panel): Panel
7070
}
7171
```
7272

73+
### Disabling on List Pages
74+
75+
To disable the sticky header on list pages, you can use the `stickOnListPages()` method.
76+
77+
```php
78+
use Awcodes\FilamentStickyHeader\StickyHeaderPlugin;
79+
80+
public function panel(Panel $panel): Panel
81+
{
82+
return $panel
83+
->plugins([
84+
StickyHeaderPlugin::make()
85+
->stickOnListPages(false)
86+
])
87+
]);
88+
}
89+
```
90+
7391
## Changelog
7492

7593
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

src/StickyHeaderPlugin.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
use Closure;
66
use Filament\Contracts\Plugin;
77
use Filament\Panel;
8-
use Filament\Support\Assets\Css;
9-
use Filament\Support\Assets\Js;
108
use Filament\Support\Concerns\EvaluatesClosures;
119
use Filament\Support\Facades\FilamentAsset;
10+
use Illuminate\Support\Facades\App;
1211

1312
class StickyHeaderPlugin implements Plugin
1413
{
@@ -18,11 +17,13 @@ class StickyHeaderPlugin implements Plugin
1817

1918
protected bool | Closure | null $isFloating = null;
2019

20+
protected bool | Closure | null $stickOnListPages = null;
21+
2122
public function boot(Panel $panel): void
2223
{
2324
FilamentAsset::registerScriptData([
2425
'stickyHeaderTheme' => $this->getTheme(),
25-
'stickyHeaderActive' => true,
26+
'stickyHeaderActive' => $this->shouldStick(),
2627
], 'awcodes-sticky-header');
2728
}
2829

@@ -40,9 +41,16 @@ public function floating(bool | Closure $condition = true): static
4041
return $this;
4142
}
4243

43-
public static function get(): static
44+
public function stickOnListPages(bool | Closure $condition = true): static
4445
{
45-
return filament(app(static::class)->getId());
46+
$this->stickOnListPages = $condition;
47+
48+
return $this;
49+
}
50+
51+
public static function get(): Plugin
52+
{
53+
return filament(App::make(static::class)->getId());
4654
}
4755

4856
public function getId(): string
@@ -76,11 +84,28 @@ public function getTheme(): string
7684

7785
public static function make(): static
7886
{
79-
return app(static::class);
87+
return App::make(static::class);
8088
}
8189

8290
public function register(Panel $panel): void
8391
{
8492
//
8593
}
94+
95+
public function shouldStickOnListPages(): bool
96+
{
97+
return $this->evaluate($this->stickOnListPages) ?? true;
98+
}
99+
100+
public function shouldStick(): bool
101+
{
102+
if (
103+
str(request()->route()->getAction('as'))->contains('index')
104+
&& ! $this->shouldStickOnListPages()
105+
) {
106+
return false;
107+
}
108+
109+
return true;
110+
}
86111
}

0 commit comments

Comments
 (0)