@pradip1995/segment-product-card 0.2.0 → 0.3.0
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 +5 -4
- package/src/product-rail-variants.tsx +101 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-product-card",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./src/index.ts",
|
|
14
14
|
"./manifest": "./src/manifest.ts",
|
|
15
|
-
"./product-scroll": "./src/product-scroll.tsx"
|
|
15
|
+
"./product-scroll": "./src/product-scroll.tsx",
|
|
16
|
+
"./product-rail-variants": "./src/product-rail-variants.tsx"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
19
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
@@ -22,8 +23,8 @@
|
|
|
22
23
|
"next": ">=15"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@pradip1995/segment-primitives": "0.
|
|
26
|
-
"@pradip1995/segment-tokens": "0.
|
|
26
|
+
"@pradip1995/segment-primitives": "0.3.0",
|
|
27
|
+
"@pradip1995/segment-tokens": "0.3.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import ProductCard from "./segment"
|
|
2
|
+
import ProductScroll from "./product-scroll"
|
|
3
|
+
import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
|
|
4
|
+
import type { ProductRailVariant } from "@pradip1995/segment-primitives/section-variants"
|
|
5
|
+
import type { HttpTypes } from "@medusajs/types"
|
|
6
|
+
|
|
7
|
+
function ProductRailHeader({
|
|
8
|
+
title,
|
|
9
|
+
viewAllLink,
|
|
10
|
+
href = "/store",
|
|
11
|
+
}: {
|
|
12
|
+
title: string
|
|
13
|
+
viewAllLink: string
|
|
14
|
+
href?: string
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<div className="home-section-header">
|
|
18
|
+
<h2 className="home-section-header__title">{title}</h2>
|
|
19
|
+
<LocalizedLink href={href} className="home-section-header__link">
|
|
20
|
+
{viewAllLink}
|
|
21
|
+
</LocalizedLink>
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ProductRailGrid({
|
|
27
|
+
products,
|
|
28
|
+
region,
|
|
29
|
+
countryCode,
|
|
30
|
+
}: {
|
|
31
|
+
products: HttpTypes.StoreProduct[]
|
|
32
|
+
region?: HttpTypes.StoreRegion
|
|
33
|
+
countryCode?: string
|
|
34
|
+
}) {
|
|
35
|
+
return (
|
|
36
|
+
<div className="product-rail__grid grid grid-cols-2 md:grid-cols-4 gap-4 md:gap-6">
|
|
37
|
+
{products.map((p) => (
|
|
38
|
+
<ProductCard key={p.id} product={p} region={region} countryCode={countryCode} />
|
|
39
|
+
))}
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ProductRailFeatured({
|
|
45
|
+
products,
|
|
46
|
+
region,
|
|
47
|
+
countryCode,
|
|
48
|
+
}: {
|
|
49
|
+
products: HttpTypes.StoreProduct[]
|
|
50
|
+
region?: HttpTypes.StoreRegion
|
|
51
|
+
countryCode?: string
|
|
52
|
+
}) {
|
|
53
|
+
const [featured, ...rest] = products
|
|
54
|
+
if (!featured) return null
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="product-rail__featured">
|
|
58
|
+
<div className="product-rail__featured-main">
|
|
59
|
+
<ProductCard product={featured} region={region} countryCode={countryCode} />
|
|
60
|
+
</div>
|
|
61
|
+
<div className="product-rail__featured-side">
|
|
62
|
+
{rest.slice(0, 3).map((p) => (
|
|
63
|
+
<ProductCard key={p.id} product={p} region={region} countryCode={countryCode} />
|
|
64
|
+
))}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function ProductRailByVariant({
|
|
71
|
+
variant,
|
|
72
|
+
products,
|
|
73
|
+
region,
|
|
74
|
+
ratings,
|
|
75
|
+
countryCode,
|
|
76
|
+
title,
|
|
77
|
+
viewAllLink,
|
|
78
|
+
href,
|
|
79
|
+
}: {
|
|
80
|
+
variant: ProductRailVariant
|
|
81
|
+
products: HttpTypes.StoreProduct[]
|
|
82
|
+
region?: HttpTypes.StoreRegion
|
|
83
|
+
ratings?: Array<{ product_id?: string; rating?: number }>
|
|
84
|
+
countryCode?: string
|
|
85
|
+
title: string
|
|
86
|
+
viewAllLink: string
|
|
87
|
+
href?: string
|
|
88
|
+
}) {
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<ProductRailHeader title={title} viewAllLink={viewAllLink} href={href} />
|
|
92
|
+
{variant === "carousel" ? (
|
|
93
|
+
<ProductScroll products={products} region={region} ratings={ratings} countryCode={countryCode} />
|
|
94
|
+
) : variant === "featured" ? (
|
|
95
|
+
<ProductRailFeatured products={products} region={region} countryCode={countryCode} />
|
|
96
|
+
) : (
|
|
97
|
+
<ProductRailGrid products={products} region={region} countryCode={countryCode} />
|
|
98
|
+
)}
|
|
99
|
+
</>
|
|
100
|
+
)
|
|
101
|
+
}
|