UNPKG

@anoki/fse-ui

Version:

FSE UI components library

246 lines (245 loc) • 8.1 kB
import * as i from "react"; import { composeEventHandlers as P } from "./index.es470.js"; import { useComposedRefs as A } from "./index.es471.js"; import { createContextScope as G } from "./index.es472.js"; import { DismissableLayer as H } from "./index.es484.js"; import { useFocusGuards as K } from "./index.es485.js"; import { FocusScope as $ } from "./index.es486.js"; import { useId as U } from "./index.es476.js"; import { createPopperScope as O, Root as V, Anchor as _, Content as W, Arrow as Z } from "./index.es487.js"; import { Portal as q } from "./index.es488.js"; import { Presence as E } from "./index.es489.js"; import { Primitive as w } from "./index.es474.js"; import { createSlot as z } from "./index.es481.js"; import { useControllableState as B } from "./index.es473.js"; import { hideOthers as J } from "./index.es491.js"; import Q from "./index.es492.js"; import { j as p } from "./index.es244.js"; var x = "Popover", [j, Oo] = G(x, [ O ]), m = O(), [X, f] = j(x), b = (o) => { const { __scopePopover: n, children: t, open: s, defaultOpen: e, onOpenChange: r, modal: a = !1 } = o, c = m(n), u = i.useRef(null), [l, g] = i.useState(!1), [h = !1, d] = B({ prop: s, defaultProp: e, onChange: r }); return /* @__PURE__ */ p.jsx(V, { ...c, children: /* @__PURE__ */ p.jsx( X, { scope: n, contentId: U(), triggerRef: u, open: h, onOpenChange: d, onOpenToggle: i.useCallback(() => d((C) => !C), [d]), hasCustomAnchor: l, onCustomAnchorAdd: i.useCallback(() => g(!0), []), onCustomAnchorRemove: i.useCallback(() => g(!1), []), modal: a, children: t } ) }); }; b.displayName = x; var F = "PopoverAnchor", N = i.forwardRef( (o, n) => { const { __scopePopover: t, ...s } = o, e = f(F, t), r = m(t), { onCustomAnchorAdd: a, onCustomAnchorRemove: c } = e; return i.useEffect(() => (a(), () => c()), [a, c]), /* @__PURE__ */ p.jsx(_, { ...r, ...s, ref: n }); } ); N.displayName = F; var S = "PopoverTrigger", y = i.forwardRef( (o, n) => { const { __scopePopover: t, ...s } = o, e = f(S, t), r = m(t), a = A(n, e.triggerRef), c = /* @__PURE__ */ p.jsx( w.button, { type: "button", "aria-haspopup": "dialog", "aria-expanded": e.open, "aria-controls": e.contentId, "data-state": L(e.open), ...s, ref: a, onClick: P(o.onClick, e.onOpenToggle) } ); return e.hasCustomAnchor ? c : /* @__PURE__ */ p.jsx(_, { asChild: !0, ...r, children: c }); } ); y.displayName = S; var R = "PopoverPortal", [Y, oo] = j(R, { forceMount: void 0 }), D = (o) => { const { __scopePopover: n, forceMount: t, children: s, container: e } = o, r = f(R, n); return /* @__PURE__ */ p.jsx(Y, { scope: n, forceMount: t, children: /* @__PURE__ */ p.jsx(E, { present: t || r.open, children: /* @__PURE__ */ p.jsx(q, { asChild: !0, container: e, children: s }) }) }); }; D.displayName = R; var v = "PopoverContent", M = i.forwardRef( (o, n) => { const t = oo(v, o.__scopePopover), { forceMount: s = t.forceMount, ...e } = o, r = f(v, o.__scopePopover); return /* @__PURE__ */ p.jsx(E, { present: s || r.open, children: r.modal ? /* @__PURE__ */ p.jsx(ro, { ...e, ref: n }) : /* @__PURE__ */ p.jsx(to, { ...e, ref: n }) }); } ); M.displayName = v; var eo = z("PopoverContent.RemoveScroll"), ro = i.forwardRef( (o, n) => { const t = f(v, o.__scopePopover), s = i.useRef(null), e = A(n, s), r = i.useRef(!1); return i.useEffect(() => { const a = s.current; if (a) return J(a); }, []), /* @__PURE__ */ p.jsx(Q, { as: eo, allowPinchZoom: !0, children: /* @__PURE__ */ p.jsx( k, { ...o, ref: e, trapFocus: t.open, disableOutsidePointerEvents: !0, onCloseAutoFocus: P(o.onCloseAutoFocus, (a) => { var c; a.preventDefault(), r.current || (c = t.triggerRef.current) == null || c.focus(); }), onPointerDownOutside: P( o.onPointerDownOutside, (a) => { const c = a.detail.originalEvent, u = c.button === 0 && c.ctrlKey === !0, l = c.button === 2 || u; r.current = l; }, { checkForDefaultPrevented: !1 } ), onFocusOutside: P( o.onFocusOutside, (a) => a.preventDefault(), { checkForDefaultPrevented: !1 } ) } ) }); } ), to = i.forwardRef( (o, n) => { const t = f(v, o.__scopePopover), s = i.useRef(!1), e = i.useRef(!1); return /* @__PURE__ */ p.jsx( k, { ...o, ref: n, trapFocus: !1, disableOutsidePointerEvents: !1, onCloseAutoFocus: (r) => { var a, c; (a = o.onCloseAutoFocus) == null || a.call(o, r), r.defaultPrevented || (s.current || (c = t.triggerRef.current) == null || c.focus(), r.preventDefault()), s.current = !1, e.current = !1; }, onInteractOutside: (r) => { var u, l; (u = o.onInteractOutside) == null || u.call(o, r), r.defaultPrevented || (s.current = !0, r.detail.originalEvent.type === "pointerdown" && (e.current = !0)); const a = r.target; ((l = t.triggerRef.current) == null ? void 0 : l.contains(a)) && r.preventDefault(), r.detail.originalEvent.type === "focusin" && e.current && r.preventDefault(); } } ); } ), k = i.forwardRef( (o, n) => { const { __scopePopover: t, trapFocus: s, onOpenAutoFocus: e, onCloseAutoFocus: r, disableOutsidePointerEvents: a, onEscapeKeyDown: c, onPointerDownOutside: u, onFocusOutside: l, onInteractOutside: g, ...h } = o, d = f(v, t), C = m(t); return K(), /* @__PURE__ */ p.jsx( $, { asChild: !0, loop: !0, trapped: s, onMountAutoFocus: e, onUnmountAutoFocus: r, children: /* @__PURE__ */ p.jsx( H, { asChild: !0, disableOutsidePointerEvents: a, onInteractOutside: g, onEscapeKeyDown: c, onPointerDownOutside: u, onFocusOutside: l, onDismiss: () => d.onOpenChange(!1), children: /* @__PURE__ */ p.jsx( W, { "data-state": L(d.open), role: "dialog", id: d.contentId, ...C, ...h, ref: n, style: { ...h.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)" } } ) } ) } ); } ), I = "PopoverClose", T = i.forwardRef( (o, n) => { const { __scopePopover: t, ...s } = o, e = f(I, t); return /* @__PURE__ */ p.jsx( w.button, { type: "button", ...s, ref: n, onClick: P(o.onClick, () => e.onOpenChange(!1)) } ); } ); T.displayName = I; var no = "PopoverArrow", so = i.forwardRef( (o, n) => { const { __scopePopover: t, ...s } = o, e = m(t); return /* @__PURE__ */ p.jsx(Z, { ...e, ...s, ref: n }); } ); so.displayName = no; function L(o) { return o ? "open" : "closed"; } var _o = b, Eo = N, wo = y, jo = D, bo = M, Fo = T; export { Eo as Anchor, Fo as Close, bo as Content, b as Popover, N as PopoverAnchor, so as PopoverArrow, T as PopoverClose, M as PopoverContent, D as PopoverPortal, y as PopoverTrigger, jo as Portal, _o as Root, wo as Trigger, Oo as createPopoverScope }; //# sourceMappingURL=index.es552.js.map