@ikas/bp-storefront 1.4.0-beta.81 → 1.4.0-beta.82
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.
|
@@ -1,37 +1,61 @@
|
|
|
1
1
|
import { IkasImage } from "../../../storefront-models/src";
|
|
2
2
|
/**
|
|
3
|
-
* Returns the default source URL for an image at 1080px resolution.
|
|
3
|
+
* Returns the default source URL for an image OR video at 1080px resolution.
|
|
4
|
+
*
|
|
5
|
+
* Product media items (IkasProductImage) can be videos. ALWAYS check `item.isVideo`
|
|
6
|
+
* and render a `<video src={getDefaultSrc(item)}>` instead of an `<img>` when it is true.
|
|
7
|
+
* Never assume every media item is an image.
|
|
4
8
|
*
|
|
5
9
|
* @ai-category Image
|
|
6
10
|
* @ai-related getThumbnailSrc, getSrc, createMediaSrcset
|
|
7
11
|
*
|
|
8
12
|
* @param image - The image object to generate the default source URL for.
|
|
9
|
-
* @returns The CDN URL string for the image at 1080px size.
|
|
13
|
+
* @returns The CDN URL string for the image or video at 1080px size.
|
|
10
14
|
*
|
|
11
15
|
* @example
|
|
12
16
|
* ```typescript
|
|
13
|
-
* import { getDefaultSrc } from "@ikas/bp-storefront";
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* import { getDefaultSrc, createMediaSrcset } from "@ikas/bp-storefront";
|
|
18
|
+
*
|
|
19
|
+
* // Product images can be videos — ALWAYS branch on isVideo when mapping media:
|
|
20
|
+
* {product.images.map((item, i) =>
|
|
21
|
+
* item.isVideo ? (
|
|
22
|
+
* <video key={i} src={getDefaultSrc(item)} muted playsInline preload="metadata">
|
|
23
|
+
* <track kind="captions" />
|
|
24
|
+
* </video>
|
|
25
|
+
* ) : (
|
|
26
|
+
* <img key={i} src={getDefaultSrc(item)} srcSet={createMediaSrcset(item)} alt={`Product ${i + 1}`} />
|
|
27
|
+
* )
|
|
28
|
+
* )}
|
|
17
29
|
* ```
|
|
18
30
|
*/
|
|
19
31
|
export declare function getDefaultSrc(image: IkasImage): string;
|
|
20
32
|
/**
|
|
21
|
-
* Returns the thumbnail source URL for an image at 180px resolution.
|
|
33
|
+
* Returns the thumbnail source URL for an image OR video at 180px resolution.
|
|
34
|
+
*
|
|
35
|
+
* When mapping over product media (IkasProductImage[]), some items are videos:
|
|
36
|
+
* check `item.isVideo` and render a `<video>` thumbnail (typically with a play
|
|
37
|
+
* overlay) instead of an `<img>` when it is true.
|
|
22
38
|
*
|
|
23
39
|
* @ai-category Image
|
|
24
40
|
* @ai-related getDefaultSrc, getSrc, createMediaSrcset
|
|
25
41
|
*
|
|
26
42
|
* @param image - The image object to generate the thumbnail source URL for.
|
|
27
|
-
* @returns The CDN URL string for the image at 180px size.
|
|
43
|
+
* @returns The CDN URL string for the image or video at 180px size.
|
|
28
44
|
*
|
|
29
45
|
* @example
|
|
30
46
|
* ```typescript
|
|
31
|
-
* import { getThumbnailSrc } from "@ikas/bp-storefront";
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
47
|
+
* import { getThumbnailSrc, getDefaultSrc } from "@ikas/bp-storefront";
|
|
48
|
+
*
|
|
49
|
+
* // Thumbnail rail — branch on isVideo per item:
|
|
50
|
+
* {product.images.map((item, i) =>
|
|
51
|
+
* item.isVideo ? (
|
|
52
|
+
* <video key={i} src={getDefaultSrc(item)} muted preload="metadata">
|
|
53
|
+
* <track kind="captions" />
|
|
54
|
+
* </video>
|
|
55
|
+
* ) : (
|
|
56
|
+
* <img key={i} src={getThumbnailSrc(item)} sizes="112px" alt={`Thumb ${i + 1}`} />
|
|
57
|
+
* )
|
|
58
|
+
* )}
|
|
35
59
|
* ```
|
|
36
60
|
*/
|
|
37
61
|
export declare function getThumbnailSrc(image: IkasImage): string;
|
|
@@ -57,6 +81,10 @@ export declare function getSrc(image: IkasImage, size: number): string;
|
|
|
57
81
|
/**
|
|
58
82
|
* Generates a complete responsive `srcset` string for an image across all standard sizes (180–3840px).
|
|
59
83
|
*
|
|
84
|
+
* srcset applies to `<img>` only — video media (`item.isVideo === true`) has no srcset
|
|
85
|
+
* and must be rendered with `<video src={getDefaultSrc(item)}>`. When mapping product
|
|
86
|
+
* images, branch on `item.isVideo` first, then only use createMediaSrcset on the image branch.
|
|
87
|
+
*
|
|
60
88
|
* @ai-category Image
|
|
61
89
|
* @ai-related getDefaultSrc, getThumbnailSrc, getSrc
|
|
62
90
|
*
|
|
@@ -67,12 +95,22 @@ export declare function getSrc(image: IkasImage, size: number): string;
|
|
|
67
95
|
* ```typescript
|
|
68
96
|
* import { createMediaSrcset, getDefaultSrc } from "@ikas/bp-storefront";
|
|
69
97
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
98
|
+
* // Product images can be videos — ALWAYS branch on isVideo when mapping media:
|
|
99
|
+
* {product.images.map((item, i) =>
|
|
100
|
+
* item.isVideo ? (
|
|
101
|
+
* <video key={i} src={getDefaultSrc(item)} muted playsInline preload="metadata">
|
|
102
|
+
* <track kind="captions" />
|
|
103
|
+
* </video>
|
|
104
|
+
* ) : (
|
|
105
|
+
* <img
|
|
106
|
+
* key={i}
|
|
107
|
+
* src={getDefaultSrc(item)}
|
|
108
|
+
* srcSet={createMediaSrcset(item)}
|
|
109
|
+
* sizes="(max-width: 768px) 100vw, 50vw"
|
|
110
|
+
* alt={`Product ${i + 1}`}
|
|
111
|
+
* />
|
|
112
|
+
* )
|
|
113
|
+
* )}
|
|
76
114
|
* ```
|
|
77
115
|
*/
|
|
78
116
|
export declare function createMediaSrcset(image?: IkasImage | null): string;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { BackInStockNotificationForm, IkasAppliedCampaignAmount, IkasProductAttributeMap, IkasProductPrice, IkasProductVariant } from "../../../../storefront-models/src";
|
|
2
2
|
/**
|
|
3
|
-
* Get the main/primary
|
|
3
|
+
* Get the main/primary media item for a product variant.
|
|
4
|
+
*
|
|
5
|
+
* The returned IkasProductImage may be a video (`isVideo === true`) — branch on it
|
|
6
|
+
* and render `<video>` instead of `<img>`.
|
|
4
7
|
*
|
|
5
8
|
* @ai-category ProductDetail, ProductList
|
|
6
9
|
* @ai-related getSelectedProductVariant
|
|
7
10
|
*
|
|
8
11
|
* @param variant - The product variant
|
|
9
|
-
* @returns The first IkasProductImage of the variant, or undefined if no images.
|
|
12
|
+
* @returns The first IkasProductImage of the variant, or undefined if no images. Check `.isVideo` to decide between `<video>` and `<img>`, and access `.image` to get the IkasImage for CDN helpers.
|
|
10
13
|
*
|
|
11
14
|
* @example
|
|
12
15
|
* ```typescript
|
|
13
|
-
* import { getProductVariantMainImage, getSelectedProductVariant, getDefaultSrc } from "@ikas/bp-storefront";
|
|
16
|
+
* import { getProductVariantMainImage, getSelectedProductVariant, getDefaultSrc, createMediaSrcset } from "@ikas/bp-storefront";
|
|
14
17
|
* import { IkasProduct } from "@ikas/bp-storefront";
|
|
15
18
|
*
|
|
16
19
|
* function ProductImage({ product }: { product: IkasProduct }) {
|
|
@@ -22,7 +25,14 @@ import { BackInStockNotificationForm, IkasAppliedCampaignAmount, IkasProductAttr
|
|
|
22
25
|
* return <div className="no-image">No image available</div>;
|
|
23
26
|
* }
|
|
24
27
|
*
|
|
25
|
-
*
|
|
28
|
+
* // Media can be a video — branch on isVideo:
|
|
29
|
+
* return productImage.isVideo ? (
|
|
30
|
+
* <video src={getDefaultSrc(image)} muted playsInline loop>
|
|
31
|
+
* <track kind="captions" />
|
|
32
|
+
* </video>
|
|
33
|
+
* ) : (
|
|
34
|
+
* <img src={getDefaultSrc(image)} srcSet={createMediaSrcset(image)} alt={product.name} />
|
|
35
|
+
* );
|
|
26
36
|
* }
|
|
27
37
|
* ```
|
|
28
38
|
*/
|