Skip to content

Commit 348c740

Browse files
committed
make it better
1 parent a37bc5a commit 348c740

File tree

4 files changed

+152
-13
lines changed

4 files changed

+152
-13
lines changed

components/Hero/CarBox.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
<div class="col-12 bg-light p-2">
88
<div class="row">
99
<div class="col-6">
10-
<span style="padding-left:2px;"><i class="bi bi-geo-alt-fill"></i> รับรถที่จังหวัด</span>
11-
<div class="border rounded-3 p-2 bg-dark text-primary" style="margin-top:2px;">
12-
นครศรีธรรมราช
13-
</div>
14-
</div>
10+
<span style="padding-left:2px;" ><i class="bi bi-geo-alt-fill"></i> รับรถที่จังหวัด</span>
11+
<ProvinceSelect v-model="selectedProvince" :options="provinces" style="margin-top:2px;" />
12+
</div>
1513
<div class="col-3">
1614
<span style="padding-left:2px;"><i class="bi bi-calendar3"></i> รับรถ</span>
1715
<div class="border rounded-3 p-2 bg-dark text-primary" style="margin-top:2px;">14 ม.ย.</div>
@@ -64,6 +62,12 @@
6462
</template>
6563

6664
<script setup>
65+
const provinces = [
66+
'กรุงเทพมหานคร', 'เชียงใหม่', 'ขอนแก่น', 'ชลบุรี', 'ภูเก็ต',
67+
'นครราชสีมา', 'นครศรีธรรมราช', 'อุบลราชธานี', 'สงขลา', 'สุราษฎร์ธานี'
68+
]
69+
70+
const selectedProvince = ref('นครศรีธรรมราช')
6771
</script>
6872

6973
<style scoped>

components/ProvinceSelect.vue

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<div class="position-relative">
3+
<div
4+
class="form-control bg-dark text-primary border rounded-3 d-flex justify-content-between align-items-center"
5+
@click="toggleDropdown"
6+
style="cursor: pointer;"
7+
>
8+
{{ selected || 'เลือกจังหวัด' }}
9+
<i class="bi" :class="dropdownOpen ? 'bi-chevron-up' : 'bi-chevron-down'"></i>
10+
</div>
11+
12+
<div
13+
v-if="dropdownOpen"
14+
class="position-absolute w-100 z-10 bg-white border rounded-3 mt-1 shadow-sm"
15+
style="max-height: 200px; overflow-y: auto;"
16+
>
17+
<input
18+
v-model="search"
19+
type="text"
20+
class="form-control border-0 border-bottom rounded-0"
21+
placeholder="ค้นหา..."
22+
@click.stop
23+
/>
24+
25+
<div
26+
v-for="province in filtered"
27+
:key="province"
28+
:class="[
29+
'px-3 py-2 dropdown-item bg-white hover-bg d-flex justify-between align-items-center',
30+
province === selected ? 'fw-bold text-primary' : ''
31+
]"
32+
style="cursor: pointer;"
33+
@mousedown.prevent="select(province)"
34+
>
35+
<span>{{ province }}</span>
36+
<i v-if="province === selected" class="bi bi-check2-circle ms-auto"></i>
37+
</div>
38+
39+
<div v-if="!filtered.length" class="text-muted text-center py-2">
40+
ไม่พบจังหวัด
41+
</div>
42+
</div>
43+
</div>
44+
</template>
45+
46+
<script setup>
47+
import { ref, computed, onMounted, onUnmounted } from 'vue'
48+
49+
const props = defineProps({
50+
modelValue: String,
51+
options: {
52+
type: Array,
53+
default: () => []
54+
}
55+
})
56+
const emit = defineEmits(['update:modelValue'])
57+
58+
const search = ref('')
59+
const selected = computed(() => props.modelValue)
60+
const dropdownOpen = ref(false)
61+
62+
const filtered = computed(() =>
63+
props.options.filter(p =>
64+
p.toLowerCase().includes(search.value.toLowerCase())
65+
)
66+
)
67+
68+
const toggleDropdown = () => {
69+
dropdownOpen.value = !dropdownOpen.value
70+
}
71+
72+
const select = (province) => {
73+
emit('update:modelValue', province)
74+
search.value = ''
75+
dropdownOpen.value = false
76+
}
77+
78+
const handleClickOutside = (e) => {
79+
if (!e.target.closest('.position-relative')) {
80+
dropdownOpen.value = false
81+
}
82+
}
83+
onMounted(() => {
84+
window.addEventListener('click', handleClickOutside)
85+
})
86+
onUnmounted(() => {
87+
window.removeEventListener('click', handleClickOutside)
88+
})
89+
</script>
90+
91+
<style scoped>
92+
.hover-bg:hover {
93+
background-color: #333 !important;
94+
color: #F16E00 !important;
95+
font-weight:bold
96+
}
97+
</style>
98+

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
"@splidejs/splide-extension-auto-scroll": "^0.5.3",
1919
"add": "^2.0.6",
2020
"boosted": "5.3.3",
21-
"bootstrap-icons": "^1.11.3",
21+
"bootstrap-icons": "^1.13.1",
2222
"google-fonts": "^1.0.0",
23-
"gsap": "^3.12.5",
23+
"gsap": "^3.13.0",
2424
"lottie-web": "^5.12.2",
2525
"module": "^1.2.5",
26-
"nuxi": "^3.12.0",
27-
"nuxt": "^3.12.3",
28-
"nuxt-delay-hydration": "^1.3.5",
26+
"nuxi": "^3.25.1",
27+
"nuxt": "^3.17.3",
28+
"nuxt-delay-hydration": "^1.3.8",
2929
"sass-loader": "^10.5.2",
30-
"vite": "^5.3.4",
31-
"vite-plugin-vue-inspector": "^5.1.2",
30+
"vite": "^5.4.19",
31+
"vite-plugin-vue-inspector": "^5.3.1",
3232
"vue": "latest",
3333
"vue3-marquee-slider": "^1.0.5"
3434
},
3535
"devDependencies": {
36-
"sass": "^1.77.8"
36+
"sass": "^1.88.0"
3737
}
3838
}

pages/test.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup>
2+
import { ref, computed } from 'vue'
3+
4+
const search = ref('')
5+
const suggestions = ['apple', 'banana', 'cherry', 'apricot']
6+
const filtered = computed(() =>
7+
search.value
8+
? suggestions.filter(item => item.toLowerCase().includes(search.value.toLowerCase()))
9+
: []
10+
)
11+
12+
const selectSuggestion = (item) => {
13+
search.value = item
14+
}
15+
</script>
16+
17+
<template>
18+
<div class="position-relative">
19+
<input
20+
v-model="search"
21+
type="text"
22+
class="form-control"
23+
placeholder="Search..."
24+
/>
25+
26+
<ul v-if="filtered.length" class="list-group position-absolute w-100 z-10">
27+
<li
28+
v-for="item in filtered"
29+
:key="item"
30+
class="list-group-item list-group-item-action"
31+
@click="selectSuggestion(item)"
32+
>
33+
{{ item }}
34+
</li>
35+
</ul>
36+
</div>
37+
</template>

0 commit comments

Comments
 (0)