UNPKG

@rnwonder/react-date-picker

Version:

A lightweight, customizable, and accessible date picker component for React applications.

103 lines (102 loc) 2.45 kB
"use client"; import { jsx as g } from "react/jsx-runtime"; import { D as E } from "./utils-CJCqI964.js"; import { useRef as P, useEffect as C } from "react"; import { createPortal as W } from "react-dom"; import { c as B } from "./class-DLUjLwnh.js"; const L = (h) => { const s = P(null), { clickOutsideRef: d, isShown: n, ignoreClickOutside: i, onClickOutsideRef: u, setIsShown: t, onClickOutside: a, onClose: c, referenceId: l, reference: f, portalContainer: m, useRefWidth: p, class: y, style: v, hideDefaultStyle: x, innerWrapperClass: O, children: R } = h; if (C(() => { const e = d; return e ? E(e, (o) => { if (n && !i) { if (u) { u(o); return; } t == null || t(!1); } }) : void 0; }, [ d, n, i, u, t ]), C(() => { if (!n || i) return; const e = (o) => { setTimeout(() => { if (s.current && !s.current.contains(o.target)) { if (a) { a(o); return; } t == null || t(!1), c == null || c(); } }, 0); }, k = setTimeout(() => { document.addEventListener("click", e); }, 10); return () => { clearTimeout(k), document.removeEventListener("click", e); }; }, [n, i, a, t, c]), !n) return null; const r = l ? document.getElementById(l) : f || m || document.getElementById("modal"); return r ? W( /* @__PURE__ */ g( "div", { ref: s, className: y, style: { ...p && (f || m || l && document.getElementById(l)) && { width: (r == null ? void 0 : r.clientWidth) + "px" }, ...v }, onClick: (e) => e.stopPropagation(), onMouseDown: (e) => e.stopPropagation(), children: /* @__PURE__ */ g( "div", { className: B( { "\n rn-absolute\n rn-z-10\n rn-flex\n rn-w-full\n rn-flex-col\n rn-bg-transparent\n ": !x }, O ), style: { ...p && { width: (r == null ? void 0 : r.clientWidth) + "px" } }, children: R } ) } ), r ) : null; }; export { L as C };