@shopify/app-bridge-react 2.0.30 → 3.0.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,47 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.1](https://github.com/Shopify/app-bridge/compare/v3.0.0...v3.0.1) (2022-06-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * add types for useRef ([9a421ac](https://github.com/Shopify/app-bridge/commit/9a421ac22ef03ce2d409d203e9498fc51b917ad9))
12
+ * rename Picker to unstable_Picker ([f82eab7](https://github.com/Shopify/app-bridge/commit/f82eab7629f64ae312847e0e49dd6d21f11aef8b))
13
+ * update missing picker ([7fefc00](https://github.com/Shopify/app-bridge/commit/7fefc00a0ec11fa21b8b83c9e5df8d2e8edb20e7))
14
+ * update preProps and args for useEffect ([c44ef10](https://github.com/Shopify/app-bridge/commit/c44ef102d4964f837dbbe434e1ea8e51fc211bd1))
15
+ * use default items for picker ([5cf5eae](https://github.com/Shopify/app-bridge/commit/5cf5eae18114a546586fe7534c27213fb7008d3d))
16
+
17
+
18
+ ### Features
19
+
20
+ * add input props ([d2ebb13](https://github.com/Shopify/app-bridge/commit/d2ebb130dfddee65d9d3ad7c39d716a219d29a9d))
21
+ * add Picker react component ([bea5429](https://github.com/Shopify/app-bridge/commit/bea542924e845f7b98ca76d1ff3b5b532121da27))
22
+
23
+
24
+
25
+
26
+
27
+ # [3.0.0](https://github.com/Shopify/app-bridge/compare/v2.1.0...v3.0.0) (2022-05-24)
28
+
29
+
30
+ ### Features
31
+
32
+ * update useContextualSaveBar API ([4a5477f](https://github.com/Shopify/app-bridge/commit/4a5477f06f879b377bcc18e197205fbd3bc1b5d6))
33
+ * update useToast API to match UI Extensions pattern ([157363d](https://github.com/Shopify/app-bridge/commit/157363d1439acfc14cf5c44d452c1bbb3b9a2cf1))
34
+
35
+
36
+
37
+
38
+
39
+ # [2.1.0](https://github.com/Shopify/app-bridge/compare/v2.0.30...v2.1.0) (2022-05-24)
40
+
41
+ **Note:** Version bump only for package @shopify/app-bridge-react
42
+
43
+
44
+
45
+
46
+
6
47
  ## [2.0.30](https://github.com/Shopify/app-bridge/compare/v2.0.29...v2.0.30) (2022-05-18)
7
48
 
8
49
  **Note:** Version bump only for package @shopify/app-bridge-react
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # `@shopify/app-bridge-react`
2
2
 
3
- **Shopify is doubling our engineering staff in 2021! [Join our team and work on libraries like this one.](https://smrtr.io/5GGrc)**
4
-
5
3
  Shopify App Bridge offers React component wrappers for some App Bridge actions. This is a great option if you are already using React and want to follow familiar patterns.
6
4
 
7
5
  Instead of using App Bridge actions directly:
@@ -74,6 +72,96 @@ function RedirectButton() {
74
72
  }
75
73
  ```
76
74
 
75
+ ## Migrating from 2.x.x to 3.0.0
76
+
77
+ There are two breaking API changes in version 3.0.0.
78
+
79
+ - `useContextualSaveBar`
80
+ - `useToast`
81
+
82
+ ### useContextualSaveBar
83
+
84
+ In version 2.x.x, `useContextualSaveBar` was called with all of its options. It then created the contextual save bar and dispatched show and hide functions as an internal side effect based on the `visible` prop and any changes in options. It did not return anything.
85
+
86
+ #### Example code
87
+
88
+ ```tsx
89
+ useContextualSaveBar({
90
+ discardAction,
91
+ saveAction,
92
+ fullWidth,
93
+ leaveConfirmationDisable,
94
+ visible,
95
+ });
96
+ ```
97
+
98
+ In version 3.0.0, `useContextualSaveBar` becomes more declarative. The hook is called without any props and it returns several objects and methods that can be used to update contextual save bar options, as well as to show and hide the component.
99
+
100
+ #### Example code
101
+
102
+ ```tsx
103
+ const {show, hide, saveAction, discardAction} = useContextualSaveBar();
104
+ const fullWidth = true;
105
+ const leaveConfirmationDisabled = false;
106
+
107
+ <Button
108
+ primary
109
+ onClick={() => {
110
+ show(fullWidth, leaveConfirmationDisabled);
111
+ discardAction.setOptions({onAction: () => console.log('On discard')});
112
+ saveAction.setOptions({onAction: () => console.log('On save')});
113
+ }}
114
+ >
115
+ Show ContextualSaveBar
116
+ </Button>
117
+ <Button onClick={hide}>Hide ContextualSaveBar</Button>
118
+ ```
119
+
120
+ See [useContextualSaveBar docs](https://shopify.dev/apps/tools/app-bridge/react-components/contextual-save-bar) for more details.
121
+
122
+ ### useToast
123
+
124
+ In version 2.x.x, `useToast` returns a `show` method that accepts one prop - an object with the following properties:
125
+
126
+ - `content`
127
+ - `duration`
128
+ - `isError`
129
+ - `onDismiss`
130
+
131
+ All the props except `content` are optional.
132
+
133
+ #### Example code
134
+
135
+ ```tsx
136
+ const {show} = useToast
137
+
138
+ show({
139
+ content: 'Success!,
140
+ duration: 2000,
141
+ isError: false,
142
+ onDismiss: () => console.log('Dismissed'),
143
+ })
144
+ ```
145
+
146
+ In version 3.0.0, the `content` moves to a top-level prop and the remaining properties are passed in as an optional options prop (all properties in the options object remain optional).
147
+ `
148
+
149
+ #### Example code
150
+
151
+ ```tsx
152
+ const {show} = useToast;
153
+
154
+ show('Success!', {
155
+ duration: 2000,
156
+ isError: false,
157
+ onDismiss: () => console.log('Dismissed'),
158
+ });
159
+ ```
160
+
161
+ See [useToast docs](https://shopify.dev/apps/tools/app-bridge/react-components/toast) for more details.
162
+
163
+ ## Legacy support
164
+
77
165
  If you are using App Bridge `v1.24.0` and below, or your project does not support React hooks, alternative methods on how to access `app` can be found in the [Provider docs](https://shopify.dev/tools/app-bridge/react-components/provider#accessing-the-app-bridge-client-directly).
78
166
 
79
167
  See [Shopify Developers](https://shopify.dev/tools/app-bridge/react-components) for full documentation.
@@ -1,9 +1,9 @@
1
1
  import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
2
2
  export interface Props {
3
- discardAction: DiscardAction & {
3
+ discardAction?: DiscardAction & {
4
4
  onAction(): void;
5
5
  };
6
- saveAction: ContextAction & {
6
+ saveAction?: ContextAction & {
7
7
  onAction(): void;
8
8
  };
9
9
  fullWidth?: boolean;
@@ -16,7 +16,7 @@ var actions_1 = require("@shopify/app-bridge/actions");
16
16
  var useAppBridge_1 = require("../../useAppBridge");
17
17
  var Action = actions_1.ContextualSaveBar.Action, create = actions_1.ContextualSaveBar.create;
18
18
  function ContextualSaveBar(_a) {
19
- var discardAction = _a.discardAction, saveAction = _a.saveAction, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
19
+ var _b = _a.discardAction, discardAction = _b === void 0 ? { onAction: function () { return null; } } : _b, _c = _a.saveAction, saveAction = _c === void 0 ? { onAction: function () { return null; } } : _c, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
20
20
  var app = useAppBridge_1.useAppBridge();
21
21
  var onSaveAction = saveAction.onAction, saveActionProps = __rest(saveAction, ["onAction"]);
22
22
  var onDiscardAction = discardAction.onAction, discardActionProps = __rest(discardAction, ["onAction"]);
@@ -50,7 +50,7 @@ function ContextualSaveBar(_a) {
50
50
  return function () {
51
51
  contextualSaveBar.unsubscribe();
52
52
  };
53
- }, [contextualSaveBar]);
53
+ }, [contextualSaveBar, onDiscardAction, onSaveAction]);
54
54
  react_1.useEffect(function () {
55
55
  if (visible) {
56
56
  contextualSaveBar.dispatch(Action.SHOW);
@@ -6,5 +6,6 @@ export { default as Provider, Props as ProviderProps } from './Provider';
6
6
  export { default as ResourcePicker, Props as ResourcePickerProps } from './ResourcePicker';
7
7
  export { default as TitleBar } from './TitleBar';
8
8
  export { default as Toast, Props as ToastProps } from './Toast';
9
+ export { default as unstable_Picker } from './unstable_Picker';
9
10
  export * from './RoutePropagator';
10
11
  export * from './ClientRouter';
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
16
+ exports.unstable_Picker = exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
17
17
  var ContextualSaveBar_1 = require("./ContextualSaveBar");
18
18
  Object.defineProperty(exports, "ContextualSaveBar", { enumerable: true, get: function () { return __importDefault(ContextualSaveBar_1).default; } });
19
19
  var Loading_1 = require("./Loading");
@@ -31,5 +31,7 @@ var TitleBar_1 = require("./TitleBar");
31
31
  Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return __importDefault(TitleBar_1).default; } });
32
32
  var Toast_1 = require("./Toast");
33
33
  Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return __importDefault(Toast_1).default; } });
34
+ var unstable_Picker_1 = require("./unstable_Picker");
35
+ Object.defineProperty(exports, "unstable_Picker", { enumerable: true, get: function () { return __importDefault(unstable_Picker_1).default; } });
34
36
  __exportStar(require("./RoutePropagator"), exports);
35
37
  __exportStar(require("./ClientRouter"), exports);
@@ -0,0 +1,3 @@
1
+ import Picker from './unstable_Picker';
2
+ export { Props } from './unstable_Picker';
3
+ export default Picker;
@@ -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 unstable_Picker_1 = __importDefault(require("./unstable_Picker"));
7
+ exports.default = unstable_Picker_1.default;
@@ -0,0 +1,21 @@
1
+ import { SearchPayload, SelectPayload } from '@shopify/app-bridge/actions/Picker';
2
+ import type { BaseResource } from '@shopify/app-bridge/actions/Picker';
3
+ /**
4
+ * @unstable This API may be updated without warning in the future
5
+ */
6
+ export interface Props {
7
+ open: boolean;
8
+ items: BaseResource[];
9
+ selectedItems?: BaseResource[];
10
+ maxSelectable?: number;
11
+ title?: string;
12
+ loading?: boolean;
13
+ searchQueryPlaceholder?: string;
14
+ searchQuery?: string;
15
+ primaryActionLabel?: string;
16
+ secondaryActionLabel?: string;
17
+ onCancel?(): void;
18
+ onSelect?(selectPayload: SelectPayload): void;
19
+ onSearch?(searchPayload: SearchPayload): void;
20
+ }
21
+ export default function Picker(props: Props): null;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var react_1 = require("react");
15
+ var Picker_1 = require("@shopify/app-bridge/actions/Picker");
16
+ var useAppBridge_1 = require("../../useAppBridge");
17
+ function Picker(props) {
18
+ var app = useAppBridge_1.useAppBridge();
19
+ var prevProps = react_1.useRef({ open: false, items: [] });
20
+ var picker = react_1.useMemo(function () { return Picker_1.create(app, getActionOptions(props)); }, [app]);
21
+ react_1.useEffect(function () {
22
+ var _a;
23
+ if (((_a = prevProps.current) === null || _a === void 0 ? void 0 : _a.open) === props.open) {
24
+ return;
25
+ }
26
+ if (props.open) {
27
+ picker.dispatch(Picker_1.Action.OPEN);
28
+ }
29
+ else {
30
+ picker.dispatch(Picker_1.Action.CANCEL);
31
+ }
32
+ }, [props.open]);
33
+ react_1.useEffect(function () {
34
+ var unsubscribeList = [];
35
+ if (props.onSelect) {
36
+ unsubscribeList.push(picker.subscribe(Picker_1.Action.SELECT, props.onSelect));
37
+ }
38
+ if (props.onCancel) {
39
+ unsubscribeList.push(picker.subscribe(Picker_1.Action.CANCEL, props.onCancel));
40
+ }
41
+ if (props.onSearch) {
42
+ unsubscribeList.push(picker.subscribe(Picker_1.Action.SEARCH, props.onSearch));
43
+ }
44
+ return function () {
45
+ unsubscribeList.forEach(function (unsubscribe) { return unsubscribe(); });
46
+ };
47
+ }, [props.onSelect, props.onCancel, props.onSearch]);
48
+ react_1.useEffect(function () {
49
+ var shouldUpdate = JSON.stringify(__assign(__assign({}, prevProps.current), { open: undefined })) !==
50
+ JSON.stringify(__assign(__assign({}, props), { open: undefined }));
51
+ if (!shouldUpdate) {
52
+ return;
53
+ }
54
+ picker.set(getActionOptions(props));
55
+ prevProps.current = props;
56
+ }, [props]);
57
+ return null;
58
+ }
59
+ exports.default = Picker;
60
+ function getActionOptions(_a) {
61
+ var items = _a.items, selectedItems = _a.selectedItems, maxSelectable = _a.maxSelectable, title = _a.title, loading = _a.loading, searchQueryPlaceholder = _a.searchQueryPlaceholder, searchQuery = _a.searchQuery, primaryActionLabel = _a.primaryActionLabel, secondaryActionLabel = _a.secondaryActionLabel;
62
+ var result = {
63
+ items: items,
64
+ selectedItems: selectedItems,
65
+ maxSelectable: maxSelectable,
66
+ title: title,
67
+ loading: loading,
68
+ searchQueryPlaceholder: searchQueryPlaceholder,
69
+ searchQuery: searchQuery,
70
+ primaryActionLabel: primaryActionLabel,
71
+ secondaryActionLabel: secondaryActionLabel,
72
+ };
73
+ return result;
74
+ }
package/hooks/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
+ export { useAppBridgeState } from './useAppBridgeState';
1
2
  export { useContextualSaveBar } from './useContextualSaveBar';
2
3
  export { useFeaturesAvailable } from './useFeaturesAvailable';
3
- export { useFeatureRequest } from './useFeatureRequest';
4
4
  export type { FeaturesAvailable } from './useFeaturesAvailable';
5
+ export { useFeatureRequest } from './useFeatureRequest';
6
+ export { useNavigate } from './useNavigate';
5
7
  export { useNavigationHistory } from './useNavigationHistory';
6
8
  export { useToast } from './useToast';
7
- export { useAppBridgeState } from './useAppBridgeState';
8
- export { useNavigate } from './useNavigate';
package/hooks/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useNavigate = exports.useAppBridgeState = exports.useToast = exports.useNavigationHistory = exports.useFeatureRequest = exports.useFeaturesAvailable = exports.useContextualSaveBar = void 0;
3
+ exports.useToast = exports.useNavigationHistory = exports.useNavigate = exports.useFeatureRequest = exports.useFeaturesAvailable = exports.useContextualSaveBar = exports.useAppBridgeState = void 0;
4
+ var useAppBridgeState_1 = require("./useAppBridgeState");
5
+ Object.defineProperty(exports, "useAppBridgeState", { enumerable: true, get: function () { return useAppBridgeState_1.useAppBridgeState; } });
4
6
  var useContextualSaveBar_1 = require("./useContextualSaveBar");
5
7
  Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
6
8
  var useFeaturesAvailable_1 = require("./useFeaturesAvailable");
7
9
  Object.defineProperty(exports, "useFeaturesAvailable", { enumerable: true, get: function () { return useFeaturesAvailable_1.useFeaturesAvailable; } });
8
10
  var useFeatureRequest_1 = require("./useFeatureRequest");
9
11
  Object.defineProperty(exports, "useFeatureRequest", { enumerable: true, get: function () { return useFeatureRequest_1.useFeatureRequest; } });
12
+ var useNavigate_1 = require("./useNavigate");
13
+ Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return useNavigate_1.useNavigate; } });
10
14
  var useNavigationHistory_1 = require("./useNavigationHistory");
11
15
  Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
12
16
  var useToast_1 = require("./useToast");
13
17
  Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
14
- var useAppBridgeState_1 = require("./useAppBridgeState");
15
- Object.defineProperty(exports, "useAppBridgeState", { enumerable: true, get: function () { return useAppBridgeState_1.useAppBridgeState; } });
16
- var useNavigate_1 = require("./useNavigate");
17
- Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return useNavigate_1.useNavigate; } });
@@ -1,13 +1,31 @@
1
1
  import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
2
- export interface Props {
3
- discardAction: DiscardAction & {
4
- onAction(): void;
2
+ interface ShowOptions {
3
+ fullWidth?: boolean;
4
+ leaveConfirmationDisabled?: boolean;
5
+ }
6
+ interface SaveActionOptions extends ContextAction {
7
+ onAction?: () => void;
8
+ }
9
+ interface DiscardActionOptions extends DiscardAction {
10
+ onAction?: () => void;
11
+ }
12
+ interface ContextualSaveBarHook {
13
+ show: ({ fullWidth, leaveConfirmationDisabled }?: ShowOptions) => void;
14
+ hide: () => void;
15
+ saveAction: {
16
+ setOptions: (options: Partial<SaveActionOptions>) => void;
5
17
  };
6
- saveAction: ContextAction & {
7
- onAction(): void;
18
+ discardAction: {
19
+ setOptions: (options: Partial<DiscardActionOptions>) => void;
8
20
  };
9
- fullWidth?: boolean;
10
- leaveConfirmationDisable?: boolean;
11
- visible?: boolean;
12
21
  }
13
- export declare function useContextualSaveBar({ discardAction, saveAction, fullWidth, leaveConfirmationDisable, visible, }: Props): null;
22
+ /**
23
+ * useContextualSaveBar hook
24
+ *
25
+ * @remarks
26
+ * React hook which wraps the Shopify App Bridge ContextualSaveBar action.
27
+ *
28
+ * @public
29
+ */
30
+ export declare function useContextualSaveBar(): ContextualSaveBarHook;
31
+ export {};
@@ -15,54 +15,63 @@ exports.useContextualSaveBar = void 0;
15
15
  var react_1 = require("react");
16
16
  var ContextualSaveBar_1 = require("@shopify/app-bridge/actions/ContextualSaveBar");
17
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;
18
+ /**
19
+ * useContextualSaveBar hook
20
+ *
21
+ * @remarks
22
+ * React hook which wraps the Shopify App Bridge ContextualSaveBar action.
23
+ *
24
+ * @public
25
+ */
26
+ function useContextualSaveBar() {
20
27
  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 _a = react_1.useState(), onSaveAction = _a[0], setOnSaveAction = _a[1];
29
+ var _b = react_1.useState(), onDiscardAction = _b[0], setOnDiscardAction = _b[1];
28
30
  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
- });
31
+ return ContextualSaveBar_1.create(app);
35
32
  }, [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
- };
33
+ var show = react_1.useCallback(function (options) {
34
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
35
+ if (options) {
36
+ contextualSaveBar.set(options);
37
+ }
38
+ }, [contextualSaveBar]);
39
+ var hide = react_1.useCallback(function () {
40
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
57
41
  }, [contextualSaveBar]);
42
+ var saveAction = react_1.useMemo(function () { return ({
43
+ setOptions: function (_a) {
44
+ var onAction = _a.onAction, saveAction = __rest(_a, ["onAction"]);
45
+ setOnSaveAction(function () { return onAction; });
46
+ if (Object.keys(saveAction).length) {
47
+ contextualSaveBar.set({ saveAction: saveAction });
48
+ }
49
+ },
50
+ }); }, [contextualSaveBar]);
51
+ var discardAction = react_1.useMemo(function () { return ({
52
+ setOptions: function (_a) {
53
+ var onAction = _a.onAction, discardAction = __rest(_a, ["onAction"]);
54
+ setOnDiscardAction(function () { return onAction; });
55
+ if (Object.keys(discardAction).length) {
56
+ contextualSaveBar.set({ discardAction: discardAction });
57
+ }
58
+ },
59
+ }); }, [contextualSaveBar]);
58
60
  react_1.useEffect(function () {
59
- if (visible) {
60
- contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
61
- }
62
- else {
61
+ return contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, function () {
63
62
  contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
64
- }
65
- }, [contextualSaveBar, visible]);
66
- return null;
63
+ onDiscardAction === null || onDiscardAction === void 0 ? void 0 : onDiscardAction();
64
+ });
65
+ }, [contextualSaveBar, onDiscardAction]);
66
+ react_1.useEffect(function () {
67
+ return contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, function () {
68
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
69
+ onSaveAction === null || onSaveAction === void 0 ? void 0 : onSaveAction();
70
+ });
71
+ }, [contextualSaveBar, onSaveAction]);
72
+ react_1.useEffect(function () {
73
+ contextualSaveBar.unsubscribe();
74
+ }, [contextualSaveBar, onSaveAction]);
75
+ return { show: show, hide: hide, saveAction: saveAction, discardAction: discardAction };
67
76
  }
68
77
  exports.useContextualSaveBar = useContextualSaveBar;
@@ -9,7 +9,5 @@ export declare const DEFAULT_TOAST_DURATION = 5000;
9
9
  * @public
10
10
  */
11
11
  export declare function useToast(): {
12
- show: ({ content: message, duration, isError, onDismiss, }: Omit<Payload, 'message'> & {
13
- content: string;
14
- }) => void;
12
+ show: (content: string, options?: Omit<Payload, "message"> | undefined) => void;
15
13
  };
@@ -16,16 +16,15 @@ exports.DEFAULT_TOAST_DURATION = 5000;
16
16
  function useToast() {
17
17
  var app = useAppBridge_1.useAppBridge();
18
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;
19
+ var show = react_1.useCallback(function (content, options) {
21
20
  toast = Toast_1.create(app, {
22
- message: message,
23
- isError: isError,
24
- duration: duration,
21
+ message: content,
22
+ isError: options === null || options === void 0 ? void 0 : options.isError,
23
+ duration: (options === null || options === void 0 ? void 0 : options.duration) || exports.DEFAULT_TOAST_DURATION,
25
24
  });
26
25
  toast.dispatch(Toast_1.Action.SHOW);
27
- if (onDismiss) {
28
- toast.subscribe(Toast_1.Action.CLEAR, onDismiss);
26
+ if (options === null || options === void 0 ? void 0 : options.onDismiss) {
27
+ toast.subscribe(Toast_1.Action.CLEAR, options === null || options === void 0 ? void 0 : options.onDismiss);
29
28
  }
30
29
  }, [app]);
31
30
  react_1.useEffect(function () {
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './components';
2
1
  export { AppBridgeContext as Context } from './context';
3
2
  export { useAppBridge } from './useAppBridge';
3
+ export * from './components';
4
4
  export * from './hooks';
package/index.js CHANGED
@@ -11,9 +11,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.useAppBridge = exports.Context = void 0;
14
- __exportStar(require("./components"), exports);
15
14
  var context_1 = require("./context");
16
15
  Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
17
16
  var useAppBridge_1 = require("./useAppBridge");
18
17
  Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
18
+ __exportStar(require("./components"), exports);
19
19
  __exportStar(require("./hooks"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/app-bridge-react",
3
- "version": "2.0.30",
3
+ "version": "3.0.1",
4
4
  "types": "index.d.ts",
5
5
  "main": "index.js",
6
6
  "unpkg": "umd/index.js",
@@ -45,7 +45,7 @@
45
45
  }
46
46
  ],
47
47
  "dependencies": {
48
- "@shopify/app-bridge": "^2.0.30"
48
+ "@shopify/app-bridge": "^3.0.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/react": "^17.0.38",
@@ -55,5 +55,5 @@
55
55
  "peerDependencies": {
56
56
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
57
57
  },
58
- "gitHead": "36f0dab294bc24817084cb917de8c0fbadd4ff9f"
58
+ "gitHead": "0b69164e205dcfdb3aac8a626cbc7919d59a6670"
59
59
  }