@langchain/macaw-components 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog.json +548 -548
- package/dist/components/Breadcrumb/Breadcrumb.d.ts +4 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +160 -42
- package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/utilities.css +1 -1
- package/docs/DESIGN.md +12 -15
- package/package.json +2 -2
|
@@ -3,6 +3,8 @@ import type { IconComponent } from '../../utils/icon-types.js';
|
|
|
3
3
|
import type { LinkProps } from '../Link/index.js';
|
|
4
4
|
type BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {
|
|
5
5
|
separator?: ReactNode;
|
|
6
|
+
/** Cap labels at 148px instead of 200px. The consuming layout chooses when. */
|
|
7
|
+
condensed?: boolean;
|
|
6
8
|
};
|
|
7
9
|
type BreadcrumbLinkProps = LinkProps;
|
|
8
10
|
type BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {
|
|
@@ -10,6 +12,8 @@ type BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {
|
|
|
10
12
|
};
|
|
11
13
|
declare const Breadcrumb: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
|
|
12
14
|
separator?: ReactNode;
|
|
15
|
+
/** Cap labels at 148px instead of 200px. The consuming layout chooses when. */
|
|
16
|
+
condensed?: boolean;
|
|
13
17
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
14
18
|
declare const BreadcrumbLink: import("react").ForwardRefExoticComponent<LinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
15
19
|
declare const BreadcrumbPage: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
@@ -1,37 +1,137 @@
|
|
|
1
1
|
import { cn } from "../../utils/cn.js";
|
|
2
2
|
import { Text } from "../Text/Text.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Tooltip } from "../Tooltip/Tooltip.js";
|
|
4
|
+
import { Children, cloneElement, createContext, forwardRef, useContext, useLayoutEffect, useRef, useState } from "react";
|
|
4
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { TooltipProvider } from "@radix-ui/react-tooltip";
|
|
5
7
|
//#region packages/components/src/components/Breadcrumb/Breadcrumb.tsx
|
|
6
|
-
var
|
|
8
|
+
var BreadcrumbContext = createContext({
|
|
9
|
+
condensed: false,
|
|
10
|
+
hasTooltipProvider: false
|
|
11
|
+
});
|
|
12
|
+
function SlashSeparator() {
|
|
13
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
14
|
+
"aria-hidden": "true",
|
|
15
|
+
width: 10,
|
|
16
|
+
height: 10,
|
|
17
|
+
viewBox: "0 0 24 24",
|
|
18
|
+
fill: "none",
|
|
19
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
20
|
+
d: "M7 22 17 2",
|
|
21
|
+
stroke: "currentColor",
|
|
22
|
+
strokeWidth: 2,
|
|
23
|
+
strokeLinecap: "round"
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
var Breadcrumb = forwardRef(({ children, className, separator = /* @__PURE__ */ jsx(SlashSeparator, {}), condensed = false, ...props }, ref) => {
|
|
7
28
|
const items = Children.toArray(children).filter((item) => item !== "");
|
|
29
|
+
const listRef = useRef(null);
|
|
30
|
+
const [scrollable, setScrollable] = useState(false);
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
const list = listRef.current;
|
|
33
|
+
if (!list) {
|
|
34
|
+
setScrollable(false);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const measure = () => setScrollable(list.scrollWidth > list.clientWidth);
|
|
38
|
+
measure();
|
|
39
|
+
const observer = new ResizeObserver(measure);
|
|
40
|
+
observer.observe(list);
|
|
41
|
+
for (const item of list.children) observer.observe(item);
|
|
42
|
+
return () => observer.disconnect();
|
|
43
|
+
}, [children, condensed]);
|
|
8
44
|
if (!items.length) return null;
|
|
9
|
-
return /* @__PURE__ */ jsx(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
children: /* @__PURE__ */ jsx("
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
return /* @__PURE__ */ jsx(BreadcrumbContext.Provider, {
|
|
46
|
+
value: {
|
|
47
|
+
condensed,
|
|
48
|
+
hasTooltipProvider: true
|
|
49
|
+
},
|
|
50
|
+
children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx("nav", {
|
|
51
|
+
ref,
|
|
52
|
+
"aria-label": "Breadcrumb",
|
|
53
|
+
className: cn("min-w-0", className),
|
|
54
|
+
...props,
|
|
55
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
56
|
+
ref: listRef,
|
|
57
|
+
role: "list",
|
|
58
|
+
tabIndex: scrollable ? 0 : -1,
|
|
59
|
+
className: "flex flex-nowrap items-center gap-space-2 overflow-x-auto rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus",
|
|
60
|
+
children: items.map((item, index) => /* @__PURE__ */ jsxs("li", {
|
|
61
|
+
className: "flex min-w-0 max-w-full shrink-0 items-center gap-space-2",
|
|
62
|
+
children: [index > 0 && /* @__PURE__ */ jsx("span", {
|
|
63
|
+
"aria-hidden": "true",
|
|
64
|
+
className: "flex shrink-0 items-center text-xxs text-quaternary",
|
|
65
|
+
children: separator
|
|
66
|
+
}), item]
|
|
67
|
+
}, typeof item === "object" && "key" in item ? item.key : index))
|
|
68
|
+
})
|
|
69
|
+
}) })
|
|
26
70
|
});
|
|
27
71
|
});
|
|
28
72
|
Breadcrumb.displayName = "Breadcrumb";
|
|
73
|
+
function useBreadcrumbLabel(children) {
|
|
74
|
+
const { condensed } = useContext(BreadcrumbContext);
|
|
75
|
+
const labelRef = useRef(null);
|
|
76
|
+
const [text, setText] = useState("");
|
|
77
|
+
const [clipped, setClipped] = useState(false);
|
|
78
|
+
const [open, setOpen] = useState(false);
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
const label = labelRef.current;
|
|
81
|
+
if (!label) return;
|
|
82
|
+
let active = true;
|
|
83
|
+
function measure() {
|
|
84
|
+
if (!active || !label) return;
|
|
85
|
+
const isClipped = label.scrollWidth > label.clientWidth;
|
|
86
|
+
setText(label.textContent ?? "");
|
|
87
|
+
setClipped(isClipped);
|
|
88
|
+
if (!isClipped) setOpen(false);
|
|
89
|
+
}
|
|
90
|
+
measure();
|
|
91
|
+
const resizeObserver = new ResizeObserver(measure);
|
|
92
|
+
resizeObserver.observe(label);
|
|
93
|
+
const mutationObserver = new MutationObserver(measure);
|
|
94
|
+
mutationObserver.observe(label, {
|
|
95
|
+
childList: true,
|
|
96
|
+
characterData: true,
|
|
97
|
+
subtree: true
|
|
98
|
+
});
|
|
99
|
+
const fonts = label.ownerDocument.fonts;
|
|
100
|
+
fonts?.ready.then(measure);
|
|
101
|
+
fonts?.addEventListener("loadingdone", measure);
|
|
102
|
+
return () => {
|
|
103
|
+
active = false;
|
|
104
|
+
resizeObserver.disconnect();
|
|
105
|
+
mutationObserver.disconnect();
|
|
106
|
+
fonts?.removeEventListener("loadingdone", measure);
|
|
107
|
+
};
|
|
108
|
+
}, [children, condensed]);
|
|
109
|
+
return {
|
|
110
|
+
labelRef,
|
|
111
|
+
clipped,
|
|
112
|
+
labelClassName: cn("min-w-0 max-w-50 truncate", condensed && "max-w-37"),
|
|
113
|
+
tooltipProps: {
|
|
114
|
+
title: /* @__PURE__ */ jsx(Text, {
|
|
115
|
+
variant: "sm",
|
|
116
|
+
className: "text-primary",
|
|
117
|
+
children: text
|
|
118
|
+
}),
|
|
119
|
+
open: clipped && open,
|
|
120
|
+
onOpenChange: (nextOpen) => setOpen(clipped && nextOpen)
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function BreadcrumbTooltip(props) {
|
|
125
|
+
const { hasTooltipProvider } = useContext(BreadcrumbContext);
|
|
126
|
+
const tooltip = /* @__PURE__ */ jsx(Tooltip, { ...props });
|
|
127
|
+
return hasTooltipProvider ? tooltip : /* @__PURE__ */ jsx(TooltipProvider, { children: tooltip });
|
|
128
|
+
}
|
|
29
129
|
var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftIcon, rightDecorator: RightIcon, iconWeight = "regular", variant = "xs", ...props }, ref) => {
|
|
130
|
+
const { labelRef, labelClassName, tooltipProps } = useBreadcrumbLabel(children);
|
|
30
131
|
const linkProps = {
|
|
31
|
-
...typeof children === "string" && as?.props.title === void 0 ? { title: children } : {},
|
|
32
132
|
...props,
|
|
33
133
|
ref,
|
|
34
|
-
className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:
|
|
134
|
+
className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus", as?.props.className, className),
|
|
35
135
|
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
36
136
|
LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
|
|
37
137
|
"aria-hidden": true,
|
|
@@ -40,10 +140,11 @@ var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftI
|
|
|
40
140
|
className: "shrink-0"
|
|
41
141
|
}),
|
|
42
142
|
/* @__PURE__ */ jsx(Text, {
|
|
143
|
+
ref: labelRef,
|
|
43
144
|
as: "span",
|
|
44
145
|
variant,
|
|
45
146
|
weight: "medium",
|
|
46
|
-
className:
|
|
147
|
+
className: labelClassName,
|
|
47
148
|
children
|
|
48
149
|
}),
|
|
49
150
|
RightIcon && /* @__PURE__ */ jsx(RightIcon, {
|
|
@@ -54,28 +155,45 @@ var BreadcrumbLink = forwardRef(({ children, className, as, leftDecorator: LeftI
|
|
|
54
155
|
})
|
|
55
156
|
] })
|
|
56
157
|
};
|
|
57
|
-
return
|
|
158
|
+
return /* @__PURE__ */ jsx(BreadcrumbTooltip, {
|
|
159
|
+
...tooltipProps,
|
|
160
|
+
children: as ? cloneElement(as, linkProps) : /* @__PURE__ */ jsx("a", { ...linkProps })
|
|
161
|
+
});
|
|
58
162
|
});
|
|
59
163
|
BreadcrumbLink.displayName = "BreadcrumbLink";
|
|
60
|
-
var BreadcrumbPage = forwardRef(({ children, className, leftDecorator: LeftIcon, ...props }, ref) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
164
|
+
var BreadcrumbPage = forwardRef(({ children, className, leftDecorator: LeftIcon, tabIndex, onFocus, ...props }, ref) => {
|
|
165
|
+
const { labelRef, labelClassName, clipped, tooltipProps } = useBreadcrumbLabel(children);
|
|
166
|
+
return /* @__PURE__ */ jsx(BreadcrumbTooltip, {
|
|
167
|
+
...tooltipProps,
|
|
168
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
169
|
+
ref,
|
|
170
|
+
"aria-current": "page",
|
|
171
|
+
tabIndex: tabIndex ?? (clipped ? 0 : -1),
|
|
172
|
+
onFocus: (event) => {
|
|
173
|
+
onFocus?.(event);
|
|
174
|
+
if (!event.defaultPrevented) event.currentTarget.scrollIntoView({
|
|
175
|
+
block: "nearest",
|
|
176
|
+
inline: "nearest"
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
className: cn("inline-flex min-w-0 items-center gap-space-1 rounded-sm text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus", className),
|
|
180
|
+
...props,
|
|
181
|
+
children: [LeftIcon && /* @__PURE__ */ jsx(LeftIcon, {
|
|
182
|
+
"aria-hidden": true,
|
|
183
|
+
size: 12,
|
|
184
|
+
weight: "regular",
|
|
185
|
+
className: "shrink-0"
|
|
186
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
187
|
+
ref: labelRef,
|
|
188
|
+
as: "span",
|
|
189
|
+
variant: "xs",
|
|
190
|
+
weight: "medium",
|
|
191
|
+
className: labelClassName,
|
|
192
|
+
children
|
|
193
|
+
})]
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
});
|
|
79
197
|
BreadcrumbPage.displayName = "BreadcrumbPage";
|
|
80
198
|
//#endregion
|
|
81
199
|
export { Breadcrumb, BreadcrumbLink, BreadcrumbPage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumb.js","names":[],"sources":["../../../src/components/Breadcrumb/Breadcrumb.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n type ComponentPropsWithoutRef,\n type ReactNode,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent } from '../../utils/icon-types';\nimport type { LinkProps } from '../Link';\nimport { Text } from '../Text';\n\ntype BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {\n separator?: ReactNode;\n};\n\ntype BreadcrumbLinkProps = LinkProps;\n\ntype BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {\n leftDecorator?: IconComponent;\n};\n\nconst Breadcrumb = forwardRef<HTMLElement, BreadcrumbProps>(\n ({ children, className, separator = '/', ...props }, ref) => {\n const items = Children.toArray(children).filter((item) => item !== '');\n if (!items.length) return null;\n\n return (\n <nav\n ref={ref}\n aria-label=\"Breadcrumb\"\n className={cn('min-w-0', className)}\n {...props}\n >\n <ol role=\"list\" className=\"flex flex-wrap items-center gap-space-2\">\n {items.map((item, index) => (\n <li\n key={typeof item === 'object' && 'key' in item ? item.key : index}\n className=\"flex min-w-0 max-w-full items-center gap-space-2\"\n >\n {index > 0 && (\n <span\n aria-hidden=\"true\"\n className=\"shrink-0 text-xxs text-quaternary\"\n >\n {separator}\n </span>\n )}\n {item}\n </li>\n ))}\n </ol>\n </nav>\n );\n }\n);\nBreadcrumb.displayName = 'Breadcrumb';\n\nconst BreadcrumbLink = forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(\n (\n {\n children,\n className,\n as,\n leftDecorator: LeftIcon,\n rightDecorator: RightIcon,\n iconWeight = 'regular',\n variant = 'xs',\n ...props\n },\n ref\n ) => {\n const linkProps = {\n ...(typeof children === 'string' && as?.props.title === undefined\n ? { title: children }\n : {}),\n ...props,\n ref,\n className: cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:text-secondary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus',\n as?.props.className,\n className\n ),\n children: (\n <>\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n <Text\n as=\"span\"\n variant={variant}\n weight=\"medium\"\n className=\"min-w-0 max-w-50 truncate\"\n >\n {children}\n </Text>\n {RightIcon && (\n <RightIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n </>\n ),\n };\n\n return as ? cloneElement(as, linkProps) : <a {...linkProps} />;\n }\n);\nBreadcrumbLink.displayName = 'BreadcrumbLink';\n\nconst BreadcrumbPage = forwardRef<HTMLSpanElement, BreadcrumbPageProps>(\n ({ children, className, leftDecorator: LeftIcon, ...props }, ref) => (\n <span\n ref={ref}\n aria-current=\"page\"\n title={typeof children === 'string' ? children : undefined}\n className={cn(\n 'inline-flex min-w-0 items-center gap-space-1 text-secondary',\n className\n )}\n {...props}\n >\n {LeftIcon && (\n <LeftIcon aria-hidden size={12} weight=\"regular\" className=\"shrink-0\" />\n )}\n <Text\n as=\"span\"\n variant=\"xs\"\n weight=\"medium\"\n className=\"min-w-0 max-w-50 truncate\"\n >\n {children}\n </Text>\n </span>\n )\n);\nBreadcrumbPage.displayName = 'BreadcrumbPage';\n\nexport { Breadcrumb, BreadcrumbLink, BreadcrumbPage };\nexport type { BreadcrumbProps, BreadcrumbLinkProps, BreadcrumbPageProps };\n"],"mappings":";;;;;AAuBA,IAAM,aAAa,YAChB,EAAE,UAAU,WAAW,YAAY,KAAK,GAAG,SAAS,QAAQ;CAC3D,MAAM,QAAQ,SAAS,QAAQ,QAAQ,CAAC,CAAC,QAAQ,SAAS,SAAS,EAAE;CACrE,IAAI,CAAC,MAAM,QAAQ,OAAO;CAE1B,OACE,oBAAC,OAAD;EACO;EACL,cAAW;EACX,WAAW,GAAG,WAAW,SAAS;EAClC,GAAI;EAEJ,UAAA,oBAAC,MAAD;GAAI,MAAK;GAAO,WAAU;GACvB,UAAA,MAAM,KAAK,MAAM,UAChB,qBAAC,MAAD;IAEE,WAAU;IAFZ,UAAA,CAIG,QAAQ,KACP,oBAAC,QAAD;KACE,eAAY;KACZ,WAAU;KAET,UAAA;IACG,CAAA,GAEP,IACC;GAZG,GAAA,OAAO,SAAS,YAAY,SAAS,OAAO,KAAK,MAAM,KAY1D,CACL;EACC,CAAA;CACD,CAAA;AAET,CACF;AACA,WAAW,cAAc;AAEzB,IAAM,iBAAiB,YAEnB,EACE,UACA,WACA,IACA,eAAe,UACf,gBAAgB,WAChB,aAAa,WACb,UAAU,MACV,GAAG,SAEL,QACG;CACH,MAAM,YAAY;EAChB,GAAI,OAAO,aAAa,YAAY,IAAI,MAAM,UAAU,KAAA,IACpD,EAAE,OAAO,SAAS,IAClB,CAAC;EACL,GAAG;EACH;EACA,WAAW,GACT,8MACA,IAAI,MAAM,WACV,SACF;EACA,UACE,qBAAA,YAAA,EAAA,UAAA;GACG,YACC,oBAAC,UAAD;IACE,eAAA;IACA,MAAM;IACN,QAAQ;IACR,WAAU;GACX,CAAA;GAEH,oBAAC,MAAD;IACE,IAAG;IACM;IACT,QAAO;IACP,WAAU;IAET;GACG,CAAA;GACL,aACC,oBAAC,WAAD;IACE,eAAA;IACA,MAAM;IACN,QAAQ;IACR,WAAU;GACX,CAAA;EAEH,EAAA,CAAA;CAEN;CAEA,OAAO,KAAK,aAAa,IAAI,SAAS,IAAI,oBAAC,KAAD,EAAG,GAAI,UAAY,CAAA;AAC/D,CACF;AACA,eAAe,cAAc;AAE7B,IAAM,iBAAiB,YACpB,EAAE,UAAU,WAAW,eAAe,UAAU,GAAG,SAAS,QAC3D,qBAAC,QAAD;CACO;CACL,gBAAa;CACb,OAAO,OAAO,aAAa,WAAW,WAAW,KAAA;CACjD,WAAW,GACT,+DACA,SACF;CACA,GAAI;CARN,UAAA,CAUG,YACC,oBAAC,UAAD;EAAU,eAAA;EAAY,MAAM;EAAI,QAAO;EAAU,WAAU;CAAY,CAAA,GAEzE,oBAAC,MAAD;EACE,IAAG;EACH,SAAQ;EACR,QAAO;EACP,WAAU;EAET;CACG,CAAA,CACF;AAEV,CAAA,CAAA;AACA,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"Breadcrumb.js","names":[],"sources":["../../../src/components/Breadcrumb/Breadcrumb.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n createContext,\n forwardRef,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentPropsWithoutRef,\n type ReactNode,\n} from 'react';\n\nimport { TooltipProvider } from '@radix-ui/react-tooltip';\n\nimport { cn } from '../../utils/cn';\nimport type { IconComponent } from '../../utils/icon-types';\nimport type { LinkProps } from '../Link';\nimport { Text } from '../Text';\nimport { Tooltip, type TooltipProps } from '../Tooltip';\n\ntype BreadcrumbProps = ComponentPropsWithoutRef<'nav'> & {\n separator?: ReactNode;\n /** Cap labels at 148px instead of 200px. The consuming layout chooses when. */\n condensed?: boolean;\n};\n\ntype BreadcrumbLinkProps = LinkProps;\n\ntype BreadcrumbPageProps = ComponentPropsWithoutRef<'span'> & {\n leftDecorator?: IconComponent;\n};\n\nconst BreadcrumbContext = createContext({\n condensed: false,\n hasTooltipProvider: false,\n});\n\nfunction SlashSeparator() {\n return (\n <svg\n aria-hidden=\"true\"\n width={10}\n height={10}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n >\n <path\n d=\"M7 22 17 2\"\n stroke=\"currentColor\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n />\n </svg>\n );\n}\n\nconst Breadcrumb = forwardRef<HTMLElement, BreadcrumbProps>(\n (\n {\n children,\n className,\n separator = <SlashSeparator />,\n condensed = false,\n ...props\n },\n ref\n ) => {\n const items = Children.toArray(children).filter((item) => item !== '');\n const listRef = useRef<HTMLOListElement>(null);\n const [scrollable, setScrollable] = useState(false);\n\n useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) {\n setScrollable(false);\n return;\n }\n const measure = () => setScrollable(list.scrollWidth > list.clientWidth);\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(list);\n for (const item of list.children) observer.observe(item);\n return () => observer.disconnect();\n }, [children, condensed]);\n\n if (!items.length) return null;\n\n return (\n <BreadcrumbContext.Provider\n value={{ condensed, hasTooltipProvider: true }}\n >\n <TooltipProvider>\n <nav\n ref={ref}\n aria-label=\"Breadcrumb\"\n className={cn('min-w-0', className)}\n {...props}\n >\n <ol\n ref={listRef}\n role=\"list\"\n tabIndex={scrollable ? 0 : -1}\n className=\"flex flex-nowrap items-center gap-space-2 overflow-x-auto rounded-sm focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus\"\n >\n {items.map((item, index) => (\n <li\n key={\n typeof item === 'object' && 'key' in item ? item.key : index\n }\n className=\"flex min-w-0 max-w-full shrink-0 items-center gap-space-2\"\n >\n {index > 0 && (\n <span\n aria-hidden=\"true\"\n className=\"flex shrink-0 items-center text-xxs text-quaternary\"\n >\n {separator}\n </span>\n )}\n {item}\n </li>\n ))}\n </ol>\n </nav>\n </TooltipProvider>\n </BreadcrumbContext.Provider>\n );\n }\n);\nBreadcrumb.displayName = 'Breadcrumb';\n\nfunction useBreadcrumbLabel(children: ReactNode) {\n const { condensed } = useContext(BreadcrumbContext);\n const labelRef = useRef<HTMLElement>(null);\n const [text, setText] = useState('');\n const [clipped, setClipped] = useState(false);\n const [open, setOpen] = useState(false);\n\n useLayoutEffect(() => {\n const label = labelRef.current;\n if (!label) return;\n let active = true;\n function measure() {\n if (!active || !label) return;\n const isClipped = label.scrollWidth > label.clientWidth;\n setText(label.textContent ?? '');\n setClipped(isClipped);\n if (!isClipped) setOpen(false);\n }\n\n measure();\n const resizeObserver = new ResizeObserver(measure);\n resizeObserver.observe(label);\n const mutationObserver = new MutationObserver(measure);\n mutationObserver.observe(label, {\n childList: true,\n characterData: true,\n subtree: true,\n });\n // A font change can change scrollWidth without changing the capped width.\n const fonts = label.ownerDocument.fonts;\n void fonts?.ready.then(measure);\n fonts?.addEventListener('loadingdone', measure);\n return () => {\n active = false;\n resizeObserver.disconnect();\n mutationObserver.disconnect();\n fonts?.removeEventListener('loadingdone', measure);\n };\n }, [children, condensed]);\n\n return {\n labelRef,\n clipped,\n labelClassName: cn('min-w-0 max-w-50 truncate', condensed && 'max-w-37'),\n tooltipProps: {\n // Keep the trigger mounted when clipping changes, preserving keyboard focus.\n title: (\n <Text variant=\"sm\" className=\"text-primary\">\n {text}\n </Text>\n ),\n open: clipped && open,\n onOpenChange: (nextOpen: boolean) => setOpen(clipped && nextOpen),\n },\n };\n}\n\nfunction BreadcrumbTooltip(props: TooltipProps) {\n const { hasTooltipProvider } = useContext(BreadcrumbContext);\n const tooltip = <Tooltip {...props} />;\n // Exported links/pages also work on their own, without an application provider.\n return hasTooltipProvider ? (\n tooltip\n ) : (\n <TooltipProvider>{tooltip}</TooltipProvider>\n );\n}\n\nconst BreadcrumbLink = forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(\n (\n {\n children,\n className,\n as,\n leftDecorator: LeftIcon,\n rightDecorator: RightIcon,\n iconWeight = 'regular',\n variant = 'xs',\n ...props\n },\n ref\n ) => {\n const { labelRef, labelClassName, tooltipProps } =\n useBreadcrumbLabel(children);\n const linkProps = {\n ...props,\n ref,\n className: cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-quaternary hover:underline underline-offset-2 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus',\n as?.props.className,\n className\n ),\n children: (\n <>\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n <Text\n ref={labelRef}\n as=\"span\"\n variant={variant}\n weight=\"medium\"\n className={labelClassName}\n >\n {children}\n </Text>\n {RightIcon && (\n <RightIcon\n aria-hidden\n size={12}\n weight={iconWeight}\n className=\"shrink-0\"\n />\n )}\n </>\n ),\n };\n\n return (\n <BreadcrumbTooltip {...tooltipProps}>\n {as ? cloneElement(as, linkProps) : <a {...linkProps} />}\n </BreadcrumbTooltip>\n );\n }\n);\nBreadcrumbLink.displayName = 'BreadcrumbLink';\n\nconst BreadcrumbPage = forwardRef<HTMLSpanElement, BreadcrumbPageProps>(\n (\n {\n children,\n className,\n leftDecorator: LeftIcon,\n tabIndex,\n onFocus,\n ...props\n },\n ref\n ) => {\n const { labelRef, labelClassName, clipped, tooltipProps } =\n useBreadcrumbLabel(children);\n return (\n <BreadcrumbTooltip {...tooltipProps}>\n <span\n ref={ref}\n aria-current=\"page\"\n tabIndex={tabIndex ?? (clipped ? 0 : -1)}\n onFocus={(event) => {\n onFocus?.(event);\n if (!event.defaultPrevented) {\n event.currentTarget.scrollIntoView({\n block: 'nearest',\n inline: 'nearest',\n });\n }\n }}\n className={cn(\n 'inline-flex min-w-0 items-center gap-space-1 rounded-sm text-secondary focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus',\n className\n )}\n {...props}\n >\n {LeftIcon && (\n <LeftIcon\n aria-hidden\n size={12}\n weight=\"regular\"\n className=\"shrink-0\"\n />\n )}\n <Text\n ref={labelRef}\n as=\"span\"\n variant=\"xs\"\n weight=\"medium\"\n className={labelClassName}\n >\n {children}\n </Text>\n </span>\n </BreadcrumbTooltip>\n );\n }\n);\nBreadcrumbPage.displayName = 'BreadcrumbPage';\n\nexport { Breadcrumb, BreadcrumbLink, BreadcrumbPage };\nexport type { BreadcrumbProps, BreadcrumbLinkProps, BreadcrumbPageProps };\n"],"mappings":";;;;;;;AAiCA,IAAM,oBAAoB,cAAc;CACtC,WAAW;CACX,oBAAoB;AACtB,CAAC;AAED,SAAS,iBAAiB;CACxB,OACE,oBAAC,OAAD;EACE,eAAY;EACZ,OAAO;EACP,QAAQ;EACR,SAAQ;EACR,MAAK;EAEL,UAAA,oBAAC,QAAD;GACE,GAAE;GACF,QAAO;GACP,aAAa;GACb,eAAc;EACf,CAAA;CACE,CAAA;AAET;AAEA,IAAM,aAAa,YAEf,EACE,UACA,WACA,YAAY,oBAAC,gBAAD,CAAiB,CAAA,GAC7B,YAAY,OACZ,GAAG,SAEL,QACG;CACH,MAAM,QAAQ,SAAS,QAAQ,QAAQ,CAAC,CAAC,QAAQ,SAAS,SAAS,EAAE;CACrE,MAAM,UAAU,OAAyB,IAAI;CAC7C,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAElD,sBAAsB;EACpB,MAAM,OAAO,QAAQ;EACrB,IAAI,CAAC,MAAM;GACT,cAAc,KAAK;GACnB;EACF;EACA,MAAM,gBAAgB,cAAc,KAAK,cAAc,KAAK,WAAW;EACvE,QAAQ;EACR,MAAM,WAAW,IAAI,eAAe,OAAO;EAC3C,SAAS,QAAQ,IAAI;EACrB,KAAK,MAAM,QAAQ,KAAK,UAAU,SAAS,QAAQ,IAAI;EACvD,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,UAAU,SAAS,CAAC;CAExB,IAAI,CAAC,MAAM,QAAQ,OAAO;CAE1B,OACE,oBAAC,kBAAkB,UAAnB;EACE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