@usequeek/theme-kit 0.1.33 → 0.1.34
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/package.json +1 -1
- package/utils/hero-content.ts +29 -5
package/package.json
CHANGED
package/utils/hero-content.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GalleryBlockData } from '../types/block';
|
|
2
|
+
import { isBlankText } from './blank-text';
|
|
2
3
|
|
|
3
4
|
type HeroSlide = GalleryBlockData['images'][number];
|
|
4
5
|
|
|
@@ -21,15 +22,38 @@ export function heroImageMode(images: GalleryBlockData['images']): 'zero' | 'sin
|
|
|
21
22
|
return images.length === 1 ? 'single' : 'multi';
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* A merchant's own slide shows exactly what they typed: a blank title, subtitle or
|
|
27
|
+
* button label renders nothing (busy slide images need bare slides). The store
|
|
28
|
+
* name, slogan and "Shop now" fill in only for the zero-image placeholder hero,
|
|
29
|
+
* where `slide` is undefined. Callers render each part only when it is non-empty.
|
|
30
|
+
*/
|
|
24
31
|
export function resolveHeroContent(
|
|
25
32
|
slide: HeroSlide | undefined,
|
|
26
33
|
fallback: HeroFallbacks,
|
|
27
34
|
): ResolvedHeroContent {
|
|
35
|
+
const ctaHref = text(slide?.cta_url) || fallback.shopHref;
|
|
36
|
+
const slideHref = text(slide?.link) || null;
|
|
37
|
+
|
|
38
|
+
if (slide === undefined) {
|
|
39
|
+
return {
|
|
40
|
+
title: fallback.title,
|
|
41
|
+
subtitle: text(fallback.subtitle) || null,
|
|
42
|
+
ctaLabel: 'Shop now',
|
|
43
|
+
ctaHref,
|
|
44
|
+
slideHref,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
return {
|
|
29
|
-
title: slide
|
|
30
|
-
subtitle: slide
|
|
31
|
-
ctaLabel: slide
|
|
32
|
-
ctaHref
|
|
33
|
-
slideHref
|
|
49
|
+
title: text(slide.title),
|
|
50
|
+
subtitle: text(slide.subtitle) || null,
|
|
51
|
+
ctaLabel: text(slide.cta_label),
|
|
52
|
+
ctaHref,
|
|
53
|
+
slideHref,
|
|
34
54
|
};
|
|
35
55
|
}
|
|
56
|
+
|
|
57
|
+
function text(value: string | null | undefined): string {
|
|
58
|
+
return isBlankText(value) ? '' : (value as string).trim();
|
|
59
|
+
}
|