Skip to content

Commit a941a16

Browse files
authored
Merge pull request rappasoft#2179 from HussamAlhennawi/configuration-for-sorting-pills-styling
Enable setting styles for sorting pills as a configuration.
2 parents 19ebe02 + 52a80ef commit a941a16

File tree

6 files changed

+239
-11
lines changed

6 files changed

+239
-11
lines changed

docs/sorting/available-methods.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,102 @@ public function configure(): void
153153
}
154154
```
155155

156+
## setSortingPillsItemAttributes
157+
Allows for customisation of the appearance of the "Sorting Pills Item"
158+
159+
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.
160+
161+
#### default-colors
162+
Setting to false will disable the default colors for the Sorting Pills Item, the default colors are:
163+
164+
Bootstrap: None
165+
166+
Tailwind: `bg-indigo-100 text-indigo-800 dark:bg-indigo-200 dark:text-indigo-900`
167+
168+
#### default-styling
169+
Setting to false will disable the default styling for the Sorting Pills Item, the default styling is:
170+
171+
Bootstrap 4: `badge badge-pill badge-info d-inline-flex align-items-center`
172+
173+
Bootstrap 5: `badge rounded-pill bg-info d-inline-flex align-items-center`
174+
175+
Tailwind: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 capitalize`
176+
177+
```php
178+
public function configure(): void
179+
{
180+
$this->setSortingPillsItemAttributes([
181+
'class' => 'bg-rose-300 text-rose-800 dark:bg-indigo-200 dark:text-indigo-900', // Add these classes to the sorting pills item
182+
'default-colors' => false, // Do not output the default colors
183+
'default-styling' => true // Output the default styling
184+
]);
185+
}
186+
```
187+
188+
## setSortingPillsClearSortButtonAttributes
189+
Allows for customisation of the appearance of the "Sorting Pills Clear Sort Button"
190+
191+
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.
192+
193+
#### default-colors
194+
Setting to false will disable the default colors for the Sorting Pills Clear Sort Button, the default colors are:
195+
196+
Bootstrap: None
197+
198+
Tailwind: `text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white`
199+
200+
#### default-styling
201+
Setting to false will disable the default styling for the Sorting Pills Clear Sort Button, the default styling is:
202+
203+
Bootstrap 4: `text-white ml-2`
204+
205+
Bootstrap 5: `text-white ms-2`
206+
207+
Tailwind: `flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none`
208+
209+
```php
210+
public function configure(): void
211+
{
212+
$this->setSortingPillsClearSortButtonAttributes([
213+
'class' => 'text-rose-400 hover:bg-rose-200 hover:text-rose-500 focus:bg-rose-500', // Add these classes to the sorting pills clear sort button
214+
'default-colors' => false, // Do not output the default colors
215+
'default-styling' => true // Output the default styling
216+
]);
217+
}
218+
```
219+
220+
## setSortingPillsClearAllButtonAttributes
221+
Allows for customisation of the appearance of the "Sorting Pills Clear All Button"
222+
223+
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.
224+
225+
#### default-colors
226+
Setting to false will disable the default colors for the Sorting Pills Clear All Button, the default colors are:
227+
228+
Bootstrap: None
229+
230+
Tailwind: `bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900`
231+
232+
#### default-styling
233+
Setting to false will disable the default styling for the Sorting Pills Clear All Button, the default styling is:
234+
235+
Bootstrap 4: `badge badge-pill badge-light`
236+
237+
Bootstrap 5: `badge rounded-pill bg-light text-dark text-decoration-none`
238+
239+
Tailwind: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium`
240+
241+
```php
242+
public function configure(): void
243+
{
244+
$this->setSortingPillsClearAllButtonAttributes([
245+
'class' => 'bg-rose-100 text-rose-800 dark:bg-gray-200 dark:text-gray-900', // Add these classes to the sorting pills clear all button
246+
'default-colors' => false, // Do not output the default colors
247+
'default-styling' => true // Output the default styling
248+
]);
249+
}
250+
```
251+
156252
---
157253

158254
## setDefaultSortingLabels

resources/views/components/tools/sorting-pills.blade.php

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,28 @@
1515

1616
<span
1717
wire:key="{{ $tableName }}-sorting-pill-{{ $columnSelectName }}"
18-
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-100 text-indigo-800 capitalize dark:bg-indigo-200 dark:text-indigo-900"
18+
{{
19+
$attributes->merge($this->getSortingPillsItemAttributes())
20+
->class([
21+
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 capitalize' => $this->getSortingPillsItemAttributes()['default-styling'],
22+
'bg-indigo-100 text-indigo-800 dark:bg-indigo-200 dark:text-indigo-900' => $this->getSortingPillsItemAttributes()['default-colors'],
23+
])
24+
->except(['default-styling', 'default-colors'])
25+
}}
1926
>
2027
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
2128

2229
<button
2330
wire:click="clearSort('{{ $columnSelectName }}')"
2431
type="button"
25-
class="flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:outline-none focus:bg-indigo-500 focus:text-white"
32+
{{
33+
$attributes->merge($this->getSortingPillsClearSortButtonAttributes())
34+
->class([
35+
'flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none' => $this->getSortingPillsClearSortButtonAttributes()['default-styling'],
36+
'text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white' => $this->getSortingPillsClearSortButtonAttributes()['default-colors'],
37+
])
38+
->except(['default-styling', 'default-colors'])
39+
}}
2640
>
2741
<span class="sr-only">{{ __($this->getLocalisationPath.'Remove sort option') }}</span>
2842
<x-heroicon-m-x-mark class="h-3 w-3" />
@@ -34,7 +48,16 @@ class="flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justif
3448
wire:click.prevent="clearSorts"
3549
class="focus:outline-none active:outline-none"
3650
>
37-
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900">
51+
<span
52+
{{
53+
$attributes->merge($this->getSortingPillsClearAllButtonAttributes())
54+
->class([
55+
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium' => $this->getSortingPillsClearAllButtonAttributes()['default-styling'],
56+
'bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900' => $this->getSortingPillsClearAllButtonAttributes()['default-colors'],
57+
])
58+
->except(['default-styling', 'default-colors'])
59+
}}
60+
>
3861
{{ __($this->getLocalisationPath.'Clear') }}
3962
</span>
4063
</button>
@@ -56,14 +79,26 @@ class="focus:outline-none active:outline-none"
5679

5780
<span
5881
wire:key="{{ $tableName . '-sorting-pill-' . $columnSelectName }}"
59-
class="badge badge-pill badge-info d-inline-flex align-items-center"
82+
{{
83+
$attributes->merge($this->getSortingPillsItemAttributes())
84+
->class([
85+
'badge badge-pill badge-info d-inline-flex align-items-center' => $this->getSortingPillsItemAttributes()['default-styling'],
86+
])
87+
->except(['default-styling', 'default-colors'])
88+
}}
6089
>
6190
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
6291

6392
<a
6493
href="#"
6594
wire:click="clearSort('{{ $columnSelectName }}')"
66-
class="text-white ml-2"
95+
{{
96+
$attributes->merge($this->getSortingPillsClearSortButtonAttributes())
97+
->class([
98+
'text-white ml-2' => $this->getSortingPillsClearSortButtonAttributes()['default-styling'],
99+
])
100+
->except(['default-styling', 'default-colors'])
101+
}}
67102
>
68103
<span class="sr-only">{{ __($this->getLocalisationPath.'Remove sort option') }}</span>
69104
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-smaller" />
@@ -74,7 +109,13 @@ class="text-white ml-2"
74109
<a
75110
href="#"
76111
wire:click.prevent="clearSorts"
77-
class="badge badge-pill badge-light"
112+
{{
113+
$attributes->merge($this->getSortingPillsClearAllButtonAttributes())
114+
->class([
115+
'badge badge-pill badge-light' => $this->getSortingPillsClearAllButtonAttributes()['default-styling'],
116+
])
117+
->except(['default-styling', 'default-colors'])
118+
}}
78119
>
79120
{{ __($this->getLocalisationPath.'Clear') }}
80121
</a>
@@ -96,14 +137,26 @@ class="badge badge-pill badge-light"
96137

97138
<span
98139
wire:key="{{ $tableName }}-sorting-pill-{{ $columnSelectName }}"
99-
class="badge rounded-pill bg-info d-inline-flex align-items-center"
140+
{{
141+
$attributes->merge($this->getSortingPillsItemAttributes())
142+
->class([
143+
'badge rounded-pill bg-info d-inline-flex align-items-center' => $this->getSortingPillsItemAttributes()['default-styling'],
144+
])
145+
->except(['default-styling', 'default-colors'])
146+
}}
100147
>
101148
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
102149

103150
<a
104151
href="#"
105152
wire:click="clearSort('{{ $columnSelectName }}')"
106-
class="text-white ms-2"
153+
{{
154+
$attributes->merge($this->getSortingPillsClearSortButtonAttributes())
155+
->class([
156+
'text-white ms-2' => $this->getSortingPillsClearSortButtonAttributes()['default-styling'],
157+
])
158+
->except(['default-styling', 'default-colors'])
159+
}}
107160
>
108161
<span class="visually-hidden">{{ __($this->getLocalisationPath.'Remove sort option') }}</span>
109162
<x-heroicon-m-x-mark class="laravel-livewire-tables-btn-smaller" />
@@ -114,7 +167,13 @@ class="text-white ms-2"
114167
<a
115168
href="#"
116169
wire:click.prevent="clearSorts"
117-
class="badge rounded-pill bg-light text-dark text-decoration-none"
170+
{{
171+
$attributes->merge($this->getSortingPillsClearAllButtonAttributes())
172+
->class([
173+
'badge rounded-pill bg-light text-dark text-decoration-none' => $this->getSortingPillsClearAllButtonAttributes()['default-styling'],
174+
])
175+
->except(['default-styling', 'default-colors'])
176+
}}
118177
>
119178
{{ __($this->getLocalisationPath.'Clear') }}
120179
</a>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration;
4+
5+
trait SortingPillsStylingConfiguration
6+
{
7+
public function setSortingPillsItemAttributes(array $attributes = []): self
8+
{
9+
$this->sortingPillsItemAttributes = [...$this->sortingPillsItemAttributes, ...$attributes];
10+
11+
return $this;
12+
}
13+
14+
public function setSortingPillsClearSortButtonAttributes(array $attributes = []): self
15+
{
16+
$this->sortingPillsClearSortButtonAttributes = [...$this->sortingPillsClearSortButtonAttributes, ...$attributes];
17+
18+
return $this;
19+
}
20+
21+
public function setSortingPillsClearAllButtonAttributes(array $attributes = []): self
22+
{
23+
$this->sortingPillsClearAllButtonAttributes = [...$this->sortingPillsClearAllButtonAttributes, ...$attributes];
24+
25+
return $this;
26+
}
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling;
4+
5+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\SortingPillsStylingConfiguration;
6+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\SortingPillsStylingHelpers;
7+
8+
trait HasSortingPillsStyling
9+
{
10+
use SortingPillsStylingConfiguration,
11+
SortingPillsStylingHelpers;
12+
13+
protected array $sortingPillsItemAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => ''];
14+
15+
protected array $sortingPillsClearSortButtonAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => ''];
16+
17+
protected array $sortingPillsClearAllButtonAttributes = ['default-styling' => true, 'default-colors' => true, 'class' => ''];
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;
4+
5+
use Livewire\Attributes\Computed;
6+
7+
trait SortingPillsStylingHelpers
8+
{
9+
#[Computed]
10+
public function getSortingPillsItemAttributes(): array
11+
{
12+
return $this->sortingPillsItemAttributes;
13+
}
14+
15+
#[Computed]
16+
public function getSortingPillsClearSortButtonAttributes(): array
17+
{
18+
return $this->sortingPillsClearSortButtonAttributes;
19+
}
20+
21+
#[Computed]
22+
public function getSortingPillsClearAllButtonAttributes(): array
23+
{
24+
return $this->sortingPillsClearAllButtonAttributes;
25+
}
26+
}

src/Traits/WithSorting.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use Rappasoft\LaravelLivewireTables\Traits\Configuration\SortingConfiguration;
88
use Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings\HasQueryStringForSort;
99
use Rappasoft\LaravelLivewireTables\Traits\Helpers\SortingHelpers;
10+
use Rappasoft\LaravelLivewireTables\Traits\Styling\HasSortingPillsStyling;
1011

1112
trait WithSorting
1213
{
1314
use SortingConfiguration,
14-
SortingHelpers;
15-
use HasQueryStringForSort;
15+
SortingHelpers,
16+
HasQueryStringForSort,
17+
HasSortingPillsStyling;
1618

1719
public array $sorts = [];
1820

0 commit comments

Comments
 (0)