@pradip1995/segment-you-may-also-like 0.2.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 ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@pradip1995/segment-you-may-also-like",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "sideEffects": [
9
+ "src/segment.css"
10
+ ],
11
+ "files": [
12
+ "src"
13
+ ],
14
+ "exports": {
15
+ ".": "./src/index.ts",
16
+ "./manifest": "./src/manifest.ts"
17
+ },
18
+ "peerDependencies": {
19
+ "@medusajs/types": "^2.0.0",
20
+ "@pradip1995/plugin-sdk": "^0.2.0",
21
+ "react": ">=19",
22
+ "react-dom": ">=19",
23
+ "next": ">=15"
24
+ },
25
+ "dependencies": {
26
+ "@pradip1995/segment-primitives": "0.3.0",
27
+ "@pradip1995/segment-tokens": "0.3.2",
28
+ "@pradip1995/segment-product-card": "0.3.2"
29
+ },
30
+ "devDependencies": {
31
+ "@medusajs/types": "^2.0.0",
32
+ "@pradip1995/plugin-sdk": "^0.2.0",
33
+ "@types/react": "^19",
34
+ "react": "19.0.3",
35
+ "typescript": "^5.7.2"
36
+ },
37
+ "scripts": {
38
+ "typecheck": "tsc --noEmit",
39
+ "lint": "tsc --noEmit"
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from "./segment"
2
+ export { default as manifest } from "./manifest"
@@ -0,0 +1,11 @@
1
+ import type { SegmentManifest } from "@pradip1995/plugin-sdk"
2
+
3
+ const manifest: SegmentManifest = {
4
+ id: "you-may-also-like",
5
+ type: "segment",
6
+ version: "0.1.0",
7
+ compatibleFramework: ["^1.0.0"],
8
+ dataKey: "cartPage",
9
+ }
10
+
11
+ export default manifest
@@ -0,0 +1,66 @@
1
+ .you-may-also-like {
2
+ margin-top: 3rem;
3
+ padding-top: 2rem;
4
+ border-top: 1px solid var(--color-border);
5
+ }
6
+
7
+ .you-may-also-like__header {
8
+ display: flex;
9
+ align-items: center;
10
+ justify-content: space-between;
11
+ margin-bottom: 1.5rem;
12
+ }
13
+
14
+ .you-may-also-like__title {
15
+ font-size: 1.25rem;
16
+ font-weight: 700;
17
+ color: var(--color-text-heading);
18
+ }
19
+
20
+ .you-may-also-like__nav {
21
+ display: flex;
22
+ gap: 0.5rem;
23
+ }
24
+
25
+ .you-may-also-like__nav-btn {
26
+ width: 2.5rem;
27
+ height: 2.5rem;
28
+ border-radius: 9999px;
29
+ border: 1px solid var(--color-border);
30
+ background: var(--color-surface);
31
+ display: inline-flex;
32
+ align-items: center;
33
+ justify-content: center;
34
+ }
35
+
36
+ .you-may-also-like__nav-btn:disabled {
37
+ opacity: 0.5;
38
+ cursor: not-allowed;
39
+ }
40
+
41
+ .you-may-also-like__nav-btn--next {
42
+ background: var(--color-brand-accent);
43
+ color: var(--color-text-inverse);
44
+ border-color: var(--color-brand-accent);
45
+ }
46
+
47
+ .you-may-also-like__grid {
48
+ display: grid;
49
+ grid-template-columns: repeat(2, minmax(0, 1fr));
50
+ gap: 1rem;
51
+ list-style: none;
52
+ padding: 0;
53
+ margin: 0;
54
+ }
55
+
56
+ @media (min-width: 768px) {
57
+ .you-may-also-like__grid {
58
+ grid-template-columns: repeat(3, minmax(0, 1fr));
59
+ }
60
+ }
61
+
62
+ @media (min-width: 1024px) {
63
+ .you-may-also-like__grid {
64
+ grid-template-columns: repeat(4, minmax(0, 1fr));
65
+ }
66
+ }
@@ -0,0 +1,70 @@
1
+ "use client"
2
+
3
+ import "./segment.css"
4
+ import { useMemo, useState } from "react"
5
+ import ProductCard from "@pradip1995/segment-product-card"
6
+ import type { HttpTypes } from "@medusajs/types"
7
+
8
+ const PAGE_SIZE = 4
9
+
10
+ export default function YouMayAlsoLike({
11
+ products = [],
12
+ region,
13
+ title = "You may also like",
14
+ }: {
15
+ products?: HttpTypes.StoreProduct[]
16
+ region?: HttpTypes.StoreRegion
17
+ title?: string
18
+ }) {
19
+ const [currentIndex, setCurrentIndex] = useState(0)
20
+ const list = useMemo(() => products.filter(Boolean), [products])
21
+ const maxIndex = Math.max(0, list.length - PAGE_SIZE)
22
+ const currentProducts = list.slice(currentIndex, currentIndex + PAGE_SIZE)
23
+
24
+ if (list.length === 0) return null
25
+
26
+ const canGoPrevious = currentIndex > 0
27
+ const canGoNext = currentIndex < maxIndex
28
+
29
+ return (
30
+ <section className="you-may-also-like" aria-label={title}>
31
+ <div className="you-may-also-like__header">
32
+ <h2 className="you-may-also-like__title">{title}</h2>
33
+ {list.length > PAGE_SIZE ? (
34
+ <div className="you-may-also-like__nav">
35
+ <button
36
+ type="button"
37
+ onClick={() => setCurrentIndex((prev) => Math.max(0, prev - PAGE_SIZE))}
38
+ disabled={!canGoPrevious}
39
+ className="you-may-also-like__nav-btn"
40
+ aria-label="Previous products"
41
+ >
42
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
43
+ <polyline points="15 18 9 12 15 6" />
44
+ </svg>
45
+ </button>
46
+ <button
47
+ type="button"
48
+ onClick={() => setCurrentIndex((prev) => Math.min(maxIndex, prev + PAGE_SIZE))}
49
+ disabled={!canGoNext}
50
+ className="you-may-also-like__nav-btn you-may-also-like__nav-btn--next"
51
+ aria-label="Next products"
52
+ >
53
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
54
+ <polyline points="9 18 15 12 9 6" />
55
+ </svg>
56
+ </button>
57
+ </div>
58
+ ) : null}
59
+ </div>
60
+
61
+ <ul className="you-may-also-like__grid">
62
+ {currentProducts.map((product) => (
63
+ <li key={product.id} className="you-may-also-like__item">
64
+ <ProductCard product={product} region={region} />
65
+ </li>
66
+ ))}
67
+ </ul>
68
+ </section>
69
+ )
70
+ }