@gem-sdk/plugin-cart-drawer 1.63.16 → 2.0.0-dev.1086

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.
@@ -1,65 +1 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
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
- !!urlCheckout && window.open(urlCheckout);
22
- }
23
- };
24
- return /*#__PURE__*/ jsxs("div", {
25
- className: "gp-flex gp-flex-col gp-gap-4 gp-border-t gp-border-t-g-line-3 gp-bg-g-bg-2 gp-px-6 gp-pb-8 gp-pt-4",
26
- children: [
27
- /*#__PURE__*/ jsxs("div", {
28
- className: "gp-g-paragraph-1 gp-flex gp-justify-between gp-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: "gp-g-paragraph-1 gp-flex gp-justify-between gp-bg-g-brand gp-px-4 gp-py-3 gp-font-semibold gp-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:p})=>{let c=t(l),a=o(null),g=i(d??0),s=(e,n)=>{if("popup"===p){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,p=(o-n)/2/l+i;a.current=window.open(c,"checkout",`scrollbars=yes, width=${e/l}, height=${n/l}, top=${p}, left=${d}`),a.current?.focus()}else c&&window.open(c)};return e("div",{className:"gp-flex gp-flex-col gp-gap-4 gp-border-t gp-border-t-g-line-3 gp-bg-g-bg-2 gp-px-6 gp-pb-8 gp-pt-4",children:[e("div",{className:"gp-g-paragraph-1 gp-flex gp-justify-between gp-font-semibold",children:[n("span",{children:"Subtotal:"}),n("span",{"aria-label":"Total price",children:g.localizedString})]}),e("div",{"aria-label":"Checkout",role:"button","aria-hidden":"true",className:"gp-g-paragraph-1 gp-flex gp-justify-between gp-bg-g-brand gp-px-4 gp-py-3 gp-font-semibold gp-text-g-text-3",onClick:()=>s(600,600),style:{...r({normal:{radiusType:"small"}})},children:[n("span",{children:g.localizedString}),n("span",{children:"Checkout"})]})]})};export{CartFooter as default};
@@ -1,139 +1 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
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: "gp-flex gp-items-center gp-gap-4 gp-border-b gp-border-b-g-line-2 gp-py-4 last:gp-border-b-transparent",
16
- children: [
17
- /*#__PURE__*/ jsx("div", {
18
- className: "gp-aspect-square gp-w-16",
19
- children: line.variant?.image?.url && /*#__PURE__*/ jsx("img", {
20
- className: "gp-h-full gp-w-full gp-object-cover",
21
- src: line.variant.image.url,
22
- alt: line.variant?.image?.altText ?? ''
23
- })
24
- }),
25
- /*#__PURE__*/ jsxs("div", {
26
- className: "gp-flex-1",
27
- children: [
28
- /*#__PURE__*/ jsxs("p", {
29
- className: "gp-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: "gp-flex gp-flex-col gp-gap-1 gp-text-sm",
38
- children: [
39
- /*#__PURE__*/ jsxs("div", {
40
- className: "gp-flex gp-gap-2",
41
- children: [
42
- /*#__PURE__*/ jsx("span", {
43
- className: "gp-font-semibold",
44
- children: money.localizedString
45
- }),
46
- line.variant?.listPrice > 0 && /*#__PURE__*/ jsx("span", {
47
- className: "gp-text-[#B4B4B4] gp-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: "gp-flex gp-items-center gp-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: "gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",
72
- children: [
73
- /*#__PURE__*/ jsx(Trash, {}),
74
- /*#__PURE__*/ jsx("p", {
75
- className: "gp-font-g-body gp-text-xl gp-font-semibold",
76
- children: "Are you sure ?"
77
- })
78
- ]
79
- }),
80
- content: /*#__PURE__*/ jsxs("div", {
81
- className: "gp-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: 'gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded',
92
- buttons: [
93
- {
94
- label: 'Cancel',
95
- className: 'gp-w-[130px] !gp-bg-g-bg-1'
96
- },
97
- {
98
- label: 'Delete',
99
- className: '!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]',
100
- onClick: ()=>{
101
- if (cartId && line.id) {
102
- removeCartLine({
103
- cartId,
104
- lineId: line.id
105
- });
106
- }
107
- }
108
- }
109
- ]
110
- });
111
- },
112
- "aria-label": "Remove item from cart",
113
- title: "Remove item from cart",
114
- type: "button",
115
- children: loading ? /*#__PURE__*/ jsx(LoadingIcon, {
116
- className: "gp-text-g-brand"
117
- }) : /*#__PURE__*/ jsx("svg", {
118
- xmlns: "http://www.w3.org/2000/svg",
119
- className: "gp-w-4 gp-text-gray-400",
120
- fill: "none",
121
- viewBox: "0 0 24 24",
122
- stroke: "currentColor",
123
- strokeWidth: 2,
124
- children: /*#__PURE__*/ jsx("path", {
125
- strokeLinecap: "round",
126
- strokeLinejoin: "round",
127
- 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"
128
- })
129
- })
130
- })
131
- ]
132
- })
133
- ]
134
- })
135
- ]
136
- });
137
- };
138
-
139
- export { CartLineItem as default };
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useCartLine as a,useCartId as r,useRemoveCartItem as i,useMoney as l}from"@gem-sdk/core";import{openConfirm as n}from"@gem-sdk/components";import p from"./CartLineItemQuantity.js";import s from"./icons/Trash.js";import g from"./LoadingIcon.js";let CartLineItem=()=>{let c=a(),{cartId:o}=r(),{isMutating:m,trigger:d}=i(),u=l(c.variant?.price?c.variant?.price:0),v=l(c.variant?.listPrice?c.variant?.listPrice:0);return e("div",{className:"gp-flex gp-items-center gp-gap-4 gp-border-b gp-border-b-g-line-2 gp-py-4 last:gp-border-b-transparent",children:[t("div",{className:"gp-aspect-square gp-w-16",children:c.variant?.image?.url&&t("img",{className:"gp-h-full gp-w-full gp-object-cover",src:c.variant.image.url,alt:c.variant?.image?.altText??""})}),e("div",{className:"gp-flex-1",children:[e("p",{className:"gp-line-clamp-2",children:[c.productTitle," ","Default Title"!==c.variant.name&&` - ${c.variant.name}`]}),e("div",{className:"gp-flex gp-flex-col gp-gap-1 gp-text-sm",children:[e("div",{className:"gp-flex gp-gap-2",children:[t("span",{className:"gp-font-semibold",children:u.localizedString}),c.variant?.listPrice>0&&t("span",{className:"gp-text-[#B4B4B4] gp-line-through",children:v.localizedString})]}),c.attributes?.map(t=>e("div",{children:[t.key,": ",t.value]},t.key))]}),e("div",{className:"gp-flex gp-items-center gp-justify-between",children:[t(p,{size:"medium"}),t("button",{onClick:()=>{n({title:e("div",{className:"gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",children:[t(s,{}),t("p",{className:"gp-font-g-body gp-text-xl gp-font-semibold",children:"Are you sure ?"})]}),content:e("div",{className:"gp-text-center",children:[t("p",{children:"Do you really want to delete these items?"}),t("p",{children:"This process cannot be undone."})]}),className:"gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded",buttons:[{label:"Cancel",className:"gp-w-[130px] !gp-bg-g-bg-1"},{label:"Delete",className:"!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]",onClick:()=>{o&&c.id&&d({cartId:o,lineId:c.id})}}]})},"aria-label":"Remove item from cart",title:"Remove item from cart",type:"button",children:m?t(g,{className:"gp-text-g-brand"}):t("svg",{xmlns:"http://www.w3.org/2000/svg",className:"gp-w-4 gp-text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t("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 { jsxs, jsx } from 'react/jsx-runtime';
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('gp-mt-2 gp-inline-flex gp-items-center gp-overflow-auto gp-rounded gp-border gp-border-g-line-3 gp-text-g-text-1', {
9
- 'gp-h-12': size === 'large',
10
- 'gp-h-10': size === 'medium',
11
- 'gp-h-8': size === 'small'
12
- }),
13
- children: [
14
- /*#__PURE__*/ jsx(CartLineQuantityAdjustButton, {
15
- adjust: "decrease",
16
- "aria-label": "Decrease quantity",
17
- className: "gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",
18
- children: /*#__PURE__*/ jsx("svg", {
19
- className: "gp-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: "gp-flex gp-h-full gp-min-w-[50px] gp-select-none gp-items-center gp-justify-center gp-border-x gp-border-g-line-3 gp-px-2 gp-text-center gp-text-base gp-font-semibold",
30
- children: line.quantity
31
- }),
32
- /*#__PURE__*/ jsx(CartLineQuantityAdjustButton, {
33
- adjust: "increase",
34
- "aria-label": "Increase quantity",
35
- className: "gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",
36
- children: /*#__PURE__*/ jsx("svg", {
37
- className: "gp-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:p})=>{let g=r();return e("div",{className:a("gp-mt-2 gp-inline-flex gp-items-center gp-overflow-auto gp-rounded gp-border gp-border-g-line-3 gp-text-g-text-1",{"gp-h-12":"large"===p,"gp-h-10":"medium"===p,"gp-h-8":"small"===p}),children:[t(l,{adjust:"decrease","aria-label":"Decrease quantity",className:"gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",children:t("svg",{className:"gp-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:"gp-flex gp-h-full gp-min-w-[50px] gp-select-none gp-items-center gp-justify-center gp-border-x gp-border-g-line-3 gp-px-2 gp-text-center gp-text-base gp-font-semibold",children:g.quantity}),t(l,{adjust:"increase","aria-label":"Increase quantity",className:"gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",children:t("svg",{className:"gp-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,145 +1 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
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: "gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",
26
- children: [
27
- /*#__PURE__*/ jsx(Trash, {}),
28
- /*#__PURE__*/ jsx("p", {
29
- className: "gp-font-g-body gp-text-xl gp-font-semibold",
30
- children: "Are you sure ?"
31
- })
32
- ]
33
- }),
34
- content: /*#__PURE__*/ jsxs("div", {
35
- className: "gp-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: 'gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded',
46
- buttons: [
47
- {
48
- label: 'Cancel',
49
- className: 'gp-w-[130px] !gp-bg-g-bg-1'
50
- },
51
- {
52
- label: 'Delete',
53
- className: '!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]',
54
- onClick: ()=>{
55
- if (cartLine.id) {
56
- removeLines({
57
- cartId,
58
- lineId: cartLine.id
59
- });
60
- }
61
- }
62
- }
63
- ]
64
- });
65
- return;
66
- }
67
- const quantity = adjust === 'decrease' ? cartLine.quantity - 1 : cartLine.quantity + 1;
68
- if (quantity <= 0) {
69
- openConfirm({
70
- title: /*#__PURE__*/ jsxs("div", {
71
- className: "gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",
72
- children: [
73
- /*#__PURE__*/ jsx(Trash, {}),
74
- /*#__PURE__*/ jsx("p", {
75
- className: "gp-font-g-body gp-text-xl gp-font-semibold",
76
- children: "Are you sure ?"
77
- })
78
- ]
79
- }),
80
- content: /*#__PURE__*/ jsxs("div", {
81
- className: "gp-text-center",
82
- children: [
83
- /*#__PURE__*/ jsx("p", {
84
- children: "Do you really want to delete this item?"
85
- }),
86
- /*#__PURE__*/ jsx("p", {
87
- children: "This process cannot be undone."
88
- })
89
- ]
90
- }),
91
- className: 'gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded',
92
- buttons: [
93
- {
94
- label: 'Cancel',
95
- className: 'gp-w-[130px] !gp-bg-g-bg-1'
96
- },
97
- {
98
- label: 'Delete',
99
- className: '!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]',
100
- onClick: ()=>{
101
- if (cartLine.id) {
102
- removeLines({
103
- cartId,
104
- lineId: cartLine.id
105
- });
106
- }
107
- }
108
- }
109
- ]
110
- });
111
- return;
112
- } else {
113
- updateLines({
114
- cartId,
115
- line: {
116
- id: cartLine.id,
117
- variantId: cartLine.variant.id,
118
- quantity,
119
- productId: cartLine.productId
120
- }
121
- });
122
- }
123
- }
124
- },
125
- children: isLoading ? /*#__PURE__*/ jsxs("div", {
126
- className: "gp-flex gp-gap-1",
127
- children: [
128
- /*#__PURE__*/ jsx("span", {
129
- className: "gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-g-brand"
130
- }),
131
- /*#__PURE__*/ jsx("span", {
132
- className: "gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-g-brand"
133
- }),
134
- /*#__PURE__*/ jsx("span", {
135
- className: "gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-g-brand"
136
- })
137
- ]
138
- }) : children
139
- });
140
- };
141
- CartLineQuantityAdjustButton.defaultProps = {
142
- adjust: 'increase'
143
- };
144
-
145
- export { CartLineQuantityAdjustButton as default };
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useUpdateCartItem as a,useRemoveCartItem as n,useCartId as l,useCartLine as g}from"@gem-sdk/core";import{openConfirm as i}from"@gem-sdk/components";import p from"./icons/Trash.js";let CartLineQuantityAdjustButton=({children:s,adjust:r,className:d,style:o})=>{let{isMutating:c,trigger:u}=a(),{isMutating:m,trigger:f}=n(),{cartId:b}=l(),x=g(),h=c||m;return e("button",{"aria-label":"Adjust quantity",className:d,style:o,disabled:h,onClick:()=>{if(b&&x.id){if("remove"===r){i({title:t("div",{className:"gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",children:[e(p,{}),e("p",{className:"gp-font-g-body gp-text-xl gp-font-semibold",children:"Are you sure ?"})]}),content:t("div",{className:"gp-text-center",children:[e("p",{children:"Do you really want to delete this item?"}),e("p",{children:"This process cannot be undone."})]}),className:"gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded",buttons:[{label:"Cancel",className:"gp-w-[130px] !gp-bg-g-bg-1"},{label:"Delete",className:"!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]",onClick:()=>{x.id&&f({cartId:b,lineId:x.id})}}]});return}let a="decrease"===r?x.quantity-1:x.quantity+1;if(a<=0){i({title:t("div",{className:"gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",children:[e(p,{}),e("p",{className:"gp-font-g-body gp-text-xl gp-font-semibold",children:"Are you sure ?"})]}),content:t("div",{className:"gp-text-center",children:[e("p",{children:"Do you really want to delete this item?"}),e("p",{children:"This process cannot be undone."})]}),className:"gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded",buttons:[{label:"Cancel",className:"gp-w-[130px] !gp-bg-g-bg-1"},{label:"Delete",className:"!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]",onClick:()=>{x.id&&f({cartId:b,lineId:x.id})}}]});return}u({cartId:b,line:{id:x.id,variantId:x.variant.id,quantity:a,productId:x.productId}})}},children:h?t("div",{className:"gp-flex gp-gap-1",children:[e("span",{className:"gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-g-brand"}),e("span",{className:"gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-g-brand"}),e("span",{className:"gp-aspect-square gp-h-1 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-g-brand"})]}):s})};CartLineQuantityAdjustButton.defaultProps={adjust:"increase"};export{CartLineQuantityAdjustButton as default};
@@ -1,68 +1 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useCartData, useCartId, useCartNoteUpdate } from '@gem-sdk/core';
3
- import { useRef, useCallback } from 'react';
4
-
5
- const CartOrderNote = ({ triggerUpdate, debounce, placeholder })=>{
6
- const textRef = useRef(null);
7
- const timeout = useRef(null);
8
- const abortControllerRef = useRef(new AbortController());
9
- const { data: cart } = useCartData();
10
- const { cartId } = useCartId();
11
- const { trigger: updateCartNote } = useCartNoteUpdate();
12
- const updateNote = useCallback((note)=>{
13
- if (cartId && cart?.note !== note) {
14
- updateCartNote({
15
- cartId,
16
- note
17
- });
18
- }
19
- }, [
20
- cart?.note,
21
- cartId,
22
- updateCartNote
23
- ]);
24
- const onBlur = (e)=>{
25
- if (abortControllerRef.current.signal.aborted) {
26
- abortControllerRef.current = new AbortController();
27
- }
28
- updateNote(e.target.value);
29
- };
30
- const onChange = ()=>{
31
- if (timeout.current) {
32
- if (!abortControllerRef.current.signal.aborted) {
33
- abortControllerRef.current.abort();
34
- }
35
- clearTimeout(timeout.current);
36
- }
37
- timeout.current = setTimeout(()=>{
38
- abortControllerRef.current = new AbortController();
39
- updateNote(textRef.current?.value ?? '');
40
- }, debounce ?? 1000);
41
- };
42
- const inputProps = triggerUpdate === 'blur' ? {
43
- onBlur
44
- } : {
45
- onChange
46
- };
47
- return /*#__PURE__*/ jsxs("div", {
48
- className: "gp-flex gp-flex-col",
49
- children: [
50
- /*#__PURE__*/ jsx("div", {
51
- className: "gp-mb-4 gp-border-b gp-border-b-[#F1F3F4] gp-pb-3",
52
- children: /*#__PURE__*/ jsx("span", {
53
- className: "gp-font-semibold gp-text-[#424242]",
54
- children: "Order Note"
55
- })
56
- }),
57
- /*#__PURE__*/ jsx("textarea", {
58
- defaultValue: cart?.note,
59
- placeholder: placeholder,
60
- ref: textRef,
61
- className: "gp-w-full gp-rounded gp-border gp-p-4 gp-outline-none",
62
- ...inputProps
63
- })
64
- ]
65
- });
66
- };
67
-
68
- export { CartOrderNote as default };
1
+ import{jsxs as e,jsx as r}from"react/jsx-runtime";import{useCartData as t,useCartId as o,useCartNoteUpdate as l}from"@gem-sdk/core";import{useRef as n,useCallback as a}from"react";let CartOrderNote=({triggerUpdate:u,debounce:c,placeholder:d})=>{let p=n(null),g=n(null),i=n(new AbortController),{data:m}=t(),{cartId:s}=o(),{trigger:b}=l(),f=a(e=>{s&&m?.note!==e&&b({cartId:s,note:e})},[m?.note,s,b]),N=e=>{i.current.signal.aborted&&(i.current=new AbortController),f(e.target.value)},x=()=>{g.current&&(i.current.signal.aborted||i.current.abort(),clearTimeout(g.current)),g.current=setTimeout(()=>{i.current=new AbortController,f(p.current?.value??"")},c??1e3)},C="blur"===u?{onBlur:N}:{onChange:x};return e("div",{className:"gp-flex gp-flex-col",children:[r("div",{className:"gp-mb-4 gp-border-b gp-border-b-[#F1F3F4] gp-pb-3",children:r("span",{className:"gp-font-semibold gp-text-[#424242]",children:"Order Note"})}),r("textarea",{defaultValue:m?.note,placeholder:d,ref:p,className:"gp-w-full gp-rounded gp-border gp-p-4 gp-outline-none",...C})]})};export{CartOrderNote as default};
@@ -1,89 +1 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { useCartId, useCartDiscountCodesUpdate, useCartData, isDefined, cls } from '@gem-sdk/core';
3
- import { openConfirm } from '@gem-sdk/components';
4
- import { useMemo, useCallback } from 'react';
5
- import Trash from './icons/Trash.js';
6
- import LoadingIcon from './LoadingIcon.js';
7
-
8
- const DiscountCodeItem = ({ item })=>{
9
- const { cartId } = useCartId();
10
- const { trigger: updateCartDiscountCode, isMutating } = useCartDiscountCodesUpdate();
11
- const { data: cart } = useCartData();
12
- const currentCode = useMemo(()=>cart?.discounts?.map((v)=>v.code).filter(isDefined) ?? [], [
13
- cart?.discounts
14
- ]);
15
- const removeCode = useCallback((code)=>{
16
- openConfirm({
17
- title: /*#__PURE__*/ jsxs("div", {
18
- className: "gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",
19
- children: [
20
- /*#__PURE__*/ jsx(Trash, {}),
21
- /*#__PURE__*/ jsx("p", {
22
- className: "gp-font-g-body gp-text-xl gp-font-semibold",
23
- children: "Are you sure ?"
24
- })
25
- ]
26
- }),
27
- content: /*#__PURE__*/ jsx("div", {
28
- className: "gp-text-center",
29
- children: /*#__PURE__*/ jsx("p", {
30
- children: "Do you really want to delete this code?"
31
- })
32
- }),
33
- className: 'gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded',
34
- buttons: [
35
- {
36
- label: 'Cancel',
37
- className: 'gp-w-[130px] !gp-bg-g-bg-1'
38
- },
39
- {
40
- label: 'Delete',
41
- className: '!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]',
42
- onClick: ()=>{
43
- if (cartId) {
44
- updateCartDiscountCode({
45
- cartId,
46
- discountCodes: currentCode.filter((v)=>v !== code)
47
- });
48
- }
49
- }
50
- }
51
- ]
52
- });
53
- }, [
54
- cartId,
55
- updateCartDiscountCode,
56
- currentCode
57
- ]);
58
- return /*#__PURE__*/ jsxs("div", {
59
- className: "gp-flex gp-h-8 gp-items-center gp-gap-2 gp-rounded-sm gp-border gp-pl-2",
60
- children: [
61
- /*#__PURE__*/ jsx("span", {
62
- className: cls('gp-flex-1', {
63
- 'gp-text-g-error gp-line-through': !item.applicable,
64
- 'gp-text-g-success': item.applicable
65
- }),
66
- children: item.code
67
- }),
68
- /*#__PURE__*/ jsx("button", {
69
- disabled: isMutating,
70
- onClick: ()=>removeCode(item.code),
71
- className: "gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",
72
- children: isMutating ? /*#__PURE__*/ jsx(LoadingIcon, {
73
- className: "gp-text-g-brand"
74
- }) : /*#__PURE__*/ jsx("svg", {
75
- className: "gp-w-4",
76
- fill: "none",
77
- viewBox: "0 0 24 24",
78
- xmlns: "http://www.w3.org/2000/svg",
79
- children: /*#__PURE__*/ jsx("path", {
80
- 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",
81
- fill: "currentColor"
82
- })
83
- })
84
- })
85
- ]
86
- }, item.code);
87
- };
88
-
89
- export { DiscountCodeItem as default };
1
+ import{jsxs as e,jsx as l}from"react/jsx-runtime";import{useCartId as t,useCartDiscountCodesUpdate as p,useCartData as g,isDefined as o,cls as s}from"@gem-sdk/core";import{openConfirm as r}from"@gem-sdk/components";import{useMemo as a,useCallback as c}from"react";import n from"./icons/Trash.js";import i from"./LoadingIcon.js";let DiscountCodeItem=({item:d})=>{let{cartId:m}=t(),{trigger:f,isMutating:u}=p(),{data:x}=g(),h=a(()=>x?.discounts?.map(e=>e.code).filter(o)??[],[x?.discounts]),b=c(t=>{r({title:e("div",{className:"gp-flex gp-w-full gp-flex-col gp-items-center gp-gap-4",children:[l(n,{}),l("p",{className:"gp-font-g-body gp-text-xl gp-font-semibold",children:"Are you sure ?"})]}),content:l("div",{className:"gp-text-center",children:l("p",{children:"Do you really want to delete this code?"})}),className:"gp-w-full gp-max-w-[572px] gp-gap-4 gp-rounded",buttons:[{label:"Cancel",className:"gp-w-[130px] !gp-bg-g-bg-1"},{label:"Delete",className:"!gp-bg-g-error !gp-text-g-text-3 !font-g-body gp-w-[130px]",onClick:()=>{m&&f({cartId:m,discountCodes:h.filter(e=>e!==t)})}}]})},[m,f,h]);return e("div",{className:"gp-flex gp-h-8 gp-items-center gp-gap-2 gp-rounded-sm gp-border gp-pl-2",children:[l("span",{className:s("gp-flex-1",{"gp-text-g-error gp-line-through":!d.applicable,"gp-text-g-success":d.applicable}),children:d.code}),l("button",{disabled:u,onClick:()=>b(d.code),className:"gp-flex gp-aspect-square gp-h-full gp-items-center gp-justify-center",children:u?l(i,{className:"gp-text-g-brand"}):l("svg",{className:"gp-w-4",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:l("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",fill:"currentColor"})})})]},d.code)};export{DiscountCodeItem as default};
@@ -1,26 +1 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { cls } from '@gem-sdk/core';
3
-
4
- const LoadingIcon = ({ className })=>/*#__PURE__*/ jsxs("svg", {
5
- className: cls('gp-w-4 gp-animate-spin', className),
6
- xmlns: "http://www.w3.org/2000/svg",
7
- fill: "none",
8
- viewBox: "0 0 24 24",
9
- children: [
10
- /*#__PURE__*/ jsx("circle", {
11
- className: "gp-opacity-25",
12
- cx: "12",
13
- cy: "12",
14
- r: "10",
15
- stroke: "currentColor",
16
- strokeWidth: "4"
17
- }),
18
- /*#__PURE__*/ jsx("path", {
19
- className: "gp-opacity-75",
20
- fill: "currentColor",
21
- d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
22
- })
23
- ]
24
- });
25
-
26
- export { LoadingIcon as default };
1
+ import{jsxs as o,jsx as r}from"react/jsx-runtime";import{cls as e}from"@gem-sdk/core";let LoadingIcon=({className:t})=>o("svg",{className:e("gp-w-4 gp-animate-spin",t),xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[r("circle",{className:"gp-opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),r("path",{className:"gp-opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]});export{LoadingIcon as default};