@homebound/beam 2.79.0 → 2.79.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/dist/components/BeamContext.d.ts +3 -3
- package/dist/components/SuperDrawer/ConfirmCloseModal.d.ts +3 -1
- package/dist/components/SuperDrawer/ConfirmCloseModal.js +7 -6
- package/dist/components/SuperDrawer/useSuperDrawer.d.ts +3 -2
- package/dist/components/SuperDrawer/useSuperDrawer.js +8 -4
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MutableRefObject, ReactNode } from "react";
|
|
2
2
|
import { ModalProps } from "./Modal/Modal";
|
|
3
3
|
import { ContentStack } from "./SuperDrawer/useSuperDrawer";
|
|
4
|
-
import { CheckFn } from "../types";
|
|
4
|
+
import { CanCloseCheck, CheckFn } from "../types";
|
|
5
5
|
/** The internal state of our Beam context; see useModal and useSuperDrawer for the public APIs. */
|
|
6
6
|
export interface BeamContextState {
|
|
7
7
|
modalState: MutableRefObject<ModalProps | undefined>;
|
|
@@ -15,9 +15,9 @@ export interface BeamContextState {
|
|
|
15
15
|
/** SuperDrawer contentStack, i.e. the main/non-detail content + 0-N detail contents. */
|
|
16
16
|
drawerContentStack: MutableRefObject<readonly ContentStack[]>;
|
|
17
17
|
/** Checks when closing SuperDrawer, for the main/non-detail drawer content. */
|
|
18
|
-
drawerCanCloseChecks: MutableRefObject<
|
|
18
|
+
drawerCanCloseChecks: MutableRefObject<CanCloseCheck[]>;
|
|
19
19
|
/** Checks when closing SuperDrawer Details, a double array to keep per-detail lists. */
|
|
20
|
-
drawerCanCloseDetailsChecks: MutableRefObject<
|
|
20
|
+
drawerCanCloseDetailsChecks: MutableRefObject<CanCloseCheck[][]>;
|
|
21
21
|
/** The ref for defining the portal element's location for Tab actions */
|
|
22
22
|
tabActionsRef: MutableRefObject<HTMLDivElement | null>;
|
|
23
23
|
/** The div for Tab actions to portal into */
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
interface ConfirmCloseModalProps {
|
|
2
2
|
onClose: () => void;
|
|
3
|
+
discardText?: string;
|
|
4
|
+
continueText?: string;
|
|
3
5
|
}
|
|
4
6
|
/** Modal content to appear when a close checks fails */
|
|
5
|
-
export declare function ConfirmCloseModal(
|
|
7
|
+
export declare function ConfirmCloseModal(props: ConfirmCloseModalProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
6
8
|
export {};
|
|
@@ -5,7 +5,8 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
|
5
5
|
const src_1 = require("../..");
|
|
6
6
|
const BeamContext_1 = require("../BeamContext");
|
|
7
7
|
/** Modal content to appear when a close checks fails */
|
|
8
|
-
function ConfirmCloseModal(
|
|
8
|
+
function ConfirmCloseModal(props) {
|
|
9
|
+
const { onClose, discardText = "Discard Changes", continueText = "Continue Editing" } = props;
|
|
9
10
|
const { modalState } = (0, BeamContext_1.useBeamContext)();
|
|
10
11
|
// TODO: Change to closeModal from useModal when canCloseChecks are reset
|
|
11
12
|
function closeModal() {
|
|
@@ -13,10 +14,10 @@ function ConfirmCloseModal({ onClose }) {
|
|
|
13
14
|
// after a close and could/will cause other close attempts to fail.
|
|
14
15
|
modalState.current = undefined;
|
|
15
16
|
}
|
|
16
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(src_1.ModalHeader, { children: "Confirm" }, void 0), (0, jsx_runtime_1.jsx)(src_1.ModalBody, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: src_1.Css.tc.wPx(400).$ }, { children: [(0, jsx_runtime_1.jsx)("p", Object.assign({ css: src_1.Css.lgEm.gray900.mb2.$ }, { children: "Are you sure you want to cancel
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(src_1.ModalHeader, { children: "Confirm" }, void 0), (0, jsx_runtime_1.jsx)(src_1.ModalBody, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: src_1.Css.tc.wPx(400).$ }, { children: [(0, jsx_runtime_1.jsx)("p", Object.assign({ css: src_1.Css.lgEm.gray900.mb2.$ }, { children: "Are you sure you want to cancel?" }), void 0), (0, jsx_runtime_1.jsx)("p", Object.assign({ css: src_1.Css.base.gray700.$ }, { children: "Any data you've entered so far will be lost." }), void 0)] }), void 0) }, void 0), (0, jsx_runtime_1.jsx)(src_1.ModalFooter, Object.assign({ xss: src_1.Css.jcc.$ }, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ css: src_1.Css.df.fdc.childGap1.aic.$ }, { children: [(0, jsx_runtime_1.jsx)(src_1.Button, { label: continueText, onClick: closeModal }, void 0), (0, jsx_runtime_1.jsx)(src_1.Button, { variant: "tertiary", label: discardText, onClick: () => {
|
|
18
|
+
// The order of these calls doesn't really matter; close this modal and tell the call to do their close
|
|
19
|
+
onClose();
|
|
20
|
+
closeModal();
|
|
21
|
+
} }, void 0)] }), void 0) }), void 0)] }, void 0));
|
|
21
22
|
}
|
|
22
23
|
exports.ConfirmCloseModal = ConfirmCloseModal;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
+
import { CanCloseCheck } from "../../types";
|
|
2
3
|
export interface OpenInDrawerOpts {
|
|
3
4
|
/** Title of the SuperDrawer */
|
|
4
5
|
title: string;
|
|
@@ -44,13 +45,13 @@ export interface UseSuperDrawerHook {
|
|
|
44
45
|
* false, a confirmation modal will appear allowing the user to confirm
|
|
45
46
|
* the action.
|
|
46
47
|
*/
|
|
47
|
-
addCanCloseDrawerCheck: (canCloseCheck:
|
|
48
|
+
addCanCloseDrawerCheck: (canCloseCheck: CanCloseCheck) => void;
|
|
48
49
|
/**
|
|
49
50
|
* Adds a check when attempting to close a SuperDrawer detail by clicking the
|
|
50
51
|
* "back" button or calling `closeDrawerDetail()`. If any checks returns
|
|
51
52
|
* false, a confirmation modal will appear allowing the user to confirm
|
|
52
53
|
* the action.
|
|
53
54
|
*/
|
|
54
|
-
addCanCloseDrawerDetailCheck: (canCloseCheck:
|
|
55
|
+
addCanCloseDrawerDetailCheck: (canCloseCheck: CanCloseCheck) => void;
|
|
55
56
|
}
|
|
56
57
|
export declare function useSuperDrawer(): UseSuperDrawerHook;
|
|
@@ -12,8 +12,8 @@ function useSuperDrawer() {
|
|
|
12
12
|
function canCloseDrawerDetails(i, doChange) {
|
|
13
13
|
var _a;
|
|
14
14
|
for (const canCloseDrawerDetail of (_a = canCloseDetailsChecks.current[i]) !== null && _a !== void 0 ? _a : []) {
|
|
15
|
-
if (!canCloseDrawerDetail
|
|
16
|
-
openModal({ content: (0, jsx_runtime_1.jsx)(ConfirmCloseModal_1.ConfirmCloseModal, { onClose: doChange }, void 0) });
|
|
15
|
+
if (!canClose(canCloseDrawerDetail)) {
|
|
16
|
+
openModal({ content: (0, jsx_runtime_1.jsx)(ConfirmCloseModal_1.ConfirmCloseModal, Object.assign({ onClose: doChange }, canCloseDrawerDetail), void 0) });
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -40,9 +40,9 @@ function useSuperDrawer() {
|
|
|
40
40
|
}
|
|
41
41
|
// Attempt to close the drawer
|
|
42
42
|
for (const canCloseDrawer of canCloseChecks.current) {
|
|
43
|
-
if (!canCloseDrawer
|
|
43
|
+
if (!canClose(canCloseDrawer)) {
|
|
44
44
|
openModal({
|
|
45
|
-
content: (0, jsx_runtime_1.jsx)(ConfirmCloseModal_1.ConfirmCloseModal, { onClose: doChange }, void 0),
|
|
45
|
+
content: (0, jsx_runtime_1.jsx)(ConfirmCloseModal_1.ConfirmCloseModal, Object.assign({ onClose: doChange }, canCloseDrawer), void 0),
|
|
46
46
|
});
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -139,3 +139,7 @@ function useSuperDrawer() {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
exports.useSuperDrawer = useSuperDrawer;
|
|
142
|
+
function canClose(canCloseCheck) {
|
|
143
|
+
return ((typeof canCloseCheck === "function" && canCloseCheck()) ||
|
|
144
|
+
(typeof canCloseCheck !== "function" && canCloseCheck.check()));
|
|
145
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -5,3 +5,8 @@ export declare type HasIdAndName<V = string> = {
|
|
|
5
5
|
export declare type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
6
6
|
export declare type Callback = () => void;
|
|
7
7
|
export declare type CheckFn = () => boolean;
|
|
8
|
+
export declare type CanCloseCheck = {
|
|
9
|
+
check: CheckFn;
|
|
10
|
+
discardText?: string;
|
|
11
|
+
continueText?: string;
|
|
12
|
+
} | CheckFn;
|