-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
98 additions
and
20 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
resources/js/components/Listing/Filters/SelectedFiltersValues.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<script> | ||
import { swatches } from '../../../stores/useSwatches' | ||
export default { | ||
props: { | ||
selectedValues: { | ||
type: Object, | ||
default: () => {}, | ||
}, | ||
}, | ||
render() { | ||
return this.$scopedSlots.default(this) | ||
}, | ||
computed: { | ||
activeFilters() { | ||
return Object.keys(this.selectedValues) | ||
.filter((filterKey) => { | ||
let { showFilter, value } = this.selectedValues[filterKey] | ||
return showFilter && (Array.isArray(value) ? value.length : !!value) | ||
}) | ||
.reduce((result, filterKey) => { | ||
let { value } = this.selectedValues[filterKey] | ||
if (filterKey === 'category') { | ||
return result.concat({ code: filterKey, value: config.subcategories[value] }) | ||
} | ||
if (filterKey === 'price') { | ||
let [minPrice, maxPrice] = value | ||
return result.concat({ code: filterKey, value: price(minPrice) + ' - ' + price(maxPrice) }) | ||
} | ||
if (Array.isArray(value)) { | ||
// Check if the value is a swatch value, boolean or just an array | ||
let items = Object.keys(swatches.value).includes(filterKey) | ||
? value.map((selected) => swatches.value[filterKey].options[selected].label) | ||
: value.map((item) => | ||
item === '0' | ||
? window.config.translations.filters.no | ||
: item === '1' | ||
? window.config.translations.filters.yes | ||
: item, | ||
) | ||
// We can have a filter where multiple values may be selected, so we need to map and concat all of them | ||
return result.concat(items.map((item) => ({ code: filterKey, value: item }))) | ||
} | ||
return result | ||
}, []) | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 27 additions & 15 deletions
42
resources/views/listing/partials/filter/selected.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
<selected-filters :inner-class="{ button: '!hidden last:!inline-flex' }"> | ||
<x-rapidez::button | ||
class="w-full mb-3 text-sm" | ||
slot-scope="{ clearValues, selectedValues, components }" | ||
v-on:click="clearValues" | ||
<selected-filters> | ||
<div | ||
slot-scope="{ clearValues, selectedValues, setValue, components }" | ||
v-if="Object.keys(selectedValues).filter(function (id) { | ||
let value = selectedValues[id].value | ||
let isArray = Array.isArray(value) | ||
return components.includes(id) | ||
&& selectedValues[id].showFilter | ||
&& ( | ||
(isArray && value.length) | ||
|| (!isArray && value) | ||
) | ||
}).length" | ||
return components.includes(id) && selectedValues[id].showFilter && ((isArray && value.length) || (!isArray && value))}).length" | ||
> | ||
@lang('Reset filters') | ||
</x-rapidez::button> | ||
<selected-filters-values :selected-values="selectedValues"> | ||
<div slot-scope="{ activeFilters }" class="flex flex-wrap items-center w-full md:w-auto relative mb-5"> | ||
<div class="flex flex-wrap items-baseline justify-between gap-2 w-full border-t py-4"> | ||
<div class="text-neutral font-semibold text-base font-sans"> | ||
@lang('You have filtered on'): | ||
</div> | ||
<button v-on:click="clearValues" class="!font-sans text-sm text-inactive transition-all hover:underline"> | ||
@lang('Reset filters') | ||
</button> | ||
</div> | ||
<div class="flex gap-2 flex-wrap"> | ||
<div class="flex flex-wrap gap-2 relative cursor-pointer" v-for="filter in activeFilters"> | ||
<div v-on:click="setValue(filter.code, null)" class="flex justify-between items-center transition hover:opacity-80"> | ||
<span class="font-sans flex gap-1 p-1 items-center text-xs test-neutral rounded-lg bg-inactive-100"> | ||
@{{ filter.value }} | ||
<x-heroicon-o-x-mark class="size-3 shrink-0 text-neutral"/> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</selected-filters-values> | ||
</div> | ||
</selected-filters> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters