srcdev-nuxt-components 9.1.7 → 9.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,523 @@
1
+ <template>
2
+ <nav
3
+ ref="navRef"
4
+ class="tab-navigation"
5
+ :class="[
6
+ elementClasses,
7
+ `tab-navigation--${navAlign}`,
8
+ { 'is-collapsed': isCollapsed, 'is-loaded': isLoaded, 'menu-open': isMenuOpen },
9
+ ]"
10
+ aria-label="Site navigation"
11
+ >
12
+ <ul
13
+ v-if="!isCollapsed || !isLoaded"
14
+ ref="navListRef"
15
+ class="tab-nav-list"
16
+ @mousemove="handleNavMousemove"
17
+ @mouseleave="hoveredItemHref = null"
18
+ >
19
+ <li
20
+ v-for="item in navItemData.main"
21
+ :key="item.href"
22
+ :data-href="item.href"
23
+ :class="[item.cssName, { 'is-active': activeHref === item.href, 'is-hovered': hoveredItemHref === item.href }]"
24
+ >
25
+ <NuxtLink :href="item.href" :external="item.isExternal || undefined" class="tab-nav-link" data-nav-item>
26
+ <Icon v-if="item.iconName" :name="item.iconName" aria-hidden="true" />
27
+ {{ item.text }}
28
+ </NuxtLink>
29
+ </li>
30
+ <li aria-hidden="true" role="none" class="nav-indicator-li"><div class="nav__hovered"></div></li>
31
+ <li aria-hidden="true" role="none" class="nav-indicator-li"><div class="nav__active-indicator"></div></li>
32
+ </ul>
33
+
34
+ <InputButtonCore
35
+ v-if="isCollapsed && isLoaded"
36
+ class="tab-nav-burger"
37
+ :class="{ 'is-open': isMenuOpen }"
38
+ variant="tertiary"
39
+ :button-text="isMenuOpen ? 'Close navigation menu' : 'Open navigation menu'"
40
+ :aria-expanded="String(isMenuOpen)"
41
+ aria-controls="tab-nav-panel"
42
+ @click="toggleMenu"
43
+ >
44
+ <template #iconOnly>
45
+ <span class="burger-bar" aria-hidden="true"></span>
46
+ <span class="burger-bar" aria-hidden="true"></span>
47
+ <span class="burger-bar" aria-hidden="true"></span>
48
+ </template>
49
+ </InputButtonCore>
50
+
51
+ <Teleport to="body">
52
+ <div
53
+ v-if="isCollapsed && isLoaded"
54
+ class="tab-nav-backdrop"
55
+ :class="{ 'is-open': isMenuOpen }"
56
+ aria-hidden="true"
57
+ @click="closeMenu"
58
+ ></div>
59
+ </Teleport>
60
+
61
+ <div
62
+ v-if="isCollapsed && isLoaded"
63
+ id="tab-nav-panel"
64
+ class="tab-nav-panel"
65
+ :class="{ 'is-open': isMenuOpen }"
66
+ :inert="!isMenuOpen ? true : undefined"
67
+ >
68
+ <div class="tab-nav-panel-inner">
69
+ <ul class="tab-nav-panel-list">
70
+ <li v-for="item in navItemData.main" :key="item.href" :class="item.cssName">
71
+ <NuxtLink
72
+ :href="item.href"
73
+ :external="item.isExternal || undefined"
74
+ class="tab-nav-panel-link"
75
+ @click="closeMenu"
76
+ >
77
+ <Icon v-if="item.iconName" :name="item.iconName" aria-hidden="true" />
78
+ {{ item.text }}
79
+ </NuxtLink>
80
+ </li>
81
+ </ul>
82
+ </div>
83
+ </div>
84
+ </nav>
85
+ </template>
86
+
87
+ <script setup lang="ts">
88
+ import { useResizeObserver, onClickOutside } from "@vueuse/core";
89
+ import type { NavItemData } from "~/types/components";
90
+
91
+ interface Props {
92
+ navItemData: NavItemData;
93
+ navAlign?: "left" | "center" | "right";
94
+ styleClassPassthrough?: string | string[];
95
+ }
96
+
97
+ const props = withDefaults(defineProps<Props>(), {
98
+ navAlign: "left",
99
+ styleClassPassthrough: () => [],
100
+ });
101
+
102
+ const navRef = ref<HTMLElement | null>(null);
103
+ const navListRef = ref<HTMLUListElement | null>(null);
104
+
105
+ const isCollapsed = ref(false);
106
+ const isLoaded = useState("tab-nav-loaded", () => false);
107
+ const isMenuOpen = ref(false);
108
+
109
+ // Stored natural width of the list — used when the list is not in the DOM
110
+ let navListNaturalWidth = 0;
111
+
112
+ const checkOverflow = () => {
113
+ if (!navRef.value) return;
114
+
115
+ if (navListRef.value) {
116
+ navListNaturalWidth = navListRef.value.scrollWidth;
117
+ }
118
+
119
+ isCollapsed.value = navListNaturalWidth > navRef.value.clientWidth;
120
+ };
121
+
122
+ const toggleMenu = () => {
123
+ isMenuOpen.value = !isMenuOpen.value;
124
+ };
125
+
126
+ const closeMenu = () => {
127
+ isMenuOpen.value = false;
128
+ };
129
+
130
+ const route = useRoute();
131
+
132
+ // Compute the active nav item href from the current route.
133
+ // Prefers an exact match; falls back to the longest prefix match.
134
+ const activeHref = computed(() => {
135
+ const items = props.navItemData.main ?? [];
136
+ const exact = items.find((item) => item.href && route.path === item.href);
137
+ if (exact) return exact.href ?? null;
138
+ return (
139
+ items
140
+ .filter((item) => item.href && route.path.startsWith(item.href + "/"))
141
+ .sort((a, b) => (b.href?.length ?? 0) - (a.href?.length ?? 0))[0]?.href ?? null
142
+ );
143
+ });
144
+
145
+ const hoveredItemHref = ref<string | null>(null);
146
+
147
+ const handleNavMousemove = (event: MouseEvent) => {
148
+ const li = (event.target as HTMLElement).closest<HTMLElement>("li[data-href]");
149
+ if (!li) return;
150
+ hoveredItemHref.value = li.dataset.href ?? null;
151
+ };
152
+
153
+ watch(
154
+ () => route.path,
155
+ () => {
156
+ closeMenu();
157
+ },
158
+ { flush: "post" }
159
+ );
160
+
161
+ useResizeObserver(navRef, () => {
162
+ checkOverflow();
163
+ if (!isCollapsed.value) closeMenu();
164
+ });
165
+
166
+ onClickOutside(navRef, closeMenu);
167
+
168
+ onMounted(async () => {
169
+ await nextTick();
170
+ checkOverflow();
171
+ isLoaded.value = true;
172
+ });
173
+
174
+ const { elementClasses, resetElementClasses } = useStyleClassPassthrough(props.styleClassPassthrough);
175
+
176
+ watch(
177
+ () => props.styleClassPassthrough,
178
+ () => resetElementClasses(props.styleClassPassthrough)
179
+ );
180
+ </script>
181
+
182
+ <style lang="css">
183
+ @layer components {
184
+ .tab-nav-backdrop {
185
+ --_backdrop-bg: var(--tab-nav-backdrop-bg, oklch(0% 0 0 / 55%));
186
+ --_backdrop-blur: var(--tab-nav-backdrop-blur, 3px);
187
+ --_backdrop-duration: var(--tab-nav-backdrop-duration, 350ms);
188
+
189
+ position: fixed;
190
+ inset: 0;
191
+ z-index: 10;
192
+ background: var(--_backdrop-bg);
193
+ backdrop-filter: blur(var(--_backdrop-blur));
194
+ opacity: 0;
195
+ pointer-events: none;
196
+ transition: opacity var(--_backdrop-duration) ease;
197
+
198
+ &.is-open {
199
+ opacity: 1;
200
+ pointer-events: auto;
201
+ }
202
+ }
203
+
204
+ .tab-navigation {
205
+ /* ─── Public token API ────────────────────────────────────────────── */
206
+
207
+ /* Decorators — horizontal nav */
208
+ --_decorator-hovered-bg: var(--tab-nav-decorator-hovered-bg, transparent);
209
+ /* --_decorator-indicator-color: var(--tab-nav-decorator-indicator-color, var(--slate-01, currentColor)); */
210
+ --_decorator-indicator-color: red;
211
+
212
+ /* Horizontal nav */
213
+ --_link-color: var(--tab-nav-link-color, var(--slate-01, currentColor));
214
+ --_link-hover-color: var(--tab-nav-link-hover-color, var(--slate-04, var(--_link-color)));
215
+ --_link-active-color: var(--tab-nav-link-active-color, var(--slate-01, var(--_link-color)));
216
+ --_link-size: var(--tab-nav-link-size, 1.6rem);
217
+ --_link-tracking: var(--tab-nav-link-tracking, 0.06em);
218
+ --_link-weight: var(--tab-nav-link-weight, 400);
219
+ --_nav-gap: var(--tab-nav-gap, 2.2rem);
220
+ --_nav-transition: var(--tab-nav-transition, 250ms ease);
221
+
222
+ /* Panel */
223
+ --_panel-bg: var(--tab-nav-panel-bg, var(--page-bg, #1a1614));
224
+ --_panel-border-color: var(
225
+ --tab-nav-panel-border-color,
226
+ color-mix(in oklch, var(--slate-01, #c0847a) 35%, transparent)
227
+ );
228
+ --_panel-item-border: var(--tab-nav-panel-item-border, color-mix(in oklch, var(--slate-01, white) 8%, transparent));
229
+ --_panel-link-color: var(--tab-nav-panel-link-color, var(--slate-01, currentColor));
230
+ --_panel-link-hover-color: var(--tab-nav-panel-link-hover-color, var(--slate-04, var(--_panel-link-color)));
231
+ --_panel-link-active-color: var(--tab-nav-panel-link-active-color, var(--slate-01, var(--_panel-link-color)));
232
+ --_panel-padding-block: var(--tab-nav-panel-padding-block, 1.4rem);
233
+ --_panel-padding-inline: var(--tab-nav-panel-padding-inline, 1.5rem);
234
+ --_panel-slide-duration: var(--tab-nav-panel-slide-duration, 350ms);
235
+ --_panel-slide-easing: var(--tab-nav-panel-slide-easing, cubic-bezier(0.4, 0, 0.2, 1));
236
+
237
+ /* Burger */
238
+ --_burger-bar-width: var(--tab-nav-burger-width, 22px);
239
+ --_burger-bar-height: var(--tab-nav-burger-height, 1.5px);
240
+ --_burger-bar-gap: var(--tab-nav-burger-gap, 5px);
241
+ --_burger-color: var(--tab-nav-burger-color, var(--slate-01, currentColor));
242
+ --_burger-transition: var(--tab-nav-burger-transition, 300ms ease);
243
+
244
+ /* ─────────────────────────────────────────────────────────────────── */
245
+
246
+ display: flex;
247
+ align-items: center;
248
+ min-width: 0;
249
+
250
+ /* Hide everything until first measurement to prevent wrong-state flash */
251
+ &:not(.is-loaded) {
252
+ opacity: 0;
253
+ }
254
+
255
+ /* ─── Horizontal list ───────────────────────────────────────────── */
256
+
257
+ .tab-nav-list {
258
+ list-style: none;
259
+ margin: 0;
260
+ padding: 0;
261
+ display: flex;
262
+ gap: var(--_nav-gap);
263
+ align-items: center;
264
+ position: relative;
265
+
266
+ .nav-indicator-li {
267
+ /* display: contents removes the li's box entirely — children become
268
+ direct participants in the flex container, so position: absolute
269
+ on .nav__hovered / .nav__active-indicator resolves against
270
+ .tab-nav-list (same containing block as the anchor li elements).
271
+ Without this, .nav-indicator-li is the containing block, which is
272
+ a different scope and Chrome's anchor positioning rejects it. */
273
+ display: contents;
274
+ }
275
+
276
+ /* Indicators hidden by default — shown only with anchor positioning support */
277
+ .nav__hovered,
278
+ .nav__active-indicator {
279
+ display: none;
280
+ pointer-events: none;
281
+ }
282
+
283
+ .tab-nav-link {
284
+ display: flex;
285
+ align-items: center;
286
+ gap: 0.4em;
287
+ color: var(--_link-color);
288
+ font-size: var(--_link-size);
289
+ font-weight: var(--_link-weight);
290
+ letter-spacing: var(--_link-tracking);
291
+ text-decoration: none;
292
+ text-wrap: nowrap;
293
+ padding-block: 0.8rem;
294
+ padding-inline: 0.4rem;
295
+ position: relative;
296
+ z-index: 4;
297
+ transition: color var(--_nav-transition);
298
+
299
+ &:hover,
300
+ &:focus-visible {
301
+ color: var(--_link-hover-color);
302
+ outline: none;
303
+ }
304
+
305
+ &.router-link-exact-active {
306
+ color: var(--_link-active-color);
307
+ }
308
+ }
309
+ }
310
+
311
+ /* ─── Alignment variants ────────────────────────────────────────── */
312
+
313
+ &.tab-navigation--center .tab-nav-list {
314
+ margin-inline: auto;
315
+ }
316
+
317
+ &.tab-navigation--right .tab-nav-list {
318
+ margin-inline-start: auto;
319
+ }
320
+
321
+ &.is-collapsed {
322
+ justify-content: end;
323
+ }
324
+
325
+ /* ─── Burger button (InputButtonCore) ──────────────────────────── */
326
+
327
+ .tab-nav-burger.input-button-core.icon-only {
328
+ margin-inline-start: auto;
329
+ color: var(--_burger-color);
330
+
331
+ /* Strip all InputButtonCore visual styling */
332
+ background: none;
333
+ border: none;
334
+ outline: none;
335
+ text-decoration: none;
336
+ padding: 8px;
337
+ border-radius: 4px;
338
+ transition: outline-color var(--_nav-transition);
339
+
340
+ &.icon-only {
341
+ aspect-ratio: unset;
342
+ border-radius: 4px;
343
+
344
+ .btn-icon {
345
+ margin: 0;
346
+ display: flex;
347
+ flex-direction: column;
348
+ gap: var(--_burger-bar-gap);
349
+ }
350
+ }
351
+
352
+ &:focus-visible {
353
+ outline: 2px solid var(--_burger-color);
354
+ outline-offset: 4px;
355
+ }
356
+ }
357
+
358
+ .burger-bar {
359
+ display: block;
360
+ width: var(--_burger-bar-width);
361
+ height: var(--_burger-bar-height);
362
+ background: currentColor;
363
+ border-radius: 1px;
364
+ transform-origin: center;
365
+ transition:
366
+ transform var(--_burger-transition),
367
+ opacity var(--_burger-transition);
368
+ }
369
+
370
+ .tab-nav-burger.is-open {
371
+ .burger-bar:nth-child(1) {
372
+ transform: translateY(calc(var(--_burger-bar-height) + var(--_burger-bar-gap))) rotate(45deg);
373
+ }
374
+
375
+ .burger-bar:nth-child(2) {
376
+ opacity: 0;
377
+ transform: scaleX(0);
378
+ }
379
+
380
+ .burger-bar:nth-child(3) {
381
+ transform: translateY(calc(-1 * (var(--_burger-bar-height) + var(--_burger-bar-gap)))) rotate(-45deg);
382
+ }
383
+ }
384
+
385
+ /* ─── Mobile drop panel ─────────────────────────────────────────── */
386
+
387
+ .tab-nav-panel {
388
+ position: absolute;
389
+ left: 0;
390
+ right: 0;
391
+ top: 100%;
392
+
393
+ display: grid;
394
+ grid-template-rows: 0fr;
395
+ border-block-start: 1px solid transparent;
396
+ transition:
397
+ grid-template-rows var(--_panel-slide-duration) var(--_panel-slide-easing),
398
+ border-color var(--_panel-slide-duration) var(--_panel-slide-easing);
399
+
400
+ z-index: 1;
401
+
402
+ &.is-open {
403
+ grid-template-rows: 1fr;
404
+ border-block-start-color: var(--_panel-border-color);
405
+ }
406
+
407
+ .tab-nav-panel-inner {
408
+ overflow: hidden;
409
+ background-color: var(--_panel-bg);
410
+ }
411
+
412
+ .tab-nav-panel-list {
413
+ list-style: none;
414
+ margin: 0;
415
+ padding: 0;
416
+
417
+ li {
418
+ border-block-end: 1px solid var(--_panel-item-border);
419
+
420
+ &:last-child {
421
+ border-block-end: none;
422
+ }
423
+
424
+ &:hover {
425
+ background-color: color-mix(in oklch, var(--slate-01, white) 5%, transparent);
426
+ }
427
+ }
428
+
429
+ .tab-nav-panel-link {
430
+ display: flex;
431
+ align-items: center;
432
+ gap: 0.5em;
433
+ color: var(--_panel-link-color);
434
+ font-size: var(--_link-size);
435
+ font-weight: var(--_link-weight);
436
+ letter-spacing: var(--_link-tracking);
437
+ text-decoration: none;
438
+ padding-block: var(--_panel-padding-block);
439
+ padding-inline: var(--_panel-padding-inline);
440
+ position: relative;
441
+ z-index: 1;
442
+ transition: color var(--_nav-transition);
443
+
444
+ &:hover,
445
+ &:focus-visible {
446
+ color: var(--_panel-link-hover-color);
447
+ outline: none;
448
+ }
449
+
450
+ &.router-link-exact-active {
451
+ color: var(--_panel-link-active-color);
452
+ }
453
+ }
454
+ }
455
+ }
456
+ }
457
+
458
+ /* ─── Anchor positioning for nav indicators ──────────────────────────────
459
+ anchor-name is declared unconditionally so the @oddbird polyfill can
460
+ read it on browsers without native support (the polyfill checks for
461
+ anchor-name in raw CSS text, but skips rules inside a failing @supports).
462
+ The display guard stays inside @supports so indicators are hidden on
463
+ truly old browsers where neither native CSS nor the polyfill will work.
464
+ Requires Chrome 125+, Edge 125+, Firefox 131+, or the polyfill.
465
+ ──────────────────────────────────────────────────────────────────────── */
466
+
467
+ /* Single anchor --tab-nav-indicator tracks the hovered item, or falls back
468
+ to the active item when nothing is hovered. No dual anchor-names needed. */
469
+
470
+ /* Nothing hovered: anchor sits on the active item */
471
+ .tab-navigation .tab-nav-list:not(:has(.is-hovered)) li.is-active {
472
+ anchor-name: --tab-nav-indicator;
473
+ }
474
+
475
+ /* Something hovered: anchor sits on the hovered item */
476
+ .tab-navigation .tab-nav-list li.is-hovered {
477
+ anchor-name: --tab-nav-indicator;
478
+ }
479
+
480
+ /* @supports (anchor-name: --x) { */
481
+ /* Hover highlight: background pill that follows the pointer */
482
+ .tab-navigation .tab-nav-list .nav__hovered {
483
+ display: block;
484
+ position: absolute;
485
+ position-anchor: --tab-nav-indicator;
486
+ left: anchor(left);
487
+ right: anchor(right);
488
+ top: 0;
489
+ bottom: 0;
490
+ opacity: 0;
491
+ pointer-events: none;
492
+ transition:
493
+ left 200ms ease,
494
+ right 200ms ease,
495
+ opacity 150ms ease;
496
+ background: var(--tab-nav-decorator-hovered-bg, transparent);
497
+ border-radius: 4px;
498
+ z-index: 1;
499
+ }
500
+
501
+ .tab-navigation .tab-nav-list:has(.is-hovered) .nav__hovered {
502
+ opacity: 1;
503
+ }
504
+
505
+ /* Active indicator bar: always follows --tab-nav-indicator */
506
+ .tab-navigation .tab-nav-list .nav__active-indicator {
507
+ display: block;
508
+ position: absolute;
509
+ position-anchor: --tab-nav-indicator;
510
+ left: anchor(left);
511
+ right: anchor(right);
512
+ bottom: 0;
513
+ height: 2px;
514
+ pointer-events: none;
515
+ transition:
516
+ left 200ms ease,
517
+ right 200ms ease;
518
+ background-color: var(--tab-nav-decorator-indicator-color, var(--slate-01, currentColor));
519
+ z-index: 3;
520
+ }
521
+ /* } */
522
+ }
523
+ </style>