UNPKG

@payfit/unity-components

Version:

57 lines (56 loc) 1.76 kB
import { Tabs as e } from "../../../../components/tabs/Tabs.js"; import { Children as t, isValidElement as n } from "react"; import { jsx as r } from "react/jsx-runtime"; import { RouterProvider as i } from "react-aria-components"; import { useChildMatches as a, useLocation as o, useNavigate as s, useRouter as c } from "@tanstack/react-router"; //#region src/integrations/tanstack-router/components/tabs/Tabs.tsx function l(e) { return typeof e == "object" && !!e; } function u(e) { return typeof e == "string" || typeof e == "number"; } function d(e, r, i) { let a; return t.forEach(e, (e) => { if (a || !n(e)) return; let t = e.props; if (l(t)) { if ("search" in t && ("to" in t || "href" in t)) try { let e = r.buildLocation(t); if (e.href === i) { a = u(t.id) ? t.id : e.href; return; } } catch {} "children" in t && (a = d(t.children, r, i)); } }), a; } function f({ children: t, selectedKey: n, onSelectionChange: l, routeMatch: u = "fuzzy", ...f }) { let p = o(), m = s(), h = c(), g = a({ select: (e) => { if (e.length !== 0) return u === "exact" ? e.reduce((e, t) => { let n = String(e.routeId); return String(t.routeId).length > n.length ? t : e; }) : e.reduce((e, t) => { let n = String(e.routeId); return String(t.routeId).length < n.length ? t : e; }); } }), _ = `${p.pathname}${p.searchStr}`, v = typeof t == "function" ? void 0 : d(t, h, _), y = (g ? g.pathname : void 0) ?? p.pathname, b = n ?? v ?? y, x = (e) => { l?.(e); }; return /* @__PURE__ */ r(i, { navigate: (e) => { m({ href: e }); }, children: /* @__PURE__ */ r(e, { ...f, selectedKey: b, onSelectionChange: x, children: t }) }); } f.displayName = "Tabs"; //#endregion export { f as Tabs };