Skip to content

Commit 0536678

Browse files
committed
Tweaks to sorting pill direction label
1 parent 99ea4e7 commit 0536678

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
wire:key="{{ $tableName }}-sorting-pill-{{ $columnSelectName }}"
1818
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"
1919
>
20-
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirection($this, $direction) }}
20+
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
2121

2222
<button
2323
wire:click="clearSort('{{ $columnSelectName }}')"
@@ -58,7 +58,7 @@ class="focus:outline-none active:outline-none"
5858
wire:key="{{ $tableName . '-sorting-pill-' . $columnSelectName }}"
5959
class="badge badge-pill badge-info d-inline-flex align-items-center"
6060
>
61-
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirection($this, $direction) }}
61+
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
6262

6363
<a
6464
href="#"
@@ -98,7 +98,7 @@ class="badge badge-pill badge-light"
9898
wire:key="{{ $tableName }}-sorting-pill-{{ $columnSelectName }}"
9999
class="badge rounded-pill bg-info d-inline-flex align-items-center"
100100
>
101-
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirection($this, $direction) }}
101+
{{ $column->getSortingPillTitle() }}: {{ $column->getSortingPillDirectionLabel($direction, $this->getDefaultSortingLabelAsc, $this->getDefaultSortingLabelDesc) }}
102102

103103
<a
104104
href="#"

src/Traits/Helpers/SortingHelpers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ public function sortingPillsAreDisabled(): bool
151151
return $this->getSortingPillsStatus() === false;
152152
}
153153

154+
#[Computed]
154155
public function getDefaultSortingLabelAsc(): string
155156
{
156157
return $this->defaultSortingLabelAsc;
157158
}
158159

160+
#[Computed]
159161
public function getDefaultSortingLabelDesc(): string
160162
{
161163
return $this->defaultSortingLabelDesc;

src/Views/Traits/Columns/IsSortable.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ public function getCustomSortingPillDirections(string $direction): string
102102
return __('livewire-tables::not_applicable');
103103
}
104104

105+
public function getCustomSortingPillDirectionsLabel(string $direction, string $defaultLabelAsc, string $defaultLabelDesc): string
106+
{
107+
if ($direction === 'asc') {
108+
return $this->sortingPillDirectionAsc ?? $defaultLabelAsc;
109+
}
110+
111+
if ($direction === 'desc') {
112+
return $this->sortingPillDirectionDesc ?? $defaultLabelDesc;
113+
}
114+
115+
return __('livewire-tables::not_applicable');
116+
}
117+
118+
105119
public function getSortingPillDirection(DataTableComponent $component, string $direction): string
106120
{
107121
if ($this->hasCustomSortingPillDirections()) {
@@ -111,6 +125,15 @@ public function getSortingPillDirection(DataTableComponent $component, string $d
111125
return $direction === 'asc' ? $component->getDefaultSortingLabelAsc() : $component->getDefaultSortingLabelDesc();
112126
}
113127

128+
public function getSortingPillDirectionLabel(string $direction, string $defaultLabelAsc, string $defaultLabelDesc): string
129+
{
130+
if ($this->hasCustomSortingPillDirections()) {
131+
return $this->getCustomSortingPillDirectionsLabel($direction, $defaultLabelAsc, $defaultLabelDesc);
132+
}
133+
134+
return $direction === 'asc' ? $defaultLabelAsc : $defaultLabelDesc;
135+
}
136+
114137
/**
115138
* Used in resources/views/components/table/th.blade.php
116139
*/

0 commit comments

Comments
 (0)