@pradip1995/segment-cart-summary 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,36 @@
1
+ {
2
+ "name": "@pradip1995/segment-cart-summary",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "sideEffects": false,
9
+ "files": [
10
+ "src"
11
+ ],
12
+ "exports": {
13
+ ".": "./src/index.ts",
14
+ "./manifest": "./src/manifest.ts"
15
+ },
16
+ "peerDependencies": {
17
+ "@pradip1995/plugin-sdk": "^0.2.0",
18
+ "react": ">=19",
19
+ "react-dom": ">=19",
20
+ "next": ">=15"
21
+ },
22
+ "dependencies": {
23
+ "@pradip1995/segment-primitives": "0.2.0",
24
+ "@pradip1995/segment-tokens": "0.2.0"
25
+ },
26
+ "devDependencies": {
27
+ "@pradip1995/plugin-sdk": "^0.2.0",
28
+ "@types/react": "^19",
29
+ "react": "19.0.3",
30
+ "typescript": "^5.7.2"
31
+ },
32
+ "scripts": {
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "tsc --noEmit"
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from "./segment"
2
+ export { default as manifest } from "./manifest"
@@ -0,0 +1,10 @@
1
+ import type { SegmentManifest } from "@pradip1995/plugin-sdk"
2
+
3
+ const manifest: SegmentManifest = {
4
+ id: "cart-summary",
5
+ type: "segment",
6
+ version: "0.1.0",
7
+ compatibleFramework: ["^1.0.0"],
8
+ }
9
+
10
+ export default manifest
@@ -0,0 +1,62 @@
1
+ import LocalizedLink from "@pradip1995/segment-primitives/localized-link"
2
+ import CouponApply from "@pradip1995/segment-primitives/coupon-apply"
3
+ import { formatPrice } from "@pradip1995/segment-primitives/format-price"
4
+ import type { HttpTypes } from "@medusajs/types"
5
+
6
+ export default function CartSummary({
7
+ cart,
8
+ summaryTitle = "Order Summary",
9
+ }: {
10
+ cart?: HttpTypes.StoreCart | null
11
+ summaryTitle?: string
12
+ }) {
13
+ const currency = cart?.currency_code || "inr"
14
+ const items = cart?.items || []
15
+
16
+ return (
17
+ <aside className="card-surface rounded-lg p-6 h-fit sticky top-24 lg:col-span-1">
18
+ <h2 className="section-heading text-lg mb-4">{summaryTitle}</h2>
19
+
20
+ {items.length > 0 && cart ? <CouponApply cart={cart} className="mb-6" /> : null}
21
+
22
+ {items.length > 0 ? (
23
+ <dl className="space-y-2 text-sm mb-6">
24
+ <div className="flex justify-between">
25
+ <dt className="text-muted">Subtotal</dt>
26
+ <dd className="text-heading">{formatPrice(cart?.subtotal, currency)}</dd>
27
+ </div>
28
+ {(cart?.discount_total ?? 0) > 0 && (
29
+ <div className="flex justify-between text-green-700">
30
+ <dt>Discount</dt>
31
+ <dd>-{formatPrice(cart?.discount_total, currency)}</dd>
32
+ </div>
33
+ )}
34
+ {cart?.shipping_total != null && cart.shipping_total > 0 && (
35
+ <div className="flex justify-between">
36
+ <dt className="text-muted">Shipping</dt>
37
+ <dd className="text-heading">{formatPrice(cart.shipping_total, currency)}</dd>
38
+ </div>
39
+ )}
40
+ {cart?.tax_total != null && cart.tax_total > 0 && (
41
+ <div className="flex justify-between">
42
+ <dt className="text-muted">Tax</dt>
43
+ <dd className="text-heading">{formatPrice(cart.tax_total, currency)}</dd>
44
+ </div>
45
+ )}
46
+ <div className="flex justify-between pt-3 border-t border-cart-border font-semibold">
47
+ <dt className="text-heading">Total</dt>
48
+ <dd className="text-brand-accent">{formatPrice(cart?.total, currency)}</dd>
49
+ </div>
50
+ </dl>
51
+ ) : (
52
+ <p className="text-muted text-sm mb-6">No items in cart</p>
53
+ )}
54
+
55
+ {items.length > 0 && (
56
+ <LocalizedLink href="/checkout" className="btn-primary block text-center w-full">
57
+ Proceed to checkout
58
+ </LocalizedLink>
59
+ )}
60
+ </aside>
61
+ )
62
+ }