@payfit/unity-components
Version:
128 lines (127 loc) • 4.83 kB
JavaScript
import { useBreakpointListener as e } from "../../hooks/use-breakpoint-listener.js";
import { Icon as t } from "../icon/Icon.js";
import { Menu as n } from "../menu/Menu.js";
import { MenuContent as r } from "../menu/parts/MenuContent.js";
import { MenuTrigger as i } from "../menu/parts/MenuTrigger.js";
import { RawMenuItem as a } from "../menu/parts/RawMenuItem.js";
import { BreadcrumbsProvider as o } from "./Breadcrumbs.context.js";
import { breadcrumbsVariant as s } from "./Breadcrumbs.variant.js";
import { Children as c, cloneElement as l, forwardRef as u, isValidElement as d } from "react";
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
import { useIntl as h } from "react-intl";
import { Button as g } from "react-aria-components/Button";
import { Breadcrumb as _, Breadcrumbs as v } from "react-aria-components/Breadcrumbs";
//#region src/components/breadcrumbs/Breadcrumbs.tsx
var y = 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 (!d(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 d(r) ? l(r, { key: i }) : null;
}).filter((e) => e !== null) : typeof t == "function" ? [] : c.toArray(t).filter(d), 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: d(r) && typeof r.props.children == "string" ? r.props.children : t(n + 2),
menuItemProps: i,
originalOnAction: a
};
});
function w({ menuItems: e, onAction: o, breadcrumbClassName: s, triggerAriaLabel: c }) {
return /* @__PURE__ */ m(_, {
className: s,
children: [/* @__PURE__ */ m(n, {
placement: "bottom start",
children: [/* @__PURE__ */ p(i, {
asChild: !0,
children: /* @__PURE__ */ p(g, {
"aria-label": c,
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__ */ p(t, {
src: "DotsThreeOutlined",
"aria-hidden": "true",
color: "inherit",
size: 20
})
})
}), /* @__PURE__ */ p(r, {
width: 248,
children: e.map((e) => /* @__PURE__ */ p(a, {
...e.menuItemProps,
onAction: () => {
e.originalOnAction?.(), o?.(e.key);
},
children: e.label
}, e.key))
})]
}), /* @__PURE__ */ p(t, {
src: "CaretRightOutlined",
"aria-hidden": "true",
color: "content.neutral.lowest"
})]
});
}
function T({ items: t, children: n, wrap: r = "nowrap", type: i = "non-collapsed", ...a }, c) {
let u = e(), d = h(), g = u === "xs" || u === "sm", _ = i === "collapsed", y = _ ? "nowrap" : r, { base: b, breadcrumb: x } = s({ wrap: y }), T = t === void 0, E = S(t, n), D = _ && E.length > 2, O = Math.max(E.length - 2, 0), k = d.formatMessage({
id: "unity:component:breadcrumbs:collapsed:trigger:label",
defaultMessage: "Show {count} more breadcrumbs"
}, { count: O }), A = D ? C(E, (e) => d.formatMessage({
id: "unity:component:breadcrumbs:collapsed:item:fallback",
defaultMessage: "Level {level}"
}, { level: e })) : [], j = E.at(0), M = E.at(-1), N = D ? /* @__PURE__ */ m(f, { children: [
j,
/* @__PURE__ */ p(w, {
menuItems: A,
onAction: a.onAction,
breadcrumbClassName: x(),
triggerAriaLabel: k
}),
M
] }) : E.map((e, t) => l(e, { key: `visible-${String(e.key ?? t)}` }));
return /* @__PURE__ */ p(o, {
wrap: y,
isMobile: g,
isStaticApi: T,
children: /* @__PURE__ */ p(v, {
"data-dd-privacy": "allow",
ref: c,
className: b(),
...a,
children: N
})
});
}
var E = u(T);
E.displayName = "Breadcrumbs";
//#endregion
export { E as Breadcrumbs };