@anoki/fse-marche-ui
Version:
FSE UI components library
261 lines (258 loc) • 8.66 kB
JavaScript
import * as s from "react";
import { composeEventHandlers as p } from "./index.es235.js";
import { useComposedRefs as C } from "./index.es236.js";
import { createContextScope as L, createContext as $ } from "./index.es237.js";
import { useId as x } from "./index.es241.js";
import { useControllableState as B } from "./index.es238.js";
import { DismissableLayer as H } from "./index.es251.js";
import { FocusScope as V } from "./index.es252.js";
import { Portal as q } from "./index.es253.js";
import { Presence as R } from "./index.es247.js";
import { Primitive as m } from "./index.es239.js";
import { useFocusGuards as K } from "./index.es254.js";
import U from "./index.es255.js";
import { hideOthers as Y } from "./index.es256.js";
import { Slot as Z } from "./index.es257.js";
import { j as i } from "./index.es137.js";
var _ = "Dialog", [P, _e] = L(_), [z, u] = P(_), y = (e) => {
const {
__scopeDialog: o,
children: n,
open: a,
defaultOpen: r,
onOpenChange: t,
modal: c = !0
} = e, l = s.useRef(null), d = s.useRef(null), [g = !1, v] = B({
prop: a,
defaultProp: r,
onChange: t
});
return /* @__PURE__ */ i.jsx(
z,
{
scope: o,
triggerRef: l,
contentRef: d,
contentId: x(),
titleId: x(),
descriptionId: x(),
open: g,
onOpenChange: v,
onOpenToggle: s.useCallback(() => v((G) => !G), [v]),
modal: c,
children: n
}
);
};
y.displayName = _;
var I = "DialogTrigger", J = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, ...a } = e, r = u(I, n), t = C(o, r.triggerRef);
return /* @__PURE__ */ i.jsx(
m.button,
{
type: "button",
"aria-haspopup": "dialog",
"aria-expanded": r.open,
"aria-controls": r.contentId,
"data-state": N(r.open),
...a,
ref: t,
onClick: p(e.onClick, r.onOpenToggle)
}
);
}
);
J.displayName = I;
var h = "DialogPortal", [Q, O] = P(h, {
forceMount: void 0
}), A = (e) => {
const { __scopeDialog: o, forceMount: n, children: a, container: r } = e, t = u(h, o);
return /* @__PURE__ */ i.jsx(Q, { scope: o, forceMount: n, children: s.Children.map(a, (c) => /* @__PURE__ */ i.jsx(R, { present: n || t.open, children: /* @__PURE__ */ i.jsx(q, { asChild: !0, container: r, children: c }) })) });
};
A.displayName = h;
var D = "DialogOverlay", j = s.forwardRef(
(e, o) => {
const n = O(D, e.__scopeDialog), { forceMount: a = n.forceMount, ...r } = e, t = u(D, e.__scopeDialog);
return t.modal ? /* @__PURE__ */ i.jsx(R, { present: a || t.open, children: /* @__PURE__ */ i.jsx(X, { ...r, ref: o }) }) : null;
}
);
j.displayName = D;
var X = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, ...a } = e, r = u(D, n);
return (
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
// ie. when `Overlay` and `Content` are siblings
/* @__PURE__ */ i.jsx(U, { as: Z, allowPinchZoom: !0, shards: [r.contentRef], children: /* @__PURE__ */ i.jsx(
m.div,
{
"data-state": N(r.open),
...a,
ref: o,
style: { pointerEvents: "auto", ...a.style }
}
) })
);
}
), f = "DialogContent", T = s.forwardRef(
(e, o) => {
const n = O(f, e.__scopeDialog), { forceMount: a = n.forceMount, ...r } = e, t = u(f, e.__scopeDialog);
return /* @__PURE__ */ i.jsx(R, { present: a || t.open, children: t.modal ? /* @__PURE__ */ i.jsx(ee, { ...r, ref: o }) : /* @__PURE__ */ i.jsx(te, { ...r, ref: o }) });
}
);
T.displayName = f;
var ee = s.forwardRef(
(e, o) => {
const n = u(f, e.__scopeDialog), a = s.useRef(null), r = C(o, n.contentRef, a);
return s.useEffect(() => {
const t = a.current;
if (t) return Y(t);
}, []), /* @__PURE__ */ i.jsx(
b,
{
...e,
ref: r,
trapFocus: n.open,
disableOutsidePointerEvents: !0,
onCloseAutoFocus: p(e.onCloseAutoFocus, (t) => {
var c;
t.preventDefault(), (c = n.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()
)
}
);
}
), te = s.forwardRef(
(e, o) => {
const n = u(f, e.__scopeDialog), a = s.useRef(!1), r = s.useRef(!1);
return /* @__PURE__ */ i.jsx(
b,
{
...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 = n.triggerRef.current) == null || l.focus(), t.preventDefault()), a.current = !1, r.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" && (r.current = !0));
const c = t.target;
((g = n.triggerRef.current) == null ? void 0 : g.contains(c)) && t.preventDefault(), t.detail.originalEvent.type === "focusin" && r.current && t.preventDefault();
}
}
);
}
), b = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, trapFocus: a, onOpenAutoFocus: r, onCloseAutoFocus: t, ...c } = e, l = u(f, n), d = s.useRef(null), g = C(o, d);
return K(), /* @__PURE__ */ i.jsxs(i.Fragment, { children: [
/* @__PURE__ */ i.jsx(
V,
{
asChild: !0,
loop: !0,
trapped: a,
onMountAutoFocus: r,
onUnmountAutoFocus: t,
children: /* @__PURE__ */ i.jsx(
H,
{
role: "dialog",
id: l.contentId,
"aria-describedby": l.descriptionId,
"aria-labelledby": l.titleId,
"data-state": N(l.open),
...c,
ref: g,
onDismiss: () => l.onOpenChange(!1)
}
)
}
),
/* @__PURE__ */ i.jsxs(i.Fragment, { children: [
/* @__PURE__ */ i.jsx(re, { titleId: l.titleId }),
/* @__PURE__ */ i.jsx(ae, { contentRef: d, descriptionId: l.descriptionId })
] })
] });
}
), E = "DialogTitle", M = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, ...a } = e, r = u(E, n);
return /* @__PURE__ */ i.jsx(m.h2, { id: r.titleId, ...a, ref: o });
}
);
M.displayName = E;
var w = "DialogDescription", oe = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, ...a } = e, r = u(w, n);
return /* @__PURE__ */ i.jsx(m.p, { id: r.descriptionId, ...a, ref: o });
}
);
oe.displayName = w;
var F = "DialogClose", S = s.forwardRef(
(e, o) => {
const { __scopeDialog: n, ...a } = e, r = u(F, n);
return /* @__PURE__ */ i.jsx(
m.button,
{
type: "button",
...a,
ref: o,
onClick: p(e.onClick, () => r.onOpenChange(!1))
}
);
}
);
S.displayName = F;
function N(e) {
return e ? "open" : "closed";
}
var W = "DialogTitleWarning", [he, k] = $(W, {
contentName: f,
titleName: E,
docsSlug: "dialog"
}), re = ({ titleId: e }) => {
const o = k(W), n = `\`${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 s.useEffect(() => {
e && (document.getElementById(e) || console.error(n));
}, [n, e]), null;
}, ne = "DialogDescriptionWarning", ae = ({ contentRef: e, descriptionId: o }) => {
const a = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${k(ne).contentName}}.`;
return s.useEffect(() => {
var t;
const r = (t = e.current) == null ? void 0 : t.getAttribute("aria-describedby");
o && r && (document.getElementById(o) || console.warn(a));
}, [a, e, o]), null;
}, Ee = y, Ne = A, Pe = j, ye = T, Ie = M, Oe = S;
export {
Oe as Close,
ye as Content,
y as Dialog,
S as DialogClose,
T as DialogContent,
oe as DialogDescription,
j as DialogOverlay,
A as DialogPortal,
M as DialogTitle,
J as DialogTrigger,
Pe as Overlay,
Ne as Portal,
Ee as Root,
Ie as Title,
he as WarningProvider,
_e as createDialogScope
};
//# sourceMappingURL=index.es181.js.map