@eldrajs/theme-cli 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/package.json +3 -3
  3. package/template/.eldra/block-types.d.ts +4 -6
  4. package/template/.eldra/manifest.json +228 -246
  5. package/template/.eldra/previews.json +35 -35
  6. package/template/.storybook/eldra.ts +7 -2
  7. package/template/app/assets/main.css +5 -0
  8. package/template/app/composables/useBlockData.ts +9 -2
  9. package/template/app/composables/usePriceTokens.ts +150 -0
  10. package/template/app/composables/useQuickAdd.ts +95 -0
  11. package/template/app/composables/useRegionalFormat.ts +94 -0
  12. package/template/app/icons.ts +4 -0
  13. package/template/app/plugins/eldra-storefront.ts +2 -0
  14. package/template/app/plugins/eldra-ui-messages.ts +22 -8
  15. package/template/app/storefront/demo.ts +188 -16
  16. package/template/app/storefront/gateway.ts +19 -0
  17. package/template/app/storefront/productCardLook.ts +76 -0
  18. package/template/app/storefront/productReference.ts +17 -0
  19. package/template/app/storefront/toProductCard.ts +12 -8
  20. package/template/app/storefront/types.ts +17 -0
  21. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
  22. package/template/blocks/announcement-bar/block.json +2 -1
  23. package/template/blocks/announcement-bar/mock.json +1 -1
  24. package/template/blocks/announcement-bar/preview.png +0 -0
  25. package/template/blocks/article/Block.vue +8 -18
  26. package/template/blocks/article/block.json +3 -1
  27. package/template/blocks/article/preview.png +0 -0
  28. package/template/blocks/article-list/block.json +10 -1
  29. package/template/blocks/article-list/preview.png +0 -0
  30. package/template/blocks/breadcrumbs/Block.vue +15 -3
  31. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
  32. package/template/blocks/breadcrumbs/block.json +1 -0
  33. package/template/blocks/breadcrumbs/preview.png +0 -0
  34. package/template/blocks/cart/Block.vue +15 -5
  35. package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
  36. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
  37. package/template/blocks/cart/block.json +8 -5
  38. package/template/blocks/cart/mock.json +2 -2
  39. package/template/blocks/cart/parts/ShippingBar.vue +24 -30
  40. package/template/blocks/cart/parts/notSold.ts +4 -3
  41. package/template/blocks/collection-grid/Block.vue +168 -85
  42. package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
  43. package/template/blocks/collection-grid/preview.png +0 -0
  44. package/template/blocks/collection-header/Block.vue +34 -11
  45. package/template/blocks/collection-header/__tests__/Block.spec.ts +3 -3
  46. package/template/blocks/collection-header/block.json +2 -0
  47. package/template/blocks/collection-header/preview.png +0 -0
  48. package/template/blocks/contact/block.json +4 -0
  49. package/template/blocks/contact/preview.png +0 -0
  50. package/template/blocks/cta/block.json +2 -0
  51. package/template/blocks/faq/Block.vue +5 -10
  52. package/template/blocks/faq/block.json +2 -1
  53. package/template/blocks/faq/mock.json +12 -1
  54. package/template/blocks/faq/preview.png +0 -0
  55. package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
  56. package/template/blocks/feature-grid/block.json +3 -2
  57. package/template/blocks/feature-grid/mock.json +1 -1
  58. package/template/blocks/feature-grid/preview.png +0 -0
  59. package/template/blocks/footer/Block.vue +64 -21
  60. package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
  61. package/template/blocks/footer/block.json +5 -2
  62. package/template/blocks/footer/mock.json +1 -1
  63. package/template/blocks/footer/preview.png +0 -0
  64. package/template/blocks/form/block.json +1 -0
  65. package/template/blocks/gallery/preview.png +0 -0
  66. package/template/blocks/hero/Block.vue +38 -9
  67. package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
  68. package/template/blocks/hero/block.json +16 -22
  69. package/template/blocks/hero/preview.json +1 -3
  70. package/template/blocks/hero/preview.png +0 -0
  71. package/template/blocks/image/block.json +2 -1
  72. package/template/blocks/image/preview.png +0 -0
  73. package/template/blocks/logo-cloud/block.json +1 -0
  74. package/template/blocks/logo-cloud/preview.png +0 -0
  75. package/template/blocks/navigation/Block.vue +404 -159
  76. package/template/blocks/navigation/__tests__/Block.spec.ts +806 -172
  77. package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
  78. package/template/blocks/navigation/block.json +2 -11
  79. package/template/blocks/navigation/mock.json +3 -3
  80. package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
  81. package/template/blocks/navigation/parts/currentItem.ts +82 -0
  82. package/template/blocks/navigation/preview.json +7 -1
  83. package/template/blocks/navigation/preview.png +0 -0
  84. package/template/blocks/newsletter/Block.vue +6 -2
  85. package/template/blocks/newsletter/block.json +2 -0
  86. package/template/blocks/newsletter/preview.png +0 -0
  87. package/template/blocks/order-status/Block.vue +8 -17
  88. package/template/blocks/order-status/block.json +3 -0
  89. package/template/blocks/order-status/preview.png +0 -0
  90. package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
  91. package/template/blocks/pricing-table/block.json +2 -0
  92. package/template/blocks/pricing-table/mock.json +6 -6
  93. package/template/blocks/pricing-table/preview.png +0 -0
  94. package/template/blocks/product-carousel/Block.vue +36 -126
  95. package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
  96. package/template/blocks/product-carousel/block.json +1 -0
  97. package/template/blocks/product-carousel/preview.png +0 -0
  98. package/template/blocks/product-detail/Block.vue +84 -31
  99. package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
  100. package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
  101. package/template/blocks/product-detail/block.json +3 -1
  102. package/template/blocks/product-detail/mock.json +54 -4
  103. package/template/blocks/product-detail/parts/Gallery.vue +8 -2
  104. package/template/blocks/product-detail/preview.png +0 -0
  105. package/template/blocks/product-detail/specs.ts +75 -0
  106. package/template/blocks/quote/block.json +1 -0
  107. package/template/blocks/rich-text/preview.png +0 -0
  108. package/template/blocks/search/Block.vue +6 -1
  109. package/template/blocks/search/TypeSection.vue +8 -1
  110. package/template/blocks/search/__tests__/Block.spec.ts +24 -1
  111. package/template/blocks/search/block.json +1 -0
  112. package/template/blocks/search/preview.png +0 -0
  113. package/template/blocks/split-content/Block.vue +12 -5
  114. package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
  115. package/template/blocks/split-content/block.json +4 -2
  116. package/template/blocks/split-content/preview.png +0 -0
  117. package/template/blocks/stats/preview.png +0 -0
  118. package/template/blocks/tabs/Block.vue +3 -4
  119. package/template/blocks/tabs/block.json +1 -1
  120. package/template/blocks/tabs/preview.png +0 -0
  121. package/template/blocks/team/block.json +3 -1
  122. package/template/blocks/team/preview.png +0 -0
  123. package/template/blocks/testimonials/block.json +2 -0
  124. package/template/blocks/testimonials/preview.png +0 -0
  125. package/template/blocks/timeline/block.json +2 -1
  126. package/template/blocks/timeline/preview.png +0 -0
  127. package/template/blocks/trust-strip/Block.vue +2 -2
  128. package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
  129. package/template/blocks/trust-strip/block.json +1 -1
  130. package/template/blocks/trust-strip/mock.json +1 -1
  131. package/template/blocks/trust-strip/preview.json +1 -1
  132. package/template/blocks/trust-strip/preview.png +0 -0
  133. package/template/blocks/video-embed/block.json +2 -0
  134. package/template/blocks/video-embed/preview.png +0 -0
  135. package/template/blocks/wishlist/Block.vue +2 -2
  136. package/template/blocks/wishlist/preview.png +0 -0
  137. package/template/i18n/en-US.json +13 -5
  138. package/template/i18n/is-IS.json +12 -4
  139. package/template/pages/article.page.json +1 -3
  140. package/template/pages/cart.page.json +1 -3
  141. package/template/pages/category.page.json +2 -4
  142. package/template/pages/collection.page.json +1 -3
  143. package/template/pages/home.page.json +7 -18
  144. package/template/pages/product.page.json +62 -131
  145. package/template/pages/products.page.json +1 -3
  146. package/template/pages/search.page.json +1 -3
  147. package/template/pages/wishlist.page.json +1 -3
  148. package/template/stories/generated/footer.stories.ts +6 -0
  149. package/template/stories/generated/navigation.stories.ts +0 -18
  150. package/template/test/inlineEditable.spec.ts +10 -2
  151. package/template/test/localePrefix.spec.ts +2 -19
  152. package/template/test/pages/article.spec.ts +0 -2
  153. package/template/test/pages/category.spec.ts +35 -13
  154. package/template/test/pages/home.spec.ts +33 -17
  155. package/template/test/pages/product.spec.ts +64 -44
  156. package/template/test/pages/ssr.spec.ts +3 -1
  157. package/template/test/prerenderRefresh.browser.spec.ts +30 -25
  158. package/template/test/priceTokens.spec.ts +309 -0
  159. package/template/test/regionalFormat.spec.ts +80 -0
  160. package/template/test/starter.spec.ts +23 -7
  161. package/template/test/storefront/demo.spec.ts +19 -18
  162. package/template/test/storefront/toProductCard.spec.ts +17 -2
  163. package/template/test/structuredData.generate.spec.ts +4 -2
  164. package/template/test/support/mockGateway.ts +21 -1
  165. package/template/test/support/mountBlock.ts +25 -4
  166. package/template/test/support/priceTokens.ts +20 -0
  167. package/template/test/uiMessagesPlugin.spec.ts +34 -1
  168. package/template/tokens.json +8 -8
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
3
  * Site footer (spec `eldra-starter-spec/02-blocks.md` lines 440–597, restyled to the Northwind
4
- * design: a dark `primary` ground by default). `variant`:
4
+ * design: a near-black `dark` ground in the seeds and the mock). `variant`:
5
5
  * - `default`: brand (wordmark, optional description, the store's address, phone · email and
6
6
  * opening hours, social), link groups as columns, an optional newsletter sign-up on a light card.
7
7
  * Bottom bar below a hairline: the legal line and links, and the locale/currency selectors.
@@ -29,10 +29,11 @@
29
29
  * platform knows, or an external URL — resolved once through `useEldraLink()`. A row whose target
30
30
  * has been deleted, or that the site has no route for, keeps its label and renders as plain text
31
31
  * rather than a dead anchor; a row with no label renders nothing. A same-site path routes through
32
- * `EldraRouterLink` (see `app/utils/links.ts`). Column and flat links are `:underline="false"`
33
- * (a list of links, not links in running text), underlined on hover; the phone and email links sit
34
- * in a line of text and the legal links keep the package's own underline-at-rest default (spec:
35
- * "always underlined").
32
+ * `EldraRouterLink` (see `app/utils/links.ts`). Every footer link is `:underline="false"` and
33
+ * underlined on hover, the design's `.nw-foot a`: the columns, the legal row and the phone · email
34
+ * line are each a run of links on their own (the line's only other text is its `·` separator), not
35
+ * links inside running text, so nothing needs an underline at rest to be told apart. Links are the
36
+ * ground's own light tone at regular weight, a step brighter than the body text around them.
36
37
  *
37
38
  * The locale selector is **not** CMS content, and it is not a theme constant either: its options are
38
39
  * the organisation's own content locales (`useEldraLocale().supported`, read once at build onto the
@@ -110,7 +111,8 @@ const NEWSLETTER_FORM_KEY = 'newsletter';
110
111
 
111
112
  const props = defineProps<{ entry: EldraBlockEntry<'footer'> }>();
112
113
  const { data } = useBlockData(props, 'footer');
113
- const { t } = useI18n();
114
+ /** Currency names are words in the page's language; prices follow the regional format instead. */
115
+ const { t, locale: contentLocale } = useI18n();
114
116
  /**
115
117
  * The spec's three Footer "States" hints (`eldra-starter-spec/02-blocks.md`): a freshly inserted
116
118
  * footer has no description, no link groups and — on a page that already carries a Newsletter
@@ -131,22 +133,50 @@ const headingId = `footer-heading-${useUiId()}`;
131
133
 
132
134
  const variant = computed(() => data.value.variant ?? 'default');
133
135
  /**
134
- * The Northwind design is a dark footer: the `primary` ground with light text. That is the look an
135
- * unset field gets; `surface-strong` stays available for a theme that wants a light footer.
136
+ * Three grounds. `dark` is the Northwind design's (`.nw-foot`): the `text` colour role as the
137
+ * ground, near-black, with the `background` role for its light text — no token of its own, so a
138
+ * site that restyles its text colour restyles this footer with it. `primary` is the brand colour
139
+ * (the look an unset field keeps, so an existing footer does not change under its author), and
140
+ * `surface-strong` a light footer.
141
+ *
142
+ * `Section` knows five grounds, not `dark`, so a dark footer is a `primary` section painted
143
+ * `bg-text`: the app's utility outranks the package's `@layer components` fill, and the section
144
+ * keeps `data-section="primary"`, which is what makes `@eldrajs/ui`'s `Link`/`Button` draw their
145
+ * light-on-dark colours (`section-primary:`) inside it. Every colour this block writes itself on the
146
+ * dark ground is in `TONES.dark` below.
136
147
  */
137
148
  const background = computed(() => data.value.background ?? 'primary');
149
+ const sectionBackground = computed(() =>
150
+ background.value === 'surface-strong' ? 'surface-strong' : 'primary'
151
+ );
152
+ const groundClass = computed(() => (background.value === 'dark' ? 'bg-text text-background' : ''));
138
153
 
139
154
  /**
140
155
  * The colours this block writes itself, per ground. `@eldrajs/ui`'s `Link` and `Button` invert on a
141
156
  * primary `Section` on their own (`section-primary:`); plain text, rules and the select trigger do
142
157
  * not, so each one is picked here. Every pair clears WCAG AA: on primary, 85% of
143
158
  * `primary-contrast` is about 8:1 and 75% about 6:1 against the ground; on `surface-strong` the
144
- * `muted` role is about 5.6:1.
159
+ * `muted` role is about 5.6:1. On `dark` the design's own steps are mixes of `background` over
160
+ * `text` (body `#d9d2c6` ≈ 85%, links `#f2ede4` ≈ 95%, column headings `#bfb6a8` ≈ 75%, the rule
161
+ * `#3a3631` ≈ 15%), the lowest of them about 9:1; the social rings are `muted` (`#5a5248`) and the
162
+ * select's box is `border-strong` (`#776c5c`), both exactly the design's.
145
163
  */
146
164
  const TONES = {
165
+ dark: {
166
+ body: 'text-background/85',
167
+ strong: 'text-background',
168
+ link: 'text-background/95 font-normal hover:text-background',
169
+ heading: 'text-background/75',
170
+ rule: 'border-background/15',
171
+ ring: 'border-muted text-background hover:border-background',
172
+ trigger: 'bg-transparent text-background border-border-strong hover:border-background',
173
+ chevron: 'text-background/75',
174
+ pickerLabel: '[&>[data-part=label]]:text-background/85',
175
+ },
147
176
  primary: {
148
177
  body: 'text-primary-contrast/85',
149
178
  strong: 'text-primary-contrast',
179
+ link: 'font-normal',
150
180
  heading: 'text-primary-contrast/75',
151
181
  rule: 'border-primary-contrast/20',
152
182
  ring: 'border-primary-contrast/40 hover:border-primary-contrast',
@@ -158,6 +188,7 @@ const TONES = {
158
188
  'surface-strong': {
159
189
  body: 'text-muted',
160
190
  strong: 'text-text',
191
+ link: 'font-normal',
161
192
  heading: 'text-muted',
162
193
  rule: 'border-border',
163
194
  ring: 'border-border-strong hover:border-text',
@@ -466,11 +497,11 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
466
497
  <template>
467
498
  <Section
468
499
  as="footer"
469
- :background="background"
500
+ :background="sectionBackground"
470
501
  spacing="none"
471
502
  :labelled-by="variant === 'default' ? headingId : undefined"
472
503
  :aria-label="variant === 'minimal' ? t('footer.title') : undefined"
473
- :class="paddingClass"
504
+ :class="[paddingClass, groundClass]"
474
505
  >
475
506
  <Container width="wide">
476
507
  <VisuallyHidden v-if="variant === 'default'" :id="headingId" as="h2">{{
@@ -490,7 +521,7 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
490
521
  :as="EldraRouterLink"
491
522
  variant="standalone"
492
523
  :underline="false"
493
- class="mb-4 inline-flex max-w-full items-center hover:no-underline active:no-underline"
524
+ class="mb-1 inline-flex max-w-full items-center hover:no-underline active:no-underline"
494
525
  :classes="{
495
526
  label: ['font-heading text-[2.5rem] leading-none font-medium', tone.strong].join(' '),
496
527
  }"
@@ -520,14 +551,20 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
520
551
  <p v-if="address">{{ address }}</p>
521
552
  <p v-if="hasContactLine" class="flex flex-wrap items-baseline gap-x-2">
522
553
  <template v-if="phone">
523
- <Link v-if="telHref" :href="telHref">{{ phone }}</Link>
554
+ <Link v-if="telHref" :href="telHref" :underline="false" :class="tone.link">{{
555
+ phone
556
+ }}</Link>
524
557
  <span v-else>{{ phone }}</span>
525
558
  </template>
526
559
  <span v-if="phone && storeEmail" aria-hidden="true">·</span>
527
560
  <template v-if="storeEmail">
528
- <Link v-if="mailtoHref" :href="mailtoHref" class="break-all">{{
529
- storeEmail
530
- }}</Link>
561
+ <Link
562
+ v-if="mailtoHref"
563
+ :href="mailtoHref"
564
+ :underline="false"
565
+ :class="['break-all', tone.link]"
566
+ >{{ storeEmail }}</Link
567
+ >
531
568
  <span v-else class="break-all">{{ storeEmail }}</span>
532
569
  </template>
533
570
  </p>
@@ -583,7 +620,7 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
583
620
  :href="link.href"
584
621
  :as="link.as"
585
622
  :underline="false"
586
- class="text-base leading-relaxed"
623
+ :class="['text-base leading-relaxed', tone.link]"
587
624
  >{{ link.label }}</Link
588
625
  >
589
626
  <span v-else :class="['text-base leading-relaxed', tone.body]">{{
@@ -701,7 +738,7 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
701
738
  :href="link.href"
702
739
  :as="link.as"
703
740
  :underline="false"
704
- class="inline-flex min-h-9 items-center text-base"
741
+ :class="['inline-flex min-h-9 items-center text-base', tone.link]"
705
742
  >{{ link.label }}</Link
706
743
  >
707
744
  <span v-else :class="['inline-flex min-h-9 items-center text-base', tone.body]">{{
@@ -748,7 +785,8 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
748
785
  v-if="link.href"
749
786
  :href="link.href"
750
787
  :as="link.as"
751
- class="inline-flex min-h-6 items-center"
788
+ :underline="false"
789
+ :class="['inline-flex min-h-6 items-center', tone.link]"
752
790
  >{{ link.label }}</Link
753
791
  >
754
792
  <span v-else class="inline-flex min-h-6 items-center">{{ link.label }}</span>
@@ -783,18 +821,23 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
783
821
  }}</span>
784
822
  </p>
785
823
  <CurrencyPicker
824
+ :locale="contentLocale"
786
825
  v-else-if="showCurrencySelector"
787
826
  :currencies="currencyCodes"
788
827
  :model-value="currencyStore.active.value"
789
828
  :busy="currencyStore.busy.value"
790
829
  :label="t('footer.currencyLabel')"
791
830
  show-label
792
- size="sm"
831
+ size="md"
793
832
  placement="above"
794
833
  :class="['flex items-center gap-2', tone.pickerLabel]"
795
834
  :classes="selectClasses"
796
835
  @update:model-value="currencyStore.choose"
797
- />
836
+ >
837
+ <!-- The design's "Prices in Icelandic króna (ISK)": the closed box names the currency in
838
+ full, as its options do, rather than the bare code the header's compact picker shows. -->
839
+ <template #value="{ label }">{{ label }}</template>
840
+ </CurrencyPicker>
798
841
  </div>
799
842
  </div>
800
843
  </Container>
@@ -699,6 +699,68 @@ describe('footer block', () => {
699
699
  expect(await axe(wrapper.element)).toHaveNoViolations();
700
700
  });
701
701
 
702
+ it('offers several currencies in a select labelled "Prices in", showing the currency in full', async () => {
703
+ const options = mountOptions(
704
+ { entry: { id: 'e1', data: { ...mock, background: 'dark' } } },
705
+ {
706
+ links: linkContext,
707
+ commerce: {
708
+ currency: 'ISK',
709
+ taxInclusivePricing: true,
710
+ defaultTaxRate: 0.24,
711
+ currencies: ['ISK', 'EUR', 'USD'],
712
+ },
713
+ }
714
+ );
715
+ const storefront = options.global.provide[STOREFRONT_KEY] as StorefrontSource;
716
+ storefront.currency.started.value = true;
717
+ const wrapper = mount(Block, { ...options, attachTo: document.body });
718
+ await flushPromises();
719
+
720
+ const trigger = selectTriggers(wrapper)[0]!;
721
+ expect(trigger.exists()).toBe(true);
722
+ // The design's boxed select: "Prices in" beside it, and the closed box names the currency in
723
+ // full, not just the code.
724
+ expect(wrapper.text()).toContain(enUS.footer.currencyLabel);
725
+ expect(enUS.footer.currencyLabel).toBe('Prices in');
726
+ expect(trigger.text()).toContain('(ISK)');
727
+ expect(trigger.text().trim()).not.toBe('ISK');
728
+ // On the dark ground the box is the design's `border-strong` outline on a clear fill.
729
+ expect(trigger.classes()).toEqual(
730
+ expect.arrayContaining(['bg-transparent', 'border-border-strong'])
731
+ );
732
+ expect(await axe(wrapper.element)).toHaveNoViolations();
733
+ wrapper.unmount();
734
+ });
735
+
736
+ it("names the currencies in the page's language, not the regional format's", async () => {
737
+ const options = mountOptions(
738
+ { entry: { id: 'e1', data: { ...mock, background: 'dark' } } },
739
+ {
740
+ links: linkContext,
741
+ locale: 'en-US',
742
+ region: { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' },
743
+ commerce: {
744
+ currency: 'ISK',
745
+ taxInclusivePricing: true,
746
+ defaultTaxRate: 0.24,
747
+ currencies: ['ISK', 'EUR'],
748
+ },
749
+ }
750
+ );
751
+ const storefront = options.global.provide[STOREFRONT_KEY] as StorefrontSource;
752
+ storefront.currency.started.value = true;
753
+ const wrapper = mount(Block, { ...options, attachTo: document.body });
754
+ await flushPromises();
755
+
756
+ // An Icelandic regional format writes prices as "4.790 kr.", but an English page still says
757
+ // "Icelandic Króna", never "Íslensk króna".
758
+ const trigger = selectTriggers(wrapper)[0]!;
759
+ expect(trigger.text()).toContain('Icelandic');
760
+ expect(trigger.text()).not.toContain('Íslensk');
761
+ wrapper.unmount();
762
+ });
763
+
702
764
  it('renders nothing for the currency when the store publishes none', async () => {
703
765
  const wrapper = mountFooter(mock, { commerce: null });
704
766
 
@@ -881,7 +943,41 @@ describe('footer block', () => {
881
943
  expect(footer.attributes('data-section')).toBe('primary');
882
944
  });
883
945
 
884
- it.each(['primary', 'surface-strong'])(
946
+ it('is near-black on `dark`: the `text` role as the ground, and a primary section inside', () => {
947
+ const footer = mountFooter({ ...mock, background: 'dark' }).find('footer');
948
+ // `Section` has no `dark` ground: the footer is a primary section (so `@eldrajs/ui`'s own
949
+ // components draw their on-dark colours) painted with the theme's text colour.
950
+ expect(footer.attributes('data-section')).toBe('primary');
951
+ expect(footer.classes()).toEqual(expect.arrayContaining(['bg-text', 'text-background']));
952
+ });
953
+
954
+ it('draws no ground of its own on the other two', () => {
955
+ for (const background of ['primary', 'surface-strong']) {
956
+ const footer = mountFooter({ ...mock, background }).find('footer');
957
+ expect(footer.classes()).not.toContain('bg-text');
958
+ }
959
+ });
960
+
961
+ it('sets every link on `dark` at regular weight in the ground’s link tone, none underlined at rest', () => {
962
+ const wrapper = mountFooter({ ...mock, background: 'dark' });
963
+ // The column, legal and phone · email links — everything but the wordmark and the social
964
+ // buttons (`target="_blank"`), which keep their own treatment.
965
+ const links = wrapper
966
+ .findAll('footer a')
967
+ .filter((a) => a.attributes('href') !== '/' && a.attributes('target') !== '_blank');
968
+ const legal = links.filter((a) => ['Privacy', 'Terms of sale'].includes(a.text()));
969
+ expect(legal).toHaveLength(2);
970
+ expect(links.some((a) => a.attributes('href')?.startsWith('tel:'))).toBe(true);
971
+ for (const link of links) {
972
+ expect(link.classes(), link.text()).toEqual(
973
+ expect.arrayContaining(['text-background/95', 'font-normal'])
974
+ );
975
+ // `Link`'s underline-at-rest recipe is `eldra:underline`; `:underline="false"` drops it.
976
+ expect(link.classes(), link.text()).not.toContain('eldra:underline');
977
+ }
978
+ });
979
+
980
+ it.each(['dark', 'primary', 'surface-strong'])(
885
981
  '%s renders both variants, with the newsletter on, with no axe violations',
886
982
  async (background) => {
887
983
  for (const variant of ['default', 'minimal']) {
@@ -68,9 +68,9 @@
68
68
  "fieldId": "background",
69
69
  "name": "Background",
70
70
  "type": "select",
71
- "helpText": "Defaults to \"primary\" when unset.",
71
+ "helpText": "\"dark\" is the text colour as the ground; \"primary\" the brand colour; \"surface-strong\" a light footer. Defaults to \"primary\" when unset.",
72
72
  "metadata": {
73
- "options": ["primary", "surface-strong"]
73
+ "options": ["dark", "primary", "surface-strong"]
74
74
  }
75
75
  },
76
76
  {
@@ -117,6 +117,7 @@
117
117
  "fieldId": "phone",
118
118
  "name": "Phone",
119
119
  "type": "string",
120
+ "allowPrices": false,
120
121
  "helpText": "Rendered as a tel: link. Shown on the default variant only.",
121
122
  "validators": {
122
123
  "maxLength": 40
@@ -126,6 +127,7 @@
126
127
  "fieldId": "email",
127
128
  "name": "Email",
128
129
  "type": "string",
130
+ "allowPrices": false,
129
131
  "helpText": "Rendered as a mailto: link. Shown on the default variant only.",
130
132
  "validators": {
131
133
  "maxLength": 120
@@ -227,6 +229,7 @@
227
229
  "fieldId": "href",
228
230
  "name": "URL",
229
231
  "type": "string",
232
+ "allowPrices": false,
230
233
  "validators": {
231
234
  "required": true
232
235
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "variant": "default",
3
- "background": "primary",
3
+ "background": "dark",
4
4
  "brandText": "Northwind Goods",
5
5
  "address": "14 Harbour Street, Northwind Bay",
6
6
  "phone": "(555) 014-2290",
Binary file
@@ -18,6 +18,7 @@
18
18
  "fieldId": "formKey",
19
19
  "name": "Form",
20
20
  "type": "string",
21
+ "allowPrices": false,
21
22
  "helpText": "The key of the form on the Forms page, for example \"contact\" or \"newsletter\".",
22
23
  "validators": { "required": true }
23
24
  },
Binary file
@@ -16,8 +16,11 @@
16
16
  * - `split-carousel`: copy in a `5fr` column beside `@eldrajs/ui`'s `Carousel` in `7fr`, one 4:5
17
17
  * slide per `slides[]` item.
18
18
  * - `card`: one wide photo (21:9) with the copy on a `background` card overlapping its
19
- * bottom-left corner, and an optional small caption link on the photo (`captionLabel`,
20
- * `captionDetail`, `captionHref` — "Glazed milk jug $34", a shoppable caption). Below 1101px
19
+ * bottom-left corner, and an optional small caption link on the photo naming the product in it
20
+ * with its price ("Glazed milk jug 4.790 kr."): `captionProduct` picks the product, read through
21
+ * the storefront like every commerce block, so the name, price (in the regional format and the
22
+ * shopper's currency) and link are the catalog's own; `captionLabel` only overrides the name.
23
+ * Below 1101px
21
24
  * of block width the card leaves the photo and sits under it, pulled up over its bottom edge
22
25
  * (16:10 photo; 4:5 below 761px), and the caption moves to the photo's top-right corner. The
23
26
  * copy comes before the photo in the DOM, so the heading is still the first thing read; `order`
@@ -36,6 +39,9 @@ import { Button, Carousel, Container, EditorPlaceholder, Link, Section } from '@
36
39
  import type { SectionBackground, SectionSpacing } from '@eldrajs/ui';
37
40
  import { DEFAULT_IMAGE_FRAMING } from '@eldrajs/theme-vue';
38
41
  import { useBlockData } from '../../app/composables/useBlockData';
42
+ import { useStorefront } from '../../app/composables/useStorefront';
43
+ import { useMoney } from '../../app/storefront/money';
44
+ import { productReferenceSlug } from '../../app/storefront/productReference';
39
45
  import { useEditing } from '../../app/composables/useEditing';
40
46
  import { useI18n } from 'vue-i18n';
41
47
  import { useUiId } from '../../app/composables/useUiId';
@@ -201,13 +207,35 @@ const subheadingClass = computed(() =>
201
207
  : 'text-body-lg mt-5 max-w-[34rem] text-pretty'
202
208
  );
203
209
 
204
- const captionLabel = computed(() => (data.value.captionLabel ?? '').trim());
205
- const captionDetail = computed(() => (data.value.captionDetail ?? '').trim());
206
- const captionHref = computed(() => safeHref(data.value.captionHref));
207
- /** The caption is a link or nothing: a label with no destination would be a pill that looks
208
- * clickable and is not. */
210
+ /**
211
+ * The caption's product, read only for the card variant with a photo — the one place it shows — so
212
+ * any other hero makes no read. A reference the public read has not resolved to a slug (a draft in
213
+ * the builder) names nothing the storefront can look up, and the caption simply waits for publish.
214
+ */
215
+ const storefront = useStorefront();
216
+ const money = useMoney();
217
+ const captionHandle = computed(() =>
218
+ isCard.value && hasImage.value ? productReferenceSlug(data.value.captionProduct) : null
219
+ );
220
+ const captionRead = storefront.catalog.product(captionHandle);
221
+ const captionItem = computed(() =>
222
+ captionHandle.value === null ? null : (captionRead.data.value ?? null)
223
+ );
224
+ const captionLabel = computed(
225
+ () => (data.value.captionLabel ?? '').trim() || captionItem.value?.title || ''
226
+ );
227
+ /** The price the shopper pays, written as every other price on the page is. */
228
+ const captionDetail = computed(() => {
229
+ const price = captionItem.value?.price;
230
+ return price === undefined ? '' : money.format(price.amount, price.currency);
231
+ });
232
+ const captionHref = computed(() => safeHref(captionItem.value?.url));
233
+ /** The caption is a link to a product someone can buy, or nothing: a sold-out product is not
234
+ * advertised on the photo, and a label with no destination would be a pill that looks clickable
235
+ * and is not. */
209
236
  const hasCaption = computed(
210
- () => isCard.value && hasImage.value && captionLabel.value !== '' && captionHref.value !== null
237
+ () =>
238
+ captionItem.value?.available === true && captionLabel.value !== '' && captionHref.value !== null
211
239
  );
212
240
  const captionLinkAs = computed(() => routerLinkAs(captionHref.value));
213
241
  const carouselAriaLabel = computed(() => data.value.heading || t('hero.carouselFallback'));
@@ -404,7 +432,8 @@ function slideAlt(slide: { alt?: string; image?: { altText?: string | null } }):
404
432
  :as="captionLinkAs"
405
433
  :underline="false"
406
434
  :classes="{ label: 'inline-flex min-w-0 items-center gap-2' }"
407
- class="bg-background/90 text-text hover:bg-background absolute top-5 right-5 inline-flex max-w-[calc(100%-2.5rem)] items-center gap-2 rounded-full px-3.5 py-2 text-sm font-semibold @min-[68.8125rem]:top-auto @min-[68.8125rem]:bottom-5"
435
+ data-eldra-hero-caption
436
+ class="bg-background/90 text-text hover:bg-background hover:text-text absolute top-5 right-5 inline-flex max-w-[calc(100%-2.5rem)] items-center gap-2 rounded-full px-3.5 py-2 text-sm font-semibold no-underline hover:no-underline active:no-underline @min-[68.8125rem]:top-auto @min-[68.8125rem]:bottom-5"
408
437
  >
409
438
  <span class="truncate">{{ captionLabel }}</span>
410
439
  <span v-if="captionDetail" class="text-muted font-normal">{{ captionDetail }}</span>
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { mount } from '@vue/test-utils';
3
3
  import { h, nextTick } from 'vue';
4
+ import { flushPromises } from '@vue/test-utils';
4
5
  import { axe } from '../../../test/support/axe';
5
6
  import { describe, expect, it } from 'vitest';
6
7
  import Block from '../Block.vue';
@@ -89,37 +90,88 @@ describe('hero block', () => {
89
90
  expect(frame.classes()).toContain('@min-[68.8125rem]:aspect-[21/9]!');
90
91
  });
91
92
 
92
- it('renders the caption as one same-site link naming the item and its detail', () => {
93
+ /**
94
+ * WS-1277: the caption was three typed fields, its price a string ("ISK 4,790") that ignored the
95
+ * regional format and the shopper's currency and went stale with the catalog. It is the picked
96
+ * product now, its name, price and link all read from the storefront.
97
+ */
98
+ it('names the picked product and its price from the catalog, and links to it', async () => {
93
99
  const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data: card } }));
94
- const caption = wrapper
95
- .findAll('a')
96
- .find((link) => link.text().includes(withImage.captionLabel));
97
- expect(caption).toBeDefined();
98
- expect(caption!.text()).toContain(withImage.captionDetail);
99
- expect(caption!.attributes('href')).toBe(withImage.captionHref);
100
+ await flushPromises();
101
+ const caption = wrapper.get('[data-eldra-hero-caption]');
102
+ expect(caption.text()).toContain('Glazed milk jug');
103
+ expect(caption.attributes('href')).toBe('/products/glazed-milk-jug');
104
+ expect(caption.text()).toContain('$34');
100
105
  });
101
106
 
102
- it('renders no caption without a link, and none in the other variants', () => {
103
- const noHref = mount(
104
- Block,
105
- mountOptions({ entry: { id: 'e1', data: { ...card, captionHref: '' } } })
106
- );
107
- expect(noHref.text()).not.toContain(withImage.captionLabel);
108
- const imageRight = mount(
107
+ it('writes the price in the regional format and the store currency', async () => {
108
+ const wrapper = mount(
109
109
  Block,
110
- mountOptions({ entry: { id: 'e1', data: { ...card, variant: 'image-right' } } })
110
+ mountOptions(
111
+ { entry: { id: 'e1', data: card } },
112
+ {
113
+ locale: 'en-US',
114
+ commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
115
+ region: { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' },
116
+ }
117
+ )
111
118
  );
112
- expect(imageRight.text()).not.toContain(withImage.captionLabel);
119
+ await flushPromises();
120
+ const caption = wrapper.get('[data-eldra-hero-caption]');
121
+ // `is-IS` writes a no-break space before the currency.
122
+ expect(caption.text()).toMatch(/34\u00a0kr\./);
123
+ expect(caption.text()).not.toContain('ISK');
113
124
  });
114
125
 
115
- it('drops an unsafe caption link', () => {
126
+ it('takes its own text in place of the product name, keeping the price and link', async () => {
116
127
  const wrapper = mount(
117
128
  Block,
118
129
  mountOptions({
119
- entry: { id: 'e1', data: { ...card, captionHref: 'javascript:alert(1)' } },
130
+ entry: { id: 'e1', data: { ...card, captionLabel: 'Our bestselling jug' } },
131
+ })
132
+ );
133
+ await flushPromises();
134
+ const caption = wrapper.get('[data-eldra-hero-caption]');
135
+ expect(caption.text()).toContain('Our bestselling jug');
136
+ expect(caption.text()).not.toContain('Glazed milk jug');
137
+ expect(caption.attributes('href')).toBe('/products/glazed-milk-jug');
138
+ });
139
+
140
+ it('draws the caption as a pill whose words are never underlined, at rest, hovered or pressed', async () => {
141
+ // The design's shoppable pill (`.nw-shoppable`): the pill is the affordance. `Link`'s
142
+ // `underline: false` still underlines on hover and press, so the caption turns both off.
143
+ const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data: card } }));
144
+ await flushPromises();
145
+ const caption = wrapper.get('[data-eldra-hero-caption]');
146
+ for (const token of [
147
+ 'no-underline',
148
+ 'hover:no-underline',
149
+ 'active:no-underline',
150
+ 'rounded-full',
151
+ ]) {
152
+ expect(caption.classes()).toContain(token);
153
+ }
154
+ expect(caption.classes()).toContain('eldra:hover:underline');
155
+ });
156
+
157
+ it('shows no caption without a product, for a sold-out one, or outside the card variant', async () => {
158
+ const caption = async (data: Record<string, unknown>) => {
159
+ const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data } }));
160
+ await flushPromises();
161
+ return wrapper.find('[data-eldra-hero-caption]').exists();
162
+ };
163
+ expect(await caption({ ...card, captionProduct: null })).toBe(false);
164
+ expect(
165
+ await caption({
166
+ ...card,
167
+ captionProduct: { _type: 'product', slug: 'enamel-camp-cups-set-of-6' },
120
168
  })
169
+ ).toBe(false);
170
+ // A draft's bare stub names no slug yet: nothing to look up until it is published.
171
+ expect(await caption({ ...card, captionProduct: { _type: 'product', id: 'abc' } })).toBe(
172
+ false
121
173
  );
122
- expect(wrapper.text()).not.toContain(withImage.captionLabel);
174
+ expect(await caption({ ...card, variant: 'image-right' })).toBe(false);
123
175
  });
124
176
  });
125
177
 
@@ -4,7 +4,7 @@
4
4
  "description": "Top-of-page banner with heading, supporting text, image and calls to action.",
5
5
  "icon": "layout-dashboard",
6
6
  "category": "marketing",
7
- "version": 2,
7
+ "version": 3,
8
8
  "migrations": [
9
9
  {
10
10
  "version": 2,
@@ -12,7 +12,8 @@
12
12
  { "from": "ctaLabel", "to": "primaryCtaLabel" },
13
13
  { "from": "ctaHref", "to": "primaryCtaHref" }
14
14
  ]
15
- }
15
+ },
16
+ { "version": 3, "renames": [] }
16
17
  ],
17
18
  "groups": [
18
19
  { "groupId": "content", "name": "Content", "defaultOpen": true },
@@ -101,39 +102,30 @@
101
102
  "type": "string",
102
103
  "localized": true
103
104
  },
104
- { "fieldId": "href", "name": "Link", "type": "string" }
105
+ { "fieldId": "href", "name": "Link", "type": "string", "allowPrices": false }
105
106
  ]
106
107
  }
107
108
  }
108
109
  }
109
110
  },
110
111
  {
111
- "fieldId": "captionLabel",
112
- "name": "Image caption",
113
- "type": "string",
112
+ "fieldId": "captionProduct",
113
+ "name": "Image caption product",
114
+ "type": "reference",
114
115
  "groupId": "content",
115
- "localized": true,
116
- "helpText": "A small link on the photo naming what is in it, e.g. \"Glazed milk jug\". Card variant only.",
117
- "showWhen": { "field": "variant", "in": ["card"] },
118
- "validators": { "maxLength": 60 }
116
+ "relation": { "allowProducts": true },
117
+ "helpText": "The product in the photo. The caption shows its name and price and links to it, and hides while it is sold out. Card variant only.",
118
+ "showWhen": { "field": "variant", "in": ["card"] }
119
119
  },
120
120
  {
121
- "fieldId": "captionDetail",
122
- "name": "Image caption detail",
121
+ "fieldId": "captionLabel",
122
+ "name": "Image caption text",
123
123
  "type": "string",
124
124
  "groupId": "content",
125
125
  "localized": true,
126
- "helpText": "Shown after the caption in a lighter weight, e.g. the price.",
126
+ "helpText": "Leave empty to use the product's name.",
127
127
  "showWhen": { "field": "variant", "in": ["card"] },
128
- "validators": { "maxLength": 30 }
129
- },
130
- {
131
- "fieldId": "captionHref",
132
- "name": "Image caption link",
133
- "type": "string",
134
- "groupId": "content",
135
- "helpText": "Where the caption goes, usually the product in the photo. No link, no caption.",
136
- "showWhen": { "field": "variant", "in": ["card"] }
128
+ "validators": { "maxLength": 60 }
137
129
  },
138
130
  {
139
131
  "fieldId": "spacing",
@@ -153,6 +145,7 @@
153
145
  "fieldId": "primaryCtaHref",
154
146
  "name": "Button link",
155
147
  "type": "string",
148
+ "allowPrices": false,
156
149
  "groupId": "action"
157
150
  },
158
151
  {
@@ -166,6 +159,7 @@
166
159
  "fieldId": "secondaryCtaHref",
167
160
  "name": "Secondary button link",
168
161
  "type": "string",
162
+ "allowPrices": false,
169
163
  "groupId": "action"
170
164
  }
171
165
  ],