dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
237 lines (236 loc) • 8.04 kB
JavaScript
import { y as T, a as l, j as z, g as K, x as R, h as j, b as h, R as w, c as X, M as Y } from "./index-DqTIeHVj-CYOpXZHK.js";
import * as u from "react";
import { M as V, R as U, d as Z, C as q, S as B } from "./createLucideIcon-B950nf2d-WasJb88J.js";
import { j as _, V as G, I as b, Y as H, X as J } from "./index-DFLDO_Wj-BDd-yI_U.js";
import { m as L } from "./utils-D0f6bOsw-HrLsble-.js";
var P = "Popover", [y, me] = z(P, [
_
]), m = _(), [Q, d] = y(P), A = (e) => {
const {
__scopePopover: n,
children: t,
open: a,
defaultOpen: o,
onOpenChange: r,
modal: s = !1
} = e, i = m(n), c = u.useRef(null), [v, g] = u.useState(!1), [x, p] = T({
prop: a,
defaultProp: o ?? !1,
onChange: r,
caller: P
});
return /* @__PURE__ */ l.jsx(G, { ...i, children: /* @__PURE__ */ l.jsx(
Q,
{
scope: n,
contentId: K(),
triggerRef: c,
open: x,
onOpenChange: p,
onOpenToggle: u.useCallback(() => p((C) => !C), [p]),
hasCustomAnchor: v,
onCustomAnchorAdd: u.useCallback(() => g(!0), []),
onCustomAnchorRemove: u.useCallback(() => g(!1), []),
modal: s,
children: t
}
) });
};
A.displayName = P;
var F = "PopoverAnchor", W = u.forwardRef(
(e, n) => {
const { __scopePopover: t, ...a } = e, o = d(F, t), r = m(t), { onCustomAnchorAdd: s, onCustomAnchorRemove: i } = o;
return u.useEffect(() => (s(), () => i()), [s, i]), /* @__PURE__ */ l.jsx(b, { ...r, ...a, ref: n });
}
);
W.displayName = F;
var D = "PopoverTrigger", E = u.forwardRef(
(e, n) => {
const { __scopePopover: t, ...a } = e, o = d(D, t), r = m(t), s = R(n, o.triggerRef), i = /* @__PURE__ */ l.jsx(
j.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": o.open,
"aria-controls": o.contentId,
"data-state": I(o.open),
...a,
ref: s,
onClick: h(e.onClick, o.onOpenToggle)
}
);
return o.hasCustomAnchor ? i : /* @__PURE__ */ l.jsx(b, { asChild: !0, ...r, children: i });
}
);
E.displayName = D;
var O = "PopoverPortal", [ee, oe] = y(O, {
forceMount: void 0
}), N = (e) => {
const { __scopePopover: n, forceMount: t, children: a, container: o } = e, r = d(O, n);
return /* @__PURE__ */ l.jsx(ee, { scope: n, forceMount: t, children: /* @__PURE__ */ l.jsx(w, { present: t || r.open, children: /* @__PURE__ */ l.jsx(V, { asChild: !0, container: o, children: a }) }) });
};
N.displayName = O;
var f = "PopoverContent", $ = u.forwardRef(
(e, n) => {
const t = oe(f, e.__scopePopover), { forceMount: a = t.forceMount, ...o } = e, r = d(f, e.__scopePopover);
return /* @__PURE__ */ l.jsx(w, { present: a || r.open, children: r.modal ? /* @__PURE__ */ l.jsx(re, { ...o, ref: n }) : /* @__PURE__ */ l.jsx(ne, { ...o, ref: n }) });
}
);
$.displayName = f;
var te = X("PopoverContent.RemoveScroll"), re = u.forwardRef(
(e, n) => {
const t = d(f, e.__scopePopover), a = u.useRef(null), o = R(n, a), r = u.useRef(!1);
return u.useEffect(() => {
const s = a.current;
if (s) return U(s);
}, []), /* @__PURE__ */ l.jsx(Z, { as: te, allowPinchZoom: !0, children: /* @__PURE__ */ l.jsx(
M,
{
...e,
ref: o,
trapFocus: t.open,
disableOutsidePointerEvents: !0,
onCloseAutoFocus: h(e.onCloseAutoFocus, (s) => {
var i;
s.preventDefault(), r.current || (i = t.triggerRef.current) == null || i.focus();
}),
onPointerDownOutside: h(
e.onPointerDownOutside,
(s) => {
const i = s.detail.originalEvent, c = i.button === 0 && i.ctrlKey === !0, v = i.button === 2 || c;
r.current = v;
},
{ checkForDefaultPrevented: !1 }
),
onFocusOutside: h(
e.onFocusOutside,
(s) => s.preventDefault(),
{ checkForDefaultPrevented: !1 }
)
}
) });
}
), ne = u.forwardRef(
(e, n) => {
const t = d(f, e.__scopePopover), a = u.useRef(!1), o = u.useRef(!1);
return /* @__PURE__ */ l.jsx(
M,
{
...e,
ref: n,
trapFocus: !1,
disableOutsidePointerEvents: !1,
onCloseAutoFocus: (r) => {
var s, i;
(s = e.onCloseAutoFocus) == null || s.call(e, r), r.defaultPrevented || (a.current || (i = t.triggerRef.current) == null || i.focus(), r.preventDefault()), a.current = !1, o.current = !1;
},
onInteractOutside: (r) => {
var s, i;
(s = e.onInteractOutside) == null || s.call(e, r), r.defaultPrevented || (a.current = !0, r.detail.originalEvent.type === "pointerdown" && (o.current = !0));
const c = r.target;
(i = t.triggerRef.current) != null && i.contains(c) && r.preventDefault(), r.detail.originalEvent.type === "focusin" && o.current && r.preventDefault();
}
}
);
}
), M = u.forwardRef(
(e, n) => {
const {
__scopePopover: t,
trapFocus: a,
onOpenAutoFocus: o,
onCloseAutoFocus: r,
disableOutsidePointerEvents: s,
onEscapeKeyDown: i,
onPointerDownOutside: c,
onFocusOutside: v,
onInteractOutside: g,
...x
} = e, p = d(f, t), C = m(t);
return q(), /* @__PURE__ */ l.jsx(
B,
{
asChild: !0,
loop: !0,
trapped: a,
onMountAutoFocus: o,
onUnmountAutoFocus: r,
children: /* @__PURE__ */ l.jsx(
Y,
{
asChild: !0,
disableOutsidePointerEvents: s,
onInteractOutside: g,
onEscapeKeyDown: i,
onPointerDownOutside: c,
onFocusOutside: v,
onDismiss: () => p.onOpenChange(!1),
children: /* @__PURE__ */ l.jsx(
H,
{
"data-state": I(p.open),
role: "dialog",
id: p.contentId,
...C,
...x,
ref: n,
style: {
...x.style,
"--radix-popover-content-transform-origin": "var(--radix-popper-transform-origin)",
"--radix-popover-content-available-width": "var(--radix-popper-available-width)",
"--radix-popover-content-available-height": "var(--radix-popper-available-height)",
"--radix-popover-trigger-width": "var(--radix-popper-anchor-width)",
"--radix-popover-trigger-height": "var(--radix-popper-anchor-height)"
}
}
)
}
)
}
);
}
), k = "PopoverClose", ae = u.forwardRef(
(e, n) => {
const { __scopePopover: t, ...a } = e, o = d(k, t);
return /* @__PURE__ */ l.jsx(
j.button,
{
type: "button",
...a,
ref: n,
onClick: h(e.onClick, () => o.onOpenChange(!1))
}
);
}
);
ae.displayName = k;
var se = "PopoverArrow", ie = u.forwardRef(
(e, n) => {
const { __scopePopover: t, ...a } = e, o = m(t);
return /* @__PURE__ */ l.jsx(J, { ...o, ...a, ref: n });
}
);
ie.displayName = se;
function I(e) {
return e ? "open" : "closed";
}
var le = A, ue = E, de = N, S = $;
const ge = le, xe = ue, ce = u.forwardRef(({ className: e, align: n = "center", sideOffset: t = 4, ...a }, o) => /* @__PURE__ */ l.jsx(de, { children: /* @__PURE__ */ l.jsx(
S,
{
ref: o,
align: n,
sideOffset: t,
className: L(
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
e
),
...a
}
) }));
ce.displayName = S.displayName;
export {
ge as O,
xe as _,
ce as u
};