-
Notifications
You must be signed in to change notification settings - Fork 47
Add product filter and sort #1482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b189aff
Add product filter and sort
w3bdesign d992b74
Delete Button.vue
w3bdesign dca4912
Filter
w3bdesign 0ca4046
Update ProductFilters.vue
w3bdesign 290e3ff
Update ProductFilters.vue
w3bdesign 501a778
Show sliders
w3bdesign 660ba70
Test filter
w3bdesign 317b038
Update products.vue
w3bdesign 14ba36c
Update ProductFilters.vue
w3bdesign 4c2ad09
Update ProductFilters.vue
w3bdesign 40c3ee6
Fix Button
w3bdesign 4f9a0ba
Create ColorSwatch.vue
w3bdesign 441fbaf
Update ProductFilters.vue
w3bdesign 3123771
Remove imports
w3bdesign 290ae8b
Update products.vue
w3bdesign 99493d6
Update products.vue
w3bdesign fcac916
Update products.vue
w3bdesign f3ed24b
Rename
w3bdesign 3223b9d
Update ProductsFilters.vue
w3bdesign 15749fd
Update ProductsFilters.vue
w3bdesign 8cd1bf1
Test filter live
w3bdesign 3652ad6
Potential fix for code scanning alert no. 10: Assignment to constant
w3bdesign 2353695
Update ProductsShowAll.vue
w3bdesign 5a8adef
Enable action
w3bdesign 31575ad
Update RangeSlider.vue
w3bdesign 2027ad7
Update ProductsSort.vue
w3bdesign 2b2df4e
Update ProductsShowAll.vue
w3bdesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,83 @@ | ||
<template> | ||
<div class="w-full md:w-64 flex-shrink-0"> | ||
<div class="bg-white px-8 pb-8 sm:px-6 sm:pb-6 rounded-lg shadow-sm"> | ||
<div class="mb-8"> | ||
<h3 class="font-semibold mb-4">PRODUKT TYPE</h3> | ||
<div class="space-y-2"> | ||
<CommonCheckbox | ||
v-for="type in productTypes" | ||
:key="type.id" | ||
:id="type.id" | ||
:label="type.name" | ||
:checked="type.checked" | ||
@change="() => toggleProductType(type.id)" | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h3 class="font-semibold mb-4">PRIS</h3> | ||
<CommonRangeSlider | ||
id="price-range" | ||
label="Pris" | ||
:min="0" | ||
:max="1000" | ||
:value="priceRange[1]" | ||
:startValue="priceRange[0]" | ||
:disabled="false" | ||
@input="(value) => setPriceRange([priceRange[0], value])" | ||
/> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h3 class="font-semibold mb-4">STØRRELSE</h3> | ||
<div class="grid grid-cols-3 gap-2"> | ||
<CommonButton | ||
v-for="size in sizes" | ||
:key="size" | ||
:selected="selectedSizes.includes(size)" | ||
variant="filter" | ||
@click="() => toggleSize(size)" | ||
> | ||
{{ size }} | ||
</CommonButton> | ||
</div> | ||
</div> | ||
|
||
<div class="mb-8"> | ||
<h3 class="font-semibold mb-4">FARGE</h3> | ||
<div class="grid grid-cols-3 gap-2"> | ||
<CommonColorSwatch | ||
v-for="color in colors" | ||
:key="color.name" | ||
:color="color.hex" | ||
:title="color.name" | ||
:class="{ 'ring-2 ring-offset-2 ring-gray-900': selectedColors.includes(color.name) }" | ||
@click="() => toggleColor(color.name)" | ||
style="cursor:pointer" | ||
/> | ||
</div> | ||
</div> | ||
|
||
<CommonButton variant="reset" class="mt-4 w-full" @click="resetFilters"> | ||
Resett filter | ||
</CommonButton> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
defineProps({ | ||
productTypes: Array, | ||
toggleProductType: Function, | ||
priceRange: Array, | ||
setPriceRange: Function, | ||
sizes: Array, | ||
selectedSizes: Array, | ||
toggleSize: Function, | ||
colors: Array, | ||
selectedColors: Array, | ||
toggleColor: Function, | ||
resetFilters: Function, | ||
}); | ||
</script> |
This file contains hidden or 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 hidden or 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,15 @@ | ||
<template> | ||
<div class="flex items-center gap-2"> | ||
<label for="sort-select" class="text-base text-gray-700">Sortering:</label> | ||
<select | ||
id="sort-select" | ||
class="min-w-[140px] border border-gray-200 rounded-lg px-3 py-2 text-base bg-gray-50 text-gray-700 focus:outline-none" | ||
disabled | ||
> | ||
<option value="popular">Populær</option> | ||
<option value="price-low">Pris: Lav til Høy</option> | ||
<option value="price-high">Pris: Høy til Lav</option> | ||
<option value="newest">Nyeste</option> | ||
</select> | ||
</div> | ||
</template> |
This file contains hidden or 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,15 @@ | ||
<template> | ||
<label class="flex items-center space-x-2 cursor-pointer"> | ||
<input type="checkbox" class="form-checkbox h-4 w-4 text-blue-600 rounded" disabled /> | ||
<span class="text-sm">{{ label }}</span> | ||
</label> | ||
</template> | ||
|
||
<script setup> | ||
defineProps({ | ||
label: { | ||
type: String, | ||
default: '', | ||
}, | ||
}); | ||
</script> |
This file contains hidden or 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,20 @@ | ||
<template> | ||
<span | ||
class="inline-block w-8 h-8 rounded-full border-2 border-white shadow" | ||
:style="{ backgroundColor: color }" | ||
:title="title" | ||
></span> | ||
</template> | ||
|
||
<script setup> | ||
defineProps({ | ||
color: { | ||
type: String, | ||
default: '#3b82f6', // Tailwind blue-500 | ||
}, | ||
title: { | ||
type: String, | ||
default: '', | ||
}, | ||
}); | ||
</script> |
This file contains hidden or 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,15 @@ | ||
<template> | ||
<div class="w-full"> | ||
<input | ||
type="range" | ||
min="0" | ||
max="1000" | ||
class="w-full accent-blue-600" | ||
disabled | ||
/> | ||
<div class="flex justify-between text-sm mt-1"> | ||
<span>kr 0</span> | ||
<span>kr 1000</span> | ||
</div> | ||
</div> | ||
</template> |
This file contains hidden or 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,19 +1,79 @@ | ||
<template> | ||
<ProductsShowAll /> | ||
<div class="container mx-auto px-4 py-8"> | ||
<div class="flex flex-col md:flex-row gap-8"> | ||
<ProductsFilters | ||
:productTypes="productTypes" | ||
:toggleProductType="toggleProductType" | ||
:priceRange="priceRange" | ||
:setPriceRange="setPriceRange" | ||
:sizes="sizes" | ||
:selectedSizes="selectedSizes" | ||
:toggleSize="toggleSize" | ||
:colors="colors" | ||
:selectedColors="selectedColors" | ||
:toggleColor="toggleColor" | ||
:resetFilters="resetFilters" | ||
/> | ||
<div class="flex-1"> | ||
<div | ||
class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-8" | ||
> | ||
<h1 class="text-xl sm:text-2xl font-medium text-center sm:text-left"> | ||
Produkter | ||
</h1> | ||
<ProductsSort v-model="sortBy" /> | ||
</div> | ||
<ProductsShowAll | ||
:sortBy="sortBy" | ||
:selectedSizes="selectedSizes" | ||
:selectedColors="selectedColors" | ||
:priceRange="priceRange" | ||
:productTypes="productTypes" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
useHead({ | ||
title: "Products", | ||
titleTemplate: "%s - Nuxt 3 Woocommerce", | ||
meta: [ | ||
{ name: "viewport", content: "width=device-width, initial-scale=1" }, | ||
{ | ||
hid: "description", | ||
name: "description", | ||
content: "Nuxt 3 Woocommerce", | ||
}, | ||
], | ||
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }], | ||
}); | ||
const sortBy = ref("popular"); | ||
const selectedSizes = ref([]); | ||
const selectedColors = ref([]); | ||
const priceRange = ref([0, 1000]); | ||
const productTypes = ref([ | ||
{ id: "clothing", name: "Clothing", checked: false }, | ||
{ id: "tshirts", name: "Tshirts", checked: false }, | ||
{ id: "uncategorized", name: "Uncategorized", checked: false }, | ||
]); | ||
const sizes = ref(["Large"]); | ||
const colors = ref([{ name: "Blue", hex: "#3b82f6" }]); | ||
|
||
function toggleProductType(id) { | ||
productTypes.value = productTypes.value.map((type) => | ||
type.id === id ? { ...type, checked: !type.checked } : type | ||
); | ||
} | ||
function setPriceRange(newRange) { | ||
priceRange.value = newRange; | ||
} | ||
function toggleSize(size) { | ||
if (selectedSizes.value.includes(size)) { | ||
selectedSizes.value = selectedSizes.value.filter((s) => s !== size); | ||
} else { | ||
selectedSizes.value = [...selectedSizes.value, size]; | ||
} | ||
} | ||
function toggleColor(color) { | ||
if (selectedColors.value.includes(color)) { | ||
selectedColors.value = selectedColors.value.filter((c) => c !== color); | ||
} else { | ||
selectedColors.value = [...selectedColors.value, color]; | ||
} | ||
} | ||
function resetFilters() { | ||
selectedSizes.value = []; | ||
selectedColors.value = []; | ||
priceRange.value = [0, 1000]; | ||
productTypes.value = productTypes.value.map((type) => ({ ...type, checked: false })); | ||
} | ||
</script> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.