@eldrajs/theme-cli 0.0.0 → 0.1.0
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.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,1348 @@
|
|
|
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';
|
|
41
|
+
import { useEldraLink, useEldraLocale } from '@eldrajs/theme-vue';
|
|
42
|
+
import type { ResolvedLink } from '@eldrajs/theme-vue';
|
|
43
|
+
import {
|
|
44
|
+
Badge,
|
|
45
|
+
Button,
|
|
46
|
+
Container,
|
|
47
|
+
Drawer,
|
|
48
|
+
EditorPlaceholder,
|
|
49
|
+
Link,
|
|
50
|
+
SearchBar,
|
|
51
|
+
SearchModal,
|
|
52
|
+
} from '@eldrajs/ui';
|
|
53
|
+
import type { SearchResultItem, SearchResults } from '@eldrajs/ui';
|
|
54
|
+
import { useBlockData } from '../../app/composables/useBlockData';
|
|
55
|
+
import { useEditing } from '../../app/composables/useEditing';
|
|
56
|
+
import { useStorefront } from '../../app/composables/useStorefront';
|
|
57
|
+
import { useWishlist } from '../../app/composables/useWishlist';
|
|
58
|
+
import { useI18n } from 'vue-i18n';
|
|
59
|
+
import { useUiId } from '../../app/composables/useUiId';
|
|
60
|
+
import EldraIcon from '../../app/components/EldraIcon.vue';
|
|
61
|
+
import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
62
|
+
import { isInternalHref, SEARCH_PATH } from '../../app/utils/links';
|
|
63
|
+
import { focusRing } from '../../app/utils/classes';
|
|
64
|
+
import { useMoney } from '../../app/storefront/money';
|
|
65
|
+
import type { StorefrontSearchResponse } from '../../app/storefront/types';
|
|
66
|
+
import { useMegaMenuKeys } from './useMegaMenuKeys';
|
|
67
|
+
|
|
68
|
+
const props = defineProps<{ entry: EldraBlockEntry<'navigation'> }>();
|
|
69
|
+
const { data } = useBlockData(props, 'navigation');
|
|
70
|
+
|
|
71
|
+
const { t } = useI18n();
|
|
72
|
+
const isEditing = useEditing();
|
|
73
|
+
const storefront = useStorefront();
|
|
74
|
+
|
|
75
|
+
const variant = computed<'default' | 'centered' | 'minimal'>(() => data.value.variant ?? 'default');
|
|
76
|
+
|
|
77
|
+
// --- brand -----------------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
const brandLogoUrl = computed(() => data.value.brandLogo?.url);
|
|
80
|
+
const brandHref = '/';
|
|
81
|
+
|
|
82
|
+
// --- links + mega-menus ------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
const rawLinks = computed(() => data.value.links ?? []);
|
|
85
|
+
|
|
86
|
+
/** The site's own route authority: a `link` value in, `{ href, label, group, children }` out. */
|
|
87
|
+
const resolveLink = useEldraLink();
|
|
88
|
+
|
|
89
|
+
function toLinkAs(href: string | undefined): typeof EldraRouterLink | undefined {
|
|
90
|
+
return href !== undefined && isInternalHref(href) ? EldraRouterLink : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
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. */
|
|
105
|
+
const links = computed(() =>
|
|
106
|
+
rawLinks.value.flatMap((item) => {
|
|
107
|
+
const resolved = resolveLink(item);
|
|
108
|
+
if (resolved === null || resolved.label === null) return [];
|
|
109
|
+
return [{ ...toRow(resolved), groups: groupChildren(resolved.children) }];
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
|
|
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)] });
|
|
135
|
+
}
|
|
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
|
+
}))
|
|
150
|
+
);
|
|
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
|
+
|
|
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;
|
|
170
|
+
}
|
|
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
|
+
|
|
266
|
+
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
|
+
|
|
280
|
+
// --- call to action ----------------------------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
const ctaLink = computed(() => resolveLink(data.value.cta));
|
|
283
|
+
const ctaHref = computed(() => ctaLink.value?.href ?? undefined);
|
|
284
|
+
const ctaLinkAs = computed(() => toLinkAs(ctaHref.value));
|
|
285
|
+
/** The button keeps its own label field; the link's own label is the fallback, so a CTA converted
|
|
286
|
+
* from the old label/href pair reads the same either way. */
|
|
287
|
+
const ctaLabel = computed(() => data.value.ctaLabel ?? ctaLink.value?.label ?? '');
|
|
288
|
+
const hasCta = computed(() => Boolean(ctaLabel.value && ctaHref.value));
|
|
289
|
+
|
|
290
|
+
// --- search ------------------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
const showSearch = computed(() => data.value.showSearch !== false);
|
|
293
|
+
/** `inline` only ever applies to `centered`; otherwise it falls back to `icon` (spec: "inline:
|
|
294
|
+
* centered variant only"). */
|
|
295
|
+
const searchStyle = computed<'icon' | 'field' | 'inline'>(() => {
|
|
296
|
+
const style = data.value.searchStyle ?? 'icon';
|
|
297
|
+
return style === 'inline' && variant.value !== 'centered' ? 'icon' : style;
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const searchOpen = ref(false);
|
|
301
|
+
const searchQuery = ref('');
|
|
302
|
+
const searchResult = storefront.search.run(searchQuery);
|
|
303
|
+
/** The store's own currency and the page's locale — never a currency guessed from either. */
|
|
304
|
+
const money = useMoney();
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* **The header's search has to stay in the page's language, and nothing else puts it there.**
|
|
308
|
+
*
|
|
309
|
+
* Three destinations, none of which `EldraRouterLink` can reach:
|
|
310
|
+
*
|
|
311
|
+
* 1. `SearchBar`/`SearchModal` render a real `<form role="search" method="get" :action>`, so
|
|
312
|
+
* pressing Enter with no active option is a native document submit. Left to its default the
|
|
313
|
+
* action is `/search`, and a shopper searching from `/is-IS/products/x` lands on the **English**
|
|
314
|
+
* results page.
|
|
315
|
+
* 2. The overlay's "See all N results" row is built by `SearchModal` as `${action}?q=…`, so it
|
|
316
|
+
* follows from the same prop — one value fixes both.
|
|
317
|
+
* 3. Every result row's href comes off the storefront (`/products/<slug>`, `/journal/…`,
|
|
318
|
+
* `/pages/…`) and is rendered as a plain `<a>` inside the library's results panel, which takes
|
|
319
|
+
* no `linkAs`. So `toSearchResults` below prefixes each one itself.
|
|
320
|
+
*
|
|
321
|
+
* The path is `app/utils/links.ts`'s `SEARCH_PATH`, shared with `blocks/search/Block.vue`, which
|
|
322
|
+
* points at the same page and prefixes it the same way. `path()` is idempotent and is the identity
|
|
323
|
+
* on a single-locale site, so a row whose href already carries a prefix, and every store with one
|
|
324
|
+
* locale, are untouched.
|
|
325
|
+
*/
|
|
326
|
+
const activeLocale = useEldraLocale();
|
|
327
|
+
const searchAction = computed(() => activeLocale.path(SEARCH_PATH));
|
|
328
|
+
|
|
329
|
+
function toSearchResults(response: StorefrontSearchResponse | null): SearchResults | undefined {
|
|
330
|
+
if (response === null) return undefined;
|
|
331
|
+
const products: SearchResultItem[] = response.products.map((product) => ({
|
|
332
|
+
id: product.productId,
|
|
333
|
+
title: product.title,
|
|
334
|
+
href: activeLocale.path(product.url),
|
|
335
|
+
// Optional on `SearchResultItem`, and `null` on a product the storefront could not price: the
|
|
336
|
+
// row keeps the product and drops the price rather than printing the store's own "$0.00"
|
|
337
|
+
// (`StorefrontSearchProduct`).
|
|
338
|
+
price: product.price === null ? undefined : money.format(product.price.amount),
|
|
339
|
+
image: product.featuredImage?.src,
|
|
340
|
+
imageAlt: product.featuredImage?.alt,
|
|
341
|
+
}));
|
|
342
|
+
const articles: SearchResultItem[] = response.articles.map((article, index) => ({
|
|
343
|
+
id: `article-${index}`,
|
|
344
|
+
title: article.title,
|
|
345
|
+
href: activeLocale.path(article.href),
|
|
346
|
+
image: article.image?.src,
|
|
347
|
+
imageAlt: article.image?.alt,
|
|
348
|
+
}));
|
|
349
|
+
const pages: SearchResultItem[] = response.pages.map((page, index) => ({
|
|
350
|
+
id: `page-${index}`,
|
|
351
|
+
title: page.title,
|
|
352
|
+
href: activeLocale.path(page.href),
|
|
353
|
+
}));
|
|
354
|
+
return { products, collections: [], articles, pages, total: response.total };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The response for the query that is **in the field right now**, or `null` while the read for it is
|
|
359
|
+
* still in flight.
|
|
360
|
+
*
|
|
361
|
+
* `searchResult.data` keeps the last answer it got until the next one lands — which is what a page
|
|
362
|
+
* showing prerendered products wants, and exactly wrong for a search panel. The very first thing
|
|
363
|
+
* `search.run()` answers is the empty query's own `{ total: 0 }`, so without this check the panel
|
|
364
|
+
* read "No results for “bowl”" (a `results` object with a zero total is `SearchModal`'s "none"
|
|
365
|
+
* view) for the whole time the request for "bowl" was in flight, and then popped the results in.
|
|
366
|
+
* `StorefrontSearchResponse.query` is the query its own answer is about, so the two can be compared
|
|
367
|
+
* directly rather than tracked alongside.
|
|
368
|
+
*/
|
|
369
|
+
const searchAnswer = computed(() => {
|
|
370
|
+
const answer = searchResult.data.value;
|
|
371
|
+
return answer !== null && answer.query === searchQuery.value ? answer : null;
|
|
372
|
+
});
|
|
373
|
+
/** `undefined` while there is no answer for this query — which is how both `SearchBar` and
|
|
374
|
+
* `SearchModal` are told "nothing yet", as opposed to "nothing found". */
|
|
375
|
+
const searchResults = computed(() => toSearchResults(searchAnswer.value));
|
|
376
|
+
/**
|
|
377
|
+
* `loading`, not `pending`: `pending` is the skeleton flag and means "a read in flight with nothing
|
|
378
|
+
* to show yet", so it is false for every search after the first one (`data` still holds the
|
|
379
|
+
* previous answer) and the panel never reached its loading view. `loading` is "a read is in
|
|
380
|
+
* flight", which is the question being asked here — narrowed to the reads this panel has no answer
|
|
381
|
+
* for, so a background refresh of an answer already on screen does not blank it.
|
|
382
|
+
*/
|
|
383
|
+
const searchLoading = computed(() => searchAnswer.value === null && searchResult.loading.value);
|
|
384
|
+
|
|
385
|
+
function openSearch(): void {
|
|
386
|
+
searchOpen.value = true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// --- cart + wishlist count pills --------------------------------------------------------------
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* A count pill is a corner badge: small, and sitting on the icon's own corner, so it reads as an
|
|
393
|
+
* annotation *on* the glyph rather than a second control beside it. The spec's "1.25rem pill,
|
|
394
|
+
* flush right with a ring" line was written for 2.75rem buttons; on this theme's 2rem ghost icon
|
|
395
|
+
* buttons it put the pill beside the icon as a detached blob, so the badge is sized and placed
|
|
396
|
+
* for the icon instead.
|
|
397
|
+
*
|
|
398
|
+
* 0.875rem square (`h-3.5`/`min-w-3.5`, `min-w` so "99+" still widens it), `0.625rem` bold tabular
|
|
399
|
+
* figures, `primary` fill, `primary-contrast` text (both from the `tone="primary"` prop, not this
|
|
400
|
+
* constant). No ring: a ring's whole job is separating a pill from what sits *beside* it, and a
|
|
401
|
+
* corner badge sits *on* the icon by design — a ring here would just push it back off the corner.
|
|
402
|
+
* `-top-0.5 -right-0.5` sits it at the button's own top-right corner, nudged slightly outside it
|
|
403
|
+
* (2px past the 2rem button's own edge on each side) rather than tucked inside — `top-0.5
|
|
404
|
+
* right-0.5` was tried first and measured worse: with real padding and a real glyph the pill is
|
|
405
|
+
* wider than its 0.875rem floor, so pulled inside the button it still buried roughly a third of
|
|
406
|
+
* the icon's area under it. Pushed just outside instead, it lands mostly over the button's own
|
|
407
|
+
* padding and clears the icon by a wide margin. `countPill.browser.spec.ts` measures the overlap
|
|
408
|
+
* against the icon's real `<svg>` box (not an assumed one) and keeps it well under a quarter of
|
|
409
|
+
* the icon's area. The same override styles both the cart and the wishlist pill (spec: "the cart
|
|
410
|
+
* button and its count badge" — the wishlist one is drawn identically), so it is one constant
|
|
411
|
+
* rather than two copies that could drift.
|
|
412
|
+
*
|
|
413
|
+
* `Badge`'s own root carries `min-h-6` and `text-badge` (1.5rem min height, the package's own
|
|
414
|
+
* type-style utility); both are stock Tailwind class groups (`min-h`, `font-size`) that
|
|
415
|
+
* `tailwind-merge` already recognises, so passing this through `classes.root` replaces them
|
|
416
|
+
* outright — the later class in the merged string always wins a group, with no `!important` and
|
|
417
|
+
* no need for a `size` prop (`Badge` has none).
|
|
418
|
+
*/
|
|
419
|
+
const COUNT_PILL_CLASSES =
|
|
420
|
+
'pointer-events-none absolute -top-0.5 -right-0.5 min-h-3.5 min-w-3.5 h-3.5 justify-center ' +
|
|
421
|
+
'px-1 text-[0.625rem] font-bold tabular-nums leading-none';
|
|
422
|
+
|
|
423
|
+
// --- cart --------------------------------------------------------------------------------------
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The count is a shopper's own state, restored from their browser after the page is up, so the
|
|
427
|
+
* server never knows it: the prerendered bag always reads "Cart, empty" with no pill. Reading the
|
|
428
|
+
* store before mount would let the client's first render disagree with that HTML on every reload
|
|
429
|
+
* that restores a cart (a hydration mismatch, with the bag re-rendered from scratch); gating it on
|
|
430
|
+
* mount makes the first client render match the server's and the count arrive as an ordinary update.
|
|
431
|
+
*/
|
|
432
|
+
const mounted = ref(false);
|
|
433
|
+
onMounted(() => {
|
|
434
|
+
mounted.value = true;
|
|
435
|
+
});
|
|
436
|
+
const cartCount = computed(() => (mounted.value ? storefront.cart.count.value : 0));
|
|
437
|
+
/**
|
|
438
|
+
* The theme mounts one cart drawer in its app shell, so on a live page this is true and the bag is a
|
|
439
|
+
* `<button>` that opens it without leaving the route; in the prerendered HTML it is still false and
|
|
440
|
+
* the bag is an `<a href="/cart">`. Both halves, and why, are documented on `CartStore` in
|
|
441
|
+
* `app/storefront/cart.ts`.
|
|
442
|
+
*/
|
|
443
|
+
const cartDrawerAvailable = computed(() => storefront.cart.drawerAvailable.value);
|
|
444
|
+
const cartHref = computed(() => (cartDrawerAvailable.value ? undefined : '/cart'));
|
|
445
|
+
/** Only the button form is a dialog trigger (spec "Cart": "It opens from the header bag button
|
|
446
|
+
* (`aria-haspopup="dialog"`)"), like the Menu and search triggers above. The link form must not
|
|
447
|
+
* claim it: in the prerendered HTML the bag goes to `/cart`, and nothing pops up. */
|
|
448
|
+
const cartPopupType = computed(() => (cartDrawerAvailable.value ? 'dialog' : undefined));
|
|
449
|
+
const cartAccessibleName = computed(() => {
|
|
450
|
+
const count = cartCount.value;
|
|
451
|
+
if (count === 0) return t('header.cartEmpty');
|
|
452
|
+
if (count === 1) return t('header.cartOne');
|
|
453
|
+
return t('header.cartMany', { count });
|
|
454
|
+
});
|
|
455
|
+
const cartBadgeLabel = computed(() => (cartCount.value > 99 ? '99+' : String(cartCount.value)));
|
|
456
|
+
|
|
457
|
+
function onCartClick(): void {
|
|
458
|
+
// A no-op in Studio's editor. The theme overlay only prevents a click that carries an `href`
|
|
459
|
+
// (`@eldrajs/theme-core`'s navigation guard), so with the drawer available the bag is a button whose
|
|
460
|
+
// click it cannot intercept — and a modal `<dialog>` over the canvas makes the rest of the page
|
|
461
|
+
// inert and unscrollable until the author finds Escape. An author inspecting the header is not
|
|
462
|
+
// shopping, so the bag simply does nothing there.
|
|
463
|
+
if (isEditing.value) return;
|
|
464
|
+
if (cartDrawerAvailable.value)
|
|
465
|
+
storefront.cart.drawerOpen.value = !storefront.cart.drawerOpen.value;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// --- wishlist ----------------------------------------------------------------------------------
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* The saved-for-later heart, beside the bag. **It is in every header but `minimal`, saved list or
|
|
472
|
+
* not** — the way into `/wishlist` is part of the bar exactly as the bag is, and a shopper who has
|
|
473
|
+
* saved nothing is precisely the shopper who has never been shown that the list exists. The heart
|
|
474
|
+
* gated itself on `wishlistCount > 0` first, and that made it a control you could only find once
|
|
475
|
+
* you had already found it.
|
|
476
|
+
*
|
|
477
|
+
* **The count badge is the only shopper state here**, and it keeps the after-mount gate: `items` is
|
|
478
|
+
* empty until `onMounted` (`useWishlist()`, the same gate `cartCount` above is written up under),
|
|
479
|
+
* so a count can never reach a prerendered file and the browser's first render of that file agrees
|
|
480
|
+
* with it. The heart itself carries nothing of the visitor's, which is why it may render on the
|
|
481
|
+
* server — one header, identical for everyone, with the badge arriving a moment later for whoever
|
|
482
|
+
* has one.
|
|
483
|
+
*
|
|
484
|
+
* No field configures it. A `showWishlist` field would be a merchant promising a feature the theme
|
|
485
|
+
* either has or does not: `/wishlist` is this theme's own route, prerendered in every build, so it
|
|
486
|
+
* always exists and the heart never leads nowhere.
|
|
487
|
+
*
|
|
488
|
+
* **Not in `minimal`.** That variant's whole definition is brand, search, cart and a Menu button
|
|
489
|
+
* (spec "Header" → Variants: "Links … and call to action live only in the drawer"), which is why
|
|
490
|
+
* the call to action carries the same `variant !== 'minimal'` guard below — a third icon there
|
|
491
|
+
* would be the theme deciding the variant means something else. The drawer gets no wishlist row
|
|
492
|
+
* either, so the variant stays consistent in both directions.
|
|
493
|
+
*
|
|
494
|
+
* **It does render at mobile widths**, unlike the call to action, which is `@content:` only.
|
|
495
|
+
* Deliberate, and the bag's own rule: a shopper who saved something on a phone has no other way
|
|
496
|
+
* back to it, where the call to action has a drawer row.
|
|
497
|
+
*/
|
|
498
|
+
const wishlist = useWishlist();
|
|
499
|
+
const wishlistCount = wishlist.count;
|
|
500
|
+
const wishlistHref = '/wishlist';
|
|
501
|
+
/** The bag's three forms, with a plainer empty one: nothing saved reads as just "Wishlist" — the
|
|
502
|
+
* control's own name, no count to read out — where the bag says "Cart, empty", which is worth
|
|
503
|
+
* saying about a bag a visitor may have just filled and says nothing about a list they have never
|
|
504
|
+
* used. A number appears only once there is one, so the name in a prerendered file is the same for
|
|
505
|
+
* every visitor. */
|
|
506
|
+
const wishlistAccessibleName = computed(() => {
|
|
507
|
+
const count = wishlistCount.value;
|
|
508
|
+
if (count === 0) return t('header.wishlistEmpty');
|
|
509
|
+
if (count === 1) return t('header.wishlistOne');
|
|
510
|
+
return t('header.wishlistMany', { count });
|
|
511
|
+
});
|
|
512
|
+
/** The bag's own rule: three digits would widen the pill past the icon it sits on. */
|
|
513
|
+
const wishlistBadgeLabel = computed(() =>
|
|
514
|
+
wishlistCount.value > 99 ? '99+' : String(wishlistCount.value)
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
// --- current page ------------------------------------------------------------------------------
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* `window.location` (a plain browser API, not a Nuxt global — `useRoute()` is what the starter's
|
|
521
|
+
* "no Nuxt globals in blocks" rule forbids) is the only way a block can tell which link is
|
|
522
|
+
* "current" without reading the router. `popstate` catches back/forward navigation; a same-site
|
|
523
|
+
* `Link`/`Button` click elsewhere on the page (pushed via the router, not a full reload) does not
|
|
524
|
+
* fire it, so the highlighted link can go stale until the next popstate/reload — a known
|
|
525
|
+
* limitation of staying router-free, not something this block can close without one.
|
|
526
|
+
*
|
|
527
|
+
* Every `watchEffect` below opens with `if (typeof window === 'undefined') return;`. That is not
|
|
528
|
+
* defensive padding: a `flush: 'pre'` effect with no callback runs its body *immediately*, during
|
|
529
|
+
* `setup()`, and `setup()` runs on the server too — so an unguarded `window.addEventListener`
|
|
530
|
+
* here throws `ReferenceError: window is not defined` on every server render of any page that
|
|
531
|
+
* carries the header (i.e. every page), which `nuxi generate` turns into a failed prerender when
|
|
532
|
+
* `nitro.prerender.failOnError` is on. `__tests__/ssr.spec.ts` server-renders this block to keep
|
|
533
|
+
* the guards honest.
|
|
534
|
+
*/
|
|
535
|
+
const currentPath = ref(typeof window === 'undefined' ? '' : window.location.pathname);
|
|
536
|
+
watchEffect((onCleanup) => {
|
|
537
|
+
if (typeof window === 'undefined') return;
|
|
538
|
+
const onPopState = (): void => {
|
|
539
|
+
currentPath.value = window.location.pathname;
|
|
540
|
+
};
|
|
541
|
+
window.addEventListener('popstate', onPopState);
|
|
542
|
+
onCleanup(() => window.removeEventListener('popstate', onPopState));
|
|
543
|
+
});
|
|
544
|
+
function isCurrent(href: string | undefined): boolean {
|
|
545
|
+
return href !== undefined && href === currentPath.value;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// --- sticky, scroll padding and scrolled shadow -----------------------------------------------
|
|
549
|
+
|
|
550
|
+
const sticky = computed(() => data.value.sticky !== false);
|
|
551
|
+
const scrolled = ref(false);
|
|
552
|
+
/**
|
|
553
|
+
* A sticky bar that stayed pinned would cover the top of every screen for the whole visit; instead
|
|
554
|
+
* it slides away while the visitor scrolls down and comes back the moment they scroll up (or reach
|
|
555
|
+
* the top), the way most storefront headers behave. Small jitters (under 4px, a trackpad settling)
|
|
556
|
+
* never toggle it, and it stays put while the visitor is *using* it: an open mega-menu, the mobile
|
|
557
|
+
* drawer, the search overlay, or keyboard focus anywhere inside the bar (a hidden bar would strand
|
|
558
|
+
* a focused control off-screen — 2.4.7). Non-sticky headers scroll away with the page and never
|
|
559
|
+
* hide.
|
|
560
|
+
*
|
|
561
|
+
* The bar that does this is `position: fixed`, not `position: sticky`, and the spacer below it
|
|
562
|
+
* (`barSpacerClasses`) reserves the room it no longer takes in the flow. A sticky box is clamped to
|
|
563
|
+
* its own containing block, and a block's containing block is the single-block wrapper rendered
|
|
564
|
+
* around it — a `<div data-eldra-block>` from the block zone, or that same wrapper nested in a
|
|
565
|
+
* layout node's container. That box is exactly the bar's own height, so a sticky bar inside it has
|
|
566
|
+
* nowhere to travel: it stays at the top of the *page*, scrolls out of view with it and never
|
|
567
|
+
* returns, however the state machine below sets its classes. Measured against the viewport instead,
|
|
568
|
+
* the bar travels — and the spacer keeps the page's own flow, where the hero starts and what the
|
|
569
|
+
* block occupies, byte for byte what it was while the bar was in it.
|
|
570
|
+
*/
|
|
571
|
+
const hiddenByScroll = ref(false);
|
|
572
|
+
/**
|
|
573
|
+
* True only while focus inside the bar is `:focus-visible`: a plain mouse click on the bag or
|
|
574
|
+
* search button focuses it too, and the drawer/dialog it opens restores focus there on close, so
|
|
575
|
+
* counting any focus would pin the bar open for the rest of the page view instead of just for the
|
|
576
|
+
* keyboard visitor 2.4.7 protects.
|
|
577
|
+
*/
|
|
578
|
+
const focusWithinBar = ref(false);
|
|
579
|
+
/**
|
|
580
|
+
* The bar's height, named once: the bar sets it on its own `<nav>` and the spacer reserves the very
|
|
581
|
+
* same box. Two literals would drift the first time a breakpoint moved, and a spacer that drifts
|
|
582
|
+
* from the bar is a page that jumps. `@content:` is a container query, so it is only ever as true
|
|
583
|
+
* as the container it is measured in — which is why both boxes sit inside an `@container` of the
|
|
584
|
+
* block's own width.
|
|
585
|
+
*/
|
|
586
|
+
const BAR_HEIGHT_CLASS = 'h-16 @content:h-[4.5rem]';
|
|
587
|
+
let lastScrollY = 0;
|
|
588
|
+
const SCROLL_JITTER = 4;
|
|
589
|
+
function onScroll(): void {
|
|
590
|
+
const y = window.scrollY;
|
|
591
|
+
scrolled.value = y > 0;
|
|
592
|
+
const delta = y - lastScrollY;
|
|
593
|
+
lastScrollY = y;
|
|
594
|
+
if (!sticky.value) return;
|
|
595
|
+
const barHeight = barRoot.value?.offsetHeight ?? 0;
|
|
596
|
+
if (y <= barHeight) {
|
|
597
|
+
hiddenByScroll.value = false;
|
|
598
|
+
} else if (delta > SCROLL_JITTER) {
|
|
599
|
+
hiddenByScroll.value = true;
|
|
600
|
+
} else if (delta < -SCROLL_JITTER) {
|
|
601
|
+
hiddenByScroll.value = false;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const barHidden = computed(
|
|
605
|
+
() =>
|
|
606
|
+
sticky.value &&
|
|
607
|
+
hiddenByScroll.value &&
|
|
608
|
+
openMenuIndex.value === null &&
|
|
609
|
+
!drawerOpen.value &&
|
|
610
|
+
!searchOpen.value &&
|
|
611
|
+
!focusWithinBar.value
|
|
612
|
+
);
|
|
613
|
+
watchEffect((onCleanup) => {
|
|
614
|
+
if (typeof window === 'undefined') return;
|
|
615
|
+
window.addEventListener('scroll', onScroll, { passive: true });
|
|
616
|
+
onCleanup(() => window.removeEventListener('scroll', onScroll));
|
|
617
|
+
});
|
|
618
|
+
function onBarFocusIn(event: FocusEvent): void {
|
|
619
|
+
const target = event.target;
|
|
620
|
+
// `:focus-visible` is the browser's own keyboard-vs-pointer call, re-read on every focusin —
|
|
621
|
+
// including a dialog's programmatic `.focus()` back onto its opener, which the browser attributes
|
|
622
|
+
// to whatever closed the dialog: a mouse on the close button or backdrop does not match, Escape
|
|
623
|
+
// does, and that pin lasts only until focus leaves the bar. An engine that can't evaluate the
|
|
624
|
+
// selector can't tell the two apart; it is treated as keyboard, the conservative 2.4.7 default.
|
|
625
|
+
try {
|
|
626
|
+
focusWithinBar.value = target instanceof Element ? target.matches(':focus-visible') : true;
|
|
627
|
+
} catch {
|
|
628
|
+
focusWithinBar.value = true;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function onBarFocusOut(event: FocusEvent): void {
|
|
632
|
+
const next = event.relatedTarget;
|
|
633
|
+
focusWithinBar.value = next instanceof Node && (barRoot.value?.contains(next) ?? false);
|
|
634
|
+
}
|
|
635
|
+
/** Spec "Header" → Accessibility, "Sticky header and focus": scroll padding equal to the sticky
|
|
636
|
+
* bar's height (2.4.11), so a focused/anchored target is never hidden under it. */
|
|
637
|
+
watchEffect((onCleanup) => {
|
|
638
|
+
if (typeof document === 'undefined') return;
|
|
639
|
+
if (!sticky.value) return;
|
|
640
|
+
document.documentElement.style.setProperty('scroll-padding-top', '5rem');
|
|
641
|
+
onCleanup(() => document.documentElement.style.removeProperty('scroll-padding-top'));
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
// --- published header height (--eldra-header-height) ------------------------------------------
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* `faq`'s two-column sticky head column and `collection-grid`'s sticky filter rail both read
|
|
648
|
+
* `var(--eldra-header-height,0px)` for the extra offset a *sticky* header needs added to their own
|
|
649
|
+
* "N rem from the top" value (see either block's own module doc comment) — otherwise their sticky
|
|
650
|
+
* content would settle directly under the viewport edge and slide underneath this bar. This is the
|
|
651
|
+
* one place that variable is ever written: a `ResizeObserver` (guarded for an environment with
|
|
652
|
+
* none, e.g. jsdom under Vitest — the same guard `trust-strip`'s own list-overflow measurement
|
|
653
|
+
* uses) keeps the published value equal to the bar's real rendered height, which changes with
|
|
654
|
+
* `sticky`/`variant`/`searchStyle` and the mobile/tablet/desktop breakpoint. The property is
|
|
655
|
+
* removed — not just left stale — the moment `sticky` turns off, so a non-sticky header never
|
|
656
|
+
* claims space it doesn't occupy in the page's fixed flow, and on unmount (`onCleanup`), so it
|
|
657
|
+
* never survives past this instance of the block.
|
|
658
|
+
*/
|
|
659
|
+
const barRoot = ref<HTMLElement | null>(null);
|
|
660
|
+
/** The same measurement, in pixels, for the spacer below the fixed bar to reserve. */
|
|
661
|
+
const barHeight = ref<number | null>(null);
|
|
662
|
+
watchEffect((onCleanup) => {
|
|
663
|
+
// Server render has no `document` at all; nothing to publish or clear there.
|
|
664
|
+
if (typeof document === 'undefined') return;
|
|
665
|
+
if (!sticky.value || typeof ResizeObserver === 'undefined' || barRoot.value === null) {
|
|
666
|
+
document.documentElement.style.removeProperty('--eldra-header-height');
|
|
667
|
+
barHeight.value = null;
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const el = barRoot.value;
|
|
671
|
+
const publish = (): void => {
|
|
672
|
+
const height = el.getBoundingClientRect().height;
|
|
673
|
+
document.documentElement.style.setProperty('--eldra-header-height', `${height}px`);
|
|
674
|
+
// The same measurement the spacer reserves, so the two can never disagree.
|
|
675
|
+
barHeight.value = height;
|
|
676
|
+
};
|
|
677
|
+
const observer = new ResizeObserver(publish);
|
|
678
|
+
observer.observe(el);
|
|
679
|
+
publish();
|
|
680
|
+
onCleanup(() => {
|
|
681
|
+
observer.disconnect();
|
|
682
|
+
document.documentElement.style.removeProperty('--eldra-header-height');
|
|
683
|
+
barHeight.value = null;
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// --- transparent-over-hero -----------------------------------------------------------------------
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* The block reads only its own field: it has no way to see the next block on the page (blocks
|
|
691
|
+
* never inspect siblings or the DOM outside themselves — see `docs/starter-kit.md`). `sticky`'s
|
|
692
|
+
* own effect (2.4.11) is unconditional; the "only when the next block really is a Hero
|
|
693
|
+
* `image-background`" half of the spec's rule is a page-composition concern outside a single
|
|
694
|
+
* block's own `__tests__/Block.spec.ts` — proven at the page level once a page fixture pairs the
|
|
695
|
+
* two. `data-eldra-transparent` is the hook that pairing
|
|
696
|
+
* reads/sets; this block turns the visual state on whenever `transparentOverHero` is on and the
|
|
697
|
+
* bar hasn't already turned solid on its own (scrolled, or a menu open).
|
|
698
|
+
*/
|
|
699
|
+
const transparentOverHero = computed(() => data.value.transparentOverHero === true);
|
|
700
|
+
const isTransparent = computed(
|
|
701
|
+
() =>
|
|
702
|
+
transparentOverHero.value &&
|
|
703
|
+
!scrolled.value &&
|
|
704
|
+
openMenuIndex.value === null &&
|
|
705
|
+
!drawerOpen.value
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
// --- the surface the bar and an open panel share ------------------------------------------------
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* One source of truth for the colour the header paints, published on the bar itself as
|
|
712
|
+
* `--eldra-header-surface` and read by an open mega-menu panel as its own ground.
|
|
713
|
+
*
|
|
714
|
+
* The panel used to name a ground token of its own (`bg-background`, the same one the bar names).
|
|
715
|
+
* The two read identically today and would drift the moment either side's ground changed — and a
|
|
716
|
+
* sheet hanging off the bar in a *slightly* different colour is the one thing an open panel must
|
|
717
|
+
* never look like. The bar now publishes what it paints and the panel takes it, so there is nothing
|
|
718
|
+
* left to keep in step by hand.
|
|
719
|
+
*
|
|
720
|
+
* `bg-background` is the only ground the bar ever has. The transparent-over-hero state is not an
|
|
721
|
+
* exception: `isTransparent` is false whenever a panel is open (a panel must never float on a
|
|
722
|
+
* transparent bar — it is also what gives the panel the full-bleed hairline along its top edge), so
|
|
723
|
+
* by the time anything reads this variable the bar has already turned solid. The value is written as
|
|
724
|
+
* the Tailwind namespace variable `bg-background` itself resolves to, so a theme whose `background`
|
|
725
|
+
* token Studio is editing live moves the bar and the panel together, in the same frame.
|
|
726
|
+
*/
|
|
727
|
+
const HEADER_SURFACE_VAR = '--eldra-header-surface';
|
|
728
|
+
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
|
+
|
|
755
|
+
/**
|
|
756
|
+
* `@eldrajs/ui`'s `classes` prop takes a plain string per part (`Partial<Record<Part, string>>`),
|
|
757
|
+
* never an array — `Section`'s own `partClass`/`cx` treats a non-string, non-falsy value as the
|
|
758
|
+
* `Record<string, boolean>` branch of its `ClassValue` union, which for a plain array reads its
|
|
759
|
+
* numeric indices as "class names" and their truthy values as "on": an empty-string entry at index
|
|
760
|
+
* 3 (falsy) got dropped and the three truthy entries before it came back out as the class string
|
|
761
|
+
* `"0 1 2"` — every real utility class silently lost. Every conditional class list handed to a
|
|
762
|
+
* `classes` prop in this file is therefore joined into one string with `[...].filter(Boolean).join(' ')`,
|
|
763
|
+
* never left as an array.
|
|
764
|
+
*/
|
|
765
|
+
/**
|
|
766
|
+
* Spec "Header" → Container/Section line: "Section background default `background` … Section
|
|
767
|
+
* spacing none (the bar sets its own height)". This root is a plain `<header>`, never
|
|
768
|
+
* `@eldrajs/ui`'s `Section`: `Section` marks every ground (including `none`) with
|
|
769
|
+
* `data-section-bg` so its own adjacent-same-background CSS rule can drop the *next* sibling's
|
|
770
|
+
* top padding, and the header must never trigger that rule against the block that follows it (a
|
|
771
|
+
* Hero, most often) — the header is fixed chrome that always sits at the page's own ground, not a
|
|
772
|
+
* coloured band the padding-collapse rule is meant to read as one continuous band with its
|
|
773
|
+
* neighbour. It also never needs `Section`'s `group/section` colour-inversion machinery: `background`
|
|
774
|
+
* is always `none` here, and transparent-over-hero mode is handled entirely by `barRootClasses`
|
|
775
|
+
* above, not by `Section`'s `primary`/`accent` invert. `@container` is kept directly on this root so
|
|
776
|
+
* `Container` and every `@content:`/`@tablet:` variant below still measure the header's own width.
|
|
777
|
+
*/
|
|
778
|
+
const barRootClasses = computed(() =>
|
|
779
|
+
[
|
|
780
|
+
'@container',
|
|
781
|
+
sticky.value
|
|
782
|
+
? 'fixed inset-x-0 top-0 z-40 motion-safe:transition-transform motion-safe:duration-base'
|
|
783
|
+
: '',
|
|
784
|
+
barHidden.value ? '-translate-y-full' : '',
|
|
785
|
+
isTransparent.value
|
|
786
|
+
? 'bg-transparent text-primary-contrast'
|
|
787
|
+
: 'bg-background text-text border-b border-border',
|
|
788
|
+
scrolled.value && !isTransparent.value ? 'shadow-float' : '',
|
|
789
|
+
]
|
|
790
|
+
.filter(Boolean)
|
|
791
|
+
.join(' ')
|
|
792
|
+
);
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The room the fixed bar is no longer in the flow to claim: an empty box of the bar's own height,
|
|
796
|
+
* rendered only when the bar is fixed, so a non-sticky header still occupies its space itself.
|
|
797
|
+
*
|
|
798
|
+
* The height classes are what the first paint of a prerendered page has, before the bar has been
|
|
799
|
+
* measured at all — a spacer that started at zero would drop the page by the bar's height and lift
|
|
800
|
+
* it again on hydration. They carry the `@content:` breakpoint, so they need a container of the
|
|
801
|
+
* block's own width to be measured in: the bar has one (its own `@container` root), and the spacer
|
|
802
|
+
* is one, which is why the box that holds the height is a child rather than the spacer itself.
|
|
803
|
+
* `barHeight` takes over the moment the `ResizeObserver` above has a real number, and from then on
|
|
804
|
+
* the spacer is the bar's measured height to the pixel, whatever either box's width does.
|
|
805
|
+
*
|
|
806
|
+
* 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
|
|
808
|
+
* the pixel lands: everything here is `border-box`, so a border on the box that *has* the height
|
|
809
|
+
* eats into it rather than adding to it. `border-transparent` contributes nothing but that pixel,
|
|
810
|
+
* and only while the bar has it — the solid bar draws `border-b` and the transparent-over-hero bar
|
|
811
|
+
* does not, so without this the page would shift by 1px the moment the bar turned solid.
|
|
812
|
+
*/
|
|
813
|
+
const barSpacerClasses = computed(() =>
|
|
814
|
+
['@container', isTransparent.value ? '' : 'border-b border-transparent'].filter(Boolean).join(' ')
|
|
815
|
+
);
|
|
816
|
+
const barSpacerStyle = computed(() =>
|
|
817
|
+
barHeight.value === null ? undefined : { height: `${barHeight.value}px` }
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
const hairlineClass = computed(() =>
|
|
821
|
+
isTransparent.value ? 'border-primary-contrast/24' : 'border-border'
|
|
822
|
+
);
|
|
823
|
+
|
|
824
|
+
// --- menu button visibility ----------------------------------------------------------------------
|
|
825
|
+
|
|
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
|
+
*/
|
|
836
|
+
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
|
+
: ''
|
|
842
|
+
);
|
|
843
|
+
const linksPositionClass = computed(() =>
|
|
844
|
+
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'
|
|
847
|
+
);
|
|
848
|
+
const searchPositionClass = computed(() =>
|
|
849
|
+
variant.value === 'centered' ? '@content:col-start-1 @content:row-start-1' : ''
|
|
850
|
+
);
|
|
851
|
+
const actionsPositionClass = computed(() =>
|
|
852
|
+
variant.value === 'centered' ? '@content:col-start-4 @content:row-start-1' : ''
|
|
853
|
+
);
|
|
854
|
+
</script>
|
|
855
|
+
|
|
856
|
+
<template>
|
|
857
|
+
<header
|
|
858
|
+
ref="barRoot"
|
|
859
|
+
:data-eldra-transparent="isTransparent ? 'true' : undefined"
|
|
860
|
+
:class="barRootClasses"
|
|
861
|
+
:style="barSurfaceStyle"
|
|
862
|
+
@focusin="onBarFocusIn"
|
|
863
|
+
@focusout="onBarFocusOut"
|
|
864
|
+
>
|
|
865
|
+
<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')"
|
|
882
|
+
:class="[
|
|
883
|
+
BAR_HEIGHT_CLASS,
|
|
884
|
+
'relative grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-1',
|
|
885
|
+
]"
|
|
886
|
+
>
|
|
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
|
+
<Link
|
|
906
|
+
:href="brandHref"
|
|
907
|
+
:as="EldraRouterLink"
|
|
908
|
+
variant="standalone"
|
|
909
|
+
:underline="false"
|
|
910
|
+
data-eldra-header-focus
|
|
911
|
+
:classes="{
|
|
912
|
+
root: `flex min-h-11 min-w-0 items-center gap-2 rounded-sm px-1 font-heading text-lg font-bold tracking-tight ${brandPositionClass}`,
|
|
913
|
+
}"
|
|
914
|
+
>
|
|
915
|
+
<img
|
|
916
|
+
v-if="brandLogoUrl"
|
|
917
|
+
:src="brandLogoUrl"
|
|
918
|
+
:alt="data.brandText"
|
|
919
|
+
class="h-8 w-auto max-w-40 object-contain"
|
|
920
|
+
loading="eager"
|
|
921
|
+
decoding="async"
|
|
922
|
+
/>
|
|
923
|
+
<!-- The spec keeps the wordmark from ever wrapping (block.json's own 20-character
|
|
924
|
+
maxLength keeps it fitting in the ordinary case); `min-w-0` on the root above stops
|
|
925
|
+
a CSS Grid item's default intrinsic min-width from blowing the brand column out
|
|
926
|
+
into its neighbours on very narrow viewports, and this span's own truncation is the
|
|
927
|
+
graceful fallback for the rare case that still doesn't leave enough room. -->
|
|
928
|
+
<span v-else class="overflow-hidden text-ellipsis whitespace-nowrap">{{
|
|
929
|
+
data.brandText
|
|
930
|
+
}}</span>
|
|
931
|
+
</Link>
|
|
932
|
+
|
|
933
|
+
<ul
|
|
934
|
+
v-if="linksVisible"
|
|
935
|
+
ref="barLinkList"
|
|
936
|
+
:class="['list-none items-center gap-1', linksPositionClass]"
|
|
937
|
+
>
|
|
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>
|
|
970
|
+
<Link
|
|
971
|
+
v-else-if="link.href"
|
|
972
|
+
:href="link.href"
|
|
973
|
+
:as="link.as"
|
|
974
|
+
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)"
|
|
981
|
+
>
|
|
982
|
+
{{ link.label }}
|
|
983
|
+
</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>
|
|
1079
|
+
<EditorPlaceholder
|
|
1080
|
+
v-else-if="isEditing && variant !== 'minimal' && links.length === 0"
|
|
1081
|
+
inline
|
|
1082
|
+
:label="t('editor.addLink')"
|
|
1083
|
+
:classes="{ root: linksPositionClass }"
|
|
1084
|
+
/>
|
|
1085
|
+
|
|
1086
|
+
<!-- `justify-end` matters in exactly one case and is inert in every other: with no Menu
|
|
1087
|
+
button in the grid (nothing to put in the drawer), the search control auto-places into
|
|
1088
|
+
the `minmax(0,1fr)` column the brand usually takes, and left-aligned it would sit
|
|
1089
|
+
against the wordmark with the cart stranded across the bar. Everywhere else this
|
|
1090
|
+
wrapper lands in an `auto` column, which is content-sized, so the rule does nothing. -->
|
|
1091
|
+
<div :class="['flex items-center justify-end', searchPositionClass]">
|
|
1092
|
+
<template v-if="showSearch">
|
|
1093
|
+
<Button
|
|
1094
|
+
v-if="searchStyle === 'icon'"
|
|
1095
|
+
variant="ghost"
|
|
1096
|
+
size="sm"
|
|
1097
|
+
icon-only
|
|
1098
|
+
:label="t('header.search')"
|
|
1099
|
+
aria-haspopup="dialog"
|
|
1100
|
+
@click="openSearch"
|
|
1101
|
+
>
|
|
1102
|
+
<template #leadingIcon>
|
|
1103
|
+
<EldraIcon name="search" size="md" />
|
|
1104
|
+
</template>
|
|
1105
|
+
</Button>
|
|
1106
|
+
<template v-else-if="searchStyle === 'field'">
|
|
1107
|
+
<Button
|
|
1108
|
+
variant="outline"
|
|
1109
|
+
size="sm"
|
|
1110
|
+
aria-haspopup="dialog"
|
|
1111
|
+
:classes="{ container: 'hidden rounded-full @content:inline-flex' }"
|
|
1112
|
+
@click="openSearch"
|
|
1113
|
+
>
|
|
1114
|
+
{{ t('header.searchField') }}
|
|
1115
|
+
<span class="text-muted ml-2 text-xs">⌘K</span>
|
|
1116
|
+
</Button>
|
|
1117
|
+
<Button
|
|
1118
|
+
variant="ghost"
|
|
1119
|
+
size="sm"
|
|
1120
|
+
icon-only
|
|
1121
|
+
:label="t('header.search')"
|
|
1122
|
+
aria-haspopup="dialog"
|
|
1123
|
+
:classes="{ container: '@content:hidden' }"
|
|
1124
|
+
@click="openSearch"
|
|
1125
|
+
>
|
|
1126
|
+
<template #leadingIcon>
|
|
1127
|
+
<EldraIcon name="search" size="md" />
|
|
1128
|
+
</template>
|
|
1129
|
+
</Button>
|
|
1130
|
+
</template>
|
|
1131
|
+
<template v-else>
|
|
1132
|
+
<SearchBar
|
|
1133
|
+
v-model="searchQuery"
|
|
1134
|
+
size="md"
|
|
1135
|
+
pill
|
|
1136
|
+
:action="searchAction"
|
|
1137
|
+
:label="t('header.searchField')"
|
|
1138
|
+
:results="searchResults"
|
|
1139
|
+
:loading="searchLoading"
|
|
1140
|
+
:classes="{ root: 'hidden w-64 @content:block' }"
|
|
1141
|
+
/>
|
|
1142
|
+
<Button
|
|
1143
|
+
variant="ghost"
|
|
1144
|
+
size="sm"
|
|
1145
|
+
icon-only
|
|
1146
|
+
:label="t('header.search')"
|
|
1147
|
+
aria-haspopup="dialog"
|
|
1148
|
+
:classes="{ container: '@content:hidden' }"
|
|
1149
|
+
@click="openSearch"
|
|
1150
|
+
>
|
|
1151
|
+
<template #leadingIcon>
|
|
1152
|
+
<EldraIcon name="search" size="md" />
|
|
1153
|
+
</template>
|
|
1154
|
+
</Button>
|
|
1155
|
+
</template>
|
|
1156
|
+
</template>
|
|
1157
|
+
</div>
|
|
1158
|
+
|
|
1159
|
+
<div data-eldra-header-actions :class="['flex items-center gap-1', actionsPositionClass]">
|
|
1160
|
+
<!-- In every header but `minimal`, prerendered ones included: see `wishlist` in the
|
|
1161
|
+
script above. `EldraRouterLink` because `/wishlist` is this theme's own route — it
|
|
1162
|
+
should route, not reload the document. -->
|
|
1163
|
+
<span v-if="variant !== 'minimal'" class="relative inline-flex">
|
|
1164
|
+
<Button
|
|
1165
|
+
variant="ghost"
|
|
1166
|
+
size="sm"
|
|
1167
|
+
icon-only
|
|
1168
|
+
:label="wishlistAccessibleName"
|
|
1169
|
+
:href="wishlistHref"
|
|
1170
|
+
:as="EldraRouterLink"
|
|
1171
|
+
>
|
|
1172
|
+
<template #leadingIcon>
|
|
1173
|
+
<EldraIcon name="heart" size="md" />
|
|
1174
|
+
</template>
|
|
1175
|
+
</Button>
|
|
1176
|
+
<!-- The bag's own two rules: no badge at zero, and `pointer-events-none`, because the
|
|
1177
|
+
count is decorative (the button's accessible name carries it) and must not swallow
|
|
1178
|
+
a click meant for the link. -->
|
|
1179
|
+
<Badge
|
|
1180
|
+
v-if="wishlistCount > 0"
|
|
1181
|
+
aria-hidden="true"
|
|
1182
|
+
tone="primary"
|
|
1183
|
+
pill
|
|
1184
|
+
:label="wishlistBadgeLabel"
|
|
1185
|
+
:classes="{ root: COUNT_PILL_CLASSES }"
|
|
1186
|
+
/>
|
|
1187
|
+
</span>
|
|
1188
|
+
|
|
1189
|
+
<span class="relative inline-flex">
|
|
1190
|
+
<Button
|
|
1191
|
+
variant="ghost"
|
|
1192
|
+
size="sm"
|
|
1193
|
+
icon-only
|
|
1194
|
+
:label="cartAccessibleName"
|
|
1195
|
+
:href="cartHref"
|
|
1196
|
+
:as="toLinkAs(cartHref)"
|
|
1197
|
+
:aria-haspopup="cartPopupType"
|
|
1198
|
+
@click="onCartClick"
|
|
1199
|
+
>
|
|
1200
|
+
<template #leadingIcon>
|
|
1201
|
+
<EldraIcon name="shopping-bag" size="md" />
|
|
1202
|
+
</template>
|
|
1203
|
+
</Button>
|
|
1204
|
+
<Badge
|
|
1205
|
+
v-if="cartCount > 0"
|
|
1206
|
+
aria-hidden="true"
|
|
1207
|
+
tone="primary"
|
|
1208
|
+
pill
|
|
1209
|
+
:label="cartBadgeLabel"
|
|
1210
|
+
:classes="{ root: COUNT_PILL_CLASSES }"
|
|
1211
|
+
/>
|
|
1212
|
+
</span>
|
|
1213
|
+
|
|
1214
|
+
<!-- Spec Header -> Layout, From 64rem: the call to action sits 0.75rem after the cart.
|
|
1215
|
+
0.25rem of that is already the actions row's own gap-1; @content:ml-2 (0.5rem) makes
|
|
1216
|
+
up the rest, so it reads as its own button rather than a fourth icon in the row. -->
|
|
1217
|
+
<Button
|
|
1218
|
+
v-if="hasCta && variant !== 'minimal'"
|
|
1219
|
+
variant="primary"
|
|
1220
|
+
size="sm"
|
|
1221
|
+
:href="ctaHref"
|
|
1222
|
+
:as="ctaLinkAs"
|
|
1223
|
+
:classes="{ container: 'hidden @content:inline-flex @content:ml-2' }"
|
|
1224
|
+
>
|
|
1225
|
+
{{ ctaLabel }}
|
|
1226
|
+
</Button>
|
|
1227
|
+
</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
|
+
</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>
|
|
1326
|
+
|
|
1327
|
+
<SearchModal
|
|
1328
|
+
v-model="searchOpen"
|
|
1329
|
+
v-model:query="searchQuery"
|
|
1330
|
+
:action="searchAction"
|
|
1331
|
+
:results="searchResults"
|
|
1332
|
+
:loading="searchLoading"
|
|
1333
|
+
/>
|
|
1334
|
+
</header>
|
|
1335
|
+
<!-- The flow the fixed bar left behind — see `barSpacerClasses`. Empty and unlabelled: it is
|
|
1336
|
+
layout, with nothing in it for a screen reader or the tab order to reach. The outer box is the
|
|
1337
|
+
`<header>`'s counterpart (the `@container` the height is measured in, and the hairline) and the
|
|
1338
|
+
inner one the `<nav>`'s (the height itself). -->
|
|
1339
|
+
<div
|
|
1340
|
+
v-if="sticky"
|
|
1341
|
+
data-eldra-header-spacer
|
|
1342
|
+
aria-hidden="true"
|
|
1343
|
+
:class="barSpacerClasses"
|
|
1344
|
+
:style="barSpacerStyle"
|
|
1345
|
+
>
|
|
1346
|
+
<div :class="BAR_HEIGHT_CLASS" />
|
|
1347
|
+
</div>
|
|
1348
|
+
</template>
|