11<script setup lang="ts">
2- import { debounce } from ' perfect-debounce'
3-
42withDefaults (
53 defineProps <{
64 showLogo? : boolean
@@ -15,28 +13,8 @@ withDefaults(
1513const { isConnected, npmUser } = useConnector ()
1614
1715const router = useRouter ()
18- const route = useRoute ()
19-
20- const searchQuery = ref (' ' )
21- const isSearchFocused = ref (false )
22-
23- const showSearchBar = computed (() => {
24- return route .name !== ' search' && route .name !== ' index'
25- })
26-
27- const debouncedNavigate = debounce (async () => {
28- const query = searchQuery .value .trim ()
29- await router .push ({
30- name: ' search' ,
31- query: query ? { q: query } : undefined ,
32- })
33- // allow time for the navigation to occur before resetting searchQuery
34- setTimeout (() => (searchQuery .value = ' ' ), 1000 )
35- }, 100 )
3616
37- async function handleSearchInput() {
38- debouncedNavigate ()
39- }
17+ const showFullSearch = ref (false )
4018
4119onKeyStroke (' ,' , e => {
4220 // Don't trigger if user is typing in an input
@@ -57,7 +35,7 @@ onKeyStroke(',', e => {
5735 class =" container h-14 flex items-center justify-start"
5836 >
5937 <!-- Start: Logo -->
60- <div class =" flex-shrink-0" >
38+ <div :class = " { 'hidden sm:block': showFullSearch } " class =" flex-shrink-0" >
6139 <NuxtLink
6240 v-if =" showLogo"
6341 to =" /"
@@ -71,41 +49,17 @@ onKeyStroke(',', e => {
7149 </div >
7250
7351 <!-- Center: Search bar + nav items -->
74- <div class =" flex-1 flex items-center justify-center gap-4 sm:gap-6" >
75- <!-- Search bar (shown on all pages except home and search) -->
76- <search v-if =" showSearchBar" class =" hidden sm:block flex-1 max-w-md" >
77- <form method =" GET" action =" /search" class =" relative" @submit.prevent =" handleSearchInput" >
78- <label for =" header-search" class =" sr-only" >
79- {{ $t('search.label') }}
80- </label >
81-
82- <div class =" relative group" :class =" { 'is-focused': isSearchFocused }" >
83- <div class =" search-box relative flex items-center" >
84- <span
85- class =" absolute inset-is-3 text-fg-subtle font-mono text-sm pointer-events-none transition-colors duration-200 motion-reduce:transition-none group-focus-within:text-accent z-1"
86- >
87- /
88- </span >
89-
90- <input
91- id =" header-search"
92- v-model =" searchQuery"
93- type =" search"
94- name =" q"
95- :placeholder =" $t('search.placeholder')"
96- v-bind =" noCorrect"
97- class =" w-full bg-bg-subtle border border-border rounded-md ps-7 pe-3 py-1.5 font-mono text-sm text-fg placeholder:text-fg-subtle transition-border-color duration-300 motion-reduce:transition-none focus:border-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
98- @input =" handleSearchInput"
99- @focus =" isSearchFocused = true"
100- @blur =" isSearchFocused = false"
101- />
102- <button type =" submit" class =" sr-only" >{{ $t('search.button') }}</button >
103- </div >
104- </div >
105- </form >
106- </search >
107-
108- <ul class =" flex items-center gap-4 sm:gap-6 list-none m-0 p-0" >
52+ <div class =" flex-1 flex items-center justify-center md:gap-6 mx-2" >
53+ <!-- Search bar (shown on all pages except home) -->
54+ <SearchBox
55+ :inputClass =" showFullSearch ? '' : 'max-w[6rem]'"
56+ @focus =" showFullSearch = true"
57+ @blur =" showFullSearch = false"
58+ />
59+ <ul
60+ :class =" { 'hidden sm:flex': showFullSearch }"
61+ class =" flex items-center gap-4 sm:gap-6 list-none m-0 p-0"
62+ >
10963 <!-- Packages dropdown (when connected) -->
11064 <li v-if =" isConnected && npmUser" class =" flex items-center" >
11165 <HeaderPackagesDropdown :username =" npmUser" />
@@ -119,11 +73,13 @@ onKeyStroke(',', e => {
11973 </div >
12074
12175 <!-- End: Bookmarks + Settings + Connector -->
122- <div class =" flex-shrink-0 flex items-center gap-4 sm:gap-6 ms-auto sm:ms-0" >
76+ <div
77+ :class =" { 'hidden sm:flex': showFullSearch }"
78+ class =" flex-shrink-0 flex items-center gap-4 sm:gap-6 ms-auto sm:ms-0"
79+ >
12380 <ClientOnly >
12481 <HeaderBookmarksDropdown />
12582 </ClientOnly >
126-
12783 <NuxtLink
12884 to =" /about"
12985 class =" sm:hidden link-subtle font-mono text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 rounded"
0 commit comments