UNPKG

@shinyongjun/react-datepicker

Version:
22 lines 1.21 kB
'use client'; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { useRef } from 'react'; import { NAME_SPACE } from '../../constants/core'; import useOutsideClick from '../../hooks/useOutsideClick'; import ConditionalWrapper from './ConditionalWrapper'; import Portal from './Portal'; function Layer(_a) { var isVisible = _a.isVisible, setIsVisible = _a.setIsVisible, withPortal = _a.withPortal, children = _a.children, inputRef = _a.inputRef; var layer = useRef(null); useOutsideClick(layer, function (e) { setTimeout(function () { var target = e.target; if (inputRef.current && !inputRef.current.contains(target)) { setIsVisible(false); } }, 1); }); return (_jsx(_Fragment, { children: isVisible && (_jsx(ConditionalWrapper, { condition: withPortal, wrapper: function (children) { return (_jsx(Portal, { selector: "body", children: _jsx("div", { className: "".concat(NAME_SPACE, "__portal"), children: children }) })); }, children: _jsx("div", { className: "".concat(NAME_SPACE, "__layer"), ref: layer, children: children }) })) })); } export default Layer; //# sourceMappingURL=Layer.js.map