generated from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
related-products.tsx
80 lines (75 loc) · 1.97 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
import { Await, useLoaderData } from "@remix-run/react";
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from "@weaverse/hydrogen";
import { Suspense, forwardRef } from "react";
import type { ProductCardFragment } from "storefrontapi.generated";
import { ProductSwimlane, Skeleton } from "~/modules";
interface RelatedProductsProps extends HydrogenComponentProps {
heading: string;
productsCount: number;
}
let RelatedProducts = forwardRef<HTMLElement, RelatedProductsProps>(
(props, ref) => {
let { recommended } = useLoaderData<{
recommended: { nodes: ProductCardFragment[] };
}>();
let { heading, productsCount, ...rest } = props;
if (recommended) {
return (
<section ref={ref} {...rest}>
<Suspense fallback={<Skeleton className="h-32" />}>
<Await
errorElement="There was a problem loading related products"
resolve={recommended}
>
{(products) => (
<ProductSwimlane
title={heading}
count={productsCount}
products={products}
/>
)}
</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: "Related products",
inputs: [
{
type: "text",
name: "heading",
label: "Heading",
defaultValue: "You may also like",
placeholder: "Related products",
},
{
type: "range",
name: "productsCount",
label: "Number of products",
defaultValue: 12,
configs: {
min: 1,
max: 12,
step: 1,
},
},
],
},
],
};