@eldrajs/theme-cli 0.2.1 → 0.2.3

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.
Files changed (67) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/previews.json +35 -35
  3. package/template/.github/workflows/eldra-deploy.yml +29 -2
  4. package/template/.gitlab-ci.yml +37 -10
  5. package/template/README.md +4 -4
  6. package/template/app/composables/useFormSpam.ts +1 -0
  7. package/template/app/plugins/chunk-reload.client.ts +29 -0
  8. package/template/app/plugins/eldra-storefront.ts +8 -0
  9. package/template/app/storefront/gateway.ts +34 -11
  10. package/template/app/storefront/sharedRead.ts +34 -0
  11. package/template/app/storefront/structuredData.ts +17 -0
  12. package/template/app/utils/chunkReload.ts +11 -0
  13. package/template/bitbucket-pipelines.yml +26 -6
  14. package/template/blocks/announcement-bar/preview.png +0 -0
  15. package/template/blocks/article/preview.png +0 -0
  16. package/template/blocks/article-list/preview.png +0 -0
  17. package/template/blocks/breadcrumbs/preview.png +0 -0
  18. package/template/blocks/cart/preview.png +0 -0
  19. package/template/blocks/collection-grid/Block.vue +146 -94
  20. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  21. package/template/blocks/collection-grid/preview.png +0 -0
  22. package/template/blocks/collection-header/preview.png +0 -0
  23. package/template/blocks/contact/preview.png +0 -0
  24. package/template/blocks/cta/preview.png +0 -0
  25. package/template/blocks/faq/preview.png +0 -0
  26. package/template/blocks/feature-grid/preview.png +0 -0
  27. package/template/blocks/footer/Block.vue +11 -4
  28. package/template/blocks/footer/__tests__/Block.spec.ts +68 -3
  29. package/template/blocks/footer/preview.png +0 -0
  30. package/template/blocks/form/preview.png +0 -0
  31. package/template/blocks/gallery/preview.png +0 -0
  32. package/template/blocks/hero/preview.png +0 -0
  33. package/template/blocks/image/preview.png +0 -0
  34. package/template/blocks/logo-cloud/preview.png +0 -0
  35. package/template/blocks/navigation/Block.vue +125 -541
  36. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  37. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  38. package/template/blocks/navigation/preview.png +0 -0
  39. package/template/blocks/newsletter/preview.png +0 -0
  40. package/template/blocks/order-status/preview.png +0 -0
  41. package/template/blocks/pricing-table/preview.png +0 -0
  42. package/template/blocks/product-carousel/preview.png +0 -0
  43. package/template/blocks/product-detail/preview.png +0 -0
  44. package/template/blocks/quote/preview.png +0 -0
  45. package/template/blocks/rich-text/preview.png +0 -0
  46. package/template/blocks/search/preview.png +0 -0
  47. package/template/blocks/split-content/preview.png +0 -0
  48. package/template/blocks/stats/preview.png +0 -0
  49. package/template/blocks/tabs/preview.png +0 -0
  50. package/template/blocks/team/preview.png +0 -0
  51. package/template/blocks/testimonials/preview.png +0 -0
  52. package/template/blocks/timeline/preview.png +0 -0
  53. package/template/blocks/trust-strip/preview.png +0 -0
  54. package/template/blocks/video-embed/preview.png +0 -0
  55. package/template/blocks/wishlist/preview.png +0 -0
  56. package/template/test/chunkReload.spec.ts +20 -0
  57. package/template/test/imageFraming.browser.spec.ts +125 -0
  58. package/template/test/pages/article.spec.ts +1 -1
  59. package/template/test/pages/collection.spec.ts +1 -1
  60. package/template/test/pages/home.spec.ts +1 -1
  61. package/template/test/pages/product.spec.ts +1 -1
  62. package/template/test/prerenderRefresh.browser.spec.ts +8 -13
  63. package/template/test/storefront/gateway.spec.ts +6 -0
  64. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  65. package/template/test/storefront/sharedRead.spec.ts +43 -0
  66. package/template/test/storefront/structuredData.spec.ts +31 -0
  67. package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
@@ -1,69 +1,35 @@
1
1
  <script setup lang="ts">
2
- /**
3
- * Header (design spec 2, lines 76-238). apiId stays `navigation` (renaming it
4
- * would orphan every Studio page that uses it); `Header` is only the display name.
5
- *
6
- * Layout: a 4-column grid (`auto minmax(0,1fr) auto auto`) whose DOM order is always
7
- * `menuButton, brand, links, search, actions` (the menu button only while the drawer has something
8
- * to show — see `drawerHasContent`) — the same "DOM order stays sensible for screen
9
- * readers, CSS reorders visually" approach the pre-rebuild block used for its `centered` variant
10
- * (see its own comment, now generalised). Hiding the menu button at `@content:` (64rem of *block*
11
- * width, not viewport — every breakpoint here is a `@container` variant measured against
12
- * `Section`'s own `@container` root, which `as="header"` keeps) or hiding the links list below it
13
- * lets the grid's implicit auto-placement
14
- * produce the right column order for `default`/`minimal` with no explicit `col-start` at all;
15
- * `centered` needs explicit placement because its visual order (search, brand, actions, with links
16
- * on a second row) differs from DOM order.
17
- *
18
- * Mega-menus are theme-drawn disclosures (`<button aria-expanded aria-controls>` + a panel placed
19
- * right after the trigger in the DOM), not a package component — the design spec is explicit that
20
- * they are "non-modal disclosures, never dialogs" and the plan's "Uses" list for this block never
21
- * names a popover/select primitive. A link's own `children` are its mega-menu, and consecutive
22
- * children sharing a `group` become one column, in order.
23
- *
24
- * An open panel spans the header's own content container rather than hanging under the trigger at
25
- * some width of its own: it is positioned against the `<nav>`, which *is* that container (the box
26
- * inside `Container`'s max-width and gutters), so `left-0 right-0` lands its edges exactly on the
27
- * brand's left edge and the actions' right edge whichever item opened it — the same box on every
28
- * variant, since each one lays its bar out inside the same `Container`. Its columns are a plain
29
- * 12-column grid, three columns per group, so four groups fill the row and one to three sit
30
- * left-aligned at the same width instead of stretching to fill — inset from the panel's own edges
31
- * rather than flush against them, so the first group's text and the trailing "View all" each keep
32
- * a 32px margin from the edge the panel shares with the brand and the actions above it (24px on a
33
- * narrower container).
34
- *
35
- * Every destination is a `link` value — a collection, product, page or entry the platform knows,
36
- * or an external URL — resolved to an href by `useEldraLink()`. A row whose target has been
37
- * deleted, or that the site has no route for, resolves to no href and renders its label as plain
38
- * text rather than a dead anchor; a row with no label at all renders nothing.
39
- */
40
- import { computed, nextTick, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
2
+ /** Header (design spec 2); apiId stays `navigation`. Layout: docs/starter-kit.md, "The header". */
3
+ import { computed, onMounted, ref, watchEffect } from 'vue';
41
4
  import { useEldraLink, useEldraLocale } from '@eldrajs/theme-vue';
42
- import type { ResolvedLink } from '@eldrajs/theme-vue';
43
5
  import {
44
6
  Badge,
45
7
  Button,
46
8
  Container,
47
- Drawer,
48
9
  EditorPlaceholder,
49
10
  Link,
11
+ NavMenu,
50
12
  SearchBar,
51
13
  SearchModal,
52
14
  } from '@eldrajs/ui';
53
- import type { SearchResultItem, SearchResults } from '@eldrajs/ui';
15
+ import type {
16
+ NavMenuItem,
17
+ NavMenuPart,
18
+ SearchResultItem,
19
+ SearchResults,
20
+ UiMessages,
21
+ } from '@eldrajs/ui';
54
22
  import { useBlockData } from '../../app/composables/useBlockData';
55
23
  import { useEditing } from '../../app/composables/useEditing';
56
24
  import { useStorefront } from '../../app/composables/useStorefront';
57
25
  import { useWishlist } from '../../app/composables/useWishlist';
58
26
  import { useI18n } from 'vue-i18n';
59
- import { useUiId } from '../../app/composables/useUiId';
60
27
  import EldraIcon from '../../app/components/EldraIcon.vue';
61
28
  import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
62
29
  import { isInternalHref, SEARCH_PATH } from '../../app/utils/links';
63
- import { focusRing } from '../../app/utils/classes';
64
30
  import { useMoney } from '../../app/storefront/money';
65
31
  import type { StorefrontSearchResponse } from '../../app/storefront/types';
66
- import { useMegaMenuKeys } from './useMegaMenuKeys';
32
+ import MenuLink from './parts/MenuLink.vue';
67
33
 
68
34
  const props = defineProps<{ entry: EldraBlockEntry<'navigation'> }>();
69
35
  const { data } = useBlockData(props, 'navigation');
@@ -90,192 +56,46 @@ function toLinkAs(href: string | undefined): typeof EldraRouterLink | undefined
90
56
  return href !== undefined && isInternalHref(href) ? EldraRouterLink : undefined;
91
57
  }
92
58
 
93
- interface NavRow {
94
- label: string;
95
- href: string | undefined;
96
- as?: typeof EldraRouterLink;
97
- }
98
-
99
- /** Resolved links. A row with no label has nothing to show and is dropped; a row whose target no
100
- * longer exists keeps its label and loses its `href`, and the template renders it as plain text.
101
- * A link with children never navigates itself (spec: the trigger is a disclosure, not a link), so
102
- * its own href never sits on the trigger — a parent that *has* a destination (anything but a
103
- * `kind: "none"` heading, which resolves to no href at all) offers it inside the panel instead, as
104
- * the "View all" row. */
59
+ /** A row with no label has nothing to show; one whose target is gone keeps its label as text. */
105
60
  const links = computed(() =>
106
61
  rawLinks.value.flatMap((item) => {
107
62
  const resolved = resolveLink(item);
108
- if (resolved === null || resolved.label === null) return [];
109
- return [{ ...toRow(resolved), groups: groupChildren(resolved.children) }];
63
+ return resolved === null || resolved.label === null ? [] : [resolved];
110
64
  })
111
65
  );
112
66
 
113
- interface MenuGroup {
114
- title?: string;
115
- links: NavRow[];
116
- }
117
-
118
- function toRow(resolved: ResolvedLink): NavRow {
119
- const href = resolved.href ?? undefined;
120
- return { label: resolved.label ?? '', href, as: toLinkAs(href) };
121
- }
122
-
123
- /** Consecutive children that share a `group` become one column, in the order they were authored —
124
- * the field's own rule (block.json `links` help text). */
125
- function groupChildren(children: ResolvedLink[]): MenuGroup[] {
126
- const groups: MenuGroup[] = [];
127
- for (const child of children) {
128
- if (child.label === null) continue;
129
- const title = child.group ?? undefined;
130
- const last = groups[groups.length - 1];
131
- if (last !== undefined && last.title === title) {
132
- last.links.push(toRow(child));
133
- } else {
134
- groups.push({ title, links: [toRow(child)] });
67
+ /** A parent with children is a disclosure, so its own destination moves to the panel's "View all". */
68
+ const navItems = computed<NavMenuItem[]>(() =>
69
+ links.value.map((link) => {
70
+ const children = link.children.filter((child) => child.label !== null);
71
+ if (children.length === 0) {
72
+ return {
73
+ label: link.label,
74
+ href: link.href,
75
+ newTab: link.newTab,
76
+ current: isCurrent(link.href),
77
+ };
135
78
  }
136
- }
137
- return groups;
138
- }
139
-
140
- const hasMegaMenu = (index: number): boolean => links.value[index]!.groups.length > 0;
141
-
142
- // --- mega-menu open state (bar) -------------------------------------------------------------
143
-
144
- const openMenuIndex = ref<number | null>(null);
145
- const menuIds = computed(() =>
146
- links.value.map((_, index) => ({
147
- trigger: `${uid}-trigger-${index}`,
148
- panel: `${uid}-panel-${index}`,
149
- }))
79
+ return {
80
+ label: link.label,
81
+ layout: 'mega',
82
+ children: children.map((child) => ({
83
+ label: child.label,
84
+ href: child.href,
85
+ newTab: child.newTab,
86
+ group: child.group,
87
+ current: isCurrent(child.href),
88
+ })),
89
+ };
90
+ })
150
91
  );
151
- const uid = useUiId();
152
- /** The bar's own `<ul>`: the element `useMegaMenuKeys` walks to find the top-level items and the
153
- * panels, so the keyboard model never keeps a second list of its own to fall out of step. */
154
- const barLinkList = ref<HTMLElement | null>(null);
155
92
 
156
- let hoverTimer: ReturnType<typeof setTimeout> | undefined;
157
- /** Whether the open panel was opened by hover (then leaving it closes it) rather than by a click,
158
- * Enter or Space (then only Esc, another trigger or an outside interaction closes it). */
159
- let openedByHover = false;
160
- function clearHoverTimer(): void {
161
- if (hoverTimer !== undefined) clearTimeout(hoverTimer);
162
- hoverTimer = undefined;
163
- }
164
- /** Opens one panel (closing any other) as a keyboard-owned one: hover never closes what a key
165
- * opened. Every keyboard path into a panel goes through here. */
166
- function openMenu(index: number): void {
167
- clearHoverTimer();
168
- openedByHover = false;
169
- openMenuIndex.value = index;
93
+ function viewAllHref(index: number): string | undefined {
94
+ return links.value[index]?.href ?? undefined;
170
95
  }
171
- function toggleMenu(index: number): void {
172
- if (openMenuIndex.value === index) {
173
- closeMenu();
174
- return;
175
- }
176
- openMenu(index);
177
- }
178
- function closeMenu(): void {
179
- clearHoverTimer();
180
- openedByHover = false;
181
- openMenuIndex.value = null;
182
- }
183
- /** "Hover may open a panel after 150ms" — never immediately, so a bare pointer pass-over never
184
- * opens anything (spec: "nothing opens on hover alone"). */
185
- function onTriggerMouseEnter(index: number): void {
186
- clearHoverTimer();
187
- if (openMenuIndex.value === index) return;
188
- hoverTimer = setTimeout(() => {
189
- openMenuIndex.value = index;
190
- openedByHover = true;
191
- hoverTimer = undefined;
192
- }, 150);
193
- }
194
- /** True while focus sits on the item's trigger or anywhere inside its panel. */
195
- function focusWithinMenu(index: number): boolean {
196
- if (typeof document === 'undefined') return false;
197
- const active = document.activeElement;
198
- const ids = menuIds.value[index];
199
- if (active === null || ids === undefined) return false;
200
- return (
201
- document.getElementById(ids.trigger)?.contains(active) === true ||
202
- document.getElementById(ids.panel)?.contains(active) === true
203
- );
204
- }
205
- /** Leaving the trigger or its panel: a pending hover-open is dropped, and a panel that hover opened
206
- * closes after the same 150ms grace — long enough to cross the gap from the trigger into the
207
- * panel (entering either clears the timer) but short enough that the panel never lingers once the
208
- * pointer has moved on. A hover-opened panel that focus has since moved into is keyboard-owned
209
- * from then on: closing it as the pointer wanders off would strand that focus on a hidden link,
210
- * so the pointer's own grace period gives way and `onNavItemFocusOut` closes it instead. */
211
- function onTriggerMouseLeave(): void {
212
- clearHoverTimer();
213
- if (openMenuIndex.value === null || !openedByHover) return;
214
- hoverTimer = setTimeout(() => {
215
- hoverTimer = undefined;
216
- const index = openMenuIndex.value;
217
- if (index === null || !openedByHover) return;
218
- if (focusWithinMenu(index)) return;
219
- closeMenu();
220
- }, 150);
221
- }
222
- /**
223
- * A disclosure closes as soon as focus leaves the trigger-and-panel pair, which is what the pattern
224
- * asks for and the one thing this block used to get wrong: `Tab` past the panel's last link,
225
- * `Shift+Tab` back before the trigger, or a click anywhere else all left the panel hanging open
226
- * under a bar whose focus had moved on. The `<li>` *is* the pair (the trigger, or plain link, and
227
- * that item's panel are its only children), so one `focusout` on it answers all three: a
228
- * `relatedTarget` still inside the `<li>` is movement within the menu, anything else — including
229
- * `null`, which is what a click on non-focusable page furniture gives — has left it. Focus itself is
230
- * never moved here; only the panel closes.
231
- *
232
- * `closeMenu()` also drops any pending hover-open, deliberately: focus leaving the header's menus is
233
- * the visitor saying they are done with them, so a panel the pointer happens to be resting over must
234
- * not spring open a moment later behind the keyboard's back. The pointer reopens it by moving.
235
- */
236
- function onNavItemFocusOut(index: number, event: FocusEvent): void {
237
- if (openMenuIndex.value !== index) return;
238
- const pair = event.currentTarget;
239
- const next = event.relatedTarget;
240
- if (!(pair instanceof HTMLElement)) return;
241
- if (next instanceof Node && pair.contains(next)) return;
242
- closeMenu();
243
- }
244
- function closeMenuAndFocusTrigger(index: number): void {
245
- closeMenu();
246
- void nextTick(() => {
247
- document.getElementById(menuIds.value[index]!.trigger)?.focus();
248
- });
249
- }
250
- /** Arrow keys, Home/End, Enter/Space and Escape across the bar and its panels — the APG's
251
- * disclosure-navigation pattern, in `useMegaMenuKeys.ts` with the reasoning for each key. */
252
- const { onTriggerKeydown, onPanelKeydown, onBarLinkKeydown } = useMegaMenuKeys({
253
- list: barLinkList,
254
- openIndex: openMenuIndex,
255
- hasPanel: hasMegaMenu,
256
- open: openMenu,
257
- toggle: toggleMenu,
258
- close: closeMenu,
259
- closeAndFocusTrigger: closeMenuAndFocusTrigger,
260
- });
261
-
262
- onBeforeUnmount(clearHoverTimer);
263
-
264
- // --- drawer (mobile menu) --------------------------------------------------------------------
265
96
 
97
+ const openMenuIndex = ref<number | null>(null);
266
98
  const drawerOpen = ref(false);
267
- const drawerId = `${uid}-drawer`;
268
- const drawerExpanded = ref<Set<number>>(new Set());
269
- function toggleDrawerGroup(index: number): void {
270
- const next = new Set(drawerExpanded.value);
271
- if (next.has(index)) next.delete(index);
272
- else next.add(index);
273
- drawerExpanded.value = next;
274
- }
275
-
276
- function onMenuButtonClick(): void {
277
- drawerOpen.value = true;
278
- }
279
99
 
280
100
  // --- call to action ----------------------------------------------------------------------------
281
101
 
@@ -541,8 +361,8 @@ watchEffect((onCleanup) => {
541
361
  window.addEventListener('popstate', onPopState);
542
362
  onCleanup(() => window.removeEventListener('popstate', onPopState));
543
363
  });
544
- function isCurrent(href: string | undefined): boolean {
545
- return href !== undefined && href === currentPath.value;
364
+ function isCurrent(href: string | null | undefined): boolean {
365
+ return typeof href === 'string' && href === currentPath.value;
546
366
  }
547
367
 
548
368
  // --- sticky, scroll padding and scrolled shadow -----------------------------------------------
@@ -577,7 +397,7 @@ const hiddenByScroll = ref(false);
577
397
  */
578
398
  const focusWithinBar = ref(false);
579
399
  /**
580
- * The bar's height, named once: the bar sets it on its own `<nav>` and the spacer reserves the very
400
+ * The bar's height, named once: the bar sets it on its own grid and the spacer reserves the very
581
401
  * same box. Two literals would drift the first time a breakpoint moved, and a spacer that drifts
582
402
  * from the bar is a page that jumps. `@content:` is a container query, so it is only ever as true
583
403
  * as the container it is measured in — which is why both boxes sit inside an `@container` of the
@@ -726,31 +546,6 @@ const isTransparent = computed(
726
546
  */
727
547
  const HEADER_SURFACE_VAR = '--eldra-header-surface';
728
548
  const barSurfaceStyle = { [HEADER_SURFACE_VAR]: 'var(--color-background)' };
729
- const panelSurfaceStyle = { background: `var(${HEADER_SURFACE_VAR})` };
730
-
731
- /**
732
- * A panel eases in and out rather than appearing and vanishing: opacity 0→1 with a 4px rise over
733
- * 150ms on the way in, and the same 4px back out over a slightly quicker 120ms on the way out, so
734
- * closing never feels slower than opening. A Vue `<Transition>` rather than a CSS class on the panel
735
- * itself, because only a `<Transition>` holds the element long enough for the leave half to play at
736
- * all — `v-show` alone would cut it to `display: none` in the same frame the panel closed.
737
- *
738
- * The panel stays mounted either way (`v-show`, never `v-if`): `aria-expanded` and the panel's
739
- * presence must never disagree, and nothing here delays the element past the attribute flip.
740
- * `pointer-events-none` while it leaves keeps a pointer crossing the fading panel from clearing the
741
- * close timer and pulling it back open.
742
- *
743
- * Under `prefers-reduced-motion: reduce` the rise is dropped — `motion-safe:` carries it — and only
744
- * the fade is left.
745
- */
746
- const panelTransition = {
747
- enterFromClass: 'opacity-0 motion-safe:-translate-y-1',
748
- enterActiveClass: 'transition-[opacity,transform] duration-[150ms] ease-out',
749
- enterToClass: 'opacity-100',
750
- leaveFromClass: 'opacity-100',
751
- leaveActiveClass: 'pointer-events-none transition-[opacity,transform] duration-[120ms] ease-in',
752
- leaveToClass: 'opacity-0 motion-safe:-translate-y-1',
753
- };
754
549
 
755
550
  /**
756
551
  * `@eldrajs/ui`'s `classes` prop takes a plain string per part (`Partial<Record<Part, string>>`),
@@ -804,7 +599,7 @@ const barRootClasses = computed(() =>
804
599
  * the spacer is the bar's measured height to the pixel, whatever either box's width does.
805
600
  *
806
601
  * The two boxes mirror the bar's own two: the outer one carries the hairline, as the `<header>`
807
- * carries `border-b`, and the inner one the height, as the `<nav>` does. Which is also the only way
602
+ * carries `border-b`, and the inner one the height, as the bar's grid does. Which is also the only way
808
603
  * the pixel lands: everything here is `border-box`, so a border on the box that *has* the height
809
604
  * eats into it rather than adding to it. `border-transparent` contributes nothing but that pixel,
810
605
  * and only while the bar has it — the solid bar draws `border-b` and the transparent-over-hero bar
@@ -821,29 +616,32 @@ const hairlineClass = computed(() =>
821
616
  isTransparent.value ? 'border-primary-contrast/24' : 'border-border'
822
617
  );
823
618
 
824
- // --- menu button visibility ----------------------------------------------------------------------
619
+ // --- the menu in the bar -----------------------------------------------------------------------
825
620
 
826
- const menuButtonHiddenClass = computed(() =>
827
- variant.value === 'minimal' ? '' : '@content:hidden'
828
- );
829
- const linksVisible = computed(() => variant.value !== 'minimal' && links.value.length > 0);
830
- /**
831
- * The drawer holds the links and the call to action — nothing else. A header with neither (the
832
- * shape this theme seeds a fresh store with) therefore has an empty drawer, and a Menu button that
833
- * opens one is a control that does nothing: the bar renders brand and actions only, and the button
834
- * goes with the drawer it has nothing to show from.
835
- */
621
+ /** The drawer holds the links and the call to action; with neither there is no Menu button either. */
836
622
  const drawerHasContent = computed(() => links.value.length > 0 || hasCta.value);
837
-
838
- const brandPositionClass = computed(() =>
839
- variant.value === 'centered'
840
- ? '@content:col-start-2 @content:row-start-1 @content:justify-self-center'
841
- : ''
623
+ const showLinksPlaceholder = computed(
624
+ () => isEditing.value && variant.value !== 'minimal' && links.value.length === 0
842
625
  );
626
+
627
+ const navMenuMessages = computed<Partial<UiMessages>>(() => ({
628
+ navMenuOpen: t('header.openMenu'),
629
+ navMenuDrawer: t('header.menu'),
630
+ }));
631
+
632
+ /** Below `@content` the Menu button holds the first column, so the brand takes the second. */
633
+ const brandPositionClass = computed(() => {
634
+ const besideToggle = drawerHasContent.value ? 'col-start-2 row-start-1' : '';
635
+ if (variant.value === 'minimal') return besideToggle;
636
+ if (variant.value === 'centered') {
637
+ return `${besideToggle} @content:col-start-2 @content:row-start-1 @content:justify-self-center`;
638
+ }
639
+ return drawerHasContent.value ? `${besideToggle} @content:col-start-1` : '';
640
+ });
843
641
  const linksPositionClass = computed(() =>
844
642
  variant.value === 'centered'
845
- ? `hidden @content:flex @content:col-start-1 @content:col-span-4 @content:row-start-2 @content:justify-center @content:border-t ${hairlineClass.value} @content:pt-3 @content:mt-1`
846
- : 'hidden @content:flex @content:col-start-2 @content:row-start-1'
643
+ ? `@content:col-start-1 @content:col-span-4 @content:row-start-2 @content:justify-center @content:border-t ${hairlineClass.value} @content:pt-3 @content:mt-1`
644
+ : '@content:col-start-2 @content:row-start-1'
847
645
  );
848
646
  const searchPositionClass = computed(() =>
849
647
  variant.value === 'centered' ? '@content:col-start-1 @content:row-start-1' : ''
@@ -851,6 +649,28 @@ const searchPositionClass = computed(() =>
851
649
  const actionsPositionClass = computed(() =>
852
650
  variant.value === 'centered' ? '@content:col-start-4 @content:row-start-1' : ''
853
651
  );
652
+
653
+ /** What this header draws differently from `NavMenu`'s own look, part by part. */
654
+ const navMenuClasses = computed<Partial<Record<NavMenuPart, string>>>(() => ({
655
+ // `contents`: the bar and the Menu button become cells of the grid, which then positions panels.
656
+ root: 'static contents',
657
+ nav: `self-stretch ${linksPositionClass.value}`,
658
+ list: variant.value === 'centered' ? 'h-full flex-nowrap justify-center' : 'h-full flex-nowrap',
659
+ link: 'text-sm',
660
+ trigger: 'text-sm',
661
+ toggle:
662
+ variant.value === 'minimal'
663
+ ? 'col-start-1 row-start-1 size-auto min-h-10 max-md:size-auto max-md:min-h-11 gap-2 px-3 text-sm font-medium'
664
+ : 'col-start-1 row-start-1',
665
+ panel: 'pt-0',
666
+ content:
667
+ 'rounded-none rounded-b-lg border-t-0 bg-(--eldra-header-surface) shadow-(--eldra-shadow-float) @wide:p-8',
668
+ columns: 'grid-cols-12 gap-6',
669
+ group: 'col-span-3',
670
+ footer: 'justify-end',
671
+ drawerLink: 'font-heading text-xl font-semibold',
672
+ drawerTrigger: 'font-heading text-xl font-semibold',
673
+ }));
854
674
  </script>
855
675
 
856
676
  <template>
@@ -863,45 +683,15 @@ const actionsPositionClass = computed(() =>
863
683
  @focusout="onBarFocusOut"
864
684
  >
865
685
  <Container width="wide">
866
- <!-- `relative` is what an open mega-menu panel measures itself against: this element is the
867
- header's content box (inside `Container`'s max-width and gutters), so a panel pinned to
868
- `left-0 right-0` here spans exactly the bar's own container.
869
-
870
- One `gap-1` (0.25rem) at every width — spec "Header" -> Layout gives that number for the
871
- mobile grid's column gap and repeats it for the actions row, and never states a larger
872
- one for any breakpoint in between, including the gap between this grid's search and
873
- actions columns. A `@tablet:gap-4` lived here before (paired with the tablet height
874
- tweak, with no basis in the spec text) and was the actual source of the uneven header: a
875
- 1rem gap between the search icon and the wishlist/cart cluster against the 0.25rem the
876
- actions row's own `gap-1` puts between the heart and the bag, so the three icon buttons
877
- read as two pairs rather than one evenly spaced row. The call to action's own closer
878
- distance ("sits 0.75rem after the cart") is set on the button itself, not here — see its
879
- `@content:ml-2` below. -->
880
- <nav
881
- :aria-label="t('header.primary')"
686
+ <!-- One `gap-1` at every width (spec "Header" -> Layout); the call to action adds its own
687
+ margin below. -->
688
+ <div
689
+ data-eldra-header-bar
882
690
  :class="[
883
691
  BAR_HEIGHT_CLASS,
884
692
  'relative grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-1',
885
693
  ]"
886
694
  >
887
- <Button
888
- v-if="drawerHasContent"
889
- :classes="{ container: menuButtonHiddenClass }"
890
- variant="ghost"
891
- size="sm"
892
- :icon-only="variant !== 'minimal'"
893
- :label="t('header.openMenu')"
894
- aria-haspopup="dialog"
895
- :aria-expanded="drawerOpen ? 'true' : 'false'"
896
- :aria-controls="drawerId"
897
- @click="onMenuButtonClick"
898
- >
899
- <template #leadingIcon>
900
- <EldraIcon name="menu-2" size="md" />
901
- </template>
902
- <template v-if="variant === 'minimal'">{{ t('header.menu') }}</template>
903
- </Button>
904
-
905
695
  <Link
906
696
  :href="brandHref"
907
697
  :as="EldraRouterLink"
@@ -930,157 +720,47 @@ const actionsPositionClass = computed(() =>
930
720
  }}</span>
931
721
  </Link>
932
722
 
933
- <ul
934
- v-if="linksVisible"
935
- ref="barLinkList"
936
- :class="['list-none items-center gap-1', linksPositionClass]"
723
+ <NavMenu
724
+ v-if="drawerHasContent"
725
+ v-model="openMenuIndex"
726
+ v-model:drawer-open="drawerOpen"
727
+ :items="navItems"
728
+ :aria-label="t('header.primary')"
729
+ :collapse-below="variant === 'minimal' ? 'always' : '@content'"
730
+ open-on-hover
731
+ :link-as="MenuLink"
732
+ :messages="navMenuMessages"
733
+ :classes="navMenuClasses"
937
734
  >
938
- <!-- One `<li>` per link, trigger (or plain link) then that item's panel: the pair the
939
- disclosure pattern closes on focus leaving, and the reading order the arrow keys
940
- walk. -->
941
- <li
942
- v-for="(link, index) in links"
943
- :key="index"
944
- @focusout="onNavItemFocusOut(index, $event)"
945
- >
946
- <button
947
- v-if="hasMegaMenu(index)"
948
- :id="menuIds[index]!.trigger"
949
- type="button"
950
- :class="[
951
- focusRing,
952
- 'inline-flex h-10 items-center gap-1 rounded-sm px-3 text-sm font-medium',
953
- openMenuIndex === index ? 'font-semibold underline underline-offset-4' : '',
954
- ]"
955
- :aria-expanded="openMenuIndex === index ? 'true' : 'false'"
956
- :aria-controls="menuIds[index]!.panel"
957
- @click="toggleMenu(index)"
958
- @keydown="onTriggerKeydown(index, $event)"
959
- @mouseenter="onTriggerMouseEnter(index)"
960
- @mouseleave="onTriggerMouseLeave"
961
- >
962
- {{ link.label }}
963
- <EldraIcon
964
- name="chevron-down"
965
- size="sm"
966
- class="transition-transform motion-reduce:transition-none"
967
- :class="openMenuIndex === index ? 'rotate-180' : ''"
968
- />
969
- </button>
735
+ <template #toggle>
736
+ <EldraIcon name="menu-2" size="md" />
737
+ <span v-if="variant === 'minimal'">{{ t('header.menu') }}</span>
738
+ </template>
739
+ <template #panelFooter="{ item, index }">
970
740
  <Link
971
- v-else-if="link.href"
972
- :href="link.href"
973
- :as="link.as"
741
+ v-if="viewAllHref(index)"
742
+ :href="viewAllHref(index)"
743
+ :as="toLinkAs(viewAllHref(index))"
974
744
  variant="standalone"
975
- :underline="false"
976
- :aria-current="isCurrent(link.href) ? 'page' : undefined"
977
- :classes="{
978
- root: `inline-flex h-10 items-center px-3 text-sm font-medium ${isCurrent(link.href) ? 'font-semibold underline underline-offset-4' : ''}`,
979
- }"
980
- @keydown="onBarLinkKeydown(index, $event)"
745
+ arrow
746
+ data-eldra-mega-view-all
747
+ :aria-label="t('header.viewAllOf', { label: item.label ?? '' })"
748
+ :classes="{ root: 'text-sm' }"
981
749
  >
982
- {{ link.label }}
750
+ {{ t('header.viewAll') }}
983
751
  </Link>
984
- <span v-else class="inline-flex h-10 items-center px-3 text-sm font-medium">
985
- {{ link.label }}
986
- </span>
987
-
988
- <!-- The panel spans the bar's own container (`left-0 right-0` against the `relative`
989
- `<nav>` above) and sits directly under it. The hairline along its top edge is the
990
- bar's own full-bleed `border-b` — the bar is never transparent while a panel is
991
- open — so the panel takes no top border of its own (`border-t-0`); the other three
992
- sides carry the border token and the bottom corners are rounded, which is what
993
- makes the open panel read as a sheet hanging off the bar rather than as a slab of
994
- background with content loose on it. Its columns are a 12-column grid at three
995
- columns each: four groups fill the row, fewer stay left-aligned at that same width
996
- rather than stretching, and a fifth group wraps to a second row — all of it inset
997
- from the panel's edges (32px, 24px below the `wide` container edge), so no text
998
- ever sits flush against the panel's own boundary. `rounded-b-lg` is this theme's
999
- 12px step: `radius-lg` is 0.75rem here, `radius-xl` 1rem.
1000
-
1001
- Its ground is the bar's own, read from the variable the bar publishes rather than
1002
- named again here, and it eases in and out — see `barSurfaceStyle` and
1003
- `panelTransition` above. -->
1004
- <Transition v-bind="panelTransition">
1005
- <div
1006
- v-if="hasMegaMenu(index)"
1007
- v-show="openMenuIndex === index"
1008
- :id="menuIds[index]!.panel"
1009
- data-eldra-mega-panel
1010
- class="border-border shadow-float @wide:p-8 absolute top-full right-0 left-0 z-30 grid grid-cols-12 gap-6 rounded-b-lg border border-t-0 p-6"
1011
- :style="panelSurfaceStyle"
1012
- @keydown="onPanelKeydown(index, $event)"
1013
- @mouseenter="clearHoverTimer"
1014
- @mouseleave="onTriggerMouseLeave"
1015
- >
1016
- <div
1017
- v-for="(group, groupIndex) in link.groups"
1018
- :key="groupIndex"
1019
- class="col-span-3"
1020
- >
1021
- <p
1022
- :id="`${menuIds[index]!.panel}-g${groupIndex}`"
1023
- class="text-muted mb-3 text-[11px] font-semibold tracking-wide uppercase"
1024
- >
1025
- {{ group.title }}
1026
- </p>
1027
- <ul
1028
- :aria-labelledby="`${menuIds[index]!.panel}-g${groupIndex}`"
1029
- class="flex list-none flex-col"
1030
- >
1031
- <li v-for="(row, rowIndex) in group.links" :key="rowIndex">
1032
- <Link
1033
- v-if="row.href"
1034
- :href="row.href"
1035
- :as="row.as"
1036
- variant="standalone"
1037
- :underline="false"
1038
- :classes="{
1039
- root: 'text-text flex min-h-9 items-center text-[15px] font-medium hover:underline-offset-4',
1040
- }"
1041
- >
1042
- {{ row.label }}
1043
- </Link>
1044
- <span
1045
- v-else
1046
- class="text-text flex min-h-9 items-center text-[15px] font-medium"
1047
- >
1048
- {{ row.label }}
1049
- </span>
1050
- </li>
1051
- </ul>
1052
- </div>
1053
- <!-- The parent's own destination, which the trigger gave up when it became a
1054
- disclosure. A `kind: "none"` heading resolves to no href and therefore offers
1055
- nothing here. A rule across the full content width separates it from the groups,
1056
- and `arrow` gives it the same trailing arrow-right every other "view all" in the
1057
- theme carries — the package draws it outside the label, so the underline runs
1058
- under the words only. -->
1059
- <div
1060
- v-if="link.href"
1061
- class="border-border col-span-12 flex justify-end border-t pt-4"
1062
- >
1063
- <Link
1064
- :href="link.href"
1065
- :as="link.as"
1066
- variant="standalone"
1067
- arrow
1068
- data-eldra-mega-view-all
1069
- :aria-label="t('header.viewAllOf', { label: link.label })"
1070
- :classes="{ root: 'text-sm' }"
1071
- >
1072
- {{ t('header.viewAll') }}
1073
- </Link>
1074
- </div>
1075
- </div>
1076
- </Transition>
1077
- </li>
1078
- </ul>
752
+ </template>
753
+ <template v-if="hasCta" #drawerFooter="{ close }">
754
+ <Button variant="primary" block :href="ctaHref" :as="ctaLinkAs" @click="close">
755
+ {{ ctaLabel }}
756
+ </Button>
757
+ </template>
758
+ </NavMenu>
1079
759
  <EditorPlaceholder
1080
- v-else-if="isEditing && variant !== 'minimal' && links.length === 0"
760
+ v-if="showLinksPlaceholder"
1081
761
  inline
1082
762
  :label="t('editor.addLink')"
1083
- :classes="{ root: linksPositionClass }"
763
+ :classes="{ root: `hidden @content:flex ${linksPositionClass}` }"
1084
764
  />
1085
765
 
1086
766
  <!-- `justify-end` matters in exactly one case and is inert in every other: with no Menu
@@ -1225,104 +905,8 @@ const actionsPositionClass = computed(() =>
1225
905
  {{ ctaLabel }}
1226
906
  </Button>
1227
907
  </div>
1228
- </nav>
1229
- </Container>
1230
-
1231
- <Drawer
1232
- v-if="drawerHasContent"
1233
- :id="drawerId"
1234
- v-model="drawerOpen"
1235
- side="left"
1236
- :aria-label="t('header.menu')"
1237
- >
1238
- <div>
1239
- <ul class="list-none">
1240
- <li v-for="(link, index) in links" :key="index" class="border-border border-b">
1241
- <button
1242
- v-if="hasMegaMenu(index)"
1243
- type="button"
1244
- :class="[
1245
- focusRing,
1246
- 'font-heading flex min-h-14 w-full items-center justify-between text-xl font-semibold',
1247
- ]"
1248
- :aria-expanded="drawerExpanded.has(index) ? 'true' : 'false'"
1249
- :aria-controls="`${uid}-drawer-panel-${index}`"
1250
- @click="toggleDrawerGroup(index)"
1251
- >
1252
- {{ link.label }}
1253
- <EldraIcon
1254
- name="chevron-down"
1255
- size="sm"
1256
- class="transition-transform motion-reduce:transition-none"
1257
- :class="drawerExpanded.has(index) ? 'rotate-180' : ''"
1258
- />
1259
- </button>
1260
- <Link
1261
- v-else-if="link.href"
1262
- :href="link.href"
1263
- :as="link.as"
1264
- variant="standalone"
1265
- :underline="false"
1266
- :aria-current="isCurrent(link.href) ? 'page' : undefined"
1267
- :classes="{
1268
- root: 'flex min-h-14 w-full items-center font-heading text-xl font-semibold',
1269
- }"
1270
- @click="drawerOpen = false"
1271
- >
1272
- {{ link.label }}
1273
- </Link>
1274
- <span
1275
- v-else
1276
- class="font-heading flex min-h-14 w-full items-center text-xl font-semibold"
1277
- >
1278
- {{ link.label }}
1279
- </span>
1280
-
1281
- <div
1282
- v-if="hasMegaMenu(index)"
1283
- v-show="drawerExpanded.has(index)"
1284
- :id="`${uid}-drawer-panel-${index}`"
1285
- class="grid gap-5 pb-5"
1286
- >
1287
- <div v-for="(group, groupIndex) in link.groups" :key="groupIndex">
1288
- <p class="text-muted mb-1 text-xs font-semibold tracking-[0.12em] uppercase">
1289
- {{ group.title }}
1290
- </p>
1291
- <ul class="list-none">
1292
- <li v-for="(row, rowIndex) in group.links" :key="rowIndex">
1293
- <Link
1294
- v-if="row.href"
1295
- :href="row.href"
1296
- :as="row.as"
1297
- variant="standalone"
1298
- :underline="false"
1299
- :classes="{ root: 'flex min-h-11 items-center text-sm' }"
1300
- @click="drawerOpen = false"
1301
- >
1302
- {{ row.label }}
1303
- </Link>
1304
- <span v-else class="flex min-h-11 items-center text-sm">{{ row.label }}</span>
1305
- </li>
1306
- </ul>
1307
- </div>
1308
- </div>
1309
- </li>
1310
- </ul>
1311
908
  </div>
1312
-
1313
- <template #footer>
1314
- <Button
1315
- v-if="hasCta"
1316
- variant="primary"
1317
- block
1318
- :href="ctaHref"
1319
- :as="ctaLinkAs"
1320
- @click="drawerOpen = false"
1321
- >
1322
- {{ ctaLabel }}
1323
- </Button>
1324
- </template>
1325
- </Drawer>
909
+ </Container>
1326
910
 
1327
911
  <SearchModal
1328
912
  v-model="searchOpen"
@@ -1335,7 +919,7 @@ const actionsPositionClass = computed(() =>
1335
919
  <!-- The flow the fixed bar left behind — see `barSpacerClasses`. Empty and unlabelled: it is
1336
920
  layout, with nothing in it for a screen reader or the tab order to reach. The outer box is the
1337
921
  `<header>`'s counterpart (the `@container` the height is measured in, and the hairline) and the
1338
- inner one the `<nav>`'s (the height itself). -->
922
+ inner one the bar grid's (the height itself). -->
1339
923
  <div
1340
924
  v-if="sticky"
1341
925
  data-eldra-header-spacer