forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileMenu.client.vue
More file actions
227 lines (209 loc) · 8.15 KB
/
MobileMenu.client.vue
File metadata and controls
227 lines (209 loc) · 8.15 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<script setup lang="ts">
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
import { useAtproto } from '~/composables/atproto/useAtproto'
import type { NavigationConfigWithGroups } from '~/types'
const isOpen = defineModel<boolean>('open', { default: false })
const { links } = defineProps<{
links: NavigationConfigWithGroups
}>()
const { isConnected, npmUser, avatar: npmAvatar } = useConnector()
const { user: atprotoUser } = useAtproto()
const navRef = useTemplateRef('navRef')
const { activate, deactivate } = useFocusTrap(navRef, { allowOutsideClick: true })
function closeMenu() {
isOpen.value = false
}
function handleShowConnector() {
const connectorModal = document.querySelector<HTMLDialogElement>('#connector-modal')
if (connectorModal) {
closeMenu()
connectorModal.showModal()
}
}
function handleShowAuth() {
const authModal = document.querySelector<HTMLDialogElement>('#auth-modal')
if (authModal) {
closeMenu()
authModal.showModal()
}
}
// Close menu on route change
const route = useRoute()
watch(() => route.fullPath, closeMenu)
// Close on escape
onKeyStroke(
e => isKeyWithoutModifiers(e, 'Escape') && isOpen.value,
e => {
isOpen.value = false
},
)
// Prevent body scroll when menu is open
const isLocked = useScrollLock(document)
watch(isOpen, open => (isLocked.value = open))
watch(isOpen, open => (open ? nextTick(activate) : deactivate()))
onUnmounted(deactivate)
</script>
<template>
<Teleport to="body">
<Transition
enter-active-class="transition-opacity duration-200"
leave-active-class="transition-opacity duration-150"
enter-from-class="opacity-0"
leave-to-class="opacity-0"
>
<div
v-if="isOpen"
class="fixed inset-0 z-[60] sm:hidden"
role="dialog"
aria-modal="true"
:aria-label="$t('nav.mobile_menu')"
>
<!-- Backdrop -->
<button
type="button"
class="absolute inset-0 bg-black/60 cursor-default"
:aria-label="$t('common.close')"
@click="closeMenu"
/>
<!-- Menu panel (slides in from right) -->
<Transition
enter-active-class="transition-transform duration-200"
enter-from-class="translate-x-full"
enter-to-class="translate-x-0"
leave-active-class="transition-transform duration-200"
leave-from-class="translate-x-0"
leave-to-class="translate-x-full"
>
<nav
v-if="isOpen"
ref="navRef"
class="absolute inset-ie-0 top-0 bottom-0 w-72 bg-bg border-is border-border shadow-xl flex flex-col"
>
<!-- Header -->
<div class="flex items-center justify-between p-4 border-b border-border">
<span class="font-mono text-sm text-fg-muted">{{ $t('nav.menu') }}</span>
<button
type="button"
class="p-2 -m-2 text-fg-subtle hover:text-fg transition-colors duration-200 focus-visible:outline-accent/70 rounded"
:aria-label="$t('common.close')"
@click="closeMenu"
>
<span class="i-carbon:close w-5 h-5" aria-hidden="true" />
</button>
</div>
<!-- Account section -->
<div class="px-2 py-2">
<span
class="px-3 py-2 block font-mono text-xs text-fg-subtle uppercase tracking-wider"
>
{{ $t('account_menu.account') }}
</span>
<!-- npm CLI connection status (only show if connected) -->
<button
v-if="isConnected && npmUser"
type="button"
class="w-full flex items-center gap-3 px-3 py-3 rounded-md font-mono text-sm text-fg hover:bg-bg-subtle transition-colors duration-200 text-start"
@click="handleShowConnector"
>
<img
v-if="npmAvatar"
:src="npmAvatar"
:alt="npmUser"
width="20"
height="20"
class="w-5 h-5 rounded-full object-cover"
/>
<span
v-else
class="w-5 h-5 rounded-full bg-bg-muted flex items-center justify-center"
>
<span class="i-carbon-terminal w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1">~{{ npmUser }}</span>
<span class="w-2 h-2 rounded-full bg-green-500" aria-hidden="true" />
</button>
<!-- Atmosphere connection status -->
<button
v-if="atprotoUser"
type="button"
class="w-full flex items-center gap-3 px-3 py-3 rounded-md font-mono text-sm text-fg hover:bg-bg-subtle transition-colors duration-200 text-start"
@click="handleShowAuth"
>
<img
v-if="atprotoUser.avatar"
:src="atprotoUser.avatar"
:alt="atprotoUser.handle"
width="20"
height="20"
class="w-5 h-5 rounded-full object-cover"
/>
<span
v-else
class="w-5 h-5 rounded-full bg-bg-muted flex items-center justify-center"
>
<span class="i-carbon-cloud w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1 truncate">@{{ atprotoUser.handle }}</span>
</button>
<!-- Connect Atmosphere button (show if not connected) -->
<button
v-else
type="button"
class="w-full flex items-center gap-3 px-3 py-3 rounded-md font-mono text-sm text-fg hover:bg-bg-subtle transition-colors duration-200 text-start"
@click="handleShowAuth"
>
<span class="w-5 h-5 rounded-full bg-bg-muted flex items-center justify-center">
<span class="i-carbon-cloud w-3 h-3 text-fg-muted" aria-hidden="true" />
</span>
<span class="flex-1">{{ $t('account_menu.connect_atmosphere') }}</span>
</button>
</div>
<!-- Divider -->
<div class="mx-4 my-2 border-t border-border" />
<!-- Navigation links -->
<div class="flex-1 overflow-y-auto overscroll-contain py-2">
<template v-for="(group, index) in links">
<div
v-if="group.type === 'separator'"
:key="`seperator-${index}`"
class="mx-4 my-2 border-t border-border"
/>
<div v-if="group.type === 'group'" :key="group.name" class="p-2">
<span
v-if="group.label"
class="px-3 py-2 font-mono text-xs text-fg-subtle uppercase tracking-wider"
>
{{ group.label }}
</span>
<div>
<NuxtLink
v-for="link in group.items"
:key="link.name"
:to="link.to"
:href="link.href"
:target="link.target"
class="flex items-center gap-3 px-3 py-3 rounded-md font-mono text-sm text-fg hover:bg-bg-subtle transition-colors duration-200"
@click="closeMenu"
>
<span
:class="link.iconClass"
class="w-5 h-5 text-fg-muted"
aria-hidden="true"
/>
{{ link.label }}
<span
v-if="link.external"
class="i-carbon:launch rtl-flip w-3 h-3 ms-auto text-fg-subtle"
aria-hidden="true"
/>
</NuxtLink>
</div>
</div>
</template>
</div>
</nav>
</Transition>
</div>
</Transition>
</Teleport>
</template>