forked from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelated-products.tsx
114 lines (110 loc) · 2.95 KB
/
related-products.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Await, useLoaderData } from "@remix-run/react";
import type { HydrogenComponentSchema } from "@weaverse/hydrogen";
import { Suspense, forwardRef } from "react";
import type { ProductCardFragment } from "storefront-api.generated";
import Heading, {
type HeadingProps,
headingInputs,
} from "~/components/heading";
import { Section, type SectionProps, layoutInputs } from "~/components/section";
import { ProductCard } from "~/components/product/product-card";
interface RelatedProductsProps
extends Omit<SectionProps, "content">,
Omit<HeadingProps, "as"> {
headingTagName?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
}
let RelatedProducts = forwardRef<HTMLElement, RelatedProductsProps>(
(props, ref) => {
let { recommended } = useLoaderData<{
recommended: { nodes: ProductCardFragment[] };
}>();
let {
headingTagName,
content,
size,
mobileSize,
desktopSize,
color,
weight,
letterSpacing,
alignment,
minSize,
maxSize,
...rest
} = props;
if (recommended) {
return (
<Section ref={ref} {...rest}>
{content && (
<Heading
content={content}
as={headingTagName}
color={color}
size={size}
mobileSize={mobileSize}
desktopSize={desktopSize}
minSize={minSize}
maxSize={maxSize}
weight={weight}
letterSpacing={letterSpacing}
alignment={alignment}
/>
)}
<Suspense>
<Await
errorElement="There was a problem loading related products"
resolve={recommended}
>
{(products) => {
return (
<div className="swimlane hidden-scroll md:pb-8 md:scroll-px-8 lg:scroll-px-12">
{products.nodes.slice(0, 12).map((product) => (
<ProductCard
key={product.id}
product={product}
className="snap-start w-80"
/>
))}
</div>
);
}}
</Await>
</Suspense>
</Section>
);
}
return <section ref={ref} {...rest} />;
},
);
export default RelatedProducts;
export let schema: HydrogenComponentSchema = {
type: "related-products",
title: "Related products",
limit: 1,
enabledOn: {
pages: ["PRODUCT"],
},
inspector: [
{
group: "Layout",
inputs: layoutInputs.filter((i) => i.name !== "borderRadius"),
},
{
group: "Heading",
inputs: headingInputs.map((input) => {
if (input.name === "as") {
return {
...input,
name: "headingTagName",
};
}
return input;
}),
},
],
presets: {
gap: 32,
width: "full",
content: "You may also like",
},
};