/
ProductShelf.tsx
98 lines (91 loc) · 3 KB
/
ProductShelf.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { SendEventOnLoad } from "$store/components/Analytics.tsx";
import ProductCard, {
Layout as cardLayout,
} from "$store/components/product/ProductCard.tsx";
import Icon from "$store/components/ui/Icon.tsx";
import Header from "$store/components/ui/SectionHeader.tsx";
import Slider from "$store/components/ui/Slider.tsx";
import SliderJS from "$store/islands/SliderJS.tsx";
import { useId } from "$store/sdk/useId.ts";
import { useOffer } from "$store/sdk/useOffer.ts";
import type { Product } from "apps/commerce/types.ts";
import { mapProductToAnalyticsItem } from "deco-sites/std/commerce/utils/productToAnalyticsItem.ts";
export interface Props {
products: Product[] | null;
title?: string;
description?: string;
layout?: {
headerAlignment?: "center" | "left";
headerfontSize?: "Normal" | "Large";
};
cardLayout?: cardLayout;
}
function ProductShelf({
products,
title,
description,
layout,
cardLayout,
}: Props) {
const id = useId();
if (!products || products.length === 0) {
return null;
}
return (
<div class="w-full container py-8 flex flex-col gap-12 lg:gap-16 lg:py-10">
<Header
title={title || ""}
description={description || ""}
fontSize={layout?.headerfontSize || "Large"}
alignment={layout?.headerAlignment || "center"}
/>
<div
id={id}
class="container grid grid-cols-[48px_1fr_48px] px-0 sm:px-5"
>
<Slider class="carousel carousel-center sm:carousel-end gap-6 col-span-full row-start-2 row-end-5">
{products?.map((product, index) => (
<Slider.Item
index={index}
class="carousel-item w-[270px] sm:w-[292px] first:pl-6 sm:first:pl-0 last:pr-6 sm:last:pr-0"
>
<ProductCard
product={product}
itemListName={title}
layout={cardLayout}
/>
</Slider.Item>
))}
</Slider>
<>
<div class="hidden relative sm:block z-10 col-start-1 row-start-3">
<Slider.PrevButton class="btn btn-circle btn-outline absolute right-1/2 bg-base-100">
<Icon size={24} id="ChevronLeft" strokeWidth={3} />
</Slider.PrevButton>
</div>
<div class="hidden relative sm:block z-10 col-start-3 row-start-3">
<Slider.NextButton class="btn btn-circle btn-outline absolute left-1/2 bg-base-100">
<Icon size={24} id="ChevronRight" strokeWidth={3} />
</Slider.NextButton>
</div>
</>
<SliderJS rootId={id} />
<SendEventOnLoad
event={{
name: "view_item_list",
params: {
item_list_name: title,
items: products.map((product) =>
mapProductToAnalyticsItem({
product,
...(useOffer(product.offers)),
})
),
},
}}
/>
</div>
</div>
);
}
export default ProductShelf;