@eldrajs/theme-cli 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +28 -7
- package/template/.eldra/manifest.json +1152 -445
- package/template/.eldra/previews.json +35 -35
- package/template/README.md +32 -0
- package/template/app/assets/main.css +23 -0
- package/template/app/plugins/eldra-storefront.ts +3 -0
- package/template/app/storefront/demo.ts +75 -24
- package/template/app/storefront/gateway.ts +16 -2
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/preview.json +4 -4
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +48 -19
- package/template/blocks/article-list/__tests__/Block.spec.ts +15 -0
- package/template/blocks/article-list/preview.json +43 -43
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +260 -9
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +202 -0
- package/template/blocks/collection-grid/block.json +3 -3
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +65 -52
- package/template/blocks/collection-header/preview.json +4 -4
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/preview.json +4 -4
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +73 -4
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +43 -1
- package/template/blocks/feature-grid/block.json +2 -2
- package/template/blocks/feature-grid/preview.json +49 -24
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +186 -71
- package/template/blocks/footer/__tests__/Block.spec.ts +127 -32
- package/template/blocks/footer/block.json +42 -4
- package/template/blocks/footer/mock.json +31 -34
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/preview.png +0 -0
- package/template/blocks/gallery/preview.json +24 -24
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +117 -19
- package/template/blocks/hero/__tests__/Block.spec.ts +46 -0
- package/template/blocks/hero/block.json +36 -1
- package/template/blocks/hero/preview.json +33 -25
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/preview.json +4 -4
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +665 -184
- package/template/blocks/navigation/__tests__/Block.spec.ts +496 -75
- package/template/blocks/navigation/__tests__/fixtures/menu.json +182 -0
- package/template/blocks/navigation/block.json +110 -6
- package/template/blocks/navigation/mock.json +372 -140
- package/template/blocks/navigation/preview.json +311 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/Block.vue +248 -144
- package/template/blocks/newsletter/__tests__/Block.spec.ts +42 -0
- package/template/blocks/newsletter/block.json +61 -2
- package/template/blocks/newsletter/preview.json +35 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +272 -26
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +90 -0
- package/template/blocks/product-carousel/block.json +61 -0
- package/template/blocks/product-carousel/preview.json +12 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +148 -96
- package/template/blocks/product-detail/__tests__/Block.spec.ts +98 -74
- package/template/blocks/product-detail/block.json +11 -4
- package/template/blocks/product-detail/mock.json +53 -22
- package/template/blocks/product-detail/parts/Gallery.vue +52 -103
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +1 -0
- package/template/blocks/search/TypeSection.vue +1 -0
- package/template/blocks/search/__tests__/Block.spec.ts +23 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/Block.vue +98 -20
- package/template/blocks/split-content/__tests__/Block.spec.ts +57 -18
- package/template/blocks/split-content/block.json +72 -6
- package/template/blocks/split-content/preview.json +34 -13
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/preview.json +16 -16
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +67 -1
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +30 -1
- package/template/blocks/trust-strip/block.json +4 -4
- package/template/blocks/trust-strip/preview.json +21 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +16 -9
- package/template/i18n/is-IS.json +16 -9
- package/template/package.json +1 -1
- package/template/pages/article.page.json +19 -18
- package/template/pages/cart.page.json +3 -13
- package/template/pages/category.page.json +15 -7
- package/template/pages/collection.page.json +15 -14
- package/template/pages/home.page.json +217 -182
- package/template/pages/product.page.json +46 -36
- package/template/pages/products.page.json +3 -13
- package/template/pages/search.page.json +3 -13
- package/template/pages/wishlist.page.json +3 -13
- package/template/public/images/CREDITS.md +28 -0
- package/template/public/images/bowl.webp +0 -0
- package/template/public/images/clay-hands.webp +0 -0
- package/template/public/images/coffee-table.webp +0 -0
- package/template/public/images/cup.webp +0 -0
- package/template/public/images/enamel-cups.webp +0 -0
- package/template/public/images/hero.webp +0 -0
- package/template/public/images/kitchen.webp +0 -0
- package/template/public/images/mug.webp +0 -0
- package/template/public/images/northwind-mark.svg +1 -0
- package/template/public/images/planters.webp +0 -0
- package/template/public/images/plates.webp +0 -0
- package/template/public/images/reading.webp +0 -0
- package/template/public/images/sweater.webp +0 -0
- package/template/public/images/terracotta.webp +0 -0
- package/template/public/images/throws.webp +0 -0
- package/template/public/images/vase.webp +0 -0
- package/template/public/images/wheel.webp +0 -0
- package/template/public/images/yarn-tools.webp +0 -0
- package/template/public/images/yarn.webp +0 -0
- package/template/stories/generated/collection-grid.stories.ts +6 -0
- package/template/stories/generated/feature-grid.stories.ts +6 -0
- package/template/stories/generated/footer.stories.ts +4 -4
- package/template/stories/generated/hero.stories.ts +6 -0
- package/template/stories/generated/navigation.stories.ts +14 -1
- package/template/stories/generated/newsletter.stories.ts +2 -1
- package/template/stories/generated/product-carousel.stories.ts +12 -0
- package/template/stories/generated/split-content.stories.ts +12 -0
- package/template/stories/generated/trust-strip.stories.ts +8 -1
- package/template/stories/pages/article.stories.ts +2 -1
- package/template/stories/pages/cart.stories.ts +2 -1
- package/template/stories/pages/category.stories.ts +2 -1
- package/template/stories/pages/collection.stories.ts +2 -1
- package/template/stories/pages/home.stories.ts +2 -1
- package/template/stories/pages/product.stories.ts +2 -1
- package/template/stories/pages/products.stories.ts +2 -1
- package/template/stories/pages/search.stories.ts +2 -1
- package/template/stories/pages/wishlist.stories.ts +2 -1
- package/template/stories/support/demoChrome.ts +32 -0
- package/template/stories/support/pageBlocks.ts +2 -4
- package/template/test/countPill.browser.spec.ts +21 -13
- package/template/test/localePrefix.spec.ts +11 -6
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/category.spec.ts +34 -11
- package/template/test/pages/collection.spec.ts +182 -148
- package/template/test/pages/home.spec.ts +35 -40
- package/template/test/pages/hydration.spec.ts +4 -4
- package/template/test/pages/product.spec.ts +17 -14
- package/template/test/pages/seededPages.spec.ts +11 -6
- package/template/test/prerenderFailure.spec.ts +4 -3
- package/template/test/prerenderRefresh.browser.spec.ts +36 -15
- package/template/test/previewParity.browser.spec.ts +1152 -0
- package/template/test/starter.spec.ts +37 -16
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -0
- package/template/test/support/previewParity.ts +302 -0
- package/template/test/support/previewParityContent.ts +726 -0
- package/template/tokens.json +13 -13
|
@@ -30,12 +30,32 @@
|
|
|
30
30
|
* below), and `recently-viewed` has no link at all. A hidden field keeps its stored value, so
|
|
31
31
|
* switching variants back restores what the author typed.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
33
|
+
* **Quick add is opt-in** (`quickAdd`, off by default and always off in `recently-viewed`). Off,
|
|
34
|
+
* each card is one tab stop, the spec's keyboard table ("Tab moves through every card in order").
|
|
35
|
+
* On, each card gains a second one, a small "Quick add" pill over the bottom-right of the photo. A
|
|
36
|
+
* list row carries no variant id (`StorefrontProductListItem.productId`'s own comment), so a press
|
|
37
|
+
* first reads the product (`catalog.product`, a result whose handle is `null` — no request — until
|
|
38
|
+
* a pill is pressed) and adds the variant that product's page would add; then the same toast as the
|
|
39
|
+
* product page's own add (`cart.added`, offering the cart), or the shared failure toast.
|
|
40
|
+
*
|
|
41
|
+
* **`layout`.** `carousel` (the default) is the row described above. `grid` shows the same cards
|
|
42
|
+
* all at once: 4 across from 1101px of block width, 3 from 761px, 2 below, under a head row with
|
|
43
|
+
* the heading on the left and, for `collection`, optional **filter chips** on the right
|
|
44
|
+
* (`filters`: a label and a category handle each, after an "All" chip). A chip is a toggle
|
|
45
|
+
* button (`aria-pressed`); choosing one narrows the collection read to that category
|
|
46
|
+
* (`filters.category`, the same vocabulary `collection-grid` sends) and the cards dim while the
|
|
47
|
+
* new read is in flight, as on any refresh. "All" — no chip — is the state the page is
|
|
48
|
+
* prerendered in, so the chips never change what the server wrote. A chip that matches fewer than
|
|
49
|
+
* two products still shows the block (with a short line when it matches none): the "fewer than 2
|
|
50
|
+
* products" floor is about whether the block is worth showing at all, not about a shopper's own
|
|
51
|
+
* narrowing.
|
|
52
|
+
*
|
|
53
|
+
* Cards are restyled through `ProductCard`'s `classes`, never forked: the title is not underlined
|
|
54
|
+
* until hover, the price sits beside the title from 761px, and the quick-add pill shares the
|
|
55
|
+
* photo's grid cell (the card root becomes a one-column grid so the pill can sit on the media
|
|
56
|
+
* without knowing its height).
|
|
37
57
|
*/
|
|
38
|
-
import { computed, inject, toValue } from 'vue';
|
|
58
|
+
import { computed, inject, nextTick, ref, toValue, watch } from 'vue';
|
|
39
59
|
import {
|
|
40
60
|
Button,
|
|
41
61
|
Carousel,
|
|
@@ -47,9 +67,13 @@ import {
|
|
|
47
67
|
ProductCard,
|
|
48
68
|
Section,
|
|
49
69
|
Skeleton,
|
|
70
|
+
useToast,
|
|
50
71
|
VisuallyHidden,
|
|
51
72
|
} from '@eldrajs/ui';
|
|
52
|
-
import type { CarouselPart, SectionBackground } from '@eldrajs/ui';
|
|
73
|
+
import type { CarouselPart, ProductCardPart, SectionBackground } from '@eldrajs/ui';
|
|
74
|
+
import { useEldraLocale } from '@eldrajs/theme-vue';
|
|
75
|
+
import { useStorefrontFeedback } from '../../app/composables/useStorefrontFeedback';
|
|
76
|
+
import { CART_ADD_TOAST_ID } from '../../app/storefront/feedback';
|
|
53
77
|
import { useBlockData } from '../../app/composables/useBlockData';
|
|
54
78
|
import { useEditing } from '../../app/composables/useEditing';
|
|
55
79
|
import { useRevalidating } from '../../app/composables/useRevalidating';
|
|
@@ -60,6 +84,7 @@ import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
|
60
84
|
import { isInternalHref, safeHref } from '../../app/utils/links';
|
|
61
85
|
import type {
|
|
62
86
|
StorefrontCollectionSelector,
|
|
87
|
+
StorefrontProduct,
|
|
63
88
|
StorefrontProductListItem,
|
|
64
89
|
} from '../../app/storefront/types';
|
|
65
90
|
import {
|
|
@@ -78,7 +103,7 @@ const headingId = `product-carousel-heading-${useUiId()}`;
|
|
|
78
103
|
/** The h2 recipe, also applied to the heading's own link so `Link`'s standalone size and weight do
|
|
79
104
|
* not shrink the title (an app utility outranks the kit's `eldra:` classes by cascade layer). */
|
|
80
105
|
const HEADING_CLASSES =
|
|
81
|
-
'font-heading
|
|
106
|
+
'font-heading text-[1.75rem] @min-[47.5625rem]:text-[2.25rem] leading-[1.1] font-medium tracking-[-0.01em] text-balance';
|
|
82
107
|
|
|
83
108
|
const storefront = useStorefront();
|
|
84
109
|
|
|
@@ -124,7 +149,38 @@ const showSwatchesField = computed(() => data.value.showSwatches ?? true);
|
|
|
124
149
|
const source = computed<StorefrontCollectionSelector | null>(() =>
|
|
125
150
|
isCollection.value ? collectionSelector(data.value.sourceCollection) : null
|
|
126
151
|
);
|
|
127
|
-
|
|
152
|
+
/** The grid layout's chips — see the module doc comment. Only the `collection` variant reads a
|
|
153
|
+
* collection, so only it has anything to narrow. At most six, each with a label and a handle. */
|
|
154
|
+
const isGrid = computed(() => data.value.layout === 'grid');
|
|
155
|
+
const filterChips = computed(() =>
|
|
156
|
+
isCollection.value && isGrid.value
|
|
157
|
+
? (data.value.filters ?? [])
|
|
158
|
+
.map((chip) => ({
|
|
159
|
+
label: (chip.label ?? '').trim(),
|
|
160
|
+
category: (chip.category ?? '').trim(),
|
|
161
|
+
}))
|
|
162
|
+
.filter((chip) => chip.label !== '' && chip.category !== '')
|
|
163
|
+
.slice(0, 6)
|
|
164
|
+
: []
|
|
165
|
+
);
|
|
166
|
+
const hasFilterChips = computed(() => filterChips.value.length > 0);
|
|
167
|
+
const allFilterLabel = computed(
|
|
168
|
+
() => (data.value.allFilterLabel ?? '').trim() || t('productCarousel.allFilter')
|
|
169
|
+
);
|
|
170
|
+
/** `null` is "All" — the prerendered state. */
|
|
171
|
+
const activeCategory = ref<string | null>(null);
|
|
172
|
+
/** A chip an editor removes (or a layout switch away from `grid`) must not leave the read narrowed
|
|
173
|
+
* to a category no chip names any more. */
|
|
174
|
+
watch(filterChips, (chips) => {
|
|
175
|
+
if (activeCategory.value !== null && !chips.some((c) => c.category === activeCategory.value)) {
|
|
176
|
+
activeCategory.value = null;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const collectionOpts = computed(() =>
|
|
180
|
+
activeCategory.value === null
|
|
181
|
+
? { page: 1, pageSize: limit.value }
|
|
182
|
+
: { page: 1, pageSize: limit.value, filters: { category: [activeCategory.value] } }
|
|
183
|
+
);
|
|
128
184
|
|
|
129
185
|
/**
|
|
130
186
|
* **Three results, and only the variant's own reads anything.** A block cannot create a result
|
|
@@ -348,7 +404,123 @@ function onClearHistory(): void {
|
|
|
348
404
|
|
|
349
405
|
/** The Carousel (and everything inside it) renders only once there is a heading to name it by and
|
|
350
406
|
* either the outcome is still unknown (`pending`) or there is enough content to show. */
|
|
351
|
-
const showCarousel = computed(
|
|
407
|
+
const showCarousel = computed(
|
|
408
|
+
() =>
|
|
409
|
+
hasHeading.value && (pending.value || hasEnoughProducts.value || activeCategory.value !== null)
|
|
410
|
+
);
|
|
411
|
+
const showFilteredEmpty = computed(
|
|
412
|
+
() => activeCategory.value !== null && !pending.value && cards.value.length === 0
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
416
|
+
/* Quick add */
|
|
417
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
418
|
+
|
|
419
|
+
const showQuickAdd = computed(() => (data.value.quickAdd ?? false) && !isRecentlyViewed.value);
|
|
420
|
+
/** `null` until a pill is pressed, so the read asks for nothing on the server or on load. */
|
|
421
|
+
const quickAddHandle = ref<string | null>(null);
|
|
422
|
+
const quickAddResult = storefront.catalog.product(quickAddHandle);
|
|
423
|
+
const quickAddBusy = ref(false);
|
|
424
|
+
const toast = useToast();
|
|
425
|
+
const feedback = useStorefrontFeedback();
|
|
426
|
+
const activeLocale = useEldraLocale();
|
|
427
|
+
|
|
428
|
+
/** Resolves once the product read for `handle` has settled: the product, or `null` when the read
|
|
429
|
+
* failed or answered nothing. */
|
|
430
|
+
async function readProduct(handle: string): Promise<StorefrontProduct | null> {
|
|
431
|
+
quickAddHandle.value = handle;
|
|
432
|
+
await nextTick();
|
|
433
|
+
const settled = (): boolean =>
|
|
434
|
+
!quickAddResult.loading.value &&
|
|
435
|
+
(quickAddResult.data.value?.handle === handle || quickAddResult.error.value !== null);
|
|
436
|
+
if (!settled()) {
|
|
437
|
+
await new Promise<void>((resolve) => {
|
|
438
|
+
const stop = watch(
|
|
439
|
+
() => [quickAddResult.loading.value, quickAddResult.data.value, quickAddResult.error.value],
|
|
440
|
+
() => {
|
|
441
|
+
if (!settled()) return;
|
|
442
|
+
stop();
|
|
443
|
+
resolve();
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
const product = quickAddResult.data.value;
|
|
449
|
+
return product !== null && product.handle === handle ? product : null;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async function onQuickAdd(item: { handle: string }): Promise<void> {
|
|
453
|
+
if (quickAddBusy.value) return;
|
|
454
|
+
quickAddBusy.value = true;
|
|
455
|
+
try {
|
|
456
|
+
const product = await readProduct(item.handle);
|
|
457
|
+
if (product === null || product.variantId === '') {
|
|
458
|
+
feedback.report(null, { id: CART_ADD_TOAST_ID });
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const cart = storefront.cart;
|
|
462
|
+
const failure = await cart.add({
|
|
463
|
+
productId: product.productId,
|
|
464
|
+
variantId: product.variantId,
|
|
465
|
+
quantity: 1,
|
|
466
|
+
});
|
|
467
|
+
if (failure !== null) {
|
|
468
|
+
feedback.report(failure, { id: CART_ADD_TOAST_ID });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
toast.show({
|
|
472
|
+
id: CART_ADD_TOAST_ID,
|
|
473
|
+
title: t('cart.added'),
|
|
474
|
+
action: cart.drawerAvailable.value
|
|
475
|
+
? {
|
|
476
|
+
label: t('cart.viewCart'),
|
|
477
|
+
onActivate: () => {
|
|
478
|
+
cart.drawerOpen.value = true;
|
|
479
|
+
},
|
|
480
|
+
}
|
|
481
|
+
: { label: t('cart.viewCart'), href: activeLocale.path('/cart') },
|
|
482
|
+
});
|
|
483
|
+
} finally {
|
|
484
|
+
quickAddBusy.value = false;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
489
|
+
/* Card and grid styling */
|
|
490
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
491
|
+
|
|
492
|
+
/** The card's own parts, restyled to the theme (see the module doc comment). The root is a
|
|
493
|
+
* one-column grid so the quick-add pill can share the photo's cell; from 761px of block width
|
|
494
|
+
* the price moves beside the title. */
|
|
495
|
+
const CARD_ROOT_CLASS = 'grid grid-cols-1 grid-rows-[auto_1fr] content-start';
|
|
496
|
+
const cardClasses = computed<Partial<Record<ProductCardPart, string>>>(() => ({
|
|
497
|
+
media: '[grid-area:1/1]',
|
|
498
|
+
body:
|
|
499
|
+
'[grid-area:2/1] @min-[47.5625rem]:grid @min-[47.5625rem]:grid-cols-[minmax(0,1fr)_auto] ' +
|
|
500
|
+
'@min-[47.5625rem]:items-baseline @min-[47.5625rem]:content-start @min-[47.5625rem]:gap-x-3',
|
|
501
|
+
title: 'leading-[1.35]',
|
|
502
|
+
link:
|
|
503
|
+
'no-underline hover:underline hover:decoration-1 hover:decoration-current ' +
|
|
504
|
+
'hover:underline-offset-[0.2em]',
|
|
505
|
+
price: 'whitespace-nowrap',
|
|
506
|
+
rating: '@min-[47.5625rem]:col-span-2',
|
|
507
|
+
stockLine: '@min-[47.5625rem]:col-span-2',
|
|
508
|
+
swatches: 'mt-1 @min-[47.5625rem]:col-span-2',
|
|
509
|
+
quickAdd:
|
|
510
|
+
'[grid-area:1/1] z-10 m-3 mt-0 self-end justify-self-end w-auto h-10 min-h-10 rounded-full ' +
|
|
511
|
+
'border-0 bg-background px-3.5 text-sm font-semibold text-text shadow-sm ' +
|
|
512
|
+
'hover:bg-text hover:text-background disabled:opacity-90',
|
|
513
|
+
}));
|
|
514
|
+
|
|
515
|
+
const GRID_CLASS =
|
|
516
|
+
'grid grid-cols-2 gap-x-3 gap-y-8 @min-[47.5625rem]:grid-cols-3 @min-[47.5625rem]:gap-x-5 ' +
|
|
517
|
+
'@min-[47.5625rem]:gap-y-10 @min-[68.8125rem]:grid-cols-4';
|
|
518
|
+
|
|
519
|
+
function chipClass(active: boolean): string {
|
|
520
|
+
return active
|
|
521
|
+
? 'border-text bg-text text-background'
|
|
522
|
+
: 'border-border-strong text-text hover:bg-surface';
|
|
523
|
+
}
|
|
352
524
|
/** The whole block gates on having a heading — spec: a block with no required content renders
|
|
353
525
|
* nothing live; in the editor an empty heading gets its own hint instead of vanishing. */
|
|
354
526
|
const showBlock = computed(() =>
|
|
@@ -395,6 +567,75 @@ const showBlock = computed(() =>
|
|
|
395
567
|
:help="t('storefront.unresolvedCollectionHelp')"
|
|
396
568
|
/>
|
|
397
569
|
|
|
570
|
+
<template v-else-if="showCarousel && isGrid">
|
|
571
|
+
<div class="mb-8 flex flex-wrap items-end justify-between gap-x-8 gap-y-4">
|
|
572
|
+
<div>
|
|
573
|
+
<p v-if="data.eyebrow" class="text-overline text-accent mb-2">{{ data.eyebrow }}</p>
|
|
574
|
+
<h2 :id="headingId" :class="HEADING_CLASSES">
|
|
575
|
+
<Link
|
|
576
|
+
v-if="hasViewAll"
|
|
577
|
+
:href="viewAllHref!"
|
|
578
|
+
:as="viewAllLinkAs"
|
|
579
|
+
variant="standalone"
|
|
580
|
+
arrow
|
|
581
|
+
:aria-label="`${heading} — ${data.viewAllLabel}${t('productCarousel.viewAllContext')}`"
|
|
582
|
+
:class="`${HEADING_CLASSES} text-inherit`"
|
|
583
|
+
>
|
|
584
|
+
{{ heading }}
|
|
585
|
+
</Link>
|
|
586
|
+
<template v-else>{{ heading }}</template>
|
|
587
|
+
</h2>
|
|
588
|
+
</div>
|
|
589
|
+
<ul
|
|
590
|
+
v-if="hasFilterChips"
|
|
591
|
+
class="eldra-scrollbar-hide flex max-w-full gap-2 overflow-x-auto px-0.5 py-1"
|
|
592
|
+
:aria-label="t('productCarousel.filterLabel', { heading })"
|
|
593
|
+
>
|
|
594
|
+
<li
|
|
595
|
+
v-for="chip in [{ label: allFilterLabel, category: null }, ...filterChips]"
|
|
596
|
+
:key="chip.category ?? ''"
|
|
597
|
+
>
|
|
598
|
+
<button
|
|
599
|
+
type="button"
|
|
600
|
+
class="eldra-focus inline-flex min-h-10 items-center rounded-full border px-4 text-[0.9375rem] font-medium whitespace-nowrap"
|
|
601
|
+
:class="chipClass(activeCategory === chip.category)"
|
|
602
|
+
:aria-pressed="activeCategory === chip.category ? 'true' : 'false'"
|
|
603
|
+
@click="activeCategory = chip.category"
|
|
604
|
+
>
|
|
605
|
+
{{ chip.label }}
|
|
606
|
+
</button>
|
|
607
|
+
</li>
|
|
608
|
+
</ul>
|
|
609
|
+
</div>
|
|
610
|
+
|
|
611
|
+
<ul v-if="showSkeletons" role="list" :class="GRID_CLASS">
|
|
612
|
+
<li v-for="n in 4" :key="n"><Skeleton variant="media" :ratio="cardRatio" /></li>
|
|
613
|
+
</ul>
|
|
614
|
+
<ul v-else-if="cards.length > 0" role="list" :class="GRID_CLASS">
|
|
615
|
+
<li v-for="entry in cards" :key="entry.item.handle">
|
|
616
|
+
<ProductCard
|
|
617
|
+
:product="entry.product"
|
|
618
|
+
:ratio="cardRatio"
|
|
619
|
+
:class="[CARD_CLASS, CARD_ROOT_CLASS]"
|
|
620
|
+
:classes="cardClasses"
|
|
621
|
+
:show-swatches="showSwatchesField"
|
|
622
|
+
:show-rating="true"
|
|
623
|
+
:quick-add="showQuickAdd"
|
|
624
|
+
:heading-level="3"
|
|
625
|
+
:revalidating="entry.revalidating"
|
|
626
|
+
:announce="false"
|
|
627
|
+
:link-as="entry.internal ? EldraRouterLink : undefined"
|
|
628
|
+
:currency="entry.currency ?? currency"
|
|
629
|
+
:locale="locale"
|
|
630
|
+
@quick-add="onQuickAdd(entry.item)"
|
|
631
|
+
/>
|
|
632
|
+
</li>
|
|
633
|
+
</ul>
|
|
634
|
+
<p v-else-if="showFilteredEmpty" class="text-muted">
|
|
635
|
+
{{ t('productCarousel.filterEmpty') }}
|
|
636
|
+
</p>
|
|
637
|
+
</template>
|
|
638
|
+
|
|
398
639
|
<Carousel
|
|
399
640
|
v-else-if="showCarousel"
|
|
400
641
|
:ariaLabel="carouselAriaLabel"
|
|
@@ -406,27 +647,30 @@ const showBlock = computed(() =>
|
|
|
406
647
|
>
|
|
407
648
|
<template #header>
|
|
408
649
|
<div class="flex flex-1 flex-wrap items-end justify-between gap-x-8 gap-y-4">
|
|
409
|
-
<
|
|
410
|
-
|
|
650
|
+
<div>
|
|
651
|
+
<p v-if="data.eyebrow" class="text-overline text-accent mb-2">{{ data.eyebrow }}</p>
|
|
652
|
+
<h2 :id="headingId" :class="HEADING_CLASSES">
|
|
653
|
+
<!-- The heading itself is the "view all" link: its visible text stays the heading (so
|
|
411
654
|
the Section this `<h2>` labels keeps that exact name) and the link's own
|
|
412
655
|
accessible name starts with it and adds `viewAllLabel` + context ("You may also
|
|
413
656
|
like — View all products"). A separate link in the same row as the arrows read
|
|
414
657
|
as a third control. No counter: a product row shows several cards at once, so
|
|
415
658
|
"3 / 6" while the track sits at its end reads wrong (spec "Carousel" → Product
|
|
416
659
|
row: no dots and no counter). -->
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
660
|
+
<Link
|
|
661
|
+
v-if="hasViewAll && !isRecentlyViewed"
|
|
662
|
+
:href="viewAllHref!"
|
|
663
|
+
:as="viewAllLinkAs"
|
|
664
|
+
variant="standalone"
|
|
665
|
+
arrow
|
|
666
|
+
:aria-label="`${heading} — ${data.viewAllLabel}${t('productCarousel.viewAllContext')}`"
|
|
667
|
+
:class="`${HEADING_CLASSES} text-inherit`"
|
|
668
|
+
>
|
|
669
|
+
{{ heading }}
|
|
670
|
+
</Link>
|
|
671
|
+
<template v-else>{{ heading }}</template>
|
|
672
|
+
</h2>
|
|
673
|
+
</div>
|
|
430
674
|
<Button v-if="isRecentlyViewed" variant="link" type="button" @click="onClearHistory">
|
|
431
675
|
{{ t('productCarousel.clearHistory') }}
|
|
432
676
|
</Button>
|
|
@@ -443,16 +687,18 @@ const showBlock = computed(() =>
|
|
|
443
687
|
<ProductCard
|
|
444
688
|
:product="entry.product"
|
|
445
689
|
:ratio="cardRatio"
|
|
446
|
-
:class="CARD_CLASS"
|
|
690
|
+
:class="[CARD_CLASS, CARD_ROOT_CLASS]"
|
|
691
|
+
:classes="cardClasses"
|
|
447
692
|
:show-swatches="!isRecentlyViewed && showSwatchesField"
|
|
448
693
|
:show-rating="!isRecentlyViewed"
|
|
449
|
-
:quick-add="
|
|
694
|
+
:quick-add="showQuickAdd"
|
|
450
695
|
:heading-level="3"
|
|
451
696
|
:revalidating="entry.revalidating"
|
|
452
697
|
:announce="false"
|
|
453
698
|
:link-as="entry.internal ? EldraRouterLink : undefined"
|
|
454
699
|
:currency="entry.currency ?? currency"
|
|
455
700
|
:locale="locale"
|
|
701
|
+
@quick-add="onQuickAdd(entry.item)"
|
|
456
702
|
/>
|
|
457
703
|
</div>
|
|
458
704
|
</template>
|
|
@@ -10,6 +10,7 @@ import { ProductCard, Skeleton } from '@eldrajs/ui';
|
|
|
10
10
|
import { axe } from '../../../test/support/axe';
|
|
11
11
|
import Block from '../Block.vue';
|
|
12
12
|
import mock from '../mock.json';
|
|
13
|
+
import preview from '../preview.json';
|
|
13
14
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
14
15
|
import { STOREFRONT_KEY } from '../../../app/storefront/types';
|
|
15
16
|
import type {
|
|
@@ -534,6 +535,95 @@ describe('product-carousel block', () => {
|
|
|
534
535
|
* draft overlay, or a depth-0 read); a theme's own seed carries the slug with
|
|
535
536
|
* no id at all.
|
|
536
537
|
*/
|
|
538
|
+
describe('grid layout, filter chips and quick add (the preview overlay)', () => {
|
|
539
|
+
const design = { ...mock, ...preview };
|
|
540
|
+
|
|
541
|
+
function cardTitles(wrapper: VueWrapper): string[] {
|
|
542
|
+
return wrapper
|
|
543
|
+
.findAllComponents(ProductCard)
|
|
544
|
+
.map((card) => (card.props('product') as { title: string }).title);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
it('renders the eyebrow, heading, chips and a grid of cards with no axe violations', async () => {
|
|
548
|
+
const wrapper = mountBlock(design);
|
|
549
|
+
await flushPromises();
|
|
550
|
+
expect(wrapper.find('[data-part="track"]').exists()).toBe(false);
|
|
551
|
+
expect(wrapper.text()).toContain(preview.eyebrow);
|
|
552
|
+
expect(wrapper.get('h2').text()).toContain(preview.heading);
|
|
553
|
+
expect(wrapper.findAllComponents(ProductCard).length).toBeGreaterThanOrEqual(2);
|
|
554
|
+
const chips = wrapper.findAll('button[aria-pressed]');
|
|
555
|
+
expect(chips.map((chip) => chip.text())).toEqual([
|
|
556
|
+
enUS.productCarousel.allFilter,
|
|
557
|
+
...preview.filters.map((chip) => chip.label),
|
|
558
|
+
]);
|
|
559
|
+
expect(chips[0]!.attributes('aria-pressed')).toBe('true');
|
|
560
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it('a chip narrows the read to its category, and "All" puts it back', async () => {
|
|
564
|
+
const wrapper = mountBlock(design);
|
|
565
|
+
await flushPromises();
|
|
566
|
+
const all = cardTitles(wrapper);
|
|
567
|
+
const chips = () => wrapper.findAll('button[aria-pressed]');
|
|
568
|
+
await chips()[1]!.trigger('click');
|
|
569
|
+
await flushPromises();
|
|
570
|
+
expect(chips()[1]!.attributes('aria-pressed')).toBe('true');
|
|
571
|
+
expect(chips()[0]!.attributes('aria-pressed')).toBe('false');
|
|
572
|
+
const ceramics = cardTitles(wrapper);
|
|
573
|
+
expect(ceramics.length).toBeGreaterThan(0);
|
|
574
|
+
expect(ceramics).not.toEqual(all);
|
|
575
|
+
const ceramicHandles = new Set([
|
|
576
|
+
'speckled-latte-mug',
|
|
577
|
+
'stoneware-dinner-plates-set-of-4',
|
|
578
|
+
'hand-thrown-serving-bowl',
|
|
579
|
+
'glazed-milk-jug',
|
|
580
|
+
]);
|
|
581
|
+
const ceramicTitles = PRODUCTS.filter((p) => ceramicHandles.has(p.handle)).map(
|
|
582
|
+
(p) => p.title
|
|
583
|
+
);
|
|
584
|
+
for (const title of ceramics) expect(ceramicTitles).toContain(title);
|
|
585
|
+
await chips()[0]!.trigger('click');
|
|
586
|
+
await flushPromises();
|
|
587
|
+
expect(cardTitles(wrapper)).toEqual(all);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('shows no chips outside the grid layout or the collection variant', async () => {
|
|
591
|
+
const carousel = mountBlock({ ...design, layout: 'carousel' });
|
|
592
|
+
await flushPromises();
|
|
593
|
+
expect(carousel.find('button[aria-pressed]').exists()).toBe(false);
|
|
594
|
+
const related = mountBlock({ ...design, variant: 'related' });
|
|
595
|
+
await flushPromises();
|
|
596
|
+
expect(related.find('button[aria-pressed]').exists()).toBe(false);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it.each(['carousel', 'grid'] as const)(
|
|
600
|
+
'quick add (%s layout) reads the product and puts its variant in the cart',
|
|
601
|
+
async (layout) => {
|
|
602
|
+
const storefront = createDemoStorefront();
|
|
603
|
+
const add = vi.spyOn(storefront.cart, 'add');
|
|
604
|
+
const wrapper = mountBlock({ ...design, layout }, { storefront });
|
|
605
|
+
await flushPromises();
|
|
606
|
+
const first = wrapper.findAllComponents(ProductCard)[0]!;
|
|
607
|
+
const button = first.get('button[data-part="quickAdd"]');
|
|
608
|
+
const title = (first.props('product') as { title: string }).title;
|
|
609
|
+
expect(button.attributes('aria-label')).toContain(title);
|
|
610
|
+
await button.trigger('click');
|
|
611
|
+
await flushPromises();
|
|
612
|
+
expect(add).toHaveBeenCalledTimes(1);
|
|
613
|
+
const input = add.mock.calls[0]![0];
|
|
614
|
+
expect(input.quantity).toBe(1);
|
|
615
|
+
expect(input.variantId).not.toBe('');
|
|
616
|
+
expect(storefront.cart.lines.value.length).toBe(1);
|
|
617
|
+
}
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
it('offers no quick add when it is off, or in recently-viewed', async () => {
|
|
621
|
+
const off = mountBlock({ ...design, quickAdd: false });
|
|
622
|
+
await flushPromises();
|
|
623
|
+
expect(off.find('[data-part="quickAdd"]').exists()).toBe(false);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
|
|
537
627
|
describe('the collection variant\u2019s source', () => {
|
|
538
628
|
const WINTER = demoCollectionId('winter-knitwear')!;
|
|
539
629
|
const BEST_SELLERS = demoCollectionId('best-sellers')!;
|
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
"category": "commerce",
|
|
7
7
|
"version": 3,
|
|
8
8
|
"fields": [
|
|
9
|
+
{
|
|
10
|
+
"fieldId": "eyebrow",
|
|
11
|
+
"name": "Eyebrow",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"localized": true,
|
|
14
|
+
"helpText": "A short line above the heading, e.g. \"Just in\". Optional."
|
|
15
|
+
},
|
|
9
16
|
{
|
|
10
17
|
"fieldId": "heading",
|
|
11
18
|
"name": "Heading",
|
|
@@ -53,6 +60,60 @@
|
|
|
53
60
|
"helpText": "Where the heading links to. The collection variant links to the collection you picked instead.",
|
|
54
61
|
"showWhen": { "field": "variant", "in": ["related"] }
|
|
55
62
|
},
|
|
63
|
+
{
|
|
64
|
+
"fieldId": "layout",
|
|
65
|
+
"name": "Layout",
|
|
66
|
+
"type": "select",
|
|
67
|
+
"helpText": "carousel is the default: one row that scrolls sideways. grid shows every product at once, 4 across on wide screens, 3 on tablets and 2 on phones.",
|
|
68
|
+
"metadata": { "options": ["carousel", "grid"] }
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"fieldId": "filters",
|
|
72
|
+
"name": "Filter chips",
|
|
73
|
+
"type": "list",
|
|
74
|
+
"helpText": "Grid layout only. Chips above the products that narrow them to one category, after an \"All\" chip. Up to 6.",
|
|
75
|
+
"showWhen": { "field": "variant", "in": ["collection"] },
|
|
76
|
+
"metadata": {
|
|
77
|
+
"item": {
|
|
78
|
+
"fieldId": "item",
|
|
79
|
+
"name": "Chip",
|
|
80
|
+
"type": "composite",
|
|
81
|
+
"metadata": {
|
|
82
|
+
"fields": [
|
|
83
|
+
{
|
|
84
|
+
"fieldId": "label",
|
|
85
|
+
"name": "Label",
|
|
86
|
+
"type": "string",
|
|
87
|
+
"localized": true,
|
|
88
|
+
"validators": { "required": true }
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"fieldId": "category",
|
|
92
|
+
"name": "Category",
|
|
93
|
+
"type": "string",
|
|
94
|
+
"helpText": "The category's handle, e.g. ceramics.",
|
|
95
|
+
"validators": { "required": true }
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"fieldId": "allFilterLabel",
|
|
104
|
+
"name": "\"All\" chip label",
|
|
105
|
+
"type": "string",
|
|
106
|
+
"localized": true,
|
|
107
|
+
"helpText": "Defaults to \"All\".",
|
|
108
|
+
"showWhen": { "field": "variant", "in": ["collection"] }
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"fieldId": "quickAdd",
|
|
112
|
+
"name": "Quick add",
|
|
113
|
+
"type": "bool",
|
|
114
|
+
"default": false,
|
|
115
|
+
"helpText": "Adds a button on each photo that puts the product straight in the cart. Off in recently-viewed."
|
|
116
|
+
},
|
|
56
117
|
{
|
|
57
118
|
"fieldId": "showSwatches",
|
|
58
119
|
"name": "Show swatches",
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
+
"eyebrow": "Just in",
|
|
3
|
+
"heading": "New arrivals",
|
|
4
|
+
"variant": "collection",
|
|
5
|
+
"layout": "grid",
|
|
6
|
+
"limit": "8",
|
|
7
|
+
"quickAdd": true,
|
|
8
|
+
"showSwatches": true,
|
|
9
|
+
"filters": [
|
|
10
|
+
{ "label": "Ceramics", "category": "ceramics" },
|
|
11
|
+
{ "label": "Knitwear", "category": "knitwear" },
|
|
12
|
+
{ "label": "Kitchen", "category": "kitchen" }
|
|
13
|
+
],
|
|
2
14
|
"sourceCollection": {
|
|
3
15
|
"_type": "collection",
|
|
4
16
|
"id": "2f1b8d54-0d3a-4a6f-9a0b-7f6c1d2e3a02",
|
|
Binary file
|