@pradip1995/segment-product-card 0.3.23 → 0.3.24
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 +8 -9
- package/src/product-card-actions.tsx +1 -1
- package/src/resolve-product-images.ts +9 -15
- package/src/segment.tsx +2 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pradip1995/segment-product-card",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,15 +17,19 @@
|
|
|
17
17
|
"./product-scroll": "./src/product-scroll.tsx",
|
|
18
18
|
"./product-rail-variants": "./src/product-rail-variants.tsx"
|
|
19
19
|
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"lint": "tsc --noEmit"
|
|
23
|
+
},
|
|
20
24
|
"peerDependencies": {
|
|
21
25
|
"@pradip1995/commerce-core": "^4.0.0",
|
|
22
26
|
"@pradip1995/plugin-sdk": "^0.2.0",
|
|
23
|
-
"@pradip1995/segment-animation-login-popup": "*",
|
|
24
27
|
"next": ">=15",
|
|
25
28
|
"react": ">=19",
|
|
26
29
|
"react-dom": ">=19"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
32
|
+
"@pradip1995/segment-login-popup": "^0.1.3",
|
|
29
33
|
"@pradip1995/segment-primitives": "^0.4.2",
|
|
30
34
|
"@pradip1995/segment-tokens": "^0.3.7"
|
|
31
35
|
},
|
|
@@ -36,11 +40,6 @@
|
|
|
36
40
|
"@types/react-dom": "^19",
|
|
37
41
|
"next": ">=15",
|
|
38
42
|
"react": "19.0.3",
|
|
39
|
-
"typescript": "^5.7.2"
|
|
40
|
-
"@pradip1995/segment-animation-login-popup": "0.1.1"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"typecheck": "tsc --noEmit",
|
|
44
|
-
"lint": "tsc --noEmit"
|
|
43
|
+
"typescript": "^5.7.2"
|
|
45
44
|
}
|
|
46
|
-
}
|
|
45
|
+
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "@pradip1995/commerce-core/client/actions/wishlist"
|
|
11
11
|
import type { HttpTypes } from "@medusajs/types"
|
|
12
12
|
import { isNextRedirect } from "@pradip1995/segment-primitives/is-next-redirect"
|
|
13
|
-
import LoginRequiredModal from "@pradip1995/segment-
|
|
13
|
+
import LoginRequiredModal from "@pradip1995/segment-login-popup/required"
|
|
14
14
|
import QuickAddPanel from "./quick-add-panel"
|
|
15
15
|
|
|
16
16
|
type Props = {
|
|
@@ -3,24 +3,18 @@ import { resolveMediaUrl } from "@pradip1995/segment-primitives/resolve-media-ur
|
|
|
3
3
|
|
|
4
4
|
export function resolveProductCardImages(product: HttpTypes.StoreProduct) {
|
|
5
5
|
const gallery =
|
|
6
|
-
|
|
7
|
-
?.map((image
|
|
8
|
-
.filter((url
|
|
6
|
+
product.images
|
|
7
|
+
?.map((image) => resolveMediaUrl(image.url))
|
|
8
|
+
.filter((url): url is string => !!url) ?? []
|
|
9
9
|
|
|
10
|
-
const variantImages = (
|
|
11
|
-
.map((variant
|
|
12
|
-
|
|
13
|
-
return resolveMediaUrl(raw) || raw?.trim()
|
|
14
|
-
})
|
|
15
|
-
.filter((url: string | undefined): url is string => Boolean(url))
|
|
10
|
+
const variantImages = (product.variants ?? [])
|
|
11
|
+
.map((variant) => resolveMediaUrl((variant as { thumbnail?: string | null }).thumbnail))
|
|
12
|
+
.filter((url): url is string => !!url)
|
|
16
13
|
|
|
17
|
-
const
|
|
18
|
-
const thumbnail = resolveMediaUrl(
|
|
19
|
-
|
|
20
|
-
const images = Array.from(new Set([thumbnail, ...gallery, ...variantImages].filter((url: string): url is string => Boolean(url))))
|
|
21
|
-
|
|
14
|
+
const images = [...gallery, ...variantImages]
|
|
15
|
+
const thumbnail = resolveMediaUrl(product.thumbnail) || ""
|
|
22
16
|
const primary = thumbnail || images[0] || ""
|
|
23
|
-
const hover = images.find((url
|
|
17
|
+
const hover = [...new Set(images)].find((url) => url && url !== primary) || ""
|
|
24
18
|
|
|
25
19
|
return { primary, hover }
|
|
26
20
|
}
|
package/src/segment.tsx
CHANGED
|
@@ -5,10 +5,8 @@ import type { HttpTypes } from "@medusajs/types"
|
|
|
5
5
|
import BeautyProductCard from "./beauty-product-card"
|
|
6
6
|
import DefaultProductCard from "./default-product-card"
|
|
7
7
|
import JewelryProductCard from "./jewelry-product-card"
|
|
8
|
-
import MotionProductCard from "./motion-product-card"
|
|
9
|
-
import ShopProductCard from "./shop-product-card"
|
|
10
8
|
|
|
11
|
-
export type ProductCardVariant = "default" | "beauty" | "jewelry"
|
|
9
|
+
export type ProductCardVariant = "default" | "beauty" | "jewelry"
|
|
12
10
|
|
|
13
11
|
type Props = {
|
|
14
12
|
product: HttpTypes.StoreProduct
|
|
@@ -21,21 +19,12 @@ type Props = {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
function resolveProductCardVariant(variant?: ProductCardVariant): ProductCardVariant {
|
|
24
|
-
if (
|
|
25
|
-
variant === "beauty" ||
|
|
26
|
-
variant === "default" ||
|
|
27
|
-
variant === "jewelry" ||
|
|
28
|
-
variant === "motion" ||
|
|
29
|
-
variant === "shop"
|
|
30
|
-
)
|
|
31
|
-
return variant
|
|
22
|
+
if (variant === "beauty" || variant === "default" || variant === "jewelry") return variant
|
|
32
23
|
return "default"
|
|
33
24
|
}
|
|
34
25
|
|
|
35
26
|
export default function ProductCard({ variant, ...props }: Props) {
|
|
36
27
|
const layout = resolveProductCardVariant(variant)
|
|
37
|
-
if (layout === "shop") return <ShopProductCard {...props} />
|
|
38
|
-
if (layout === "motion") return <MotionProductCard {...props} />
|
|
39
28
|
if (layout === "beauty") return <BeautyProductCard {...props} />
|
|
40
29
|
if (layout === "jewelry") return <JewelryProductCard {...props} />
|
|
41
30
|
return <DefaultProductCard {...props} />
|