feat: Create mobile filter drawer UI and logic

This commit is contained in:
Kerby Martino (aider) committed 2025-05-11 03:35:27 +08:00
1 parent bdffb23613
commit c7a58dfaca
1 file changed
+163 -3
+163 -3
View File
@@ -1,7 +1,19 @@
<!-- Filter Section --> <!-- Filter Section -->
<section class="bg-white py-4 border-b border-gray-200 text-sm"> <section class="bg-white py-2 sm:py-4 border-b border-gray-200 text-sm">
<div class="container mx-auto px-4 sm:px-16 md:px-10 lg:px-12 xl:px-24 xxl:px-32"> <div class="container mx-auto px-4 sm:px-16 md:px-10 lg:px-12 xl:px-24 xxl:px-32">
<div class="flex flex-wrap justify-between items-center gap-4"> <!-- Mobile Filter Trigger -->
<div class="sm:hidden flex justify-between items-center">
<span class="text-base font-semibold text-gray-800">Filters & Sort</span>
<button id="open-mobile-filters-btn" class="bg-indigo-700 text-white font-semibold py-2 px-4 rounded-lg text-sm inline-flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h6a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z" clip-rule="evenodd" />
</svg>
Show Filters
</button>
</div>
<!-- Desktop Filters -->
<div class="hidden sm:flex flex-wrap justify-between items-center gap-4">
<!-- Filters Group --> <!-- Filters Group -->
<div class="flex flex-wrap gap-4 items-center"> <div class="flex flex-wrap gap-4 items-center">
<!-- Geolocation Filter --> <!-- Geolocation Filter -->
@@ -173,6 +185,154 @@
</div> </div>
</div> </div>
</div> </div>
</div> <!-- Closing main flex container for filters and sorting --> </div> <!-- Closing main flex container for desktop filters and sorting -->
</div> </div>
<!-- Mobile Filter Drawer -->
<div id="mobile-filters-drawer" class="fixed inset-x-0 bottom-0 z-[60] bg-white shadow-[0_-4px_15px_-3px_rgba(0,0,0,0.1)] transform translate-y-full transition-transform duration-300 ease-in-out flex flex-col" style="max-height: 90vh;">
<!-- Drawer Header -->
<div class="flex items-center justify-between p-4 border-b border-gray-200">
<div class="w-8 h-1 bg-gray-300 rounded-full mx-auto absolute top-2 left-1/2 -translate-x-1/2"></div> <!-- Drag handle -->
<h3 class="text-lg font-semibold text-gray-800 flex-1 text-center">Filters & Sort</h3>
<button id="close-mobile-filters-btn" class="text-gray-500 hover:text-gray-700 p-1 rounded-full hover:bg-gray-100">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<!-- Drawer Scrollable Content -->
<div class="overflow-y-auto p-4 space-y-4 flex-1">
<!-- Location Filter Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Location</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden pt-2 pl-2 pr-2 space-y-2">
<input type="text" placeholder="Type city or area..." class="w-full px-3 py-2 border border-gray-300 rounded-base text-sm focus:outline-none focus:ring-1 focus:ring-indigo-700 focus:border-indigo-700">
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Nearby</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Anywhere</a>
<!-- Placeholder for city list -->
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Manila</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Makati</a>
</div>
</div>
<!-- Availability Filter Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Availability</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden pt-2 pl-2 pr-2 space-y-2">
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Open Now</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Open Always</a>
<input type="text" placeholder="e.g., 1 hour from now" class="w-full px-3 py-2 border border-gray-300 rounded-base text-sm focus:outline-none focus:ring-1 focus:ring-indigo-700 focus:border-indigo-700">
</div>
</div>
<!-- Rates Filter Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Rates</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden pt-2 pl-2 pr-2 space-y-2">
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Hourly</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Daily</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Weekly</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Monthly</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Annually</a>
</div>
</div>
<!-- Space Type Filter Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Space Type</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden pt-2 pl-2 pr-2 space-y-2">
{% assign space_types = "Coworking,Room,Conference,Event Space,Virtual Office" | split: "," %}
{% for type in space_types %}
<label class="flex items-center px-2 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm cursor-pointer">
<input type="checkbox" class="appearance-none h-5 w-5 border-2 border-gray-300 rounded-sm focus:ring-indigo-700 checked:bg-indigo-700 checked:border-indigo-700">
<span class="ml-2">{{ type }}</span>
</label>
{% endfor %}
</div>
</div>
<!-- Price Range Filter Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Price Range</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden p-3 space-y-3">
<div id="slider-distance-mobile" slider class="pb-4">
<div class="relative h-4 flex items-center my-3">
<div class="h-1 bg-gray-300" inverse-left style="width:10%;"></div>
<div class="h-1 bg-gray-300" inverse-right style="width:30%;"></div>
<div range class="h-1 bg-indigo-700" style="left:10%;right:30%;"></div>
<span class="block h-4 w-4 bg-indigo-700 rounded-full shadow" style="left:10%;" thumb></span>
<span class="block h-4 w-4 bg-indigo-700 rounded-full shadow" style="left:70%;" thumb></span>
<div sign class="-mt-2 text-xs text-gray-700" style="left:10%;">
<span id="minSliderValueDisplay-mobile">$100</span>
</div>
<div sign class="-mt-2 text-xs text-gray-700" style="left:70%;">
<span id="maxSliderValueDisplay-mobile">$700</span>
</div>
</div>
<input id="minRangeSlider-mobile" max="1000" min="0"
oninput="var minS = this; var maxS = this.parentNode.children[2]; minS.value = Math.min(parseInt(minS.value), parseInt(maxS.value) - 1); var valP = (100/(parseInt(minS.max)-parseInt(minS.min)))*parseInt(minS.value)-(100/(parseInt(minS.max)-parseInt(minS.min)))*parseInt(minS.min); var visElems = this.parentNode.children[0].children; visElems[0].style.width=valP+'%'; visElems[2].style.left=valP+'%'; visElems[3].style.left=valP+'%'; visElems[5].style.left=valP+'%'; document.getElementById('minSliderValueDisplay-mobile').innerHTML='$'+minS.value; document.getElementById('minPriceInput-mobile').value=minS.value;"
step="1" tabindex="0" type="range" value="100"/>
<input id="maxRangeSlider-mobile" max="1000" min="0"
oninput="var maxS = this; var minS = this.parentNode.children[1]; maxS.value = Math.max(parseInt(maxS.value), parseInt(minS.value) + 1); var valP = (100/(parseInt(maxS.max)-parseInt(maxS.min)))*parseInt(maxS.value)-(100/(parseInt(maxS.max)-parseInt(maxS.min)))*parseInt(maxS.min); var visElems = this.parentNode.children[0].children; visElems[1].style.width=(100-valP)+'%'; visElems[2].style.right=(100-valP)+'%'; visElems[4].style.left=valP+'%'; visElems[6].style.left=valP+'%'; document.getElementById('maxSliderValueDisplay-mobile').innerHTML='$'+maxS.value; document.getElementById('maxPriceInput-mobile').value=maxS.value;"
step="1" tabindex="0" type="range" value="700"/>
</div>
<div class="flex justify-between items-center mt-4 space-x-2">
<input type="number" id="minPriceInput-mobile" value="100" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-indigo-700 focus:border-indigo-700"
oninput="var minSlider = document.getElementById('minRangeSlider-mobile'); var maxSlider = document.getElementById('maxRangeSlider-mobile'); var val = parseInt(this.value); if (isNaN(val)) { this.value = minSlider.value; return; } if (val >= parseInt(maxSlider.value)) val = parseInt(maxSlider.value) -1; if (val < parseInt(minSlider.min)) val = parseInt(minSlider.min); this.value = val; minSlider.value = val; minSlider.dispatchEvent(new Event('input'));">
<span class="text-gray-500 text-sm">-</span>
<input type="number" id="maxPriceInput-mobile" value="700" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-indigo-700 focus:border-indigo-700"
oninput="var minSlider = document.getElementById('minRangeSlider-mobile'); var maxSlider = document.getElementById('maxRangeSlider-mobile'); var val = parseInt(this.value); if (isNaN(val)) { this.value = maxSlider.value; return; } if (val <= parseInt(minSlider.value)) val = parseInt(minSlider.value) + 1; if (val > parseInt(maxSlider.max)) val = parseInt(maxSlider.max); this.value = val; maxSlider.value = val; maxSlider.dispatchEvent(new Event('input'));">
</div>
</div>
</div>
<!-- Sort By Accordion -->
<div>
<button type="button" class="accordion-toggle-mobile w-full flex justify-between items-center py-3 px-2 text-left text-sm font-semibold text-gray-700 hover:bg-gray-50 rounded-md">
<span>Sort By</span>
<svg class="accordion-icon-mobile h-5 w-5 transform transition-transform duration-200" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
<div class="accordion-content-mobile hidden pt-2 pl-2 pr-2 space-y-2">
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Relevance</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Newest</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Price: High to Low</a>
<a href="#" class="block px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-sm">Price: Low to High</a>
</div>
</div>
</div>
<!-- Drawer Footer -->
<div class="p-4 border-t border-gray-200 flex justify-between items-center sticky bottom-0 bg-white">
<button id="reset-mobile-filters-btn" class="text-gray-700 hover:text-indigo-700 font-semibold py-2 px-4 rounded-lg text-sm border border-gray-300 hover:border-indigo-600">Clear All</button>
<button id="apply-mobile-filters-btn" class="bg-indigo-700 hover:bg-indigo-800 text-white font-semibold py-2 px-6 rounded-lg text-sm">Apply Filters</button>
</div>
</div>
<!-- Overlay for mobile drawer -->
<div id="mobile-filters-overlay" class="fixed inset-0 z-50 bg-black bg-opacity-50 hidden"></div>
</section> </section>