Skip to content

Commit 001392b

Browse files
committed
Added sort Component
1 parent ceed260 commit 001392b

File tree

2 files changed

+308
-81
lines changed

2 files changed

+308
-81
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<script setup>
2+
import { ref, computed } from "vue";
3+
import { Link } from "@inertiajs/inertia-vue3";
4+
5+
const props = defineProps({
6+
label: {
7+
type: String,
8+
default: "",
9+
},
10+
attribute: {
11+
type: String,
12+
default: "",
13+
},
14+
});
15+
16+
const downFill = ref("lightgray");
17+
const upFill = ref("lightgray");
18+
19+
const sortLink = computed(() => {
20+
let url = new URL(document.location);
21+
let sortValue = url.searchParams.get("sort");
22+
23+
if (sortValue == props.attribute) {
24+
url.searchParams.set("sort", "-" + props.attribute);
25+
upFill.value = "black";
26+
} else if (sortValue === "-" + props.attribute) {
27+
url.searchParams.set("sort", props.attribute);
28+
downFill.value = "black";
29+
} else {
30+
url.searchParams.set("sort", props.attribute);
31+
}
32+
return url.href;
33+
});
34+
</script>
35+
36+
<template>
37+
<div class="flex items-center gap-4">
38+
<Link
39+
:href="sortLink"
40+
class="no-underline hover:underline text-cyan-600 dark:text-cyan-400"
41+
>{{ label }}</Link
42+
>
43+
<div class="flex flex-col">
44+
<svg
45+
class="inline-block"
46+
xmlns="http://www.w3.org/2000/svg"
47+
width="15px"
48+
height="15px"
49+
viewBox="0 0 15 15"
50+
fill="none"
51+
>
52+
<path d="M7.5 3L15 11H0L7.5 3Z" :fill="upFill" />
53+
</svg>
54+
<svg
55+
class="inline-block"
56+
xmlns="http://www.w3.org/2000/svg"
57+
width="15px"
58+
height="15px"
59+
viewBox="0 0 15 15"
60+
fill="none"
61+
>
62+
<path
63+
d="M7.49988 12L-0.00012207 4L14.9999 4L7.49988 12Z"
64+
:fill="downFill"
65+
/>
66+
</svg>
67+
</div>
68+
</div>
69+
</template>

0 commit comments

Comments
 (0)