dgz-ui
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript
249 lines (246 loc) • 8.17 kB
JavaScript
import * as i from "react";
import { P as R, c as p } from "./index-DljuG5oz.js";
import { u as _ } from "./index-DLcqcWxM.js";
import { c as B, a as H } from "./index-ljY4mZHt.js";
import { u as V, a as C } from "./index-C-L1jRHK.js";
import { D as q } from "./index-BL59b1Bz.js";
import { P as K, R as U, h as Y, u as Z, F as z } from "./index-1abu5A4A.js";
import { P as m } from "./index-l3y0hILL.js";
import { c as J } from "./index-Dq2jN6bR.js";
import { j as s } from "./jsx-runtime-DS1N_tNq.js";
var v = "Dialog", [y, De] = B(v), [Q, u] = y(v), N = (e) => {
const {
__scopeDialog: o,
children: r,
open: a,
defaultOpen: n,
onOpenChange: t,
modal: c = !0
} = e, l = i.useRef(null), d = i.useRef(null), [g, x] = V({
prop: a,
defaultProp: n ?? !1,
onChange: t,
caller: v
});
return /* @__PURE__ */ s.jsx(
Q,
{
scope: o,
triggerRef: l,
contentRef: d,
contentId: C(),
titleId: C(),
descriptionId: C(),
open: g,
onOpenChange: x,
onOpenToggle: i.useCallback(() => x(($) => !$), [x]),
modal: c,
children: r
}
);
};
N.displayName = v;
var O = "DialogTrigger", I = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, ...a } = e, n = u(O, r), t = _(o, n.triggerRef);
return /* @__PURE__ */ s.jsx(
m.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": n.open,
"aria-controls": n.contentId,
"data-state": P(n.open),
...a,
ref: t,
onClick: p(e.onClick, n.onOpenToggle)
}
);
}
);
I.displayName = O;
var h = "DialogPortal", [X, A] = y(h, {
forceMount: void 0
}), T = (e) => {
const { __scopeDialog: o, forceMount: r, children: a, container: n } = e, t = u(h, o);
return /* @__PURE__ */ s.jsx(X, { scope: o, forceMount: r, children: i.Children.map(a, (c) => /* @__PURE__ */ s.jsx(R, { present: r || t.open, children: /* @__PURE__ */ s.jsx(K, { asChild: !0, container: n, children: c }) })) });
};
T.displayName = h;
var D = "DialogOverlay", j = i.forwardRef(
(e, o) => {
const r = A(D, e.__scopeDialog), { forceMount: a = r.forceMount, ...n } = e, t = u(D, e.__scopeDialog);
return t.modal ? /* @__PURE__ */ s.jsx(R, { present: a || t.open, children: /* @__PURE__ */ s.jsx(te, { ...n, ref: o }) }) : null;
}
);
j.displayName = D;
var ee = J("DialogOverlay.RemoveScroll"), te = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, ...a } = e, n = u(D, r);
return (
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
// ie. when `Overlay` and `Content` are siblings
/* @__PURE__ */ s.jsx(U, { as: ee, allowPinchZoom: !0, shards: [n.contentRef], children: /* @__PURE__ */ s.jsx(
m.div,
{
"data-state": P(n.open),
...a,
ref: o,
style: { pointerEvents: "auto", ...a.style }
}
) })
);
}
), f = "DialogContent", b = i.forwardRef(
(e, o) => {
const r = A(f, e.__scopeDialog), { forceMount: a = r.forceMount, ...n } = e, t = u(f, e.__scopeDialog);
return /* @__PURE__ */ s.jsx(R, { present: a || t.open, children: t.modal ? /* @__PURE__ */ s.jsx(oe, { ...n, ref: o }) : /* @__PURE__ */ s.jsx(ne, { ...n, ref: o }) });
}
);
b.displayName = f;
var oe = i.forwardRef(
(e, o) => {
const r = u(f, e.__scopeDialog), a = i.useRef(null), n = _(o, r.contentRef, a);
return i.useEffect(() => {
const t = a.current;
if (t) return Y(t);
}, []), /* @__PURE__ */ s.jsx(
M,
{
...e,
ref: n,
trapFocus: r.open,
disableOutsidePointerEvents: !0,
onCloseAutoFocus: p(e.onCloseAutoFocus, (t) => {
var c;
t.preventDefault(), (c = r.triggerRef.current) == null || c.focus();
}),
onPointerDownOutside: p(e.onPointerDownOutside, (t) => {
const c = t.detail.originalEvent, l = c.button === 0 && c.ctrlKey === !0;
(c.button === 2 || l) && t.preventDefault();
}),
onFocusOutside: p(
e.onFocusOutside,
(t) => t.preventDefault()
)
}
);
}
), ne = i.forwardRef(
(e, o) => {
const r = u(f, e.__scopeDialog), a = i.useRef(!1), n = i.useRef(!1);
return /* @__PURE__ */ s.jsx(
M,
{
...e,
ref: o,
trapFocus: !1,
disableOutsidePointerEvents: !1,
onCloseAutoFocus: (t) => {
var c, l;
(c = e.onCloseAutoFocus) == null || c.call(e, t), t.defaultPrevented || (a.current || (l = r.triggerRef.current) == null || l.focus(), t.preventDefault()), a.current = !1, n.current = !1;
},
onInteractOutside: (t) => {
var d, g;
(d = e.onInteractOutside) == null || d.call(e, t), t.defaultPrevented || (a.current = !0, t.detail.originalEvent.type === "pointerdown" && (n.current = !0));
const c = t.target;
((g = r.triggerRef.current) == null ? void 0 : g.contains(c)) && t.preventDefault(), t.detail.originalEvent.type === "focusin" && n.current && t.preventDefault();
}
}
);
}
), M = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, trapFocus: a, onOpenAutoFocus: n, onCloseAutoFocus: t, ...c } = e, l = u(f, r), d = i.useRef(null), g = _(o, d);
return Z(), /* @__PURE__ */ s.jsxs(s.Fragment, { children: [
/* @__PURE__ */ s.jsx(
z,
{
asChild: !0,
loop: !0,
trapped: a,
onMountAutoFocus: n,
onUnmountAutoFocus: t,
children: /* @__PURE__ */ s.jsx(
q,
{
role: "dialog",
id: l.contentId,
"aria-describedby": l.descriptionId,
"aria-labelledby": l.titleId,
"data-state": P(l.open),
...c,
ref: g,
onDismiss: () => l.onOpenChange(!1)
}
)
}
),
/* @__PURE__ */ s.jsxs(s.Fragment, { children: [
/* @__PURE__ */ s.jsx(re, { titleId: l.titleId }),
/* @__PURE__ */ s.jsx(se, { contentRef: d, descriptionId: l.descriptionId })
] })
] });
}
), E = "DialogTitle", F = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, ...a } = e, n = u(E, r);
return /* @__PURE__ */ s.jsx(m.h2, { id: n.titleId, ...a, ref: o });
}
);
F.displayName = E;
var w = "DialogDescription", S = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, ...a } = e, n = u(w, r);
return /* @__PURE__ */ s.jsx(m.p, { id: n.descriptionId, ...a, ref: o });
}
);
S.displayName = w;
var W = "DialogClose", k = i.forwardRef(
(e, o) => {
const { __scopeDialog: r, ...a } = e, n = u(W, r);
return /* @__PURE__ */ s.jsx(
m.button,
{
type: "button",
...a,
ref: o,
onClick: p(e.onClick, () => n.onOpenChange(!1))
}
);
}
);
k.displayName = W;
function P(e) {
return e ? "open" : "closed";
}
var G = "DialogTitleWarning", [ve, L] = H(G, {
contentName: f,
titleName: E,
docsSlug: "dialog"
}), re = ({ titleId: e }) => {
const o = L(G), r = `\`${o.contentName}\` requires a \`${o.titleName}\` for the component to be accessible for screen reader users.
If you want to hide the \`${o.titleName}\`, you can wrap it with our VisuallyHidden component.
For more information, see https://radix-ui.com/primitives/docs/components/${o.docsSlug}`;
return i.useEffect(() => {
e && (document.getElementById(e) || console.error(r));
}, [r, e]), null;
}, ae = "DialogDescriptionWarning", se = ({ contentRef: e, descriptionId: o }) => {
const a = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${L(ae).contentName}}.`;
return i.useEffect(() => {
var t;
const n = (t = e.current) == null ? void 0 : t.getAttribute("aria-describedby");
o && n && (document.getElementById(o) || console.warn(a));
}, [a, e, o]), null;
}, xe = N, Ce = I, Re = T, _e = j, he = b, Ee = F, Pe = S, ye = k;
export {
ye as C,
Pe as D,
_e as O,
Re as P,
xe as R,
Ce as T,
ve as W,
he as a,
Ee as b,
De as c
};