@frontify/fondue 12.0.0-beta.362 → 12.0.0-beta.363
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,18 +1,17 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const [e, s] = f
|
|
4
|
-
(
|
|
5
|
-
|
|
1
|
+
import { useState as c, useCallback as p, useEffect as i } from "react";
|
|
2
|
+
const d = (f = !1, { isBlockingModal: t, callback: n } = { isBlockingModal: !1 }) => {
|
|
3
|
+
const [e, s] = c(f), o = p(
|
|
4
|
+
(r) => {
|
|
5
|
+
const a = typeof n == "function" ? n : () => ({});
|
|
6
|
+
e && r.stopPropagation(), e && !t && r.key === "Escape" && (s(!1), a());
|
|
6
7
|
},
|
|
7
|
-
[n, e]
|
|
8
|
+
[n, t, e]
|
|
8
9
|
);
|
|
9
|
-
|
|
10
|
+
return i(() => (window.addEventListener("keydown", o), () => {
|
|
10
11
|
window.removeEventListener("keydown", o);
|
|
11
|
-
}), [o,
|
|
12
|
-
const c = r((t) => s(t), []);
|
|
13
|
-
return [e, c];
|
|
12
|
+
}), [o, t]), [e, s];
|
|
14
13
|
};
|
|
15
14
|
export {
|
|
16
|
-
|
|
15
|
+
d as useToggleOverlay
|
|
17
16
|
};
|
|
18
17
|
//# sourceMappingURL=useToggleOverlay.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToggleOverlay.es.js","sources":["../../src/hooks/useToggleOverlay.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nexport const useToggleOverlay = (\n initialState = false,\n { isBlockingModal }: { isBlockingModal?: boolean } = { isBlockingModal: false },\n): [boolean, (value: boolean) => void] => {\n const [open, setOpen] = useState<boolean>(initialState);\n const checkKeyboardEvent = useCallback(\n (event: KeyboardEvent) => {\n if (open) {\n event.stopPropagation();\n }\n if (open && !isBlockingModal && event.key === 'Escape') {\n setOpen(false);\n }\n },\n [isBlockingModal, open],\n );\n\n useEffect(() => {\n window.addEventListener('keydown', checkKeyboardEvent);\n\n return () => {\n window.removeEventListener('keydown', checkKeyboardEvent);\n };\n }, [checkKeyboardEvent, isBlockingModal]);\n\n
|
|
1
|
+
{"version":3,"file":"useToggleOverlay.es.js","sources":["../../src/hooks/useToggleOverlay.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nexport const useToggleOverlay = (\n initialState = false,\n { isBlockingModal, callback }: { isBlockingModal?: boolean; callback?: () => void } = { isBlockingModal: false },\n): [boolean, (value: boolean) => void] => {\n const [open, setOpen] = useState<boolean>(initialState);\n\n const checkKeyboardEvent = useCallback(\n (event: KeyboardEvent) => {\n const callbackFnc = typeof callback === 'function' ? callback : () => ({});\n\n if (open) {\n event.stopPropagation();\n }\n if (open && !isBlockingModal && event.key === 'Escape') {\n setOpen(false);\n callbackFnc();\n }\n },\n [callback, isBlockingModal, open],\n );\n\n useEffect(() => {\n window.addEventListener('keydown', checkKeyboardEvent);\n\n return () => {\n window.removeEventListener('keydown', checkKeyboardEvent);\n };\n }, [checkKeyboardEvent, isBlockingModal]);\n\n return [open, setOpen];\n};\n"],"names":["useToggleOverlay","initialState","isBlockingModal","callback","open","setOpen","useState","checkKeyboardEvent","useCallback","event","callbackFnc","useEffect"],"mappings":";AAIa,MAAAA,IAAmB,CAC5BC,IAAe,IACf,EAAE,iBAAAC,GAAiB,UAAAC,MAAmE,EAAE,iBAAiB,SACnE;AACtC,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAkBL,CAAY,GAEhDM,IAAqBC;AAAA,IACvB,CAACC,MAAyB;AACtB,YAAMC,IAAc,OAAOP,KAAa,aAAaA,IAAW,OAAO,CAAA;AAEvE,MAAIC,KACAK,EAAM,gBAAgB,GAEtBL,KAAQ,CAACF,KAAmBO,EAAM,QAAQ,aAC1CJ,EAAQ,EAAK,GACDK;IAEpB;AAAA,IACA,CAACP,GAAUD,GAAiBE,CAAI;AAAA,EAAA;AAGpC,SAAAO,EAAU,OACC,OAAA,iBAAiB,WAAWJ,CAAkB,GAE9C,MAAM;AACF,WAAA,oBAAoB,WAAWA,CAAkB;AAAA,EAAA,IAE7D,CAACA,GAAoBL,CAAe,CAAC,GAEjC,CAACE,GAAMC,CAAO;AACzB;"}
|