UNPKG

@payfit/unity-components

Version:

122 lines (121 loc) • 4.75 kB
import { useBreakpointListener as e } from "../../hooks/use-breakpoint-listener.js"; import { Menu as t } from "../menu/Menu.js"; import { MenuContent as n } from "../menu/parts/MenuContent.js"; import { MenuTrigger as r } from "../menu/parts/MenuTrigger.js"; import { RawMenuItem as i } from "../menu/parts/RawMenuItem.js"; import { BreadcrumbsProvider as a } from "./Breadcrumbs.context.js"; import { breadcrumbsVariant as o } from "./Breadcrumbs.variant.js"; import { Children as s, cloneElement as c, forwardRef as l, isValidElement as u } from "react"; import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime"; import { useTranslation as m } from "react-i18next"; import { Button as h } from "react-aria-components/Button"; import { Icon as g } from "@payfit/unity-icons"; import { Breadcrumb as _, Breadcrumbs as v } from "react-aria-components/Breadcrumbs"; //#region src/core/components/breadcrumbs/Breadcrumbs.tsx var y = /* @__PURE__ */ new Set([ "href", "target", "rel", "download", "isDisabled", "onClick", "onPress", "onPressStart", "onPressEnd", "onPressChange", "onPressUp", "onFocus", "onBlur", "onKeyDown", "onKeyUp", "onHoverStart", "onHoverChange", "onHoverEnd", "id" ]), b = (e) => { let t = {}; if (!u(e)) return { menuItemProps: t, originalOnAction: void 0 }; let n = e.props; for (let [e, r] of Object.entries(n)) e !== "children" && e !== "onAction" && (y.has(e) || e.startsWith("aria-") || e.startsWith("data-")) && (t[e] = r); return { menuItemProps: t, originalOnAction: typeof n.onAction == "function" ? n.onAction : void 0 }; }, x = (e, t) => "id" in e && e.id && typeof e.id == "string" ? e.id : `${e.label}-${t}`, S = (e, t) => e ? e.map((e, n) => { if (typeof t != "function") return null; let r = t(e), i = x(e, n); return u(r) ? c(r, { key: i }) : null; }).filter((e) => e !== null) : typeof t == "function" ? [] : s.toArray(t).filter(u), C = (e, t) => e.slice(1, -1).map((e, n) => { let r = e.props.children, { menuItemProps: i, originalOnAction: a } = b(r), o = e.props.id ?? e.key; return { key: typeof o == "string" || typeof o == "number" ? o : `collapsed-breadcrumb-${n}`, label: u(r) && typeof r.props.children == "string" ? r.props.children : t(n + 2), menuItemProps: i, originalOnAction: a }; }); function w({ menuItems: e, onAction: a, breadcrumbClassName: o, triggerAriaLabel: s }) { return /* @__PURE__ */ p(_, { className: o, children: [/* @__PURE__ */ p(t, { placement: "bottom start", children: [/* @__PURE__ */ f(r, { asChild: !0, children: /* @__PURE__ */ f(h, { "aria-label": s, className: "uy:flex uy:h-300 uy:w-300 uy:cursor-pointer uy:items-center uy:justify-center uy:rounded-75 uy:text-content-neutral-enabled uy:hover:bg-surface-neutral-hover uy:hover:text-content-neutral-hover uy:active:bg-surface-neutral-active uy:active:text-content-neutral-active uy:data-[pressed=true]:bg-surface-neutral-pressed uy:data-[pressed=true]:text-content-neutral-pressed uy:focus-visible:outline-none uy:focus-visible:ring-2 uy:focus-visible:ring-offset-2 uy:focus-visible:ring-utility-focus-ring", children: /* @__PURE__ */ f(g, { src: "DotsThreeOutlined", "aria-hidden": "true", color: "inherit", size: 20 }) }) }), /* @__PURE__ */ f(n, { width: 248, children: e.map((e) => /* @__PURE__ */ f(i, { ...e.menuItemProps, onAction: () => { e.originalOnAction?.(), a?.(e.key); }, children: e.label }, e.key)) })] }), /* @__PURE__ */ f(g, { src: "CaretRightOutlined", "aria-hidden": "true", color: "content.neutral.lowest" })] }); } function T({ items: t, children: n, wrap: r = "nowrap", type: i = "non-collapsed", ...s }, l) { let u = e(), { t: h } = m("unity"), g = u === "xs" || u === "sm", _ = i === "collapsed", y = _ ? "nowrap" : r, { base: b, breadcrumb: x } = o({ wrap: y }), T = t === void 0, E = S(t, n), D = _ && E.length > 2, O = h((e) => e.unity.component.breadcrumbs.collapsed.trigger.label, { count: Math.max(E.length - 2, 0) }), k = D ? C(E, (e) => h((e) => e.unity.component.breadcrumbs.collapsed.item.fallback, { level: e })) : [], A = E.at(0), j = E.at(-1), M = D ? /* @__PURE__ */ p(d, { children: [ A, /* @__PURE__ */ f(w, { menuItems: k, onAction: s.onAction, breadcrumbClassName: x(), triggerAriaLabel: O }), j ] }) : E.map((e, t) => c(e, { key: `visible-${String(e.key ?? t)}` })); return /* @__PURE__ */ f(a, { wrap: y, isMobile: g, isStaticApi: T, children: /* @__PURE__ */ f(v, { "data-dd-privacy": "allow", ref: l, className: b(), ...s, children: M }) }); } var E = l(T); E.displayName = "Breadcrumbs"; //#endregion export { E as Breadcrumbs };