Skip to content

Commit 38bde1e

Browse files
committed
improvements
Signed-off-by: rishichawda <[email protected]>
1 parent 0b84b65 commit 38bde1e

File tree

2 files changed

+283
-108
lines changed

2 files changed

+283
-108
lines changed

src/components/landing/hero.astro

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const navItems = [
66
// { label: "services", path: "#services" },
77
{ label: "articles", path: "/articles/" },
88
{ label: "gallery", path: "/gallery/" },
9-
{ label: "search", path: "/search/" },
109
];
1110
import logo from "../../../content/assets/logo/Group 489.svg";
1211
---
@@ -28,7 +27,7 @@ import logo from "../../../content/assets/logo/Group 489.svg";
2827
>
2928
<Image alt="logo" width={40} class="max-h-auto max-w-10" src={logo} />
3029
</div>
31-
<nav class="flex flex-wrap justify-center gap-1 md:gap-4">
30+
<nav class="flex flex-wrap justify-center gap-1 md:gap-4 items-center">
3231
{
3332
navItems.map((item) => (
3433
<a
@@ -40,6 +39,61 @@ import logo from "../../../content/assets/logo/Group 489.svg";
4039
</a>
4140
))
4241
}
42+
43+
<!-- Search Icon and Input -->
44+
<div class="relative">
45+
<button
46+
id="search-icon-btn"
47+
class="flex justify-center items-center px-3 md:px-4 h-[2.3125rem] rounded-lg text-white hover:bg-white/10 hover:cursor-pointer transition-colors focus:outline-none focus:ring-2 focus:ring-white/50"
48+
aria-label="Open search"
49+
>
50+
<svg
51+
xmlns="http://www.w3.org/2000/svg"
52+
class="h-4 w-4"
53+
fill="none"
54+
viewBox="0 0 24 24"
55+
stroke="currentColor"
56+
stroke-width="2"
57+
>
58+
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-6-6m2-5a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z" />
59+
</svg>
60+
</button>
61+
62+
<!-- Search Input Form (initially hidden) -->
63+
<form
64+
id="search-form"
65+
method="GET"
66+
action="/search/"
67+
class="absolute right-0 top-full mt-2 hidden z-50"
68+
>
69+
<div class="flex items-center gap-2 bg-white/95 backdrop-blur-sm rounded-lg p-2 shadow-lg border border-white/20 min-w-[280px]">
70+
<input
71+
type="text"
72+
name="q"
73+
id="search-input"
74+
placeholder="Search articles, gallery..."
75+
class="flex-1 px-3 py-2 text-sm border-0 bg-transparent text-gray-800 placeholder-gray-500 focus:outline-none font-['Montserrat_Variable']"
76+
autocomplete="on"
77+
/>
78+
<button
79+
type="submit"
80+
class="bg-brand-600 hover:bg-brand-700 text-white p-2 rounded-md transition-colors duration-200 flex-shrink-0"
81+
aria-label="Search"
82+
>
83+
<svg
84+
xmlns="http://www.w3.org/2000/svg"
85+
class="h-4 w-4"
86+
fill="none"
87+
viewBox="0 0 24 24"
88+
stroke="currentColor"
89+
stroke-width="2"
90+
>
91+
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-6-6m2-5a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z" />
92+
</svg>
93+
</button>
94+
</div>
95+
</form>
96+
</div>
4397
</nav>
4498
</div>
4599
</div>
@@ -182,3 +236,73 @@ import logo from "../../../content/assets/logo/Group 489.svg";
182236
</a>
183237
</div>
184238
</section>
239+
240+
<script>
241+
function searchInput() {
242+
const searchIconBtn = document.getElementById('search-icon-btn');
243+
const searchForm = document.getElementById('search-form');
244+
const searchInput = document.getElementById('search-input') as HTMLInputElement;
245+
246+
if (searchIconBtn && searchForm && searchInput) {
247+
searchIconBtn.addEventListener('click', function(e) {
248+
e.preventDefault();
249+
250+
// Show the search form with animation
251+
searchForm.classList.remove('hidden');
252+
searchForm.style.opacity = '0';
253+
searchForm.style.transform = 'translateY(-10px)';
254+
255+
// Animate in
256+
requestAnimationFrame(() => {
257+
searchForm.style.transition = 'opacity 0.2s ease-out, transform 0.2s ease-out';
258+
searchForm.style.opacity = '1';
259+
searchForm.style.transform = 'translateY(0)';
260+
});
261+
262+
// Focus on the input field
263+
setTimeout(() => searchInput.focus(), 100);
264+
});
265+
266+
// Function to close search form
267+
function closeSearchForm() {
268+
searchForm.style.transition = 'opacity 0.2s ease-out, transform 0.2s ease-out';
269+
searchForm.style.opacity = '0';
270+
searchForm.style.transform = 'translateY(-10px)';
271+
272+
setTimeout(() => {
273+
searchForm.classList.add('hidden');
274+
searchInput.value = '';
275+
}, 200);
276+
}
277+
278+
// Handle clicking outside to close the search form
279+
document.addEventListener('click', function(e) {
280+
const target = e.target as Node;
281+
if (!searchForm.contains(target) && !searchIconBtn.contains(target)) {
282+
closeSearchForm();
283+
}
284+
});
285+
286+
// Handle form submission
287+
searchForm.addEventListener('submit', function(e) {
288+
const query = searchInput.value.trim();
289+
if (!query) {
290+
e.preventDefault();
291+
return;
292+
}
293+
e.preventDefault();
294+
// Always navigate to /search?q=... (absolute path)
295+
window.location.href = `/search/?q=${encodeURIComponent(query)}`;
296+
});
297+
298+
// Handle escape key to close search
299+
searchInput.addEventListener('keydown', function(e) {
300+
if (e.key === 'Escape') {
301+
closeSearchForm();
302+
}
303+
});
304+
}
305+
}
306+
document.addEventListener('DOMContentLoaded', searchInput);
307+
document.addEventListener('astro:page-load', searchInput);
308+
</script>

0 commit comments

Comments
 (0)