diff --git a/docs/filters/available-methods.md b/docs/filters/available-methods.md index 413181f37..e9701a8a5 100644 --- a/docs/filters/available-methods.md +++ b/docs/filters/available-methods.md @@ -352,6 +352,21 @@ Example blade: ``` +### setFilterLabelAttributes +Set custom attributes for a Filter Label. At present it is recommended to only use this for "class" and "style" attributes to avoid conflicts. + +By default, this replaces the default classes on the Filter Label wrapper, if you would like to keep them, set the default flag to true. + +```php +TextFilter::make('Name') + ->setFilterLabelAttributes( + [ + 'class' => 'text-xl', + 'default' => true, + ] + ), +``` + ### Config If the filter takes any config options, you can set them with the `config` method: diff --git a/resources/views/components/tools/filter-label.blade.php b/resources/views/components/tools/filter-label.blade.php index 742a098e4..3ee014d82 100644 --- a/resources/views/components/tools/filter-label.blade.php +++ b/resources/views/components/tools/filter-label.blade.php @@ -1,12 +1,26 @@ @aware(['component', 'tableName']) -@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table']) - - +@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false]) + +@php + $customAttributes = $filter->getFilterLabelAttributes(); +@endphp + +@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) + @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName, 'isTailwind' => $isTailwind, 'isBootstrap' => $isBootstrap, 'isBootstrap4' => $isBootstrap4, 'isBootstrap5' => $isBootstrap5, 'customAttributes' => $customAttributes]) +@elseif(!$filter->hasCustomPosition()) + + +@endif + diff --git a/resources/views/components/tools/filters/date-range.blade.php b/resources/views/components/tools/filters/date-range.blade.php index bfc86eb83..9b67cc896 100644 --- a/resources/views/components/tools/filters/date-range.blade.php +++ b/resources/views/components/tools/filters/date-range.blade.php @@ -25,11 +25,8 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif + +
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif + +
$isTailwind, diff --git a/resources/views/components/tools/filters/datetime.blade.php b/resources/views/components/tools/filters/datetime.blade.php index 3eb487beb..1311a3085 100644 --- a/resources/views/components/tools/filters/datetime.blade.php +++ b/resources/views/components/tools/filters/datetime.blade.php @@ -1,9 +1,5 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(), ['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif +
$isTailwind, diff --git a/resources/views/components/tools/filters/multi-select-dropdown.blade.php b/resources/views/components/tools/filters/multi-select-dropdown.blade.php index 705956f2f..94ab306f4 100644 --- a/resources/views/components/tools/filters/multi-select-dropdown.blade.php +++ b/resources/views/components/tools/filters/multi-select-dropdown.blade.php @@ -1,9 +1,6 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif + + @if ($isTailwind)
diff --git a/resources/views/components/tools/filters/multi-select.blade.php b/resources/views/components/tools/filters/multi-select.blade.php index b3da9285b..64da23f84 100644 --- a/resources/views/components/tools/filters/multi-select.blade.php +++ b/resources/views/components/tools/filters/multi-select.blade.php @@ -1,9 +1,6 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif + + @if ($isTailwind)
diff --git a/resources/views/components/tools/filters/number-range.blade.php b/resources/views/components/tools/filters/number-range.blade.php index e62143d07..ded89505a 100644 --- a/resources/views/components/tools/filters/number-range.blade.php +++ b/resources/views/components/tools/filters/number-range.blade.php @@ -4,11 +4,8 @@ $currentMax = $maxRange = $filter->getConfig('maxRange'); @endphp
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName ]) - @elseif(!$filter->hasCustomPosition()) - - @endif + +
$isTailwind, diff --git a/resources/views/components/tools/filters/number.blade.php b/resources/views/components/tools/filters/number.blade.php index cc12ed0d8..2cd3a8a21 100644 --- a/resources/views/components/tools/filters/number.blade.php +++ b/resources/views/components/tools/filters/number.blade.php @@ -1,9 +1,6 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif + +
$isTailwind, diff --git a/resources/views/components/tools/filters/select.blade.php b/resources/views/components/tools/filters/select.blade.php index ef06e18c6..ae23ea5f7 100644 --- a/resources/views/components/tools/filters/select.blade.php +++ b/resources/views/components/tools/filters/select.blade.php @@ -1,9 +1,5 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif +
$isTailwind, diff --git a/resources/views/components/tools/filters/text-field.blade.php b/resources/views/components/tools/filters/text-field.blade.php index 65a746fa2..3f032a5cb 100644 --- a/resources/views/components/tools/filters/text-field.blade.php +++ b/resources/views/components/tools/filters/text-field.blade.php @@ -1,9 +1,5 @@
- @if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition()) - @include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName]) - @elseif(!$filter->hasCustomPosition()) - - @endif +
$isTailwind, diff --git a/src/Views/Filter.php b/src/Views/Filter.php index d13e42dbf..a3f57d661 100644 --- a/src/Views/Filter.php +++ b/src/Views/Filter.php @@ -35,6 +35,8 @@ abstract class Filter protected ?string $filterCustomLabel = null; + protected array $filterLabelAttributes = []; + protected ?int $filterSlidedownRow = null; protected ?int $filterSlidedownColspan = null; diff --git a/src/Views/Traits/Configuration/FilterConfiguration.php b/src/Views/Traits/Configuration/FilterConfiguration.php index bcf7045bf..9a8fcc252 100644 --- a/src/Views/Traits/Configuration/FilterConfiguration.php +++ b/src/Views/Traits/Configuration/FilterConfiguration.php @@ -118,4 +118,12 @@ public function setFilterDefaultValue($value): self return $this; } + + public function setFilterLabelAttributes(array $filterLabelAttributes): self + { + $this->filterLabelAttributes = [...['default' => false], ...$filterLabelAttributes]; + + return $this; + + } } diff --git a/src/Views/Traits/Helpers/FilterHelpers.php b/src/Views/Traits/Helpers/FilterHelpers.php index 4b5187b33..7a3fedff7 100644 --- a/src/Views/Traits/Helpers/FilterHelpers.php +++ b/src/Views/Traits/Helpers/FilterHelpers.php @@ -240,4 +240,16 @@ public function hasFilterDefaultValue(): bool { return ! is_null($this->filterDefaultValue); } + + + public function getFilterLabelAttributes(): array + { + return [...['default' => true], ...$this->filterLabelAttributes]; + } + + public function hasFilterLabelAttributes(): bool + { + return !($this->filterLabelAttributes != ['default' => true] && $this->filterLabelAttributes != ['default' => false]); + } + } diff --git a/tests/Views/Traits/Helpers/FilterHelpersTest.php b/tests/Views/Traits/Helpers/FilterHelpersTest.php index e8469935b..5c553c8ea 100644 --- a/tests/Views/Traits/Helpers/FilterHelpersTest.php +++ b/tests/Views/Traits/Helpers/FilterHelpersTest.php @@ -353,4 +353,26 @@ public function can_get_filter_custom_filter_pills_blade(): void $this->assertTrue($filter->hasCustomPillBlade()); $this->assertSame('foo', $filter->getCustomPillBlade()); } + + /** @test */ + public function can_get_filter_label_attributes(): void + { + $filter1 = TextFilter::make('Filter1'); + $filter2 = TextFilter::make('Filter2')->setFilterLabelAttributes( + ['class' => 'text-xl', 'default' => true] + ); + $filter3 = TextFilter::make('Filter3')->setFilterLabelAttributes( + ['class' => 'text-2xl', 'default' => false] + ); + + $this->assertFalse($filter1->hasFilterLabelAttributes()); + $this->assertTrue($filter2->hasFilterLabelAttributes()); + $this->assertTrue($filter3->hasFilterLabelAttributes()); + + $this->assertSame($filter1->getFilterLabelAttributes(), ['default' => true]); + $this->assertSame($filter2->getFilterLabelAttributes(), ['class' => 'text-xl', 'default' => true]); + $this->assertSame($filter3->getFilterLabelAttributes(), ['class' => 'text-2xl', 'default' => false]); + + + } }