UNPKG

@redocly/theme

Version:

Shared UI components lib

31 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useControl = void 0; const react_1 = require("react"); const DEFAULT_CONTROL_OPEN_DELAY = 300; const useControl = (initialVal = false) => { const [isOpened, setIsOpened] = (0, react_1.useState)(initialVal); const timeoutRef = (0, react_1.useRef)(null); const clearOpenTimer = (0, react_1.useCallback)(() => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } }, []); const handleOpen = (0, react_1.useCallback)(() => { clearOpenTimer(); timeoutRef.current = setTimeout(() => { setIsOpened(true); }, DEFAULT_CONTROL_OPEN_DELAY); }, [clearOpenTimer]); const handleClose = (0, react_1.useCallback)(() => { clearOpenTimer(); setIsOpened(false); }, [clearOpenTimer]); return { isOpened, handleOpen, handleClose, }; }; exports.useControl = useControl; //# sourceMappingURL=use-control.js.map