@shopify/app-bridge-react 2.0.18 → 2.0.21

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/components/ClientRouter/ClientRouter.d.ts +21 -0
  3. package/components/ClientRouter/ClientRouter.js +50 -0
  4. package/components/ClientRouter/hook.d.ts +10 -0
  5. package/components/ClientRouter/hook.js +20 -0
  6. package/components/ClientRouter/index.d.ts +3 -0
  7. package/components/ClientRouter/index.js +6 -0
  8. package/components/ClientRouter/router.d.ts +5 -0
  9. package/components/ClientRouter/router.js +11 -0
  10. package/components/ContextualSaveBar/ContextualSaveBar.d.ts +13 -0
  11. package/components/ContextualSaveBar/ContextualSaveBar.js +64 -0
  12. package/components/ContextualSaveBar/index.d.ts +3 -0
  13. package/components/ContextualSaveBar/index.js +7 -0
  14. package/components/Loading/Loading.d.ts +17 -0
  15. package/components/Loading/Loading.js +53 -0
  16. package/components/Loading/index.d.ts +2 -0
  17. package/components/Loading/index.js +7 -0
  18. package/components/Modal/Modal.d.ts +43 -0
  19. package/components/Modal/Modal.js +131 -0
  20. package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
  21. package/components/Modal/ModalContent/ModalContent.js +59 -0
  22. package/components/Modal/ModalContent/index.d.ts +2 -0
  23. package/components/Modal/ModalContent/index.js +7 -0
  24. package/components/Modal/index.d.ts +4 -0
  25. package/components/Modal/index.js +9 -0
  26. package/components/Provider/Provider.d.ts +36 -0
  27. package/components/Provider/Provider.js +93 -0
  28. package/components/Provider/index.d.ts +3 -0
  29. package/components/Provider/index.js +7 -0
  30. package/components/ResourcePicker/ResourcePicker.d.ts +77 -0
  31. package/components/ResourcePicker/ResourcePicker.js +129 -0
  32. package/components/ResourcePicker/index.d.ts +3 -0
  33. package/components/ResourcePicker/index.js +7 -0
  34. package/components/RoutePropagator/RoutePropagator.d.ts +20 -0
  35. package/components/RoutePropagator/RoutePropagator.js +52 -0
  36. package/components/RoutePropagator/globals.d.ts +3 -0
  37. package/components/RoutePropagator/globals.js +15 -0
  38. package/components/RoutePropagator/hook.d.ts +10 -0
  39. package/components/RoutePropagator/hook.js +20 -0
  40. package/components/RoutePropagator/index.d.ts +3 -0
  41. package/components/RoutePropagator/index.js +6 -0
  42. package/components/RoutePropagator/route-propagator.d.ts +7 -0
  43. package/components/RoutePropagator/route-propagator.js +91 -0
  44. package/components/TitleBar/TitleBar.d.ts +38 -0
  45. package/components/TitleBar/TitleBar.js +78 -0
  46. package/components/TitleBar/index.d.ts +3 -0
  47. package/components/TitleBar/index.js +7 -0
  48. package/components/Toast/Toast.d.ts +31 -0
  49. package/components/Toast/Toast.js +57 -0
  50. package/components/Toast/index.d.ts +3 -0
  51. package/components/Toast/index.js +7 -0
  52. package/components/index.d.ts +9 -0
  53. package/components/index.js +29 -0
  54. package/context.d.ts +13 -0
  55. package/context.js +10 -0
  56. package/hooks/index.d.ts +3 -0
  57. package/hooks/index.js +8 -0
  58. package/hooks/useContextualSaveBar/index.d.ts +1 -0
  59. package/hooks/useContextualSaveBar/index.js +4 -0
  60. package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +13 -0
  61. package/hooks/useContextualSaveBar/useContextualSaveBar.js +68 -0
  62. package/hooks/useNavigationHistory/index.d.ts +1 -0
  63. package/hooks/useNavigationHistory/index.js +4 -0
  64. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
  65. package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
  66. package/hooks/useToast/index.d.ts +1 -0
  67. package/hooks/useToast/index.js +4 -0
  68. package/hooks/useToast/useToast.d.ts +15 -0
  69. package/hooks/useToast/useToast.js +38 -0
  70. package/index.d.ts +3 -0
  71. package/index.js +17 -0
  72. package/package.json +4 -3
  73. package/types.d.ts +33 -0
  74. package/types.js +2 -0
  75. package/umd/index.js +14 -0
  76. package/useAppBridge.d.ts +1 -0
  77. package/useAppBridge.js +13 -0
  78. package/utilities/transformers.d.ts +19 -0
  79. package/utilities/transformers.js +86 -0
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var react_1 = __importDefault(require("react"));
20
+ var actions_1 = require("@shopify/app-bridge/actions");
21
+ var transformers_1 = require("../../utilities/transformers");
22
+ var context_1 = require("../../context");
23
+ var TitleBar = /** @class */ (function (_super) {
24
+ __extends(TitleBar, _super);
25
+ function TitleBar() {
26
+ return _super !== null && _super.apply(this, arguments) || this;
27
+ }
28
+ TitleBar.prototype.componentDidMount = function () {
29
+ var app = this.context;
30
+ this.titleBar = actions_1.TitleBar.create(app, this.transformProps());
31
+ };
32
+ TitleBar.prototype.componentDidUpdate = function () {
33
+ this.titleBar.unsubscribe();
34
+ this.titleBar.set(this.transformProps());
35
+ };
36
+ TitleBar.prototype.componentWillUnmount = function () {
37
+ this.titleBar.unsubscribe();
38
+ };
39
+ TitleBar.prototype.render = function () {
40
+ return null;
41
+ };
42
+ TitleBar.prototype.transformProps = function () {
43
+ var app = this.context;
44
+ var _a = this.props, title = _a.title, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, actionGroups = _a.actionGroups;
45
+ return {
46
+ title: title,
47
+ buttons: transformers_1.transformActions(app, {
48
+ primaryAction: primaryAction,
49
+ secondaryActions: secondaryActions,
50
+ actionGroups: actionGroups,
51
+ }),
52
+ breadcrumbs: this.transformBreadcrumbs(),
53
+ };
54
+ };
55
+ TitleBar.prototype.transformBreadcrumbs = function () {
56
+ var app = this.context;
57
+ var breadcrumbs = this.props.breadcrumbs;
58
+ if (breadcrumbs == null || breadcrumbs.length === 0) {
59
+ return undefined;
60
+ }
61
+ var breadcrumb = breadcrumbs[breadcrumbs.length - 1];
62
+ var url = breadcrumb.url, onAction = breadcrumb.onAction, target = breadcrumb.target, content = breadcrumb.content;
63
+ var button = actions_1.Button.create(app, {
64
+ label: content || '',
65
+ });
66
+ var redirect = transformers_1.generateRedirect(app, url, target);
67
+ if (redirect != null) {
68
+ button.subscribe(actions_1.Button.Action.CLICK, redirect);
69
+ }
70
+ if (onAction != null) {
71
+ button.subscribe(actions_1.Button.Action.CLICK, onAction);
72
+ }
73
+ return button;
74
+ };
75
+ TitleBar.contextType = context_1.AppBridgeContext;
76
+ return TitleBar;
77
+ }(react_1.default.PureComponent));
78
+ exports.default = TitleBar;
@@ -0,0 +1,3 @@
1
+ import TitleBar from './TitleBar';
2
+ export { Props } from './TitleBar';
3
+ export default TitleBar;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var TitleBar_1 = __importDefault(require("./TitleBar"));
7
+ exports.default = TitleBar_1.default;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export interface Props {
3
+ /** The content that should appear in the toast message */
4
+ content: string;
5
+ /**
6
+ * The length of time in milliseconds the toast message should persist
7
+ * @default 5000
8
+ */
9
+ duration?: number;
10
+ /** Display an error toast. */
11
+ error?: boolean;
12
+ /** Callback when the dismiss icon is clicked */
13
+ onDismiss(): void;
14
+ }
15
+ export declare const DEFAULT_TOAST_DURATION = 5000;
16
+ /**
17
+ * Toast component
18
+ *
19
+ * @remarks
20
+ * React component which wraps the Shopify App Bridge Toast action.
21
+ *
22
+ * @public
23
+ */
24
+ declare class Toast extends React.PureComponent<Props, never> {
25
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
26
+ private toast;
27
+ componentDidMount(): void;
28
+ componentWillUnmount(): void;
29
+ render(): null;
30
+ }
31
+ export default Toast;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.DEFAULT_TOAST_DURATION = void 0;
20
+ var react_1 = __importDefault(require("react"));
21
+ var actions_1 = require("@shopify/app-bridge/actions");
22
+ var context_1 = require("../../context");
23
+ exports.DEFAULT_TOAST_DURATION = 5000;
24
+ /**
25
+ * Toast component
26
+ *
27
+ * @remarks
28
+ * React component which wraps the Shopify App Bridge Toast action.
29
+ *
30
+ * @public
31
+ */
32
+ var Toast = /** @class */ (function (_super) {
33
+ __extends(Toast, _super);
34
+ function Toast() {
35
+ return _super !== null && _super.apply(this, arguments) || this;
36
+ }
37
+ Toast.prototype.componentDidMount = function () {
38
+ var app = this.context;
39
+ var _a = this.props, error = _a.error, content = _a.content, _b = _a.duration, duration = _b === void 0 ? exports.DEFAULT_TOAST_DURATION : _b, onDismiss = _a.onDismiss;
40
+ this.toast = actions_1.Toast.create(app, {
41
+ message: content,
42
+ duration: duration,
43
+ isError: error,
44
+ });
45
+ this.toast.subscribe(actions_1.Toast.Action.CLEAR, onDismiss);
46
+ this.toast.dispatch(actions_1.Toast.Action.SHOW);
47
+ };
48
+ Toast.prototype.componentWillUnmount = function () {
49
+ this.toast.unsubscribe();
50
+ };
51
+ Toast.prototype.render = function () {
52
+ return null;
53
+ };
54
+ Toast.contextType = context_1.AppBridgeContext;
55
+ return Toast;
56
+ }(react_1.default.PureComponent));
57
+ exports.default = Toast;
@@ -0,0 +1,3 @@
1
+ import Toast from './Toast';
2
+ export { Props } from './Toast';
3
+ export default Toast;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var Toast_1 = __importDefault(require("./Toast"));
7
+ exports.default = Toast_1.default;
@@ -0,0 +1,9 @@
1
+ export { default as ContextualSaveBar, Props as ContextualSaveBarProps } from './ContextualSaveBar';
2
+ export { default as Provider, Props as ProviderProps } from './Provider';
3
+ export { default as Loading } from './Loading';
4
+ export { default as Toast, Props as ToastProps } from './Toast';
5
+ export { default as TitleBar } from './TitleBar';
6
+ export { default as Modal, Props as ModalProps, ModalContent } from './Modal';
7
+ export { default as ResourcePicker, Props as ResourcePickerProps } from './ResourcePicker';
8
+ export * from './RoutePropagator';
9
+ export * from './ClientRouter';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ var ContextualSaveBar_1 = require("./ContextualSaveBar");
14
+ Object.defineProperty(exports, "ContextualSaveBar", { enumerable: true, get: function () { return ContextualSaveBar_1.default; } });
15
+ var Provider_1 = require("./Provider");
16
+ Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return Provider_1.default; } });
17
+ var Loading_1 = require("./Loading");
18
+ Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return Loading_1.default; } });
19
+ var Toast_1 = require("./Toast");
20
+ Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_1.default; } });
21
+ var TitleBar_1 = require("./TitleBar");
22
+ Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return TitleBar_1.default; } });
23
+ var Modal_1 = require("./Modal");
24
+ Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return Modal_1.default; } });
25
+ Object.defineProperty(exports, "ModalContent", { enumerable: true, get: function () { return Modal_1.ModalContent; } });
26
+ var ResourcePicker_1 = require("./ResourcePicker");
27
+ Object.defineProperty(exports, "ResourcePicker", { enumerable: true, get: function () { return ResourcePicker_1.default; } });
28
+ __exportStar(require("./RoutePropagator"), exports);
29
+ __exportStar(require("./ClientRouter"), exports);
package/context.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ClientApplication } from '@shopify/app-bridge/client';
2
+ /**
3
+ * App Bridge context consumer type.
4
+ *
5
+ * @public
6
+ */
7
+ export declare type IAppBridgeContext = ClientApplication<any> | null;
8
+ /**
9
+ * App Bridge context.
10
+ *
11
+ * @public
12
+ */
13
+ export declare const AppBridgeContext: import("react").Context<IAppBridgeContext>;
package/context.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBridgeContext = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * App Bridge context.
7
+ *
8
+ * @public
9
+ */
10
+ exports.AppBridgeContext = react_1.createContext(null);
@@ -0,0 +1,3 @@
1
+ export { useContextualSaveBar } from './useContextualSaveBar';
2
+ export { useNavigationHistory } from './useNavigationHistory';
3
+ export { useToast } from './useToast';
package/hooks/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useContextualSaveBar_1 = require("./useContextualSaveBar");
4
+ Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
5
+ var useNavigationHistory_1 = require("./useNavigationHistory");
6
+ Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
7
+ var useToast_1 = require("./useToast");
8
+ Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
@@ -0,0 +1 @@
1
+ export { useContextualSaveBar } from './useContextualSaveBar';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useContextualSaveBar_1 = require("./useContextualSaveBar");
4
+ Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
@@ -0,0 +1,13 @@
1
+ import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
2
+ export interface Props {
3
+ discardAction: DiscardAction & {
4
+ onAction(): void;
5
+ };
6
+ saveAction: ContextAction & {
7
+ onAction(): void;
8
+ };
9
+ fullWidth?: boolean;
10
+ leaveConfirmationDisable?: boolean;
11
+ visible?: boolean;
12
+ }
13
+ export declare function useContextualSaveBar({ discardAction, saveAction, fullWidth, leaveConfirmationDisable, visible, }: Props): null;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useContextualSaveBar = void 0;
15
+ var react_1 = require("react");
16
+ var ContextualSaveBar_1 = require("@shopify/app-bridge/actions/ContextualSaveBar");
17
+ var useAppBridge_1 = require("../../useAppBridge");
18
+ function useContextualSaveBar(_a) {
19
+ var discardAction = _a.discardAction, saveAction = _a.saveAction, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
20
+ var app = useAppBridge_1.useAppBridge();
21
+ var onSaveAction = saveAction.onAction, saveActionProps = __rest(saveAction, ["onAction"]);
22
+ var onDiscardAction = discardAction.onAction, discardActionProps = __rest(discardAction, ["onAction"]);
23
+ /* We want to reuse the same ContextualSaveBar instance, even when props change
24
+ * (so we don't include all the props in the dependency array).
25
+ * Instead of recreating the component on every change, we use the set method,
26
+ * in the useEffect block below, to dispatch updates when props change.
27
+ */
28
+ var contextualSaveBar = react_1.useMemo(function () {
29
+ return ContextualSaveBar_1.create(app, {
30
+ saveAction: saveActionProps,
31
+ discardAction: discardActionProps,
32
+ fullWidth: fullWidth,
33
+ leaveConfirmationDisable: leaveConfirmationDisable,
34
+ });
35
+ }, [app]);
36
+ react_1.useEffect(function () {
37
+ contextualSaveBar.set({
38
+ saveAction: saveActionProps,
39
+ discardAction: discardActionProps,
40
+ fullWidth: fullWidth,
41
+ leaveConfirmationDisable: leaveConfirmationDisable,
42
+ }, Boolean(visible));
43
+ }, [
44
+ contextualSaveBar,
45
+ saveActionProps,
46
+ discardActionProps,
47
+ fullWidth,
48
+ leaveConfirmationDisable,
49
+ visible,
50
+ ]);
51
+ react_1.useEffect(function () {
52
+ contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, onDiscardAction);
53
+ contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, onSaveAction);
54
+ return function () {
55
+ contextualSaveBar.unsubscribe();
56
+ };
57
+ }, [contextualSaveBar]);
58
+ react_1.useEffect(function () {
59
+ if (visible) {
60
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
61
+ }
62
+ else {
63
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
64
+ }
65
+ }, [contextualSaveBar, visible]);
66
+ return null;
67
+ }
68
+ exports.useContextualSaveBar = useContextualSaveBar;
@@ -0,0 +1 @@
1
+ export { useNavigationHistory } from './useNavigationHistory';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useNavigationHistory_1 = require("./useNavigationHistory");
4
+ Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * useNavigationHistory hook
3
+ *
4
+ * @remarks
5
+ * React hook which wraps the Shopify App Bridge History action.
6
+ *
7
+ * @public
8
+ */
9
+ export declare function useNavigationHistory(): {
10
+ push: (location: {
11
+ pathname: string;
12
+ }) => void;
13
+ replace: (location: {
14
+ pathname: string;
15
+ }) => void;
16
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNavigationHistory = void 0;
4
+ var react_1 = require("react");
5
+ var actions_1 = require("@shopify/app-bridge/actions");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ /**
8
+ * useNavigationHistory hook
9
+ *
10
+ * @remarks
11
+ * React hook which wraps the Shopify App Bridge History action.
12
+ *
13
+ * @public
14
+ */
15
+ function useNavigationHistory() {
16
+ var app = useAppBridge_1.useAppBridge();
17
+ return react_1.useMemo(function () {
18
+ var history = actions_1.History.create(app);
19
+ function push(location) {
20
+ history.dispatch(actions_1.History.Action.PUSH, location.pathname);
21
+ }
22
+ function replace(location) {
23
+ history.dispatch(actions_1.History.Action.REPLACE, location.pathname);
24
+ }
25
+ return { push: push, replace: replace };
26
+ }, []);
27
+ }
28
+ exports.useNavigationHistory = useNavigationHistory;
@@ -0,0 +1 @@
1
+ export { useToast } from './useToast';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useToast_1 = require("./useToast");
4
+ Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
@@ -0,0 +1,15 @@
1
+ import type { Payload } from '@shopify/app-bridge/actions/Toast';
2
+ export declare const DEFAULT_TOAST_DURATION = 5000;
3
+ /**
4
+ * useToast hook
5
+ *
6
+ * @remarks
7
+ * React hook which wraps the Shopify App Bridge Toast action.
8
+ *
9
+ * @public
10
+ */
11
+ export declare function useToast(): {
12
+ show: ({ content: message, duration, isError, onDismiss, }: Omit<Payload, 'message'> & {
13
+ content: string;
14
+ }) => void;
15
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToast = exports.DEFAULT_TOAST_DURATION = void 0;
4
+ var react_1 = require("react");
5
+ var Toast_1 = require("@shopify/app-bridge/actions/Toast");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ exports.DEFAULT_TOAST_DURATION = 5000;
8
+ /**
9
+ * useToast hook
10
+ *
11
+ * @remarks
12
+ * React hook which wraps the Shopify App Bridge Toast action.
13
+ *
14
+ * @public
15
+ */
16
+ function useToast() {
17
+ var app = useAppBridge_1.useAppBridge();
18
+ var toast;
19
+ var show = react_1.useCallback(function (_a) {
20
+ var message = _a.content, _b = _a.duration, duration = _b === void 0 ? exports.DEFAULT_TOAST_DURATION : _b, isError = _a.isError, onDismiss = _a.onDismiss;
21
+ toast = Toast_1.create(app, {
22
+ message: message,
23
+ isError: isError,
24
+ duration: duration,
25
+ });
26
+ toast.dispatch(Toast_1.Action.SHOW);
27
+ if (onDismiss) {
28
+ toast.subscribe(Toast_1.Action.CLEAR, onDismiss);
29
+ }
30
+ }, [app]);
31
+ react_1.useEffect(function () {
32
+ return function () {
33
+ toast.unsubscribe();
34
+ };
35
+ }, []);
36
+ return { show: show };
37
+ }
38
+ exports.useToast = useToast;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { AppBridgeContext as Context } from './context';
3
+ export { useAppBridge } from './useAppBridge';
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./components"), exports);
14
+ var context_1 = require("./context");
15
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
16
+ var useAppBridge_1 = require("./useAppBridge");
17
+ Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/app-bridge-react",
3
- "version": "2.0.18",
3
+ "version": "2.0.21",
4
4
  "types": "index.d.ts",
5
5
  "main": "index.js",
6
6
  "unpkg": "umd/index.js",
@@ -8,6 +8,7 @@
8
8
  "files": [
9
9
  "/components/",
10
10
  "/umd/",
11
+ "/hooks/",
11
12
  "/utilities/",
12
13
  "/context.d.ts",
13
14
  "/context.js",
@@ -44,7 +45,7 @@
44
45
  }
45
46
  ],
46
47
  "dependencies": {
47
- "@shopify/app-bridge": "^2.0.18"
48
+ "@shopify/app-bridge": "^2.0.21"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/react": "^17.0.38",
@@ -54,5 +55,5 @@
54
55
  "peerDependencies": {
55
56
  "react": "^16.0.0 || ^17.0.0"
56
57
  },
57
- "gitHead": "9d45b5643e94febbccc111e198db7fafe309c2a0"
58
+ "gitHead": "343a8216ef007c80076142c5da308f012ab15d37"
58
59
  }
package/types.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { Redirect } from '@shopify/app-bridge/actions';
2
+ export declare type Target = Exclude<keyof typeof Redirect.Action, 'ADMIN_SECTION'>;
3
+ export interface ActionProps {
4
+ /** Content the action displays */
5
+ content?: string;
6
+ /** Should the action be styled as destructive */
7
+ destructive?: boolean;
8
+ /** Should the action be disabled */
9
+ disabled?: boolean;
10
+ /** Should the action be loading */
11
+ loading?: boolean;
12
+ /** Forces url to open in a new tab */
13
+ external?: boolean;
14
+ /** Use Polaris plain styling */
15
+ plain?: boolean;
16
+ /**
17
+ * Where to display the target link
18
+ * @default 'APP'
19
+ */
20
+ target?: Target;
21
+ /** A destination to link to */
22
+ url?: string;
23
+ /** Callback when an action takes place */
24
+ onAction?(): void;
25
+ }
26
+ export interface ActionGroupProps {
27
+ /** Action group title */
28
+ title: string;
29
+ /** Use Polaris plain styling */
30
+ plain?: boolean;
31
+ /** List of actions */
32
+ actions: ActionProps[];
33
+ }
package/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });