UNPKG

820 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4function useOpenState(_a) {
5 var _b;
6 var open = _a.open, onOpen = _a.onOpen, onClose = _a.onClose;
7 var setIsOpenState = null;
8 if (open === undefined || open === null) {
9 // The component is uncontrolled, so we need to give it its own state.
10 _b = react_1.useState(false), open = _b[0], setIsOpenState = _b[1];
11 }
12 // prettier-ignore
13 var setIsOpen = react_1.useCallback(function (newIsOpen) {
14 setIsOpenState && setIsOpenState(newIsOpen);
15 return newIsOpen
16 ? onOpen && onOpen()
17 : onClose && onClose();
18 }, [onOpen, onClose, setIsOpenState]);
19 return { isOpen: open, setIsOpen: setIsOpen };
20}
21exports.useOpenState = useOpenState;