|
9 | 9 | Stack, |
10 | 10 | } from '@ui'; |
11 | 11 | import { injectListingContext } from '../Listing/Listing.vue'; |
| 12 | +import { dateFormatter } from '@/api'; |
12 | 13 | import { computed, ref, watch, nextTick } from 'vue'; |
13 | 14 | import FieldFilter from './FieldFilter.vue'; |
14 | 15 | import DataListFilter from './Filter.vue'; |
@@ -39,6 +40,27 @@ function removeFieldFilter(filterHandle, fieldHandle) { |
39 | 40 | setFilter(filterHandle, fields); |
40 | 41 | } |
41 | 42 |
|
| 43 | +function getFieldFilterBadgeLabel(handle, badge) { |
| 44 | + if (handle === 'date') { |
| 45 | + const df = dateFormatter.options('date'); |
| 46 | + const parts = [badge.field, badge.translatedOperator]; |
| 47 | +
|
| 48 | + if (badge.operator === 'between') { |
| 49 | + parts.push(df.date(badge.value.start), __('and'), df.date(badge.value.end)); |
| 50 | + } else { |
| 51 | + parts.push(df.date(badge.value)); |
| 52 | + } |
| 53 | +
|
| 54 | + return parts.filter(Boolean).join(' '); |
| 55 | + } |
| 56 | +
|
| 57 | + return badge; |
| 58 | +} |
| 59 | +
|
| 60 | +function getClearFilterLabel(label) { |
| 61 | + return __('Clear :filter', { filter: label }); |
| 62 | +} |
| 63 | +
|
42 | 64 | function isActive(handle) { |
43 | 65 | return activeFilters.value.hasOwnProperty(handle); |
44 | 66 | } |
@@ -172,38 +194,47 @@ function handleStackClosed() { |
172 | 194 | </Stack> |
173 | 195 |
|
174 | 196 | <Button |
| 197 | + as="div" |
| 198 | + variant="filled" |
175 | 199 | v-for="({ filter, handle, badge }, index) in fieldFilterBadges" |
176 | 200 | :key="`${filter}-${handle}`" |
177 | | - variant="filled" |
178 | | - :icon-append="reorderable ? null : 'x'" |
179 | | - :disabled="reorderable" |
180 | | - class="last:me-12" |
181 | | - @click="removeFieldFilter(filter, handle)" |
| 201 | + class="cursor-default ps-4 gap-1 text-gray-900 dark:text-gray-200 last:me-12 hover:bg-gray-950/5 dark:hover:bg-white/4" |
| 202 | + :class="reorderable ? 'pe-4 text-gray-400 dark:text-gray-600' : 'pe-2'" |
182 | 203 | > |
183 | | - <template v-if="handle == 'date'"> |
184 | | - {{ badge.field }} |
185 | | - {{ badge.translatedOperator }} |
186 | | - <template v-if="badge.operator === 'between'"> |
187 | | - <date-time :of="badge.value.start" options="date" /> |
188 | | - {{ __('and') }} |
189 | | - <date-time :of="badge.value.end" options="date" /> |
190 | | - </template> |
191 | | - <date-time v-else :of="badge.value" options="date" /> |
192 | | - </template> |
193 | | - |
194 | | - <template v-else> |
195 | | - {{ badge }} |
196 | | - </template> |
| 204 | + <span class="whitespace-nowrap" v-text="getFieldFilterBadgeLabel(handle, badge)" /> |
| 205 | + |
| 206 | + <Button |
| 207 | + v-if="!reorderable" |
| 208 | + variant="ghost" |
| 209 | + size="xs" |
| 210 | + icon="x" |
| 211 | + iconOnly |
| 212 | + inset |
| 213 | + class="opacity-100 [&_svg]:size-4" |
| 214 | + :aria-label="getClearFilterLabel(getFieldFilterBadgeLabel(handle, badge))" |
| 215 | + @click="removeFieldFilter(filter, handle)" |
| 216 | + /> |
197 | 217 | </Button> |
198 | 218 | <Button |
| 219 | + as="div" |
| 220 | + variant="filled" |
199 | 221 | v-for="(badge, handle, index) in standardBadges" |
200 | 222 | :key="handle" |
201 | | - variant="filled" |
202 | | - :icon-append="reorderable ? null : 'x'" |
203 | | - :text="badge" |
204 | | - :disabled="reorderable" |
205 | | - class="last:me-12" |
206 | | - @click="setFilter(handle, null)" |
207 | | - /> |
| 223 | + class="cursor-default ps-4 gap-1 text-gray-900 dark:text-gray-200 last:me-12 hover:bg-gray-950/5 dark:hover:bg-white/4" |
| 224 | + :class="reorderable ? 'pe-4 text-gray-400 dark:text-gray-600' : 'pe-2'" |
| 225 | + > |
| 226 | + <span class="whitespace-nowrap">{{ badge }}</span> |
| 227 | + <Button |
| 228 | + v-if="!reorderable" |
| 229 | + variant="ghost" |
| 230 | + size="xs" |
| 231 | + icon="x" |
| 232 | + iconOnly |
| 233 | + inset |
| 234 | + class="opacity-100 [&_svg]:size-4" |
| 235 | + :aria-label="getClearFilterLabel(badge)" |
| 236 | + @click="setFilter(handle, null)" |
| 237 | + /> |
| 238 | + </Button> |
208 | 239 | </div> |
209 | 240 | </template> |
0 commit comments