UNPKG

@undp/design-system-react

Version:

React based design system for UNDP

62 lines (61 loc) 1.76 kB
import { i as e, n as t } from "./dist-DxuGUd9a.js"; import { n } from "./dist-BKfyhBSH.js"; import * as r from "react"; import { jsx as i } from "react/jsx-runtime"; //#region node_modules/@radix-ui/react-collection/dist/index.mjs function a(a) { let o = a + "CollectionProvider", [s, c] = n(o), [l, u] = s(o, { collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }), d = (e) => { let { scope: t, children: n } = e, a = r.useRef(null), o = r.useRef(/* @__PURE__ */ new Map()).current; return /* @__PURE__ */ i(l, { scope: t, itemMap: o, collectionRef: a, children: n }); }; d.displayName = o; let f = a + "CollectionSlot", p = t(f), m = r.forwardRef((t, n) => { let { scope: r, children: a } = t, o = e(n, u(f, r).collectionRef); return /* @__PURE__ */ i(p, { ref: o, children: a }); }); m.displayName = f; let h = a + "CollectionItemSlot", g = "data-radix-collection-item", _ = t(h), v = r.forwardRef((t, n) => { let { scope: a, children: o, ...s } = t, c = r.useRef(null), l = e(n, c), d = u(h, a); return r.useEffect(() => (d.itemMap.set(c, { ref: c, ...s }), () => void d.itemMap.delete(c))), /* @__PURE__ */ i(_, { [g]: "", ref: l, children: o }); }); v.displayName = h; function y(e) { let t = u(a + "CollectionConsumer", e); return r.useCallback(() => { let e = t.collectionRef.current; if (!e) return []; let n = Array.from(e.querySelectorAll(`[${g}]`)); return Array.from(t.itemMap.values()).sort((e, t) => n.indexOf(e.ref.current) - n.indexOf(t.ref.current)); }, [t.collectionRef, t.itemMap]); } return [ { Provider: d, Slot: m, ItemSlot: v }, y, c ]; } //#endregion export { a as t }; //# sourceMappingURL=dist-J8GU8wyT.js.map