grep-components 2.5.1 → 2.5.2
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,4 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
export interface NavguardExclusion {
|
|
3
|
+
current: string;
|
|
4
|
+
next: string;
|
|
5
|
+
}
|
|
2
6
|
export interface NavGuardProperties {
|
|
3
7
|
when: boolean;
|
|
4
8
|
title: string;
|
|
@@ -6,9 +10,11 @@ export interface NavGuardProperties {
|
|
|
6
10
|
txtSave: string;
|
|
7
11
|
txtCancel: string;
|
|
8
12
|
txtDiscard: string;
|
|
13
|
+
/** Pass in an array of NavguardExclusions that the Navguard will not trigger when navigating from current to next. */
|
|
14
|
+
exclude?: NavguardExclusion[];
|
|
9
15
|
onDiscard?: () => void;
|
|
10
16
|
onCancel?: () => void;
|
|
11
17
|
onSave?: () => void;
|
|
12
18
|
}
|
|
13
|
-
declare const NavGuard: ({ when, title, txt, txtSave, txtCancel, txtDiscard, onSave, onCancel, onDiscard, }: NavGuardProperties) => React.JSX.Element;
|
|
19
|
+
declare const NavGuard: ({ when, exclude, title, txt, txtSave, txtCancel, txtDiscard, onSave, onCancel, onDiscard, }: NavGuardProperties) => React.JSX.Element;
|
|
14
20
|
export default NavGuard;
|
package/dist/index.js
CHANGED
|
@@ -15653,7 +15653,7 @@ const AppBar = ({ username, currentPath, environmentTitle, appTitle, userMenuIte
|
|
|
15653
15653
|
React.createElement(MobileAppBar, { menuItems: menuItems, userMenuItems: userMenuItems, colors: colors }))));
|
|
15654
15654
|
};
|
|
15655
15655
|
|
|
15656
|
-
const NavGuard = ({ when, title, txt, txtSave, txtCancel, txtDiscard, onSave, onCancel, onDiscard, }) => {
|
|
15656
|
+
const NavGuard = ({ when, exclude, title, txt, txtSave, txtCancel, txtDiscard, onSave, onCancel, onDiscard, }) => {
|
|
15657
15657
|
const [open, setOpen] = React.useState(false);
|
|
15658
15658
|
const handleCancel = () => {
|
|
15659
15659
|
setOpen(false);
|
|
@@ -15669,7 +15669,16 @@ const NavGuard = ({ when, title, txt, txtSave, txtCancel, txtDiscard, onSave, on
|
|
|
15669
15669
|
setOpen(false);
|
|
15670
15670
|
blocker.proceed ? blocker.proceed() : null;
|
|
15671
15671
|
};
|
|
15672
|
-
const blocker = useBlocker(({ currentLocation, nextLocation }) =>
|
|
15672
|
+
const blocker = useBlocker(({ currentLocation, nextLocation }) => {
|
|
15673
|
+
let excluded = false;
|
|
15674
|
+
exclude?.forEach((navGuardExclusion) => {
|
|
15675
|
+
if (navGuardExclusion.current.includes(currentLocation.pathname) &&
|
|
15676
|
+
navGuardExclusion.next.includes(nextLocation.pathname)) {
|
|
15677
|
+
excluded = true;
|
|
15678
|
+
}
|
|
15679
|
+
});
|
|
15680
|
+
return (when && !excluded && currentLocation.pathname !== nextLocation.pathname);
|
|
15681
|
+
});
|
|
15673
15682
|
React.useEffect(() => {
|
|
15674
15683
|
if (blocker.state === 'blocked') {
|
|
15675
15684
|
setOpen(true);
|