@stanfordspezi/spezi-web-design-system
Version:
Stanford Biodesign Digital Health Spezi Web Design System
268 lines (265 loc) • 8.37 kB
JavaScript
import * as s from "react";
import { c as p } from "./index-hURUNS5V.mjs";
import { c as I, u as h } from "./index-D2LZVjSn.mjs";
import { c as q, a as K } from "./index-DFZozV_h.mjs";
import { u as R } from "./index-C3vaq8Fy.mjs";
import { u as U } from "./index-DOCb3WPZ.mjs";
import { P as Y, D as Z } from "./index-DJ6gB4bU.mjs";
import { h as z, R as J, u as Q, F as X } from "./index-dzIOViH8.mjs";
import { P as _ } from "./index-DlW0DMEl.mjs";
import "react-dom";
import { jsx as i, jsxs as N, Fragment as O } from "react/jsx-runtime";
var ee = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"select",
"span",
"svg",
"ul"
], g = ee.reduce((e, t) => {
const a = I(`Primitive.${t}`), n = s.forwardRef((r, o) => {
const { asChild: l, ...c } = r, d = l ? a : t;
return typeof window < "u" && (window[/* @__PURE__ */ Symbol.for("radix-ui")] = !0), /* @__PURE__ */ i(d, { ...c, ref: o });
});
return n.displayName = `Primitive.${t}`, { ...e, [t]: n };
}, {}), v = "Dialog", [x] = q(v), [te, u] = x(v), b = (e) => {
const {
__scopeDialog: t,
children: a,
open: n,
defaultOpen: r,
onOpenChange: o,
modal: l = !0
} = e, c = s.useRef(null), d = s.useRef(null), [D, C] = U({
prop: n,
defaultProp: r ?? !1,
onChange: o,
caller: v
});
return /* @__PURE__ */ i(
te,
{
scope: t,
triggerRef: c,
contentRef: d,
contentId: R(),
titleId: R(),
descriptionId: R(),
open: D,
onOpenChange: C,
onOpenToggle: s.useCallback(() => C((V) => !V), [C]),
modal: l,
children: a
}
);
};
b.displayName = v;
var A = "DialogTrigger", T = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, ...n } = e, r = u(A, a), o = h(t, r.triggerRef);
return /* @__PURE__ */ i(
g.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": r.open,
"aria-controls": r.contentId,
"data-state": E(r.open),
...n,
ref: o,
onClick: p(e.onClick, r.onOpenToggle)
}
);
}
);
T.displayName = A;
var P = "DialogPortal", [oe, w] = x(P, {
forceMount: void 0
}), M = (e) => {
const { __scopeDialog: t, forceMount: a, children: n, container: r } = e, o = u(P, t);
return /* @__PURE__ */ i(oe, { scope: t, forceMount: a, children: s.Children.map(n, (l) => /* @__PURE__ */ i(_, { present: a || o.open, children: /* @__PURE__ */ i(Y, { asChild: !0, container: r, children: l }) })) });
};
M.displayName = P;
var m = "DialogOverlay", S = s.forwardRef(
(e, t) => {
const a = w(m, e.__scopeDialog), { forceMount: n = a.forceMount, ...r } = e, o = u(m, e.__scopeDialog);
return o.modal ? /* @__PURE__ */ i(_, { present: n || o.open, children: /* @__PURE__ */ i(ne, { ...r, ref: t }) }) : null;
}
);
S.displayName = m;
var re = I("DialogOverlay.RemoveScroll"), ne = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, ...n } = e, r = u(m, a);
return (
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
// ie. when `Overlay` and `Content` are siblings
/* @__PURE__ */ i(J, { as: re, allowPinchZoom: !0, shards: [r.contentRef], children: /* @__PURE__ */ i(
g.div,
{
"data-state": E(r.open),
...n,
ref: t,
style: { pointerEvents: "auto", ...n.style }
}
) })
);
}
), f = "DialogContent", F = s.forwardRef(
(e, t) => {
const a = w(f, e.__scopeDialog), { forceMount: n = a.forceMount, ...r } = e, o = u(f, e.__scopeDialog);
return /* @__PURE__ */ i(_, { present: n || o.open, children: o.modal ? /* @__PURE__ */ i(ae, { ...r, ref: t }) : /* @__PURE__ */ i(ie, { ...r, ref: t }) });
}
);
F.displayName = f;
var ae = s.forwardRef(
(e, t) => {
const a = u(f, e.__scopeDialog), n = s.useRef(null), r = h(t, a.contentRef, n);
return s.useEffect(() => {
const o = n.current;
if (o) return z(o);
}, []), /* @__PURE__ */ i(
W,
{
...e,
ref: r,
trapFocus: a.open,
disableOutsidePointerEvents: !0,
onCloseAutoFocus: p(e.onCloseAutoFocus, (o) => {
o.preventDefault(), a.triggerRef.current?.focus();
}),
onPointerDownOutside: p(e.onPointerDownOutside, (o) => {
const l = o.detail.originalEvent, c = l.button === 0 && l.ctrlKey === !0;
(l.button === 2 || c) && o.preventDefault();
}),
onFocusOutside: p(
e.onFocusOutside,
(o) => o.preventDefault()
)
}
);
}
), ie = s.forwardRef(
(e, t) => {
const a = u(f, e.__scopeDialog), n = s.useRef(!1), r = s.useRef(!1);
return /* @__PURE__ */ i(
W,
{
...e,
ref: t,
trapFocus: !1,
disableOutsidePointerEvents: !1,
onCloseAutoFocus: (o) => {
e.onCloseAutoFocus?.(o), o.defaultPrevented || (n.current || a.triggerRef.current?.focus(), o.preventDefault()), n.current = !1, r.current = !1;
},
onInteractOutside: (o) => {
e.onInteractOutside?.(o), o.defaultPrevented || (n.current = !0, o.detail.originalEvent.type === "pointerdown" && (r.current = !0));
const l = o.target;
a.triggerRef.current?.contains(l) && o.preventDefault(), o.detail.originalEvent.type === "focusin" && r.current && o.preventDefault();
}
}
);
}
), W = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, trapFocus: n, onOpenAutoFocus: r, onCloseAutoFocus: o, ...l } = e, c = u(f, a), d = s.useRef(null), D = h(t, d);
return Q(), /* @__PURE__ */ N(O, { children: [
/* @__PURE__ */ i(
X,
{
asChild: !0,
loop: !0,
trapped: n,
onMountAutoFocus: r,
onUnmountAutoFocus: o,
children: /* @__PURE__ */ i(
Z,
{
role: "dialog",
id: c.contentId,
"aria-describedby": c.descriptionId,
"aria-labelledby": c.titleId,
"data-state": E(c.open),
...l,
ref: D,
onDismiss: () => c.onOpenChange(!1)
}
)
}
),
/* @__PURE__ */ N(O, { children: [
/* @__PURE__ */ i(se, { titleId: c.titleId }),
/* @__PURE__ */ i(le, { contentRef: d, descriptionId: c.descriptionId })
] })
] });
}
), y = "DialogTitle", k = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, ...n } = e, r = u(y, a);
return /* @__PURE__ */ i(g.h2, { id: r.titleId, ...n, ref: t });
}
);
k.displayName = y;
var G = "DialogDescription", L = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, ...n } = e, r = u(G, a);
return /* @__PURE__ */ i(g.p, { id: r.descriptionId, ...n, ref: t });
}
);
L.displayName = G;
var $ = "DialogClose", B = s.forwardRef(
(e, t) => {
const { __scopeDialog: a, ...n } = e, r = u($, a);
return /* @__PURE__ */ i(
g.button,
{
type: "button",
...n,
ref: t,
onClick: p(e.onClick, () => r.onOpenChange(!1))
}
);
}
);
B.displayName = $;
function E(e) {
return e ? "open" : "closed";
}
var j = "DialogTitleWarning", [he, H] = K(j, {
contentName: f,
titleName: y,
docsSlug: "dialog"
}), se = ({ titleId: e }) => {
const t = H(j), a = `\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;
return s.useEffect(() => {
e && (document.getElementById(e) || console.error(a));
}, [a, e]), null;
}, ce = "DialogDescriptionWarning", le = ({ contentRef: e, descriptionId: t }) => {
const n = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${H(ce).contentName}}.`;
return s.useEffect(() => {
const r = e.current?.getAttribute("aria-describedby");
t && r && (document.getElementById(t) || console.warn(n));
}, [n, e, t]), null;
}, _e = b, Pe = T, ye = M, Ee = S, Ne = F, Oe = k, Ie = L, xe = B;
export {
xe as C,
Ie as D,
Ee as O,
ye as P,
_e as R,
Pe as T,
Ne as a,
Oe as b
};