From d1682976c980c80244bd930032e488112c113b9f Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Tue, 24 Dec 2024 03:00:38 +0000 Subject: [PATCH 1/2] Add Custom FIlter Input Attributes, Cleanup Filter Tests --- docs/filter-types/filters-number.md | 46 +++ docs/filters/available-filter-methods.md | 52 ++++ .../tools/filters/boolean.blade.php | 17 +- .../components/tools/filters/date.blade.php | 21 +- .../tools/filters/datetime.blade.php | 21 +- .../filters/multi-select-dropdown.blade.php | 47 ++- .../tools/filters/multi-select.blade.php | 88 +++--- .../components/tools/filters/number.blade.php | 21 +- .../components/tools/filters/select.blade.php | 2 +- .../tools/filters/text-field.blade.php | 20 +- src/Views/Filters/BooleanFilter.php | 16 + src/Views/Filters/DateFilter.php | 14 + src/Views/Filters/DateTimeFilter.php | 14 + src/Views/Filters/NumberFilter.php | 15 + src/Views/Filters/TextFilter.php | 16 + .../Configuration/FilterConfiguration.php | 6 - src/Views/Traits/Core/HasWireables.php | 4 +- src/Views/Traits/Helpers/FilterHelpers.php | 13 +- src/Views/Traits/IsFilter.php | 7 +- .../Styling/HandlesFilterInputAttributes.php | 43 +++ .../Styling/HandlesFilterLabelAttributes.php | 27 ++ .../Configuration/FilterConfigurationTest.php | 2 + .../QueryStringForFiltersTest.php | 2 + .../Unit/Traits/Helpers/FilterHelpersTest.php | 2 + .../Styling/FilterPopoverStylingTest.php | 2 + .../Styling/FilterSlidedownStylingTest.php | 2 + .../Unit/Views/Filters/BooleanFilterTest.php | 113 +++++-- tests/Unit/Views/Filters/DateFilterTest.php | 22 +- .../Views/Filters/DateRangeFilterTest.php | 2 + .../Unit/Views/Filters/DateTimeFilterTest.php | 22 +- tests/Unit/Views/Filters/FilterTestCase.php | 63 ++++ .../Filters/LivewireComponentFilterTest.php | 28 +- .../Filters/MultiSelectDropdownFilterTest.php | 212 ++++++-------- .../Views/Filters/MultiSelectFilterTest.php | 185 ++++++------ tests/Unit/Views/Filters/NumberFilterTest.php | 156 +++++----- .../Views/Filters/NumberRangeFilterTest.php | 276 ++++++++---------- tests/Unit/Views/Filters/SelectFilterTest.php | 14 +- tests/Unit/Views/Filters/TextFilterTest.php | 22 +- .../Configuration/FilterConfigurationTest.php | 2 + .../Traits/Helpers/FilterHelpersTest.php | 2 + .../Visuals/ActionsVisualsTest.php | 4 +- .../Visuals/BulkActionsVisualsTest.php | 4 +- .../Visuals/Columns/IconColumnVisualsTest.php | 4 +- .../Visuals/ComponentVisualsTest.php | 4 +- .../Visuals/FilterVisualsTest.php | 4 +- .../Filters/BooleanFilterVisualsTest.php | 45 +++ .../Visuals/Filters/DateFilterVisualsTest.php | 66 +++++ .../Filters/DateTimeFilterVisualsTest.php | 65 +++++ .../Visuals/Filters/FilterVisualsTestCase.php | 18 ++ .../Filters/NumberFilterVisualsTest.php | 46 +++ .../Visuals/Filters/TextFilterVisualsTest.php | 30 +- .../Visuals/HideableTableTest.php | 4 +- .../Visuals/LoadingPlaceholderVisualsTest.php | 4 +- .../Visuals/PaginationVisualsTest.php | 4 +- .../Visuals/RefreshVisualsTest.php | 4 +- .../Visuals/ReorderingVisualsTest.php | 4 +- .../Visuals/SearchVisualsTest.php | 4 +- .../Visuals/SortingVisualsTest.php | 4 +- 58 files changed, 1284 insertions(+), 673 deletions(-) create mode 100644 src/Views/Traits/Styling/HandlesFilterInputAttributes.php create mode 100644 src/Views/Traits/Styling/HandlesFilterLabelAttributes.php rename tests/Unit/{Traits => }/Visuals/ActionsVisualsTest.php (96%) rename tests/Unit/{Traits => }/Visuals/BulkActionsVisualsTest.php (98%) rename tests/Unit/{Traits => }/Visuals/Columns/IconColumnVisualsTest.php (95%) rename tests/Unit/{Traits => }/Visuals/ComponentVisualsTest.php (98%) rename tests/Unit/{Traits => }/Visuals/FilterVisualsTest.php (98%) create mode 100644 tests/Unit/Visuals/Filters/BooleanFilterVisualsTest.php create mode 100644 tests/Unit/Visuals/Filters/DateFilterVisualsTest.php create mode 100644 tests/Unit/Visuals/Filters/DateTimeFilterVisualsTest.php create mode 100644 tests/Unit/Visuals/Filters/FilterVisualsTestCase.php create mode 100644 tests/Unit/Visuals/Filters/NumberFilterVisualsTest.php rename tests/Unit/{Traits => }/Visuals/Filters/TextFilterVisualsTest.php (88%) rename tests/Unit/{Traits => }/Visuals/HideableTableTest.php (93%) rename tests/Unit/{Traits => }/Visuals/LoadingPlaceholderVisualsTest.php (93%) rename tests/Unit/{Traits => }/Visuals/PaginationVisualsTest.php (99%) rename tests/Unit/{Traits => }/Visuals/RefreshVisualsTest.php (90%) rename tests/Unit/{Traits => }/Visuals/ReorderingVisualsTest.php (99%) rename tests/Unit/{Traits => }/Visuals/SearchVisualsTest.php (97%) rename tests/Unit/{Traits => }/Visuals/SortingVisualsTest.php (98%) diff --git a/docs/filter-types/filters-number.md b/docs/filter-types/filters-number.md index 2bfba4404..78dd191a3 100644 --- a/docs/filter-types/filters-number.md +++ b/docs/filter-types/filters-number.md @@ -5,6 +5,27 @@ weight: 9 Number filters are just HTML number inputs. +```php +public function filters(): array +{ + return [ + NumberFilter::make('Amount') + ->filter(function(Builder $builder, string $value) { + $builder->where('amount', '<', $value); + }), + ]; +} +``` + +Historically, min/max/placeholders were set using the "config" option, which is still available. However, it is strongly recommended to use the new setInputAttributes for enhanced customisation. + +## Old Behaviour +The following would: +- Set a min of 0 +- Set a max of 100 +- Add a placeholder +- Keep the default colors & styling + ```php public function filters(): array { @@ -21,3 +42,28 @@ public function filters(): array ]; } ``` + +## New Behaviour +The following would: +- Set a min of 5 +- Set a max of 20 +- Set steps to be 0.5 +- Add a placeholder +- Keep the default colors & styling + +```php +public function filters(): array +{ + return [ + NumberFilter::make('Age') + ->setInputAttributes([ + 'min' => '5', // Minimum Value Accepted + 'max' => '20', // Maximum Value Accepted + 'step' => '0.5', // Set step + 'placeholder' => 'Enter Number 0 - 100', // A placeholder value + 'default-colors' => true, + 'default-styling' => true, + ]), + ]; +} +``` \ No newline at end of file diff --git a/docs/filters/available-filter-methods.md b/docs/filters/available-filter-methods.md index 6e17a63b4..9597372d4 100644 --- a/docs/filters/available-filter-methods.md +++ b/docs/filters/available-filter-methods.md @@ -208,6 +208,58 @@ TextFilter::make('Name') ), ``` +## setInputAttributes +Allows for customising the attributes that will apply to the input field for the filter. + +By default, this replaces the default classes on the Filter Input, if you would like to keep them, set the default-styling and/or default-colors flags to true. + +### TextFilter Example +The following would: +- Set a maxlength of 75 +- Set a placeholder of "Enter a Name" +- Replace the default colors +- Retain the default styling (e.g. rounding/shadow) + +```php +public function filters(): array +{ + return [ + TextFilter::make('Name') + ->setInputAttributes([ + 'maxlength' => '75', + 'placeholder' => 'Enter a Name', + 'class' => 'text-white bg-red-500 dark:bg-red-500', + 'default-colors' => false, + 'default-styling' => true, + ]), + ]; +} +``` + +### NumberFilter Example +The following would: +- Set a min of 5 +- Set a max of 20 +- Set steps to be 0.5 +- Keep the default colors & styling + +```php +public function filters(): array +{ + return [ + NumberFilter::make('Age') + ->setInputAttributes([ + 'min' => '5', + 'max' => '20', + 'step' => '0.5', + 'default-colors' => true, + 'default-styling' => true, + ]), + ]; +} +``` + + ## setCustomView Use a fully custom view for a filter. This will utilise solely your view when rendering this filter. Note that the following methods will no longer apply to a filter using this: - setCustomFilterLabel diff --git a/resources/views/components/tools/filters/boolean.blade.php b/resources/views/components/tools/filters/boolean.blade.php index abc983581..759400e13 100644 --- a/resources/views/components/tools/filters/boolean.blade.php +++ b/resources/views/components/tools/filters/boolean.blade.php @@ -7,14 +7,15 @@ -