@gem-sdk/plugin-cart-drawer 1.11.1 → 1.14.0-dev.284
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/dist/cjs/components/CartDiscountCode.js +1 -96
- package/dist/cjs/components/CartDrawer.js +1 -142
- package/dist/cjs/components/CartFooter.js +1 -69
- package/dist/cjs/components/CartLineItem.js +1 -172
- package/dist/cjs/components/CartLineItemQuantity.js +1 -57
- package/dist/cjs/components/CartLineQuantityAdjustButton.js +1 -207
- package/dist/cjs/components/CartOrderNote.js +1 -72
- package/dist/cjs/components/DiscountCodeItem.js +1 -122
- package/dist/cjs/components/LoadingIcon.js +1 -30
- package/dist/cjs/components/icons/Trash.js +1 -28
- package/dist/cjs/index.js +1 -9
- package/dist/esm/components/CartDiscountCode.js +1 -92
- package/dist/esm/components/CartDrawer.js +1 -138
- package/dist/esm/components/CartFooter.js +1 -65
- package/dist/esm/components/CartLineItem.js +1 -168
- package/dist/esm/components/CartLineItemQuantity.js +1 -53
- package/dist/esm/components/CartLineQuantityAdjustButton.js +1 -203
- package/dist/esm/components/CartOrderNote.js +1 -68
- package/dist/esm/components/DiscountCodeItem.js +1 -118
- package/dist/esm/components/LoadingIcon.js +1 -26
- package/dist/esm/components/icons/Trash.js +1 -24
- package/dist/esm/index.js +1 -5
- package/package.json +4 -4
|
@@ -1,138 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCartData, useCartUI, cls, CartLineProvider } from '@gem-sdk/core';
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
import { Transition } from 'react-transition-group';
|
|
5
|
-
import CartDiscountCode from './CartDiscountCode.js';
|
|
6
|
-
import CartFooter from './CartFooter.js';
|
|
7
|
-
import CartLineItem from './CartLineItem.js';
|
|
8
|
-
import CartOrderNote from './CartOrderNote.js';
|
|
9
|
-
|
|
10
|
-
const duration = 300;
|
|
11
|
-
const defaultStyle = {
|
|
12
|
-
transition: `opacity ${duration}ms ease-in-out`,
|
|
13
|
-
opacity: 0
|
|
14
|
-
};
|
|
15
|
-
const transitionStyles = {
|
|
16
|
-
entering: {
|
|
17
|
-
opacity: 1
|
|
18
|
-
},
|
|
19
|
-
entered: {
|
|
20
|
-
opacity: 1
|
|
21
|
-
},
|
|
22
|
-
exiting: {
|
|
23
|
-
opacity: 0
|
|
24
|
-
},
|
|
25
|
-
exited: {
|
|
26
|
-
opacity: 0
|
|
27
|
-
},
|
|
28
|
-
unmounted: {
|
|
29
|
-
opacity: 0
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const CartDrawer = ({ className , style , setting })=>{
|
|
33
|
-
const { data , isLoading: loading , error } = useCartData();
|
|
34
|
-
const { closeCart , isCartOpen } = useCartUI();
|
|
35
|
-
const nodeRef = useRef(null);
|
|
36
|
-
return /*#__PURE__*/ jsx(Transition, {
|
|
37
|
-
in: isCartOpen,
|
|
38
|
-
timeout: duration,
|
|
39
|
-
nodeRef: nodeRef,
|
|
40
|
-
children: (state)=>/*#__PURE__*/ jsxs("div", {
|
|
41
|
-
ref: nodeRef,
|
|
42
|
-
className: cls('fixed inset-0 z-90', className, {
|
|
43
|
-
invisible: !isCartOpen,
|
|
44
|
-
visible: isCartOpen
|
|
45
|
-
}),
|
|
46
|
-
style: {
|
|
47
|
-
...style,
|
|
48
|
-
...defaultStyle,
|
|
49
|
-
...transitionStyles[state]
|
|
50
|
-
},
|
|
51
|
-
children: [
|
|
52
|
-
/*#__PURE__*/ jsx("div", {
|
|
53
|
-
"aria-hidden": true,
|
|
54
|
-
onClick: ()=>closeCart(),
|
|
55
|
-
className: "fixed inset-0 z-80 bg-slate-600/40"
|
|
56
|
-
}),
|
|
57
|
-
/*#__PURE__*/ jsx("div", {
|
|
58
|
-
className: "fixed inset-y-0 right-0 z-90 flex w-full max-w-[400px] flex-col bg-white text-g-text-1 shadow-2xl mobile:w-full",
|
|
59
|
-
children: loading ? /*#__PURE__*/ jsx("div", {
|
|
60
|
-
className: "w-full pt-10 text-center",
|
|
61
|
-
children: "Loading..."
|
|
62
|
-
}) : error ? /*#__PURE__*/ jsxs("div", {
|
|
63
|
-
className: "w-full pt-10 text-center text-g-error",
|
|
64
|
-
children: [
|
|
65
|
-
"Error: ",
|
|
66
|
-
error?.[0]?.message
|
|
67
|
-
]
|
|
68
|
-
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
69
|
-
children: [
|
|
70
|
-
/*#__PURE__*/ jsxs("div", {
|
|
71
|
-
className: "flex items-center justify-between border-b border-b-g-line-3 px-6 py-3",
|
|
72
|
-
children: [
|
|
73
|
-
/*#__PURE__*/ jsx("span", {
|
|
74
|
-
className: "font-g-heading text-xl font-semibold",
|
|
75
|
-
children: setting?.title
|
|
76
|
-
}),
|
|
77
|
-
/*#__PURE__*/ jsx("button", {
|
|
78
|
-
onClick: closeCart,
|
|
79
|
-
title: "Close cart drawer",
|
|
80
|
-
children: /*#__PURE__*/ jsx("svg", {
|
|
81
|
-
className: "w-5",
|
|
82
|
-
fill: "currentColor",
|
|
83
|
-
viewBox: "0 0 24 24",
|
|
84
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
85
|
-
children: /*#__PURE__*/ jsx("path", {
|
|
86
|
-
d: "m4.397 4.554.073-.084a.75.75 0 0 1 .976-.073l.084.073L12 10.939l6.47-6.47a.75.75 0 1 1 1.06 1.061L13.061 12l6.47 6.47a.75.75 0 0 1 .072.976l-.073.084a.75.75 0 0 1-.976.073l-.084-.073L12 13.061l-6.47 6.47a.75.75 0 0 1-1.06-1.061L10.939 12l-6.47-6.47a.75.75 0 0 1-.072-.976l.073-.084-.073.084Z"
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
]
|
|
91
|
-
}),
|
|
92
|
-
/*#__PURE__*/ jsx("div", {
|
|
93
|
-
className: "group h-full overflow-y-auto px-6 pb-4 scrollbar:!h-1.5 scrollbar:!w-1.5 scrollbar:bg-transparent scrollbar-track:!rounded scrollbar-track:!bg-slate-100 scrollbar-thumb:!rounded scrollbar-thumb:!bg-slate-300",
|
|
94
|
-
children: !data || !data.lineItems.length ? /*#__PURE__*/ jsx("div", {
|
|
95
|
-
className: "w-full pt-10 text-center",
|
|
96
|
-
children: setting?.emptyLabel
|
|
97
|
-
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
98
|
-
children: [
|
|
99
|
-
/*#__PURE__*/ jsx("div", {
|
|
100
|
-
className: "flex flex-col",
|
|
101
|
-
children: data.lineItems.map((line)=>{
|
|
102
|
-
if (!line) return null;
|
|
103
|
-
return /*#__PURE__*/ jsx(CartLineProvider, {
|
|
104
|
-
line: line,
|
|
105
|
-
children: /*#__PURE__*/ jsx(CartLineItem, {})
|
|
106
|
-
}, line.id);
|
|
107
|
-
})
|
|
108
|
-
}),
|
|
109
|
-
/*#__PURE__*/ jsx(CartOrderNote, {
|
|
110
|
-
placeholder: "Leave your order note here...",
|
|
111
|
-
triggerUpdate: "blur"
|
|
112
|
-
})
|
|
113
|
-
]
|
|
114
|
-
})
|
|
115
|
-
}),
|
|
116
|
-
/*#__PURE__*/ jsx(CartDiscountCode, {}),
|
|
117
|
-
!!data && !!data.lineItems.length && /*#__PURE__*/ jsx(CartFooter, {
|
|
118
|
-
openMode: setting?.openMode,
|
|
119
|
-
checkoutUrl: data.checkoutUrl,
|
|
120
|
-
price: data?.totalPrice,
|
|
121
|
-
currencyCode: data?.currency.code
|
|
122
|
-
})
|
|
123
|
-
]
|
|
124
|
-
})
|
|
125
|
-
})
|
|
126
|
-
]
|
|
127
|
-
})
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
CartDrawer.defaultProps = {
|
|
131
|
-
setting: {
|
|
132
|
-
title: 'Your Cart',
|
|
133
|
-
emptyLabel: 'Your cart is empty',
|
|
134
|
-
openMode: 'page'
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export { CartDrawer as default };
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{useCartData as l,useCartUI as i,cls as a,CartLineProvider as o}from"@gem-sdk/core";import{useRef as n}from"react";import{Transition as s}from"react-transition-group";import c from"./CartDiscountCode.js";import d from"./CartFooter.js";import m from"./CartLineItem.js";import p from"./CartOrderNote.js";let duration=300,defaultStyle={transition:"opacity 300ms ease-in-out",opacity:0},transitionStyles={entering:{opacity:1},entered:{opacity:1},exiting:{opacity:0},exited:{opacity:0},unmounted:{opacity:0}},CartDrawer=({className:u,style:f,setting:h})=>{let{data:b,isLoading:g,error:x}=l(),{closeCart:y,isCartOpen:w}=i(),v=n(null);return e(s,{in:w,timeout:300,nodeRef:v,children:l=>t("div",{ref:v,className:a("fixed inset-0 z-90",u,{invisible:!w,visible:w}),style:{...f,...defaultStyle,...transitionStyles[l]},children:[e("div",{"aria-hidden":!0,onClick:()=>y(),className:"fixed inset-0 z-80 bg-slate-600/40"}),e("div",{className:"fixed inset-y-0 right-0 z-90 flex w-full max-w-[400px] flex-col bg-white text-g-text-1 shadow-2xl mobile:w-full",children:g?e("div",{className:"w-full pt-10 text-center",children:"Loading..."}):x?t("div",{className:"w-full pt-10 text-center text-g-error",children:["Error: ",x?.[0]?.message]}):t(r,{children:[t("div",{className:"flex items-center justify-between border-b border-b-g-line-3 px-6 py-3",children:[e("span",{className:"font-g-heading text-xl font-semibold",children:h?.title}),e("button",{onClick:y,title:"Close cart drawer",children:e("svg",{className:"w-5",fill:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e("path",{d:"m4.397 4.554.073-.084a.75.75 0 0 1 .976-.073l.084.073L12 10.939l6.47-6.47a.75.75 0 1 1 1.06 1.061L13.061 12l6.47 6.47a.75.75 0 0 1 .072.976l-.073.084a.75.75 0 0 1-.976.073l-.084-.073L12 13.061l-6.47 6.47a.75.75 0 0 1-1.06-1.061L10.939 12l-6.47-6.47a.75.75 0 0 1-.072-.976l.073-.084-.073.084Z"})})})]}),e("div",{className:"group h-full overflow-y-auto px-6 pb-4 scrollbar:!h-1.5 scrollbar:!w-1.5 scrollbar:bg-transparent scrollbar-track:!rounded scrollbar-track:!bg-slate-100 scrollbar-thumb:!rounded scrollbar-thumb:!bg-slate-300",children:b&&b.lineItems.length?t(r,{children:[e("div",{className:"flex flex-col",children:b.lineItems.map(t=>t?e(o,{line:t,children:e(m,{})},t.id):null)}),e(p,{placeholder:"Leave your order note here...",triggerUpdate:"blur"})]}):e("div",{className:"w-full pt-10 text-center",children:h?.emptyLabel})}),e(c,{}),!!b&&!!b.lineItems.length&&e(d,{openMode:h?.openMode,checkoutUrl:b.checkoutUrl,price:b?.totalPrice,currencyCode:b?.currency.code})]})})]})})};CartDrawer.defaultProps={setting:{title:"Your Cart",emptyLabel:"Your cart is empty",openMode:"page"}};export{CartDrawer as default};
|
|
@@ -1,65 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useCheckoutUrl, useMoney, composeRadius } from '@gem-sdk/core';
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
const CartFooter = ({ checkoutUrl , price , openMode })=>{
|
|
6
|
-
const urlCheckout = useCheckoutUrl(checkoutUrl);
|
|
7
|
-
const checkoutPopup = useRef(null);
|
|
8
|
-
const money = useMoney(price ?? 0);
|
|
9
|
-
const openCheckout = (w, h)=>{
|
|
10
|
-
if (openMode === 'popup') {
|
|
11
|
-
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
|
|
12
|
-
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
|
|
13
|
-
const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
|
14
|
-
const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
|
15
|
-
const systemZoom = width / window.screen.availWidth;
|
|
16
|
-
const left = (width - w) / 2 / systemZoom + dualScreenLeft;
|
|
17
|
-
const top = (height - h) / 2 / systemZoom + dualScreenTop;
|
|
18
|
-
checkoutPopup.current = window.open(urlCheckout, 'checkout', `scrollbars=yes, width=${w / systemZoom}, height=${h / systemZoom}, top=${top}, left=${left}`);
|
|
19
|
-
checkoutPopup.current?.focus();
|
|
20
|
-
} else {
|
|
21
|
-
window.open(urlCheckout);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
25
|
-
className: "flex flex-col gap-4 border-t border-t-g-line-3 bg-g-bg-2 px-6 pb-8 pt-4",
|
|
26
|
-
children: [
|
|
27
|
-
/*#__PURE__*/ jsxs("div", {
|
|
28
|
-
className: "g-paragraph-1 flex justify-between font-semibold",
|
|
29
|
-
children: [
|
|
30
|
-
/*#__PURE__*/ jsx("span", {
|
|
31
|
-
children: "Subtotal:"
|
|
32
|
-
}),
|
|
33
|
-
/*#__PURE__*/ jsx("span", {
|
|
34
|
-
"aria-label": "Total price",
|
|
35
|
-
children: money.localizedString
|
|
36
|
-
})
|
|
37
|
-
]
|
|
38
|
-
}),
|
|
39
|
-
/*#__PURE__*/ jsxs("div", {
|
|
40
|
-
"aria-label": "Checkout",
|
|
41
|
-
role: "button",
|
|
42
|
-
"aria-hidden": "true",
|
|
43
|
-
className: "g-paragraph-1 flex justify-between bg-g-brand px-4 py-3 font-semibold text-g-text-3",
|
|
44
|
-
onClick: ()=>openCheckout(600, 600),
|
|
45
|
-
style: {
|
|
46
|
-
...composeRadius({
|
|
47
|
-
normal: {
|
|
48
|
-
radiusType: 'small'
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
},
|
|
52
|
-
children: [
|
|
53
|
-
/*#__PURE__*/ jsx("span", {
|
|
54
|
-
children: money.localizedString
|
|
55
|
-
}),
|
|
56
|
-
/*#__PURE__*/ jsx("span", {
|
|
57
|
-
children: "Checkout"
|
|
58
|
-
})
|
|
59
|
-
]
|
|
60
|
-
})
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export { CartFooter as default };
|
|
1
|
+
import{jsxs as e,jsx as n}from"react/jsx-runtime";import{useCheckoutUrl as t,useMoney as i,composeRadius as r}from"@gem-sdk/core";import{useRef as o}from"react";let CartFooter=({checkoutUrl:l,price:d,openMode:c})=>{let a=t(l),s=o(null),w=i(d??0),h=(e,n)=>{if("popup"===c){let t=void 0!==window.screenLeft?window.screenLeft:window.screenX,i=void 0!==window.screenTop?window.screenTop:window.screenY,r=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,o=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height,l=r/window.screen.availWidth,d=(r-e)/2/l+t,c=(o-n)/2/l+i;s.current=window.open(a,"checkout",`scrollbars=yes, width=${e/l}, height=${n/l}, top=${c}, left=${d}`),s.current?.focus()}else window.open(a)};return e("div",{className:"flex flex-col gap-4 border-t border-t-g-line-3 bg-g-bg-2 px-6 pb-8 pt-4",children:[e("div",{className:"g-paragraph-1 flex justify-between font-semibold",children:[n("span",{children:"Subtotal:"}),n("span",{"aria-label":"Total price",children:w.localizedString})]}),e("div",{"aria-label":"Checkout",role:"button","aria-hidden":"true",className:"g-paragraph-1 flex justify-between bg-g-brand px-4 py-3 font-semibold text-g-text-3",onClick:()=>h(600,600),style:{...r({normal:{radiusType:"small"}})},children:[n("span",{children:w.localizedString}),n("span",{children:"Checkout"})]})]})};export{CartFooter as default};
|
|
@@ -1,168 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useCartLine, useCartId, useRemoveCartItem, useMoney } from '@gem-sdk/core';
|
|
3
|
-
import { openConfirm } from '@gem-sdk/components';
|
|
4
|
-
import CartLineItemQuantity from './CartLineItemQuantity.js';
|
|
5
|
-
import Trash from './icons/Trash.js';
|
|
6
|
-
import LoadingIcon from './LoadingIcon.js';
|
|
7
|
-
|
|
8
|
-
const CartLineItem = ()=>{
|
|
9
|
-
const line = useCartLine();
|
|
10
|
-
const { cartId } = useCartId();
|
|
11
|
-
const { isMutating: loading , trigger: removeCartLine } = useRemoveCartItem();
|
|
12
|
-
const money = useMoney(line.variant?.price ? line.variant?.price : 0);
|
|
13
|
-
const compareAtPrice = useMoney(line.variant?.listPrice ? line.variant?.listPrice : 0);
|
|
14
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
15
|
-
className: "flex items-center gap-4 border-b border-b-g-line-2 py-4 last:border-b-transparent",
|
|
16
|
-
children: [
|
|
17
|
-
/*#__PURE__*/ jsx("div", {
|
|
18
|
-
className: "aspect-square w-16",
|
|
19
|
-
children: line.variant?.image?.url && /*#__PURE__*/ jsx("img", {
|
|
20
|
-
className: "h-full w-full object-cover",
|
|
21
|
-
src: line.variant.image.url,
|
|
22
|
-
alt: line.variant?.image?.altText ?? ''
|
|
23
|
-
})
|
|
24
|
-
}),
|
|
25
|
-
/*#__PURE__*/ jsxs("div", {
|
|
26
|
-
className: "flex-1",
|
|
27
|
-
children: [
|
|
28
|
-
/*#__PURE__*/ jsxs("p", {
|
|
29
|
-
className: "line-clamp-2",
|
|
30
|
-
children: [
|
|
31
|
-
line.productTitle,
|
|
32
|
-
" ",
|
|
33
|
-
line.variant.name !== 'Default Title' && ` - ${line.variant.name}`
|
|
34
|
-
]
|
|
35
|
-
}),
|
|
36
|
-
/*#__PURE__*/ jsxs("div", {
|
|
37
|
-
className: "flex flex-col gap-1 text-sm",
|
|
38
|
-
children: [
|
|
39
|
-
/*#__PURE__*/ jsxs("div", {
|
|
40
|
-
className: "flex gap-2",
|
|
41
|
-
children: [
|
|
42
|
-
/*#__PURE__*/ jsx("span", {
|
|
43
|
-
className: "font-semibold",
|
|
44
|
-
children: money.localizedString
|
|
45
|
-
}),
|
|
46
|
-
line.variant?.listPrice > 0 && /*#__PURE__*/ jsx("span", {
|
|
47
|
-
className: "text-[#B4B4B4] line-through",
|
|
48
|
-
children: compareAtPrice.localizedString
|
|
49
|
-
})
|
|
50
|
-
]
|
|
51
|
-
}),
|
|
52
|
-
line.attributes?.map((attribute)=>/*#__PURE__*/ jsxs("div", {
|
|
53
|
-
children: [
|
|
54
|
-
attribute.key,
|
|
55
|
-
": ",
|
|
56
|
-
attribute.value
|
|
57
|
-
]
|
|
58
|
-
}, attribute.key))
|
|
59
|
-
]
|
|
60
|
-
}),
|
|
61
|
-
/*#__PURE__*/ jsxs("div", {
|
|
62
|
-
className: "flex items-center justify-between",
|
|
63
|
-
children: [
|
|
64
|
-
/*#__PURE__*/ jsx(CartLineItemQuantity, {
|
|
65
|
-
size: "medium"
|
|
66
|
-
}),
|
|
67
|
-
/*#__PURE__*/ jsx("button", {
|
|
68
|
-
onClick: ()=>{
|
|
69
|
-
openConfirm({
|
|
70
|
-
title: /*#__PURE__*/ jsxs("div", {
|
|
71
|
-
className: "flex w-full flex-col items-center gap-4",
|
|
72
|
-
children: [
|
|
73
|
-
/*#__PURE__*/ jsx(Trash, {}),
|
|
74
|
-
/*#__PURE__*/ jsx("p", {
|
|
75
|
-
className: "font-g-body text-xl font-semibold",
|
|
76
|
-
children: "Are you sure ?"
|
|
77
|
-
})
|
|
78
|
-
]
|
|
79
|
-
}),
|
|
80
|
-
content: /*#__PURE__*/ jsxs("div", {
|
|
81
|
-
className: "text-center",
|
|
82
|
-
children: [
|
|
83
|
-
/*#__PURE__*/ jsx("p", {
|
|
84
|
-
children: "Do you really want to delete these items?"
|
|
85
|
-
}),
|
|
86
|
-
/*#__PURE__*/ jsx("p", {
|
|
87
|
-
children: "This process cannot be undone."
|
|
88
|
-
})
|
|
89
|
-
]
|
|
90
|
-
}),
|
|
91
|
-
className: 'w-full max-w-[572px] gap-4 rounded',
|
|
92
|
-
buttons: [
|
|
93
|
-
{
|
|
94
|
-
label: 'Cancel',
|
|
95
|
-
className: 'w-[130px]',
|
|
96
|
-
styles: {
|
|
97
|
-
backgroundColor: {
|
|
98
|
-
normal: 'bg-1'
|
|
99
|
-
},
|
|
100
|
-
roundedBtn: {
|
|
101
|
-
normal: {
|
|
102
|
-
radiusType: 'small'
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
btnSpacing: {
|
|
106
|
-
type: 'small'
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
label: 'Delete',
|
|
112
|
-
className: 'w-[130px]',
|
|
113
|
-
styles: {
|
|
114
|
-
textColor: {
|
|
115
|
-
normal: 'text-3'
|
|
116
|
-
},
|
|
117
|
-
backgroundColor: {
|
|
118
|
-
normal: 'error'
|
|
119
|
-
},
|
|
120
|
-
roundedBtn: {
|
|
121
|
-
normal: {
|
|
122
|
-
radiusType: 'small'
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
btnSpacing: {
|
|
126
|
-
type: 'small'
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
onClick: ()=>{
|
|
130
|
-
if (cartId && line.id) {
|
|
131
|
-
removeCartLine({
|
|
132
|
-
cartId,
|
|
133
|
-
lineId: line.id
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
]
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
"aria-label": "Remove item from cart",
|
|
142
|
-
title: "Remove item from cart",
|
|
143
|
-
type: "button",
|
|
144
|
-
children: loading ? /*#__PURE__*/ jsx(LoadingIcon, {
|
|
145
|
-
className: "text-g-brand"
|
|
146
|
-
}) : /*#__PURE__*/ jsx("svg", {
|
|
147
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
148
|
-
className: "w-4 text-gray-400",
|
|
149
|
-
fill: "none",
|
|
150
|
-
viewBox: "0 0 24 24",
|
|
151
|
-
stroke: "currentColor",
|
|
152
|
-
strokeWidth: 2,
|
|
153
|
-
children: /*#__PURE__*/ jsx("path", {
|
|
154
|
-
strokeLinecap: "round",
|
|
155
|
-
strokeLinejoin: "round",
|
|
156
|
-
d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
|
|
157
|
-
})
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
]
|
|
161
|
-
})
|
|
162
|
-
]
|
|
163
|
-
})
|
|
164
|
-
]
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export { CartLineItem as default };
|
|
1
|
+
import{jsxs as e,jsx as a}from"react/jsx-runtime";import{useCartLine as t,useCartId as l,useRemoveCartItem as r,useMoney as i}from"@gem-sdk/core";import{openConfirm as n}from"@gem-sdk/components";import s from"./CartLineItemQuantity.js";import o from"./icons/Trash.js";import m from"./LoadingIcon.js";let CartLineItem=()=>{let c=t(),{cartId:d}=l(),{isMutating:p,trigger:u}=r(),g=i(c.variant?.price?c.variant?.price:0),v=i(c.variant?.listPrice?c.variant?.listPrice:0);return e("div",{className:"flex items-center gap-4 border-b border-b-g-line-2 py-4 last:border-b-transparent",children:[a("div",{className:"aspect-square w-16",children:c.variant?.image?.url&&a("img",{className:"h-full w-full object-cover",src:c.variant.image.url,alt:c.variant?.image?.altText??""})}),e("div",{className:"flex-1",children:[e("p",{className:"line-clamp-2",children:[c.productTitle," ","Default Title"!==c.variant.name&&` - ${c.variant.name}`]}),e("div",{className:"flex flex-col gap-1 text-sm",children:[e("div",{className:"flex gap-2",children:[a("span",{className:"font-semibold",children:g.localizedString}),c.variant?.listPrice>0&&a("span",{className:"text-[#B4B4B4] line-through",children:v.localizedString})]}),c.attributes?.map(a=>e("div",{children:[a.key,": ",a.value]},a.key))]}),e("div",{className:"flex items-center justify-between",children:[a(s,{size:"medium"}),a("button",{onClick:()=>{n({title:e("div",{className:"flex w-full flex-col items-center gap-4",children:[a(o,{}),a("p",{className:"font-g-body text-xl font-semibold",children:"Are you sure ?"})]}),content:e("div",{className:"text-center",children:[a("p",{children:"Do you really want to delete these items?"}),a("p",{children:"This process cannot be undone."})]}),className:"w-full max-w-[572px] gap-4 rounded",buttons:[{label:"Cancel",className:"w-[130px]",styles:{backgroundColor:{normal:"bg-1"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}}},{label:"Delete",className:"w-[130px]",styles:{textColor:{normal:"text-3"},backgroundColor:{normal:"error"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}},onClick:()=>{d&&c.id&&u({cartId:d,lineId:c.id})}}]})},"aria-label":"Remove item from cart",title:"Remove item from cart",type:"button",children:p?a(m,{className:"text-g-brand"}):a("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:a("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})]})]})};export{CartLineItem as default};
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useCartLine, cls } from '@gem-sdk/core';
|
|
3
|
-
import CartLineQuantityAdjustButton from './CartLineQuantityAdjustButton.js';
|
|
4
|
-
|
|
5
|
-
const CartLineItemQuantity = ({ size })=>{
|
|
6
|
-
const line = useCartLine();
|
|
7
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
8
|
-
className: cls('mt-2 inline-flex items-center overflow-auto rounded border border-g-line-3 text-g-text-1', {
|
|
9
|
-
'h-12': size === 'large',
|
|
10
|
-
'h-10': size === 'medium',
|
|
11
|
-
'h-8': size === 'small'
|
|
12
|
-
}),
|
|
13
|
-
children: [
|
|
14
|
-
/*#__PURE__*/ jsx(CartLineQuantityAdjustButton, {
|
|
15
|
-
adjust: "decrease",
|
|
16
|
-
"aria-label": "Decrease quantity",
|
|
17
|
-
className: "flex aspect-square h-full items-center justify-center",
|
|
18
|
-
children: /*#__PURE__*/ jsx("svg", {
|
|
19
|
-
className: "h-4",
|
|
20
|
-
fill: "currentColor",
|
|
21
|
-
viewBox: "0 0 24 24",
|
|
22
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
23
|
-
children: /*#__PURE__*/ jsx("path", {
|
|
24
|
-
d: "M3.755 12.5h16.492a.75.75 0 0 0 0-1.5H3.755a.75.75 0 0 0 0 1.5Z"
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
}),
|
|
28
|
-
/*#__PURE__*/ jsx("div", {
|
|
29
|
-
className: "flex h-full min-w-[50px] select-none items-center justify-center border-x border-g-line-3 px-2 text-center text-base font-semibold",
|
|
30
|
-
children: line.quantity
|
|
31
|
-
}),
|
|
32
|
-
/*#__PURE__*/ jsx(CartLineQuantityAdjustButton, {
|
|
33
|
-
adjust: "increase",
|
|
34
|
-
"aria-label": "Increase quantity",
|
|
35
|
-
className: "flex aspect-square h-full items-center justify-center",
|
|
36
|
-
children: /*#__PURE__*/ jsx("svg", {
|
|
37
|
-
className: "h-4",
|
|
38
|
-
fill: "currentColor",
|
|
39
|
-
viewBox: "0 0 24 24",
|
|
40
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
41
|
-
children: /*#__PURE__*/ jsx("path", {
|
|
42
|
-
d: "M11.75 3a.75.75 0 0 1 .743.648l.007.102.001 7.25h7.253a.75.75 0 0 1 .102 1.493l-.102.007h-7.253l.002 7.25a.75.75 0 0 1-1.493.101l-.007-.102-.002-7.249H3.752a.75.75 0 0 1-.102-1.493L3.752 11h7.25L11 3.75a.75.75 0 0 1 .75-.75Z"
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
]
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
CartLineItemQuantity.defaultProps = {
|
|
50
|
-
size: 'medium'
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export { CartLineItemQuantity as default };
|
|
1
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useCartLine as r,cls as a}from"@gem-sdk/core";import l from"./CartLineQuantityAdjustButton.js";let CartLineItemQuantity=({size:i})=>{let s=r();return e("div",{className:a("mt-2 inline-flex items-center overflow-auto rounded border border-g-line-3 text-g-text-1",{"h-12":"large"===i,"h-10":"medium"===i,"h-8":"small"===i}),children:[t(l,{adjust:"decrease","aria-label":"Decrease quantity",className:"flex aspect-square h-full items-center justify-center",children:t("svg",{className:"h-4",fill:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:t("path",{d:"M3.755 12.5h16.492a.75.75 0 0 0 0-1.5H3.755a.75.75 0 0 0 0 1.5Z"})})}),t("div",{className:"flex h-full min-w-[50px] select-none items-center justify-center border-x border-g-line-3 px-2 text-center text-base font-semibold",children:s.quantity}),t(l,{adjust:"increase","aria-label":"Increase quantity",className:"flex aspect-square h-full items-center justify-center",children:t("svg",{className:"h-4",fill:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:t("path",{d:"M11.75 3a.75.75 0 0 1 .743.648l.007.102.001 7.25h7.253a.75.75 0 0 1 .102 1.493l-.102.007h-7.253l.002 7.25a.75.75 0 0 1-1.493.101l-.007-.102-.002-7.249H3.752a.75.75 0 0 1-.102-1.493L3.752 11h7.25L11 3.75a.75.75 0 0 1 .75-.75Z"})})})]})};CartLineItemQuantity.defaultProps={size:"medium"};export{CartLineItemQuantity as default};
|
|
@@ -1,203 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useUpdateCartItem, useRemoveCartItem, useCartId, useCartLine } from '@gem-sdk/core';
|
|
3
|
-
import { openConfirm } from '@gem-sdk/components';
|
|
4
|
-
import Trash from './icons/Trash.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The `CartLineQuantityAdjustButton` component renders a button that adjusts the cart line's quantity when pressed.
|
|
8
|
-
* It must be a descendent of a `CartLineProvider` component.
|
|
9
|
-
*/ const CartLineQuantityAdjustButton = ({ children , adjust , className , style })=>{
|
|
10
|
-
const { isMutating: updateLoading , trigger: updateLines } = useUpdateCartItem();
|
|
11
|
-
const { isMutating: removeLoading , trigger: removeLines } = useRemoveCartItem();
|
|
12
|
-
const { cartId } = useCartId();
|
|
13
|
-
const cartLine = useCartLine();
|
|
14
|
-
const isLoading = updateLoading || removeLoading;
|
|
15
|
-
return /*#__PURE__*/ jsx("button", {
|
|
16
|
-
"aria-label": "Adjust quantity",
|
|
17
|
-
className,
|
|
18
|
-
style,
|
|
19
|
-
disabled: isLoading,
|
|
20
|
-
onClick: ()=>{
|
|
21
|
-
if (cartId && cartLine.id) {
|
|
22
|
-
if (adjust === 'remove') {
|
|
23
|
-
openConfirm({
|
|
24
|
-
title: /*#__PURE__*/ jsxs("div", {
|
|
25
|
-
className: "flex w-full flex-col items-center gap-4",
|
|
26
|
-
children: [
|
|
27
|
-
/*#__PURE__*/ jsx(Trash, {}),
|
|
28
|
-
/*#__PURE__*/ jsx("p", {
|
|
29
|
-
className: "font-g-body text-xl font-semibold",
|
|
30
|
-
children: "Are you sure ?"
|
|
31
|
-
})
|
|
32
|
-
]
|
|
33
|
-
}),
|
|
34
|
-
content: /*#__PURE__*/ jsxs("div", {
|
|
35
|
-
className: "text-center",
|
|
36
|
-
children: [
|
|
37
|
-
/*#__PURE__*/ jsx("p", {
|
|
38
|
-
children: "Do you really want to delete this item?"
|
|
39
|
-
}),
|
|
40
|
-
/*#__PURE__*/ jsx("p", {
|
|
41
|
-
children: "This process cannot be undone."
|
|
42
|
-
})
|
|
43
|
-
]
|
|
44
|
-
}),
|
|
45
|
-
className: 'w-full max-w-[572px] gap-4 rounded',
|
|
46
|
-
buttons: [
|
|
47
|
-
{
|
|
48
|
-
label: 'Cancel',
|
|
49
|
-
className: 'w-[130px]',
|
|
50
|
-
styles: {
|
|
51
|
-
backgroundColor: {
|
|
52
|
-
normal: 'bg-1'
|
|
53
|
-
},
|
|
54
|
-
roundedBtn: {
|
|
55
|
-
normal: {
|
|
56
|
-
radiusType: 'small'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
btnSpacing: {
|
|
60
|
-
type: 'small'
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
label: 'Delete',
|
|
66
|
-
className: 'w-[130px]',
|
|
67
|
-
styles: {
|
|
68
|
-
textColor: {
|
|
69
|
-
normal: 'text-3'
|
|
70
|
-
},
|
|
71
|
-
backgroundColor: {
|
|
72
|
-
normal: 'error'
|
|
73
|
-
},
|
|
74
|
-
roundedBtn: {
|
|
75
|
-
normal: {
|
|
76
|
-
radiusType: 'small'
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
btnSpacing: {
|
|
80
|
-
type: 'small'
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
onClick: ()=>{
|
|
84
|
-
if (cartLine.id) {
|
|
85
|
-
removeLines({
|
|
86
|
-
cartId,
|
|
87
|
-
lineId: cartLine.id
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const quantity = adjust === 'decrease' ? cartLine.quantity - 1 : cartLine.quantity + 1;
|
|
97
|
-
if (quantity <= 0) {
|
|
98
|
-
openConfirm({
|
|
99
|
-
title: /*#__PURE__*/ jsxs("div", {
|
|
100
|
-
className: "flex w-full flex-col items-center gap-4",
|
|
101
|
-
children: [
|
|
102
|
-
/*#__PURE__*/ jsx(Trash, {}),
|
|
103
|
-
/*#__PURE__*/ jsx("p", {
|
|
104
|
-
className: "font-g-body text-xl font-semibold",
|
|
105
|
-
children: "Are you sure ?"
|
|
106
|
-
})
|
|
107
|
-
]
|
|
108
|
-
}),
|
|
109
|
-
content: /*#__PURE__*/ jsxs("div", {
|
|
110
|
-
className: "text-center",
|
|
111
|
-
children: [
|
|
112
|
-
/*#__PURE__*/ jsx("p", {
|
|
113
|
-
children: "Do you really want to delete this item?"
|
|
114
|
-
}),
|
|
115
|
-
/*#__PURE__*/ jsx("p", {
|
|
116
|
-
children: "This process cannot be undone."
|
|
117
|
-
})
|
|
118
|
-
]
|
|
119
|
-
}),
|
|
120
|
-
className: 'w-full max-w-[572px] gap-4 rounded',
|
|
121
|
-
buttons: [
|
|
122
|
-
{
|
|
123
|
-
label: 'Cancel',
|
|
124
|
-
className: 'w-[130px]',
|
|
125
|
-
styles: {
|
|
126
|
-
backgroundColor: {
|
|
127
|
-
normal: 'bg-1'
|
|
128
|
-
},
|
|
129
|
-
roundedBtn: {
|
|
130
|
-
normal: {
|
|
131
|
-
radiusType: 'small'
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
btnSpacing: {
|
|
135
|
-
type: 'small'
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
label: 'Delete',
|
|
141
|
-
className: 'w-[130px]',
|
|
142
|
-
styles: {
|
|
143
|
-
textColor: {
|
|
144
|
-
normal: 'text-3'
|
|
145
|
-
},
|
|
146
|
-
backgroundColor: {
|
|
147
|
-
normal: 'error'
|
|
148
|
-
},
|
|
149
|
-
roundedBtn: {
|
|
150
|
-
normal: {
|
|
151
|
-
radiusType: 'small'
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
btnSpacing: {
|
|
155
|
-
type: 'small'
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
onClick: ()=>{
|
|
159
|
-
if (cartLine.id) {
|
|
160
|
-
removeLines({
|
|
161
|
-
cartId,
|
|
162
|
-
lineId: cartLine.id
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
});
|
|
169
|
-
return;
|
|
170
|
-
} else {
|
|
171
|
-
updateLines({
|
|
172
|
-
cartId,
|
|
173
|
-
line: {
|
|
174
|
-
id: cartLine.id,
|
|
175
|
-
variantId: cartLine.variant.id,
|
|
176
|
-
quantity,
|
|
177
|
-
productId: cartLine.productId
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
children: isLoading ? /*#__PURE__*/ jsxs("div", {
|
|
184
|
-
className: "flex gap-1",
|
|
185
|
-
children: [
|
|
186
|
-
/*#__PURE__*/ jsx("span", {
|
|
187
|
-
className: "aspect-square h-1 animate-[flashing_500ms_infinite_alternate] rounded-full bg-g-brand"
|
|
188
|
-
}),
|
|
189
|
-
/*#__PURE__*/ jsx("span", {
|
|
190
|
-
className: "aspect-square h-1 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-g-brand"
|
|
191
|
-
}),
|
|
192
|
-
/*#__PURE__*/ jsx("span", {
|
|
193
|
-
className: "aspect-square h-1 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-g-brand"
|
|
194
|
-
})
|
|
195
|
-
]
|
|
196
|
-
}) : children
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
CartLineQuantityAdjustButton.defaultProps = {
|
|
200
|
-
adjust: 'increase'
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export { CartLineQuantityAdjustButton as default };
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useUpdateCartItem as a,useRemoveCartItem as l,useCartId as n,useCartLine as r}from"@gem-sdk/core";import{openConfirm as s}from"@gem-sdk/components";import i from"./icons/Trash.js";let CartLineQuantityAdjustButton=({children:o,adjust:d,className:c,style:m})=>{let{isMutating:u,trigger:p}=a(),{isMutating:g,trigger:b}=l(),{cartId:f}=n(),y=r(),x=u||g;return e("button",{"aria-label":"Adjust quantity",className:c,style:m,disabled:x,onClick:()=>{if(f&&y.id){if("remove"===d){s({title:t("div",{className:"flex w-full flex-col items-center gap-4",children:[e(i,{}),e("p",{className:"font-g-body text-xl font-semibold",children:"Are you sure ?"})]}),content:t("div",{className:"text-center",children:[e("p",{children:"Do you really want to delete this item?"}),e("p",{children:"This process cannot be undone."})]}),className:"w-full max-w-[572px] gap-4 rounded",buttons:[{label:"Cancel",className:"w-[130px]",styles:{backgroundColor:{normal:"bg-1"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}}},{label:"Delete",className:"w-[130px]",styles:{textColor:{normal:"text-3"},backgroundColor:{normal:"error"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}},onClick:()=>{y.id&&b({cartId:f,lineId:y.id})}}]});return}let a="decrease"===d?y.quantity-1:y.quantity+1;if(a<=0){s({title:t("div",{className:"flex w-full flex-col items-center gap-4",children:[e(i,{}),e("p",{className:"font-g-body text-xl font-semibold",children:"Are you sure ?"})]}),content:t("div",{className:"text-center",children:[e("p",{children:"Do you really want to delete this item?"}),e("p",{children:"This process cannot be undone."})]}),className:"w-full max-w-[572px] gap-4 rounded",buttons:[{label:"Cancel",className:"w-[130px]",styles:{backgroundColor:{normal:"bg-1"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}}},{label:"Delete",className:"w-[130px]",styles:{textColor:{normal:"text-3"},backgroundColor:{normal:"error"},roundedBtn:{normal:{radiusType:"small"}},btnSpacing:{type:"small"}},onClick:()=>{y.id&&b({cartId:f,lineId:y.id})}}]});return}p({cartId:f,line:{id:y.id,variantId:y.variant.id,quantity:a,productId:y.productId}})}},children:x?t("div",{className:"flex gap-1",children:[e("span",{className:"aspect-square h-1 animate-[flashing_500ms_infinite_alternate] rounded-full bg-g-brand"}),e("span",{className:"aspect-square h-1 animate-[flashing_500ms_infinite_200ms_linear_alternate] rounded-full bg-g-brand"}),e("span",{className:"aspect-square h-1 animate-[flashing_500ms_infinite_500ms_alternate] rounded-full bg-g-brand"})]}):o})};CartLineQuantityAdjustButton.defaultProps={adjust:"increase"};export{CartLineQuantityAdjustButton as default};
|