From 4f0c1c2ab3f9b41e2572c3526e77d0fa56a9db36 Mon Sep 17 00:00:00 2001 From: Hussam Alhennawi Date: Fri, 17 Jan 2025 23:46:53 +0400 Subject: [PATCH] Enable setting styles for filter pills (item, reset button and reset all button) as a configuration. --- docs/filters/available-component-methods.md | 94 +++++++++++++++++++ .../filter-pills/buttons/reset-all.blade.php | 61 +++++++----- .../buttons/reset-filter.blade.php | 22 +++-- .../tools/filter-pills/item.blade.php | 17 ++-- .../Core/Filters/HasFilterPillsStyling.php | 11 +++ .../FilterPillsStylingConfiguration.php | 27 ++++++ .../Helpers/FilterPillsStylingHelpers.php | 26 +++++ 7 files changed, 220 insertions(+), 38 deletions(-) create mode 100644 src/Traits/Styling/Configuration/FilterPillsStylingConfiguration.php create mode 100644 src/Traits/Styling/Helpers/FilterPillsStylingHelpers.php diff --git a/docs/filters/available-component-methods.md b/docs/filters/available-component-methods.md index 9a463edbf..bf3c51c43 100644 --- a/docs/filters/available-component-methods.md +++ b/docs/filters/available-component-methods.md @@ -121,6 +121,100 @@ public function configure(): void } ``` +## setFilterPillsItemAttributes +Allows for customisation of the appearance of the "Filter Pills Item" + +Note that this utilises a refreshed approach for attributes, and allows for appending to, or replacing the styles and colors independently, via the below methods. + +#### default-colors +Setting to false will disable the default colors for the Filter Pills Item, the default colors are: + +Bootstrap: None + +Tailwind: `bg-indigo-100 text-indigo-800 dark:bg-indigo-200 dark:text-indigo-900` + +#### default-styling +Setting to false will disable the default styling for the Filter Pills Item, the default styling is: + +Bootstrap 4: `badge badge-pill badge-info d-inline-flex align-items-center` + +Bootstrap 5: `badge rounded-pill bg-info d-inline-flex align-items-center` + +Tailwind: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 capitalize` + +```php +public function configure(): void +{ + $this->setFilterPillsItemAttributes([ + 'class' => 'bg-rose-300 text-rose-800 dark:bg-indigo-200 dark:text-indigo-900', // Add these classes to the filter pills item + 'default-colors' => false, // Do not output the default colors + 'default-styling' => true // Output the default styling + ]); +} +``` + +## setFilterPillsResetFilterButtonAttributes +Allows for customisation of the appearance of the "Filter Pills Reset Filter Button" + +Note that this utilises a refreshed approach for attributes, and allows for appending to, or replacing the styles and colors independently, via the below methods. + +#### default-colors +Setting to false will disable the default colors for the Filter Pills Reset Filter Button, the default colors are: + +Bootstrap: None + +Tailwind: `text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white` + +#### default-styling +Setting to false will disable the default styling for the Filter Pills Reset Filter Button, the default styling is: + +Bootstrap: `text-white ml-2` + +Tailwind: `flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none` + +```php +public function configure(): void +{ + $this->setFilterPillsResetFilterButtonAttributes([ + 'class' => 'text-rose-400 hover:bg-rose-200 hover:text-rose-500 focus:bg-rose-500', // Add these classes to the filter pills reset filter button + 'default-colors' => false, // Do not output the default colors + 'default-styling' => true // Output the default styling + ]); +} +``` + +## setFilterPillsResetAllButtonAttributes +Allows for customisation of the appearance of the "Filter Pills Reset All Button" + +Note that this utilises a refreshed approach for attributes, and allows for appending to, or replacing the styles and colors independently, via the below methods. + +#### default-colors +Setting to false will disable the default colors for the Filter Pills Reset All Button, the default colors are: + +Bootstrap: None + +Tailwind: `bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900` + +#### default-styling +Setting to false will disable the default styling for the Filter Pills Reset All Button, the default styling is: + +Bootstrap 4: `badge badge-pill badge-light` + +Bootstrap 5: `badge rounded-pill bg-light text-dark text-decoration-none` + +Tailwind: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium` + +```php +public function configure(): void +{ + $this->setFilterPillsResetAllButtonAttributes([ + 'class' => 'bg-rose-100 text-rose-800 dark:bg-gray-200 dark:text-gray-900', // Add these classes to the filter pills reset all button + 'default-colors' => false, // Do not output the default colors + 'default-styling' => true // Output the default styling + ]); +} +``` + --- ## setFilterLayout diff --git a/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php b/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php index 508c3e201..7acdc1904 100644 --- a/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php +++ b/resources/views/components/tools/filter-pills/buttons/reset-all.blade.php @@ -1,25 +1,36 @@ -@aware(['isTailwind','isBootstrap','isBootstrap4','isBootstrap5']) -@if ($isTailwind) - -@else - $isBootstrap4, - 'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5, - ])> - {{ __($this->getLocalisationPath.'Clear') }} - -@endif +@aware(['isTailwind','isBootstrap','isBootstrap4','isBootstrap5']) +@if ($isTailwind) + +@else + merge($this->getFilterPillsResetAllButtonAttributes()) + ->class([ + 'badge badge-pill badge-light' => $isBootstrap4 && $this->getFilterPillsResetAllButtonAttributes()['default-styling'], + 'badge rounded-pill bg-light text-dark text-decoration-none' => $isBootstrap5 && $this->getFilterPillsResetAllButtonAttributes()['default-styling'], + ]) + ->except(['default-styling', 'default-colors']) + }} + > + {{ __($this->getLocalisationPath.'Clear') }} + +@endif diff --git a/resources/views/components/tools/filter-pills/buttons/reset-filter.blade.php b/resources/views/components/tools/filter-pills/buttons/reset-filter.blade.php index c52e42a96..1a02d413e 100644 --- a/resources/views/components/tools/filter-pills/buttons/reset-filter.blade.php +++ b/resources/views/components/tools/filter-pills/buttons/reset-filter.blade.php @@ -4,10 +4,14 @@