|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers; |
| 3 | +namespace Rappasoft\LaravelLivewireTables\Traits\Core\Filters; |
4 | 4 |
|
| 5 | +use Closure; |
5 | 6 | use Illuminate\Support\Arr; |
6 | | -use Livewire\Attributes\Computed; |
| 7 | +use Livewire\Attributes\{Computed, Locked}; |
| 8 | +use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; |
7 | 9 | use Rappasoft\LaravelLivewireTables\Views\Filter; |
8 | 10 |
|
9 | | -trait FilterMenuStylingHelpers |
| 11 | +trait HasFilterMenuStyling |
10 | 12 | { |
| 13 | + |
| 14 | + #[Locked] |
| 15 | + public string $filterLayout = 'popover'; |
| 16 | + |
| 17 | + // Entangled in JS |
| 18 | + public bool $filterSlideDownDefaultVisible = false; |
| 19 | + |
| 20 | + protected array $filterPopoverAttributes = ['class' => '', 'default-width' => true, 'default-colors' => true, 'default-styling' => true]; |
| 21 | + |
| 22 | + protected array $filterSlidedownWrapperAttributes = ['class' => '', 'default-colors' => true, 'default-styling' => true]; |
| 23 | + |
| 24 | + protected ?Closure $filterSlidedownRowCallback; |
| 25 | + |
| 26 | + |
| 27 | + /** |
| 28 | + * Used to set attributes for the Filter Popover |
| 29 | + */ |
| 30 | + public function setFilterPopoverAttributes(array $filterPopoverAttributes): self |
| 31 | + { |
| 32 | + $this->filterPopoverAttributes = array_merge($this->filterPopoverAttributes, $filterPopoverAttributes); |
| 33 | + |
| 34 | + return $this; |
| 35 | + } |
| 36 | + |
11 | 37 | /** |
| 38 | + * Used to set attributes for the Filter Slidedown Wrapper |
| 39 | + */ |
| 40 | + public function setFilterSlidedownWrapperAttributes(array $filterSlidedownWrapperAttributes): self |
| 41 | + { |
| 42 | + $this->filterSlidedownWrapperAttributes = array_merge($this->filterSlidedownWrapperAttributes, $filterSlidedownWrapperAttributes); |
| 43 | + |
| 44 | + return $this; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Set a list of attributes to override on the th sort button elements |
| 49 | + */ |
| 50 | + public function setFilterSlidedownRowAttributes(Closure $callback): self |
| 51 | + { |
| 52 | + $this->filterSlidedownRowCallback = $callback; |
| 53 | + |
| 54 | + return $this; |
| 55 | + } |
| 56 | + |
| 57 | + public function setFilterLayout(string $type): self |
| 58 | + { |
| 59 | + if (! in_array($type, ['popover', 'slide-down'], true)) { |
| 60 | + throw new DataTableConfigurationException('Invalid filter layout type'); |
| 61 | + } |
| 62 | + |
| 63 | + $this->filterLayout = $type; |
| 64 | + |
| 65 | + return $this; |
| 66 | + } |
| 67 | + |
| 68 | + public function setFilterLayoutPopover(): self |
| 69 | + { |
| 70 | + $this->setFilterLayout('popover'); |
| 71 | + |
| 72 | + return $this; |
| 73 | + } |
| 74 | + |
| 75 | + public function setFilterLayoutSlideDown(): self |
| 76 | + { |
| 77 | + $this->setFilterLayout('slide-down'); |
| 78 | + |
| 79 | + return $this; |
| 80 | + } |
| 81 | + |
| 82 | + public function setFilterSlideDownDefaultStatus(bool $status): self |
| 83 | + { |
| 84 | + $this->filterSlideDownDefaultVisible = $status; |
| 85 | + |
| 86 | + return $this; |
| 87 | + } |
| 88 | + |
| 89 | + public function setFilterSlideDownDefaultStatusDisabled(): self |
| 90 | + { |
| 91 | + $this->setFilterSlideDownDefaultStatus(false); |
| 92 | + |
| 93 | + return $this; |
| 94 | + } |
| 95 | + |
| 96 | + public function setFilterSlideDownDefaultStatusEnabled(): self |
| 97 | + { |
| 98 | + $this->setFilterSlideDownDefaultStatus(true); |
| 99 | + |
| 100 | + return $this; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
12 | 104 | * Used to get attributes for the Filter Popover |
13 | 105 | * |
14 | 106 | * @return array<mixed> |
@@ -119,4 +211,5 @@ public function getFiltersByRow(): array |
119 | 211 |
|
120 | 212 | return $orderedFilters; |
121 | 213 | } |
| 214 | + |
122 | 215 | } |
0 commit comments