55use Closure ;
66use Filament \Contracts \Plugin ;
77use Filament \Panel ;
8- use Filament \Support \Assets \Css ;
9- use Filament \Support \Assets \Js ;
108use Filament \Support \Concerns \EvaluatesClosures ;
119use Filament \Support \Facades \FilamentAsset ;
10+ use Illuminate \Support \Facades \App ;
1211
1312class 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