@payfit/unity-components
Version:
54 lines (53 loc) • 1.58 kB
JavaScript
import { Tooltip as e } from "../../tooltip/Tooltip.js";
import { RawLink as t } from "../../link/RawLink.js";
import { forwardRef as n, useCallback as r, useEffect as i, useLayoutEffect as a, useRef as o, useState as s } from "react";
import { jsx as c } from "react/jsx-runtime";
//#region src/components/breadcrumbs/parts/RawBreadcrumbLink.tsx
var l = 180, u = n(({ children: n, href: l, ...u }, d) => {
let f = typeof n == "string" ? n : "", [p, m] = s(!1), h = o(null), g = r(() => {
let e = h.current;
if (!e || !f) {
m(!1);
return;
}
m(e.scrollWidth > e.clientWidth);
}, [f]), _ = r((e) => {
h.current = e, typeof d == "function" ? d(e) : d && (d.current = e);
}, [d]);
a(() => {
g();
}, [g, n]), i(() => {
let e = h.current;
if (!e || typeof ResizeObserver > "u") return;
let t = new ResizeObserver(g);
return t.observe(e), () => {
t.disconnect();
};
}, [g]), i(() => {
if (!(typeof window > "u")) return window.addEventListener("resize", g), () => {
window.removeEventListener("resize", g);
};
}, [g]), i(() => {
if (!("fonts" in document)) return;
let e = document.fonts;
return e.addEventListener("loadingdone", g), () => {
e.removeEventListener("loadingdone", g);
};
}, [g]);
let v = /* @__PURE__ */ c(t, {
isExact: !0,
href: l,
color: "inherit",
maxWidthTruncation: 180,
ref: _,
...u,
children: n
});
return p && f ? /* @__PURE__ */ c(e, {
title: f,
children: v
}) : v;
});
u.displayName = "BreadcrumbLink";
//#endregion
export { l as BREADCRUMB_ITEM_MAX_WIDTH, u as RawBreadcrumbLink };