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, i as R, h as w, b as h, R as j, S as U, M as X } from "./index-BL59b1Bz-C9bJE_xn.js";
import * as u from "react";
import { M as Y, R as Z, d as q, C as B, S as G } from "./createLucideIcon-B950nf2d-9wLYOF5y.js";
import { o as _, i as H, r as b, s as J, c as L } from "./index-ZsCkaYy6-Cw9HUeiu.js";
import { m as Q } from "./utils-B6fNqzRf-B1_jG1K7.js";
var P = "Popover", [y, me] = z(P, [
_
]), m = _(), [V, d] = y(P), A = (e) => {
const {
__scopePopover: a,
children: t,
open: n,
defaultOpen: o,
onOpenChange: r,
modal: s = !1
} = e, i = m(a), c = u.useRef(null), [v, g] = u.useState(!1), [x, p] = T({
prop: n,
defaultProp: o ?? !1,
onChange: r,
caller: P
});
return /* @__PURE__ */ l.jsx(H, { ...i, children: /* @__PURE__ */ l.jsx(
V,
{
scope: a,
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, a) => {
const { __scopePopover: t, ...n } = 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, ...n, ref: a });
}
);
W.displayName = F;
var D = "PopoverTrigger", $ = u.forwardRef(
(e, a) => {
const { __scopePopover: t, ...n } = e, o = d(D, t), r = m(t), s = R(a, o.triggerRef), i = /* @__PURE__ */ l.jsx(
w.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": o.open,
"aria-controls": o.contentId,
"data-state": I(o.open),
...n,
ref: s,
onClick: h(e.onClick, o.onOpenToggle)
}
);
return o.hasCustomAnchor ? i : /* @__PURE__ */ l.jsx(b, { asChild: !0, ...r, children: i });
}
);
$.displayName = D;
var O = "PopoverPortal", [ee, oe] = y(O, {
forceMount: void 0
}), E = (e) => {
const { __scopePopover: a, forceMount: t, children: n, container: o } = e, r = d(O, a);
return /* @__PURE__ */ l.jsx(ee, { scope: a, forceMount: t, children: /* @__PURE__ */ l.jsx(j, { present: t || r.open, children: /* @__PURE__ */ l.jsx(Y, { asChild: !0, container: o, children: n }) }) });
};
E.displayName = O;
var f = "PopoverContent", N = u.forwardRef(
(e, a) => {
const t = oe(f, e.__scopePopover), { forceMount: n = t.forceMount, ...o } = e, r = d(f, e.__scopePopover);
return /* @__PURE__ */ l.jsx(j, { present: n || r.open, children: r.modal ? /* @__PURE__ */ l.jsx(re, { ...o, ref: a }) : /* @__PURE__ */ l.jsx(ae, { ...o, ref: a }) });
}
);
N.displayName = f;
var te = U("PopoverContent.RemoveScroll"), re = u.forwardRef(
(e, a) => {
const t = d(f, e.__scopePopover), n = u.useRef(null), o = R(a, n), r = u.useRef(!1);
return u.useEffect(() => {
const s = n.current;
if (s) return Z(s);
}, []), /* @__PURE__ */ l.jsx(q, { 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 }
)
}
) });
}
), ae = u.forwardRef(
(e, a) => {
const t = d(f, e.__scopePopover), n = u.useRef(!1), o = u.useRef(!1);
return /* @__PURE__ */ l.jsx(
M,
{
...e,
ref: a,
trapFocus: !1,
disableOutsidePointerEvents: !1,
onCloseAutoFocus: (r) => {
var s, i;
(s = e.onCloseAutoFocus) == null || s.call(e, r), r.defaultPrevented || (n.current || (i = t.triggerRef.current) == null || i.focus(), r.preventDefault()), n.current = !1, o.current = !1;
},
onInteractOutside: (r) => {
var s, i;
(s = e.onInteractOutside) == null || s.call(e, r), r.defaultPrevented || (n.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, a) => {
const {
__scopePopover: t,
trapFocus: n,
onOpenAutoFocus: o,
onCloseAutoFocus: r,
disableOutsidePointerEvents: s,
onEscapeKeyDown: i,
onPointerDownOutside: c,
onFocusOutside: v,
onInteractOutside: g,
...x
} = e, p = d(f, t), C = m(t);
return B(), /* @__PURE__ */ l.jsx(
G,
{
asChild: !0,
loop: !0,
trapped: n,
onMountAutoFocus: o,
onUnmountAutoFocus: r,
children: /* @__PURE__ */ l.jsx(
X,
{
asChild: !0,
disableOutsidePointerEvents: s,
onInteractOutside: g,
onEscapeKeyDown: i,
onPointerDownOutside: c,
onFocusOutside: v,
onDismiss: () => p.onOpenChange(!1),
children: /* @__PURE__ */ l.jsx(
J,
{
"data-state": I(p.open),
role: "dialog",
id: p.contentId,
...C,
...x,
ref: a,
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", ne = u.forwardRef(
(e, a) => {
const { __scopePopover: t, ...n } = e, o = d(k, t);
return /* @__PURE__ */ l.jsx(
w.button,
{
type: "button",
...n,
ref: a,
onClick: h(e.onClick, () => o.onOpenChange(!1))
}
);
}
);
ne.displayName = k;
var se = "PopoverArrow", ie = u.forwardRef(
(e, a) => {
const { __scopePopover: t, ...n } = e, o = m(t);
return /* @__PURE__ */ l.jsx(L, { ...o, ...n, ref: a });
}
);
ie.displayName = se;
function I(e) {
return e ? "open" : "closed";
}
var le = A, ue = $, de = E, S = N;
const ge = le, xe = ue, ce = u.forwardRef(({ className: e, align: a = "center", sideOffset: t = 4, ...n }, o) => /* @__PURE__ */ l.jsx(de, { children: /* @__PURE__ */ l.jsx(
S,
{
ref: o,
align: a,
sideOffset: t,
className: Q(
"bg-popover text-popover-foreground 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 z-50 w-72 rounded-md border p-4 shadow-md outline-none",
e
),
...n
}
) }));
ce.displayName = S.displayName;
export {
ge as _,
ce as u,
xe as w
};