|
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 | + #[Locked] |
| 14 | + public string $filterLayout = 'popover'; |
| 15 | + |
| 16 | + // Entangled in JS |
| 17 | + public bool $filterSlideDownDefaultVisible = false; |
| 18 | + |
| 19 | + protected array $filterPopoverAttributes = ['class' => '', 'default-width' => true, 'default-colors' => true, 'default-styling' => true]; |
| 20 | + |
| 21 | + protected array $filterSlidedownWrapperAttributes = ['class' => '', 'default-colors' => true, 'default-styling' => true]; |
| 22 | + |
| 23 | + protected ?Closure $filterSlidedownRowCallback; |
| 24 | + |
| 25 | + /** |
| 26 | + * Used to set attributes for the Filter Popover |
| 27 | + */ |
| 28 | + public function setFilterPopoverAttributes(array $filterPopoverAttributes): self |
| 29 | + { |
| 30 | + $this->filterPopoverAttributes = array_merge($this->filterPopoverAttributes, $filterPopoverAttributes); |
| 31 | + |
| 32 | + return $this; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Used to set attributes for the Filter Slidedown Wrapper |
| 37 | + */ |
| 38 | + public function setFilterSlidedownWrapperAttributes(array $filterSlidedownWrapperAttributes): self |
| 39 | + { |
| 40 | + $this->filterSlidedownWrapperAttributes = array_merge($this->filterSlidedownWrapperAttributes, $filterSlidedownWrapperAttributes); |
| 41 | + |
| 42 | + return $this; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Set a list of attributes to override on the th sort button elements |
| 47 | + */ |
| 48 | + public function setFilterSlidedownRowAttributes(Closure $callback): self |
| 49 | + { |
| 50 | + $this->filterSlidedownRowCallback = $callback; |
| 51 | + |
| 52 | + return $this; |
| 53 | + } |
| 54 | + |
| 55 | + public function setFilterLayout(string $type): self |
| 56 | + { |
| 57 | + if (! in_array($type, ['popover', 'slide-down'], true)) { |
| 58 | + throw new DataTableConfigurationException('Invalid filter layout type'); |
| 59 | + } |
| 60 | + |
| 61 | + $this->filterLayout = $type; |
| 62 | + |
| 63 | + return $this; |
| 64 | + } |
| 65 | + |
| 66 | + public function setFilterLayoutPopover(): self |
| 67 | + { |
| 68 | + $this->setFilterLayout('popover'); |
| 69 | + |
| 70 | + return $this; |
| 71 | + } |
| 72 | + |
| 73 | + public function setFilterLayoutSlideDown(): self |
| 74 | + { |
| 75 | + $this->setFilterLayout('slide-down'); |
| 76 | + |
| 77 | + return $this; |
| 78 | + } |
| 79 | + |
| 80 | + public function setFilterSlideDownDefaultStatus(bool $status): self |
| 81 | + { |
| 82 | + $this->filterSlideDownDefaultVisible = $status; |
| 83 | + |
| 84 | + return $this; |
| 85 | + } |
| 86 | + |
| 87 | + public function setFilterSlideDownDefaultStatusDisabled(): self |
| 88 | + { |
| 89 | + $this->setFilterSlideDownDefaultStatus(false); |
| 90 | + |
| 91 | + return $this; |
| 92 | + } |
| 93 | + |
| 94 | + public function setFilterSlideDownDefaultStatusEnabled(): self |
| 95 | + { |
| 96 | + $this->setFilterSlideDownDefaultStatus(true); |
| 97 | + |
| 98 | + return $this; |
| 99 | + } |
| 100 | + |
11 | 101 | /** |
12 | 102 | * Used to get attributes for the Filter Popover |
13 | 103 | * |
|
0 commit comments