UNPKG

@undp/design-system-react

Version:

React based design system for UNDP

181 lines (180 loc) 5.66 kB
import { i as e } from "./dist-DxuGUd9a.js"; import { t } from "./dist-jqIPNHDe.js"; import { n, t as r } from "./dist-BKfyhBSH.js"; import { t as i } from "./dist-J8GU8wyT.js"; import { n as a, t as o } from "./dist-CwCVtfik.js"; import { t as s } from "./dist-DfB3OR9K.js"; import { t as c } from "./dist-pXPIaj85.js"; import { t as l } from "./dist-C8FJXTu6.js"; import * as u from "react"; import { jsx as d } from "react/jsx-runtime"; //#region node_modules/@radix-ui/react-use-is-hydrated/dist/index.mjs var f = !1; function p() { let [e, t] = u.useState(f); return u.useEffect(() => { f || (f = !0, t(!0)); }, []), e; } var m = u.useSyncExternalStore; function h() { return () => {}; } function g() { return m(h, () => !0, () => !1); } var _ = typeof m == "function" ? g : p, v = Object.defineProperty, y = (e, t) => v(e, "name", { value: t, configurable: !0 }), b = "rovingFocusGroup.onEntryFocus", x = { bubbles: !1, cancelable: !0 }, S = "RovingFocusGroup", [C, w, T] = i(S), [E, D] = n(S, [T]), [O, k] = E(S), A = /* @__PURE__ */ u.forwardRef(/* @__PURE__ */ y(function(e, t) { return /* @__PURE__ */ d(C.Provider, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ d(C.Slot, { scope: e.__scopeRovingFocusGroup, children: /* @__PURE__ */ d(j, { ...e, ref: t }) }) }); }, "RovingFocusGroup")), j = /* @__PURE__ */ u.forwardRef(/* @__PURE__ */ y(function(n, r) { let { __scopeRovingFocusGroup: i, orientation: s, loop: f = !1, dir: p, currentTabStopId: m, defaultCurrentTabStopId: h, onCurrentTabStopIdChange: g, onEntryFocus: _, preventScrollOnEntryFocus: v = !1, ...y } = n, C = u.useRef(null), T = e(r, C), E = c(p), [D, k] = o({ prop: m, defaultProp: h ?? null, onChange: g, caller: S }), [A, j] = u.useState(!1), M = l(_), N = w(i), P = u.useRef(!1), [F, I] = u.useState(0); return u.useEffect(() => { let e = C.current; if (e) return e.addEventListener(b, M), () => e.removeEventListener(b, M); }, [M]), /* @__PURE__ */ d(O, { scope: i, orientation: s, dir: E, loop: f, currentTabStopId: D, onItemFocus: u.useCallback((e) => k(e), [k]), onItemShiftTab: u.useCallback(() => j(!0), []), onFocusableItemAdd: u.useCallback(() => I((e) => e + 1), []), onFocusableItemRemove: u.useCallback(() => I((e) => e - 1), []), children: /* @__PURE__ */ d(t.div, { tabIndex: A || F === 0 ? -1 : 0, "data-orientation": s, ...y, ref: T, style: { outline: "none", ...n.style }, onMouseDown: a(n.onMouseDown, () => { P.current = !0; }), onFocus: a(n.onFocus, (e) => { let t = !P.current; if (e.target === e.currentTarget && t && !A) { let t = new CustomEvent(b, x); if (e.currentTarget.dispatchEvent(t), !t.defaultPrevented) { let e = N().filter((e) => e.focusable); L([ e.find((e) => e.active), e.find((e) => e.id === D), ...e ].filter(Boolean).map((e) => e.ref.current), v); } } P.current = !1; }), onBlur: a(n.onBlur, () => j(!1)) }) }); }, "RovingFocusGroupImpl")), M = "RovingFocusGroupItem", N = /* @__PURE__ */ u.forwardRef(/* @__PURE__ */ y(function(e, n) { let { __scopeRovingFocusGroup: i, focusable: o = !0, active: c = !1, tabStopId: l, children: f, ...p } = e, m = s(), h = l || m, g = k(M, i), v = g.currentTabStopId === h, y = w(i), { onFocusableItemAdd: b, onFocusableItemRemove: x, currentTabStopId: S } = g, T = _(); return r(() => { if (!(!T || !o)) return b(), () => x(); }, [ T, o, b, x ]), u.useEffect(() => { if (!(T || !o)) return b(), () => x(); }, [ T, o, b, x ]), /* @__PURE__ */ d(C.ItemSlot, { scope: i, id: h, focusable: o, active: c, children: /* @__PURE__ */ d(t.span, { tabIndex: v ? 0 : -1, "data-orientation": g.orientation, ...p, ref: n, onMouseDown: a(e.onMouseDown, (e) => { o ? g.onItemFocus(h) : e.preventDefault(); }), onFocus: a(e.onFocus, () => g.onItemFocus(h)), onKeyDown: a(e.onKeyDown, (e) => { if (e.key === "Tab" && e.shiftKey) { g.onItemShiftTab(); return; } if (e.target !== e.currentTarget) return; let t = I(e, g.orientation, g.dir); if (t !== void 0) { if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return; e.preventDefault(); let n = y().filter((e) => e.focusable).map((e) => e.ref.current); if (t === "last") n.reverse(); else if (t === "prev" || t === "next") { t === "prev" && n.reverse(); let r = n.indexOf(e.currentTarget); n = g.loop ? R(n, r + 1) : n.slice(r + 1); } setTimeout(() => L(n)); } }), children: typeof f == "function" ? f({ isCurrentTabStop: v, hasTabStop: S != null }) : f }) }); }, "RovingFocusGroupItem")), P = { ArrowLeft: "prev", ArrowUp: "prev", ArrowRight: "next", ArrowDown: "next", PageUp: "first", Home: "first", PageDown: "last", End: "last" }; function F(e, t) { return t === "rtl" ? e === "ArrowLeft" ? "ArrowRight" : e === "ArrowRight" ? "ArrowLeft" : e : e; } y(F, "getDirectionAwareKey"); function I(e, t, n) { let r = F(e.key, n); if (!(t === "vertical" && ["ArrowLeft", "ArrowRight"].includes(r)) && !(t === "horizontal" && ["ArrowUp", "ArrowDown"].includes(r))) return P[r]; } y(I, "getFocusIntent"); function L(e, t = !1) { let n = document.activeElement; for (let r of e) if (r === n || (r.focus({ preventScroll: t }), document.activeElement !== n)) return; } y(L, "focusFirst"); function R(e, t) { return e.map((n, r) => e[(t + r) % e.length]); } y(R, "wrapArray"); var z = A, B = N; //#endregion export { z as n, D as r, B as t }; //# sourceMappingURL=dist-CNDtQX6n.js.map