forked from renproject/command-center
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popupContainer.ts
53 lines (46 loc) · 1.45 KB
/
popupContainer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// import { useState } from "react";
import { useCallback, useState } from "react";
import { createContainer } from "unstated-next";
interface PopupDetails {
popup: JSX.Element;
overlay?: boolean;
dismissible?: boolean;
onCancel: () => void;
}
const usePopupContainer = () => {
// const { network, web3 } = Web3Container.useContainer();
const [popup, setPopupElement] = useState<JSX.Element | null>(null);
const [overlay, setOverlay] = useState<boolean>(false);
const [dismissible, setDismissible] = useState<boolean>(true);
const [onCancel, setOnCancel] = useState<() => void>(() => null);
const setPopup: (details: PopupDetails) => void = useCallback(
({
popup: newPopup,
overlay: newOverlay,
dismissible: newDismissible,
onCancel: newOnCancel,
}: PopupDetails) => {
setPopupElement(newPopup);
setOverlay(newOverlay || false);
setDismissible(newDismissible || false);
setOnCancel(() => newOnCancel);
},
[],
);
const clearPopup = useCallback(() => {
setPopupElement(null);
setOverlay(false);
setDismissible(true);
setOnCancel(() => null);
}, []);
return {
setPopup,
clearPopup,
popup,
overlay,
setOverlay,
dismissible,
onCancel,
};
};
export const PopupContainer = createContainer(usePopupContainer);