-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathAppHeader.vue
More file actions
162 lines (142 loc) · 4.77 KB
/
AppHeader.vue
File metadata and controls
162 lines (142 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<script setup lang="ts">
import { LinkBase } from '#components'
const { open: openCommandPalette } = useCommandPalette()
const { commandPaletteShortcutLabel } = usePlatformModifierKey()
withDefaults(
defineProps<{
showLogo?: boolean
}>(),
{
showLogo: true,
},
)
const { isConnected, npmUser } = useConnector()
const { desktopLinks } = useGlobalNavLinks()
const showFullSearch = shallowRef(false)
const { env, prNumber } = useAppConfig().buildInfo
const route = useRoute()
const searchBoxRef = useTemplateRef('searchBoxRef')
const isOnHomePage = computed(() => route.name === 'index')
const isOnSearchPage = computed(() => route.name === 'search')
watch(
isOnSearchPage,
visible => {
if (!visible) return
searchBoxRef.value?.focus()
nextTick(() => {
searchBoxRef.value?.focus()
})
},
{ flush: 'sync' },
)
function handleSearchBlur() {
showFullSearch.value = false
}
function handleSearchFocus() {
showFullSearch.value = true
}
useShortcuts({
'c': () => ({ name: 'compare' }),
',': () => ({ name: 'settings' }),
})
</script>
<template>
<header class="hidden sm:block sticky top-0 z-50 border-b border-border">
<div class="absolute inset-0 bg-bg/80 backdrop-blur-md" />
<nav
:aria-label="$t('nav.main_navigation')"
class="relative container min-h-14 flex items-center gap-2 z-1 justify-end"
>
<!-- Desktop: Logo (navigates home) -->
<LogoContextMenu v-if="showLogo" class="hidden sm:flex flex-shrink-0 items-center">
<NuxtLink
:to="{ name: 'index' }"
:aria-label="$t('header.home')"
dir="ltr"
class="relative inline-flex items-center gap-1 py-2 header-logo font-mono text-lg font-medium text-fg hover:text-fg/90 transition-colors duration-200 me-4"
>
<AppLogo class="h-4.5 w-auto" />
<span
aria-hidden="true"
class="scale-35 transform-origin-br font-mono tracking-wide text-accent absolute bottom-0.75 -inset-ie-1"
>
{{ env === 'release' ? 'alpha' : env }}
</span>
</NuxtLink>
</LogoContextMenu>
<NuxtLink
v-if="showLogo && prNumber"
:to="`https://github.com/npmx-dev/npmx.dev/pull/${prNumber}`"
:aria-label="$t('header.pr', { prNumber })"
>
<span class="text-xs px-1.5 py-0.5 rounded badge-green font-sans font-medium">
PR #{{ prNumber }}
</span>
</NuxtLink>
<!-- Spacer when logo is hidden on desktop -->
<span v-else class="hidden sm:block w-1" />
<ButtonBase
type="button"
variant="secondary"
class="hidden lg:inline-flex shrink-0 gap-2 px-2.5 me-3"
:aria-label="$t('shortcuts.command_palette')"
:title="$t('shortcuts.command_palette_description', { ctrlKey: $t('shortcuts.ctrl_key') })"
@click="openCommandPalette"
>
<span>{{ $t('command_palette.quick_actions') }}</span>
<span class="inline-flex items-center gap-1 text-xs text-fg-subtle">
<kbd
class="inline-flex items-center justify-center rounded border border-border bg-bg-muted px-1.5 py-0.5 font-mono text-[0.7rem] text-fg-muted"
>
{{ commandPaletteShortcutLabel }}
</kbd>
</span>
</ButtonBase>
<!-- Center: Search bar + nav items -->
<div
class="flex-1 flex items-center md:gap-6"
:class="{
'justify-end': isOnHomePage,
'justify-center': !isOnHomePage,
}"
>
<!-- Search bar -->
<HeaderSearchBox
ref="searchBoxRef"
:class="{ 'max-w-md': !showFullSearch }"
@focus="handleSearchFocus"
@blur="handleSearchBlur"
/>
<ul
v-if="isConnected && npmUser"
:class="{ hidden: showFullSearch }"
class="hidden sm:flex items-center gap-4 sm:gap-6 list-none m-0 p-0"
>
<!-- Packages dropdown (when connected) -->
<li v-if="isConnected && npmUser" class="flex items-center">
<HeaderPackagesDropdown :username="npmUser" />
</li>
<!-- Orgs dropdown (when connected) -->
<li v-if="isConnected && npmUser" class="flex items-center">
<HeaderOrgsDropdown :username="npmUser" />
</li>
</ul>
</div>
<!-- End: Desktop nav items -->
<div class="hidden sm:flex flex-shrink-0 items-center gap-2">
<!-- Desktop: Explore link -->
<LinkBase
v-for="link in desktopLinks"
:key="link.name"
class="border-none"
variant="button-secondary"
:to="link.to"
:aria-keyshortcuts="link.keyshortcut"
>
{{ link.label }}
</LinkBase>
<HeaderAccountMenu />
</div>
</nav>
</header>
</template>