@shopify/hydrogen-react 0.0.0-next-182fb2f → 0.0.0-next-59d697b
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/dev/AddToCartButton.js +2 -27
- package/dist/dev/AddToCartButton.js.map +1 -1
- package/dist/dev/AddToCartButton.mjs +2 -27
- package/dist/dev/AddToCartButton.mjs.map +1 -1
- package/dist/dev/BaseButton.js +31 -0
- package/dist/dev/BaseButton.js.map +1 -0
- package/dist/dev/BaseButton.mjs +31 -0
- package/dist/dev/BaseButton.mjs.map +1 -0
- package/dist/dev/CartCheckoutButton.js +29 -0
- package/dist/dev/CartCheckoutButton.js.map +1 -0
- package/dist/dev/CartCheckoutButton.mjs +29 -0
- package/dist/dev/CartCheckoutButton.mjs.map +1 -0
- package/dist/dev/index.js +2 -0
- package/dist/dev/index.js.map +1 -1
- package/dist/dev/index.mjs +2 -0
- package/dist/dev/index.mjs.map +1 -1
- package/dist/prod/AddToCartButton.js +2 -27
- package/dist/prod/AddToCartButton.js.map +1 -1
- package/dist/prod/AddToCartButton.mjs +2 -27
- package/dist/prod/AddToCartButton.mjs.map +1 -1
- package/dist/prod/BaseButton.js +31 -0
- package/dist/prod/BaseButton.js.map +1 -0
- package/dist/prod/BaseButton.mjs +31 -0
- package/dist/prod/BaseButton.mjs.map +1 -0
- package/dist/prod/CartCheckoutButton.js +29 -0
- package/dist/prod/CartCheckoutButton.js.map +1 -0
- package/dist/prod/CartCheckoutButton.mjs +29 -0
- package/dist/prod/CartCheckoutButton.mjs.map +1 -0
- package/dist/prod/index.js +2 -0
- package/dist/prod/index.js.map +1 -1
- package/dist/prod/index.mjs +2 -0
- package/dist/prod/index.mjs.map +1 -1
- package/dist/types/AddToCartButton.d.ts +1 -15
- package/dist/types/BaseButton.d.ts +15 -0
- package/dist/types/CartCheckoutButton.d.ts +11 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/umd/hydrogen-react.dev.js +58 -28
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +14 -14
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartCheckoutButton.js","sources":["../../src/CartCheckoutButton.tsx"],"sourcesContent":["import {ReactNode, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\n\ntype PropsWeControl = 'onClick';\n\n/**\n * The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.\n * It must be a descendent of a `CartProvider` component.\n */\nexport function CartCheckoutButton(\n props: Omit<JSX.IntrinsicElements['button'], PropsWeControl> & {\n /** A `ReactNode` element. */\n children: ReactNode;\n }\n) {\n const [requestedCheckout, setRequestedCheckout] = useState(false);\n const {status, checkoutUrl} = useCart();\n const {children, ...passthroughProps} = props;\n\n useEffect(() => {\n if (requestedCheckout && checkoutUrl && status === 'idle') {\n window.location.href = checkoutUrl;\n }\n }, [requestedCheckout, status, checkoutUrl]);\n\n return (\n <button\n {...passthroughProps}\n disabled={requestedCheckout || passthroughProps.disabled}\n onClick={() => setRequestedCheckout(true)}\n >\n {children}\n </button>\n );\n}\n"],"names":["CartCheckoutButton","props","requestedCheckout","setRequestedCheckout","useState","status","checkoutUrl","useCart","children","passthroughProps","useEffect","window","location","href","disabled"],"mappings":";;;;;AASO,SAASA,mBACdC,OAIA;AACA,QAAM,CAACC,mBAAmBC,oBAApB,IAA4CC,eAAS,KAAD;AACpD,QAAA;AAAA,IAACC;AAAAA,IAAQC;AAAAA,MAAeC,aAA9B,QAAA;AACM,QAAA;AAAA,IAACC;AAAAA,OAAaC;AAAAA,EAAoBR,IAAAA;AAExCS,QAAAA,UAAU,MAAM;AACVR,QAAAA,qBAAqBI,eAAeD,WAAW,QAAQ;AACzDM,aAAOC,SAASC,OAAOP;AAAAA,IACxB;AAAA,EACA,GAAA,CAACJ,mBAAmBG,QAAQC,WAA5B,CAJM;AAMT;OAEQG;AAAAA,IACJ,UAAUP,qBAAqBO,iBAAiBK;AAAAA,IAChD,SAAS,MAAMX,qBAAqB,IAAD;AAAA,IAHrC;AAAA,EAAA,CADF;AASD;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { useCart } from "./CartProvider.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
function CartCheckoutButton(props) {
|
|
5
|
+
const [requestedCheckout, setRequestedCheckout] = useState(false);
|
|
6
|
+
const {
|
|
7
|
+
status,
|
|
8
|
+
checkoutUrl
|
|
9
|
+
} = useCart();
|
|
10
|
+
const {
|
|
11
|
+
children,
|
|
12
|
+
...passthroughProps
|
|
13
|
+
} = props;
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (requestedCheckout && checkoutUrl && status === "idle") {
|
|
16
|
+
window.location.href = checkoutUrl;
|
|
17
|
+
}
|
|
18
|
+
}, [requestedCheckout, status, checkoutUrl]);
|
|
19
|
+
return /* @__PURE__ */ jsx("button", {
|
|
20
|
+
...passthroughProps,
|
|
21
|
+
disabled: requestedCheckout || passthroughProps.disabled,
|
|
22
|
+
onClick: () => setRequestedCheckout(true),
|
|
23
|
+
children
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
CartCheckoutButton
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=CartCheckoutButton.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartCheckoutButton.mjs","sources":["../../src/CartCheckoutButton.tsx"],"sourcesContent":["import {ReactNode, useEffect, useState} from 'react';\nimport {useCart} from './CartProvider.js';\n\ntype PropsWeControl = 'onClick';\n\n/**\n * The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.\n * It must be a descendent of a `CartProvider` component.\n */\nexport function CartCheckoutButton(\n props: Omit<JSX.IntrinsicElements['button'], PropsWeControl> & {\n /** A `ReactNode` element. */\n children: ReactNode;\n }\n) {\n const [requestedCheckout, setRequestedCheckout] = useState(false);\n const {status, checkoutUrl} = useCart();\n const {children, ...passthroughProps} = props;\n\n useEffect(() => {\n if (requestedCheckout && checkoutUrl && status === 'idle') {\n window.location.href = checkoutUrl;\n }\n }, [requestedCheckout, status, checkoutUrl]);\n\n return (\n <button\n {...passthroughProps}\n disabled={requestedCheckout || passthroughProps.disabled}\n onClick={() => setRequestedCheckout(true)}\n >\n {children}\n </button>\n );\n}\n"],"names":["CartCheckoutButton","props","requestedCheckout","setRequestedCheckout","useState","status","checkoutUrl","useCart","children","passthroughProps","useEffect","window","location","href","disabled"],"mappings":";;;AASO,SAASA,mBACdC,OAIA;AACA,QAAM,CAACC,mBAAmBC,oBAApB,IAA4CC,SAAS,KAAD;AACpD,QAAA;AAAA,IAACC;AAAAA,IAAQC;AAAAA,MAAeC,QAA9B;AACM,QAAA;AAAA,IAACC;AAAAA,OAAaC;AAAAA,EAAoBR,IAAAA;AAExCS,YAAU,MAAM;AACVR,QAAAA,qBAAqBI,eAAeD,WAAW,QAAQ;AACzDM,aAAOC,SAASC,OAAOP;AAAAA,IACxB;AAAA,EACA,GAAA,CAACJ,mBAAmBG,QAAQC,WAA5B,CAJM;AAMT;OAEQG;AAAAA,IACJ,UAAUP,qBAAqBO,iBAAiBK;AAAAA,IAChD,SAAS,MAAMX,qBAAqB,IAAD;AAAA,IAHrC;AAAA,EAAA,CADF;AASD;"}
|
package/dist/prod/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const AddToCartButton = require("./AddToCartButton.js");
|
|
4
|
+
const CartCheckoutButton = require("./CartCheckoutButton.js");
|
|
4
5
|
const CartProvider = require("./CartProvider.js");
|
|
5
6
|
const ExternalVideo = require("./ExternalVideo.js");
|
|
6
7
|
const flattenConnection = require("./flatten-connection.js");
|
|
@@ -18,6 +19,7 @@ const storefrontClient = require("./storefront-client.js");
|
|
|
18
19
|
const useMoney = require("./useMoney.js");
|
|
19
20
|
const Video = require("./Video.js");
|
|
20
21
|
exports.AddToCartButton = AddToCartButton.AddToCartButton;
|
|
22
|
+
exports.CartCheckoutButton = CartCheckoutButton.CartCheckoutButton;
|
|
21
23
|
exports.CartProvider = CartProvider.CartProvider;
|
|
22
24
|
exports.useCart = CartProvider.useCart;
|
|
23
25
|
exports.ExternalVideo = ExternalVideo.ExternalVideo;
|
package/dist/prod/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/prod/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AddToCartButton } from "./AddToCartButton.mjs";
|
|
2
|
+
import { CartCheckoutButton } from "./CartCheckoutButton.mjs";
|
|
2
3
|
import { CartProvider, useCart } from "./CartProvider.mjs";
|
|
3
4
|
import { ExternalVideo } from "./ExternalVideo.mjs";
|
|
4
5
|
import { flattenConnection } from "./flatten-connection.mjs";
|
|
@@ -17,6 +18,7 @@ import { useMoney } from "./useMoney.mjs";
|
|
|
17
18
|
import { Video } from "./Video.mjs";
|
|
18
19
|
export {
|
|
19
20
|
AddToCartButton,
|
|
21
|
+
CartCheckoutButton,
|
|
20
22
|
CartProvider,
|
|
21
23
|
ExternalVideo,
|
|
22
24
|
Image,
|
package/dist/prod/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseButtonProps } from './BaseButton.js';
|
|
2
2
|
interface AddToCartButtonProps {
|
|
3
3
|
/** An array of cart line attributes that belong to the item being added to the cart. */
|
|
4
4
|
attributes?: {
|
|
@@ -19,18 +19,4 @@ interface AddToCartButtonProps {
|
|
|
19
19
|
* It must be a descendent of the `CartProvider` component.
|
|
20
20
|
*/
|
|
21
21
|
export declare function AddToCartButton<AsType extends React.ElementType = 'button'>(props: AddToCartButtonProps & BaseButtonProps<AsType>): JSX.Element;
|
|
22
|
-
export interface CustomBaseButtonProps<AsType> {
|
|
23
|
-
/** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */
|
|
24
|
-
as?: AsType;
|
|
25
|
-
/** Any ReactNode elements. */
|
|
26
|
-
children: ReactNode;
|
|
27
|
-
/** Click event handler. Default behaviour triggers unless prevented */
|
|
28
|
-
onClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
29
|
-
/** A default onClick behavior */
|
|
30
|
-
defaultOnClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
31
|
-
/** A ref to the underlying button */
|
|
32
|
-
buttonRef?: Ref<HTMLButtonElement>;
|
|
33
|
-
}
|
|
34
|
-
export declare type BaseButtonProps<AsType extends React.ElementType> = CustomBaseButtonProps<AsType> & Omit<React.ComponentPropsWithoutRef<AsType>, keyof CustomBaseButtonProps<AsType>>;
|
|
35
|
-
export declare function BaseButton<AsType extends React.ElementType = 'button'>(props: BaseButtonProps<AsType>): JSX.Element;
|
|
36
22
|
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode, Ref } from 'react';
|
|
2
|
+
export interface CustomBaseButtonProps<AsType> {
|
|
3
|
+
/** Provide a React element or component to render as the underlying button. Note: for accessibility compliance, almost always you should use a `button` element, or a component that renders an underlying button. */
|
|
4
|
+
as?: AsType;
|
|
5
|
+
/** Any ReactNode elements. */
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Click event handler. Default behaviour triggers unless prevented */
|
|
8
|
+
onClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
9
|
+
/** A default onClick behavior */
|
|
10
|
+
defaultOnClick?: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | boolean;
|
|
11
|
+
/** A ref to the underlying button */
|
|
12
|
+
buttonRef?: Ref<HTMLButtonElement>;
|
|
13
|
+
}
|
|
14
|
+
export declare type BaseButtonProps<AsType extends React.ElementType> = CustomBaseButtonProps<AsType> & Omit<React.ComponentPropsWithoutRef<AsType>, keyof CustomBaseButtonProps<AsType>>;
|
|
15
|
+
export declare function BaseButton<AsType extends React.ElementType = 'button'>(props: BaseButtonProps<AsType>): JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
declare type PropsWeControl = 'onClick';
|
|
3
|
+
/**
|
|
4
|
+
* The `CartCheckoutButton` component renders a button that redirects to the checkout URL for the cart.
|
|
5
|
+
* It must be a descendent of a `CartProvider` component.
|
|
6
|
+
*/
|
|
7
|
+
export declare function CartCheckoutButton(props: Omit<JSX.IntrinsicElements['button'], PropsWeControl> & {
|
|
8
|
+
/** A `ReactNode` element. */
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): JSX.Element;
|
|
11
|
+
export {};
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AddToCartButton } from './AddToCartButton.js';
|
|
2
2
|
export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
|
|
3
|
+
export { CartCheckoutButton } from './CartCheckoutButton.js';
|
|
3
4
|
export { CartProvider, useCart } from './CartProvider.js';
|
|
4
5
|
export { ExternalVideo } from './ExternalVideo.js';
|
|
5
6
|
export { flattenConnection } from './flatten-connection.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AddToCartButton } from './AddToCartButton.js';
|
|
2
2
|
export type { CartState, CartStatus, Cart, CartWithActions, CartAction, } from './cart-types.js';
|
|
3
|
+
export { CartCheckoutButton } from './CartCheckoutButton.js';
|
|
3
4
|
export { CartProvider, useCart } from './CartProvider.js';
|
|
4
5
|
export { ExternalVideo } from './ExternalVideo.js';
|
|
5
6
|
export { flattenConnection } from './flatten-connection.js';
|
|
@@ -766,7 +766,7 @@ query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ)
|
|
|
766
766
|
${cartFragment}
|
|
767
767
|
`;
|
|
768
768
|
const SFAPI_VERSION = "2022-10";
|
|
769
|
-
var _jsxFileName$
|
|
769
|
+
var _jsxFileName$e = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
|
|
770
770
|
const ShopifyContext = React.createContext({
|
|
771
771
|
storeDomain: "test.myshopify.com",
|
|
772
772
|
storefrontToken: "abc123",
|
|
@@ -797,7 +797,7 @@ ${cartFragment}
|
|
|
797
797
|
value: finalConfig,
|
|
798
798
|
__self: this,
|
|
799
799
|
__source: {
|
|
800
|
-
fileName: _jsxFileName$
|
|
800
|
+
fileName: _jsxFileName$e,
|
|
801
801
|
lineNumber: 49,
|
|
802
802
|
columnNumber: 5
|
|
803
803
|
}
|
|
@@ -1312,7 +1312,7 @@ ${cartFragment}
|
|
|
1312
1312
|
function isCartFetchResultEvent(event) {
|
|
1313
1313
|
return event.type === "RESOLVE" || event.type === "ERROR" || event.type === "CART_COMPLETED";
|
|
1314
1314
|
}
|
|
1315
|
-
var _jsxFileName$
|
|
1315
|
+
var _jsxFileName$d = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";
|
|
1316
1316
|
const CartContext = React.createContext(null);
|
|
1317
1317
|
function useCart() {
|
|
1318
1318
|
const context = React.useContext(CartContext);
|
|
@@ -1625,7 +1625,7 @@ ${cartFragment}
|
|
|
1625
1625
|
value: cartContextValue,
|
|
1626
1626
|
__self: this,
|
|
1627
1627
|
__source: {
|
|
1628
|
-
fileName: _jsxFileName$
|
|
1628
|
+
fileName: _jsxFileName$d,
|
|
1629
1629
|
lineNumber: 425,
|
|
1630
1630
|
columnNumber: 5
|
|
1631
1631
|
}
|
|
@@ -1791,7 +1791,7 @@ fragment ImageFragment on Image {
|
|
|
1791
1791
|
height
|
|
1792
1792
|
}
|
|
1793
1793
|
`;
|
|
1794
|
-
var _jsxFileName$
|
|
1794
|
+
var _jsxFileName$c = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ProductProvider.tsx";
|
|
1795
1795
|
const ProductOptionsContext = React.createContext(null);
|
|
1796
1796
|
function ProductProvider({
|
|
1797
1797
|
children,
|
|
@@ -1877,7 +1877,7 @@ fragment ImageFragment on Image {
|
|
|
1877
1877
|
value,
|
|
1878
1878
|
__self: this,
|
|
1879
1879
|
__source: {
|
|
1880
|
-
fileName: _jsxFileName$
|
|
1880
|
+
fileName: _jsxFileName$c,
|
|
1881
1881
|
lineNumber: 201,
|
|
1882
1882
|
columnNumber: 5
|
|
1883
1883
|
}
|
|
@@ -1950,7 +1950,38 @@ fragment ImageFragment on Image {
|
|
|
1950
1950
|
}
|
|
1951
1951
|
return true;
|
|
1952
1952
|
}
|
|
1953
|
-
var _jsxFileName$
|
|
1953
|
+
var _jsxFileName$b = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/BaseButton.tsx";
|
|
1954
|
+
function BaseButton(props) {
|
|
1955
|
+
const {
|
|
1956
|
+
as,
|
|
1957
|
+
onClick,
|
|
1958
|
+
defaultOnClick,
|
|
1959
|
+
children,
|
|
1960
|
+
buttonRef,
|
|
1961
|
+
...passthroughProps
|
|
1962
|
+
} = props;
|
|
1963
|
+
const handleOnClick = React.useCallback((event) => {
|
|
1964
|
+
if (onClick) {
|
|
1965
|
+
const clickShouldContinue = onClick(event);
|
|
1966
|
+
if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
defaultOnClick == null ? void 0 : defaultOnClick(event);
|
|
1970
|
+
}, [defaultOnClick, onClick]);
|
|
1971
|
+
const Component = as || "button";
|
|
1972
|
+
return /* @__PURE__ */ React__default.default.createElement(Component, {
|
|
1973
|
+
ref: buttonRef,
|
|
1974
|
+
onClick: handleOnClick,
|
|
1975
|
+
...passthroughProps,
|
|
1976
|
+
__self: this,
|
|
1977
|
+
__source: {
|
|
1978
|
+
fileName: _jsxFileName$b,
|
|
1979
|
+
lineNumber: 59,
|
|
1980
|
+
columnNumber: 5
|
|
1981
|
+
}
|
|
1982
|
+
}, children);
|
|
1983
|
+
}
|
|
1984
|
+
var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/AddToCartButton.tsx";
|
|
1954
1985
|
function AddToCartButton(props) {
|
|
1955
1986
|
var _a;
|
|
1956
1987
|
const [addingItem, setAddingItem] = React.useState(false);
|
|
@@ -1994,8 +2025,8 @@ fragment ImageFragment on Image {
|
|
|
1994
2025
|
defaultOnClick: handleAddItem,
|
|
1995
2026
|
__self: this,
|
|
1996
2027
|
__source: {
|
|
1997
|
-
fileName: _jsxFileName$
|
|
1998
|
-
lineNumber:
|
|
2028
|
+
fileName: _jsxFileName$a,
|
|
2029
|
+
lineNumber: 71,
|
|
1999
2030
|
columnNumber: 7
|
|
2000
2031
|
}
|
|
2001
2032
|
}, children), accessibleAddingToCartLabel ? /* @__PURE__ */ React__default.default.createElement("p", {
|
|
@@ -2014,38 +2045,36 @@ fragment ImageFragment on Image {
|
|
|
2014
2045
|
"aria-live": "assertive",
|
|
2015
2046
|
__self: this,
|
|
2016
2047
|
__source: {
|
|
2017
|
-
fileName: _jsxFileName$
|
|
2018
|
-
lineNumber:
|
|
2048
|
+
fileName: _jsxFileName$a,
|
|
2049
|
+
lineNumber: 80,
|
|
2019
2050
|
columnNumber: 9
|
|
2020
2051
|
}
|
|
2021
2052
|
}, addingItem ? accessibleAddingToCartLabel : null) : null);
|
|
2022
2053
|
}
|
|
2023
|
-
|
|
2054
|
+
var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartCheckoutButton.tsx";
|
|
2055
|
+
function CartCheckoutButton(props) {
|
|
2056
|
+
const [requestedCheckout, setRequestedCheckout] = React.useState(false);
|
|
2057
|
+
const {
|
|
2058
|
+
status,
|
|
2059
|
+
checkoutUrl
|
|
2060
|
+
} = useCart();
|
|
2024
2061
|
const {
|
|
2025
|
-
as,
|
|
2026
|
-
onClick,
|
|
2027
|
-
defaultOnClick,
|
|
2028
2062
|
children,
|
|
2029
|
-
buttonRef,
|
|
2030
2063
|
...passthroughProps
|
|
2031
2064
|
} = props;
|
|
2032
|
-
|
|
2033
|
-
if (
|
|
2034
|
-
|
|
2035
|
-
if (typeof clickShouldContinue === "boolean" && clickShouldContinue === false || (event == null ? void 0 : event.defaultPrevented))
|
|
2036
|
-
return;
|
|
2065
|
+
React.useEffect(() => {
|
|
2066
|
+
if (requestedCheckout && checkoutUrl && status === "idle") {
|
|
2067
|
+
window.location.href = checkoutUrl;
|
|
2037
2068
|
}
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
const Component = as || "button";
|
|
2041
|
-
return /* @__PURE__ */ React__default.default.createElement(Component, {
|
|
2042
|
-
ref: buttonRef,
|
|
2043
|
-
onClick: handleOnClick,
|
|
2069
|
+
}, [requestedCheckout, status, checkoutUrl]);
|
|
2070
|
+
return /* @__PURE__ */ React__default.default.createElement("button", {
|
|
2044
2071
|
...passthroughProps,
|
|
2072
|
+
disabled: requestedCheckout || passthroughProps.disabled,
|
|
2073
|
+
onClick: () => setRequestedCheckout(true),
|
|
2045
2074
|
__self: this,
|
|
2046
2075
|
__source: {
|
|
2047
2076
|
fileName: _jsxFileName$9,
|
|
2048
|
-
lineNumber:
|
|
2077
|
+
lineNumber: 27,
|
|
2049
2078
|
columnNumber: 5
|
|
2050
2079
|
}
|
|
2051
2080
|
}, children);
|
|
@@ -3357,6 +3386,7 @@ fragment ImageFragment on Image {
|
|
|
3357
3386
|
};
|
|
3358
3387
|
}
|
|
3359
3388
|
exports2.AddToCartButton = AddToCartButton;
|
|
3389
|
+
exports2.CartCheckoutButton = CartCheckoutButton;
|
|
3360
3390
|
exports2.CartProvider = CartProvider;
|
|
3361
3391
|
exports2.ExternalVideo = ExternalVideo;
|
|
3362
3392
|
exports2.Image = Image;
|