@fanvue/ui 3.40.1 → 3.42.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/cjs/components/Checkbox/Checkbox.cjs +6 -6
- package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/cjs/components/Dialog/Dialog.cjs +63 -55
- package/dist/cjs/components/Dialog/Dialog.cjs.map +1 -1
- package/dist/cjs/components/Icons/CommentIcon.cjs +74 -0
- package/dist/cjs/components/Icons/CommentIcon.cjs.map +1 -0
- package/dist/cjs/components/Tabs/Tabs.cjs +26 -1
- package/dist/cjs/components/Tabs/Tabs.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsList.cjs +163 -22
- package/dist/cjs/components/Tabs/TabsList.cjs.map +1 -1
- package/dist/cjs/components/Tabs/TabsOverflow.cjs +123 -0
- package/dist/cjs/components/Tabs/TabsOverflow.cjs.map +1 -0
- package/dist/cjs/components/Tabs/TabsTrigger.cjs +27 -14
- package/dist/cjs/components/Tabs/TabsTrigger.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/components/Checkbox/Checkbox.mjs +6 -6
- package/dist/components/Checkbox/Checkbox.mjs.map +1 -1
- package/dist/components/Dialog/Dialog.mjs +63 -55
- package/dist/components/Dialog/Dialog.mjs.map +1 -1
- package/dist/components/Icons/CommentIcon.mjs +57 -0
- package/dist/components/Icons/CommentIcon.mjs.map +1 -0
- package/dist/components/Tabs/Tabs.mjs +26 -2
- package/dist/components/Tabs/Tabs.mjs.map +1 -1
- package/dist/components/Tabs/TabsList.mjs +164 -23
- package/dist/components/Tabs/TabsList.mjs.map +1 -1
- package/dist/components/Tabs/TabsOverflow.mjs +106 -0
- package/dist/components/Tabs/TabsOverflow.mjs.map +1 -0
- package/dist/components/Tabs/TabsTrigger.mjs +27 -14
- package/dist/components/Tabs/TabsTrigger.mjs.map +1 -1
- package/dist/index.d.ts +103 -19
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { cn } from "../../utils/cn.mjs";
|
|
6
|
+
const TabsAppearanceContext = React.createContext({ appearance: "underline", size: "32" });
|
|
7
|
+
const PILL_EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
8
|
+
const PILL_STEP_MS = 360;
|
|
9
|
+
const PILL_STEP_MS_TOUCH = 200;
|
|
10
|
+
const PILL_EXTRA_STEP_MS = 220;
|
|
11
|
+
const PILL_MAX_MS = 1e3;
|
|
12
|
+
const PILL_ARRIVAL_SHARE = 0.27;
|
|
13
|
+
function pillStepMs(canHover) {
|
|
14
|
+
return canHover ? PILL_STEP_MS : PILL_STEP_MS_TOUCH;
|
|
15
|
+
}
|
|
16
|
+
function pillSlideMs(distance, canHover) {
|
|
17
|
+
if (!canHover) return PILL_STEP_MS_TOUCH;
|
|
18
|
+
return Math.min(PILL_STEP_MS + Math.max(distance - 1, 0) * PILL_EXTRA_STEP_MS, PILL_MAX_MS);
|
|
19
|
+
}
|
|
20
|
+
const prefersReducedMotion = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
21
|
+
function pillTarget(list, hovered, activeTab) {
|
|
22
|
+
return list.querySelector('[role="tab"][aria-expanded="true"]') ?? (hovered?.isConnected ? hovered : activeTab);
|
|
23
|
+
}
|
|
24
|
+
function measureTabs(list, observer) {
|
|
25
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
26
|
+
const order = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const tab of list.querySelectorAll('[role="tab"]')) {
|
|
28
|
+
observer?.observe(tab);
|
|
29
|
+
order.set(tab, order.size);
|
|
30
|
+
boxes.set(tab, {
|
|
31
|
+
left: tab.offsetLeft,
|
|
32
|
+
top: tab.offsetTop,
|
|
33
|
+
width: tab.offsetWidth,
|
|
34
|
+
height: tab.offsetHeight
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return { boxes, order };
|
|
38
|
+
}
|
|
39
|
+
function slideFromPrevious(list, previous, next, durationMs) {
|
|
40
|
+
const moved = [];
|
|
41
|
+
for (const [tab, box] of next) {
|
|
42
|
+
const before = previous.get(tab);
|
|
43
|
+
if (!before || before.left === box.left || !(tab instanceof HTMLElement)) continue;
|
|
44
|
+
tab.style.transition = "none";
|
|
45
|
+
tab.style.transform = `translateX(${before.left - box.left}px)`;
|
|
46
|
+
moved.push(tab);
|
|
47
|
+
}
|
|
48
|
+
if (moved.length === 0) return;
|
|
49
|
+
list.getBoundingClientRect();
|
|
50
|
+
for (const tab of moved) {
|
|
51
|
+
tab.style.transition = `transform ${durationMs}ms var(--pill-ease)`;
|
|
52
|
+
tab.style.transform = "";
|
|
53
|
+
const settle = (event) => {
|
|
54
|
+
if (event.propertyName !== "transform") return;
|
|
55
|
+
tab.style.transition = "";
|
|
56
|
+
tab.removeEventListener("transitionend", settle);
|
|
57
|
+
};
|
|
58
|
+
tab.addEventListener("transitionend", settle);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
6
61
|
const alignLeftClasses = {
|
|
7
62
|
always: "[&>[role=tab]]:flex-initial",
|
|
8
63
|
sm: "[&>[role=tab]]:sm:flex-initial",
|
|
@@ -28,11 +83,61 @@ const TabsList = React.forwardRef(
|
|
|
28
83
|
variant,
|
|
29
84
|
flushLeft = false,
|
|
30
85
|
scrollable = false,
|
|
86
|
+
appearance = "underline",
|
|
87
|
+
size = "32",
|
|
88
|
+
followHover = false,
|
|
89
|
+
onPointerOver,
|
|
90
|
+
onPointerLeave,
|
|
91
|
+
style,
|
|
31
92
|
...props
|
|
32
93
|
}, ref) => {
|
|
33
94
|
const innerRef = React.useRef(null);
|
|
34
95
|
const indicatorRef = React.useRef(null);
|
|
35
96
|
React.useImperativeHandle(ref, () => innerRef.current);
|
|
97
|
+
const tabBoxes = React.useRef(/* @__PURE__ */ new Map());
|
|
98
|
+
const resizeObserverRef = React.useRef(null);
|
|
99
|
+
const listWidth = React.useRef(null);
|
|
100
|
+
const hoveredTab = React.useRef(null);
|
|
101
|
+
const pillTab = React.useRef(null);
|
|
102
|
+
const tabOrder = React.useRef(/* @__PURE__ */ new Map());
|
|
103
|
+
const canHover = React.useRef(false);
|
|
104
|
+
const placePill = React.useCallback((tab) => {
|
|
105
|
+
const list = innerRef.current;
|
|
106
|
+
const indicator = indicatorRef.current;
|
|
107
|
+
if (!list || !indicator) return;
|
|
108
|
+
const box = tabBoxes.current.get(tab);
|
|
109
|
+
if (!box) return;
|
|
110
|
+
const from = pillTab.current;
|
|
111
|
+
pillTab.current = tab;
|
|
112
|
+
const distance = from && from !== tab ? Math.abs((tabOrder.current.get(tab) ?? 0) - (tabOrder.current.get(from) ?? 0)) : 0;
|
|
113
|
+
const slideMs = pillSlideMs(distance, canHover.current);
|
|
114
|
+
list.style.setProperty("--pill-slide", `${slideMs}ms`);
|
|
115
|
+
list.style.setProperty("--pill-arrive", `${Math.round(slideMs * PILL_ARRIVAL_SHARE)}ms`);
|
|
116
|
+
indicator.style.width = `${box.width}px`;
|
|
117
|
+
indicator.style.height = `${box.height}px`;
|
|
118
|
+
indicator.style.transform = `translate(${box.left}px, ${box.top}px)`;
|
|
119
|
+
for (const marked of list.querySelectorAll("[data-pill]")) {
|
|
120
|
+
if (marked !== tab) marked.removeAttribute("data-pill");
|
|
121
|
+
}
|
|
122
|
+
tab.setAttribute("data-pill", "");
|
|
123
|
+
}, []);
|
|
124
|
+
const layoutPill = React.useCallback(
|
|
125
|
+
(list, indicator, activeTab) => {
|
|
126
|
+
indicator.style.background = "var(--color-content-primary)";
|
|
127
|
+
indicator.style.inset = "0 auto auto 0";
|
|
128
|
+
const previous = tabBoxes.current;
|
|
129
|
+
const rowResized = listWidth.current !== null && listWidth.current !== list.offsetWidth;
|
|
130
|
+
listWidth.current = list.offsetWidth;
|
|
131
|
+
const { boxes, order } = measureTabs(list, resizeObserverRef.current);
|
|
132
|
+
tabBoxes.current = boxes;
|
|
133
|
+
tabOrder.current = order;
|
|
134
|
+
if (!rowResized && previous.size > 0 && !prefersReducedMotion()) {
|
|
135
|
+
slideFromPrevious(list, previous, boxes, pillStepMs(canHover.current));
|
|
136
|
+
}
|
|
137
|
+
placePill(pillTarget(list, hoveredTab.current, activeTab));
|
|
138
|
+
},
|
|
139
|
+
[placePill]
|
|
140
|
+
);
|
|
36
141
|
const updateIndicator = React.useCallback(() => {
|
|
37
142
|
const list = innerRef.current;
|
|
38
143
|
const indicator = indicatorRef.current;
|
|
@@ -40,11 +145,14 @@ const TabsList = React.forwardRef(
|
|
|
40
145
|
const activeTab = list.querySelector('[data-state="active"]');
|
|
41
146
|
if (!activeTab) {
|
|
42
147
|
indicator.style.opacity = "0";
|
|
148
|
+
list.querySelector("[data-pill]")?.removeAttribute("data-pill");
|
|
43
149
|
return;
|
|
44
150
|
}
|
|
45
151
|
const isVertical = list.dataset.orientation === "vertical";
|
|
46
152
|
indicator.style.opacity = "1";
|
|
47
|
-
if (
|
|
153
|
+
if (appearance === "pill") {
|
|
154
|
+
layoutPill(list, indicator, activeTab);
|
|
155
|
+
} else if (isVertical) {
|
|
48
156
|
indicator.style.background = "linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)";
|
|
49
157
|
indicator.style.inset = `0 -1px auto auto`;
|
|
50
158
|
indicator.style.width = "1px";
|
|
@@ -57,19 +165,42 @@ const TabsList = React.forwardRef(
|
|
|
57
165
|
indicator.style.width = `${activeTab.offsetWidth}px`;
|
|
58
166
|
indicator.style.transform = `translateX(${activeTab.offsetLeft}px)`;
|
|
59
167
|
}
|
|
60
|
-
}, []);
|
|
168
|
+
}, [appearance, layoutPill]);
|
|
169
|
+
const followsHover = appearance === "pill" && followHover;
|
|
170
|
+
const handlePointerOver = (event) => {
|
|
171
|
+
onPointerOver?.(event);
|
|
172
|
+
if (!followsHover || event.pointerType !== "mouse") return;
|
|
173
|
+
if (prefersReducedMotion()) return;
|
|
174
|
+
const tab = event.target.closest('[role="tab"]');
|
|
175
|
+
if (!tab || tab === hoveredTab.current || !event.currentTarget.contains(tab)) return;
|
|
176
|
+
hoveredTab.current = tab;
|
|
177
|
+
placePill(pillTarget(event.currentTarget, tab, tab));
|
|
178
|
+
};
|
|
179
|
+
const handlePointerLeave = (event) => {
|
|
180
|
+
onPointerLeave?.(event);
|
|
181
|
+
if (!hoveredTab.current) return;
|
|
182
|
+
hoveredTab.current = null;
|
|
183
|
+
const list = innerRef.current;
|
|
184
|
+
const activeTab = list?.querySelector('[data-state="active"]');
|
|
185
|
+
if (list && activeTab) placePill(pillTarget(list, null, activeTab));
|
|
186
|
+
};
|
|
61
187
|
const revealActiveTab = React.useCallback(() => {
|
|
62
188
|
const list = innerRef.current;
|
|
63
|
-
|
|
189
|
+
const scrolls = scrollable || appearance === "pill";
|
|
190
|
+
if (!list || !scrolls || list.dataset.orientation === "vertical") return;
|
|
64
191
|
const activeTab = list.querySelector('[data-state="active"]');
|
|
65
192
|
if (!activeTab) return;
|
|
66
193
|
const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;
|
|
67
194
|
if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;
|
|
68
|
-
}, [scrollable]);
|
|
195
|
+
}, [scrollable, appearance]);
|
|
69
196
|
React.useLayoutEffect(() => {
|
|
70
197
|
const list = innerRef.current;
|
|
71
198
|
const indicator = indicatorRef.current;
|
|
72
199
|
if (!list || !indicator) return;
|
|
200
|
+
canHover.current = window.matchMedia?.("(hover: hover)").matches ?? false;
|
|
201
|
+
const resizeObserver = new ResizeObserver(updateIndicator);
|
|
202
|
+
resizeObserver.observe(list);
|
|
203
|
+
resizeObserverRef.current = resizeObserver;
|
|
73
204
|
indicator.style.transitionDuration = "0s";
|
|
74
205
|
updateIndicator();
|
|
75
206
|
indicator.getBoundingClientRect();
|
|
@@ -78,12 +209,10 @@ const TabsList = React.forwardRef(
|
|
|
78
209
|
const mutationObserver = new MutationObserver(updateIndicator);
|
|
79
210
|
mutationObserver.observe(list, {
|
|
80
211
|
attributes: true,
|
|
81
|
-
attributeFilter: ["data-state"],
|
|
212
|
+
attributeFilter: ["data-state", "aria-expanded"],
|
|
82
213
|
childList: true,
|
|
83
214
|
subtree: true
|
|
84
215
|
});
|
|
85
|
-
const resizeObserver = new ResizeObserver(updateIndicator);
|
|
86
|
-
resizeObserver.observe(list);
|
|
87
216
|
let cancelled = false;
|
|
88
217
|
if (document.fonts?.status !== "loaded") {
|
|
89
218
|
document.fonts?.ready.then(() => {
|
|
@@ -96,29 +225,37 @@ const TabsList = React.forwardRef(
|
|
|
96
225
|
cancelled = true;
|
|
97
226
|
mutationObserver.disconnect();
|
|
98
227
|
resizeObserver.disconnect();
|
|
228
|
+
resizeObserverRef.current = null;
|
|
99
229
|
};
|
|
100
230
|
}, [updateIndicator, revealActiveTab]);
|
|
101
|
-
|
|
231
|
+
const isPill = appearance === "pill";
|
|
232
|
+
const listStyle = isPill ? { "--pill-ease": PILL_EASE, ...style } : { ...style };
|
|
233
|
+
return /* @__PURE__ */ jsx(TabsAppearanceContext.Provider, { value: { appearance, size }, children: /* @__PURE__ */ jsxs(
|
|
102
234
|
TabsPrimitive.List,
|
|
103
235
|
{
|
|
104
236
|
ref: innerRef,
|
|
237
|
+
onPointerOver: handlePointerOver,
|
|
238
|
+
onPointerLeave: handlePointerLeave,
|
|
239
|
+
style: listStyle,
|
|
105
240
|
className: cn(
|
|
106
241
|
// `isolate` scopes the active indicator's `z-10` to a local stacking
|
|
107
242
|
// context. Without it, `relative` alone creates no stacking context, so
|
|
108
243
|
// the indicator escapes and paints above page chrome (e.g. the header).
|
|
109
244
|
"relative isolate",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
245
|
+
isPill ? "inline-flex w-fit max-w-full items-center gap-1 overflow-x-auto rounded-full bg-background-secondary p-1 shadow-md [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" : [
|
|
246
|
+
getLayoutClass(variant, fullWidth, alignLeft),
|
|
247
|
+
// Horizontal only: in the vertical orientation the leading padding is
|
|
248
|
+
// the row's left inset, not a label offset, so zeroing it would pull
|
|
249
|
+
// the first label out of line with the others.
|
|
250
|
+
flushLeft && "data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0",
|
|
251
|
+
// `flex-none` is what stops the tabs compressing — without it they
|
|
252
|
+
// share the row and never overflow, so there is nothing to scroll.
|
|
253
|
+
// The scrollbar is hidden in both engines: Firefox reads
|
|
254
|
+
// `scrollbar-width`, WebKit and Blink the pseudo-element.
|
|
255
|
+
scrollable && "data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none",
|
|
256
|
+
"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]",
|
|
257
|
+
"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]"
|
|
258
|
+
],
|
|
122
259
|
className
|
|
123
260
|
),
|
|
124
261
|
...props,
|
|
@@ -129,17 +266,21 @@ const TabsList = React.forwardRef(
|
|
|
129
266
|
{
|
|
130
267
|
ref: indicatorRef,
|
|
131
268
|
"aria-hidden": true,
|
|
132
|
-
className:
|
|
269
|
+
className: cn(
|
|
270
|
+
"pointer-events-none absolute rounded-full motion-safe:transition-[transform,width,height]",
|
|
271
|
+
isPill ? "z-5 motion-safe:duration-(--pill-slide) motion-safe:ease-(--pill-ease)" : "z-10 motion-safe:duration-200 motion-safe:ease-in-out"
|
|
272
|
+
),
|
|
133
273
|
style: { opacity: 0 }
|
|
134
274
|
}
|
|
135
275
|
)
|
|
136
276
|
]
|
|
137
277
|
}
|
|
138
|
-
);
|
|
278
|
+
) });
|
|
139
279
|
}
|
|
140
280
|
);
|
|
141
281
|
TabsList.displayName = "TabsList";
|
|
142
282
|
export {
|
|
283
|
+
TabsAppearanceContext,
|
|
143
284
|
TabsList
|
|
144
285
|
};
|
|
145
286
|
//# sourceMappingURL=TabsList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabsList.mjs","sources":["../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n /**\n * Drops the leading padding on the first tab so its label sits flush with the\n * list's left edge, lining it up with page content above or below the bar\n * (a heading, for instance) rather than being indented by the tab's own\n * padding. Spacing between tabs is unaffected. Pair with `alignLeft` or\n * `variant=\"hug\"`. @default false\n */\n flushLeft?: boolean;\n /**\n * Scrolls the row horizontally when the tabs don't fit, instead of letting\n * them compress. By default a tab may shrink until its label ellipsises,\n * which on a narrow viewport can truncate every label at once; here each tab\n * keeps its natural width and the overflow scrolls. The scrollbar itself is\n * hidden — the clipped tab at the edge is the affordance.\n *\n * Because the tabs are content-sized, they no longer spread to fill the row:\n * a set that does fit sits left-aligned, as with `alignLeft`.\n *\n * Horizontal orientation only: a vertical list already grows downwards.\n * @default false\n */\n scrollable?: boolean;\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(\n (\n {\n className,\n children,\n fullWidth = true,\n alignLeft,\n variant,\n flushLeft = false,\n scrollable = false,\n ...props\n },\n ref,\n ) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${activeTab.offsetWidth}px`;\n indicator.style.transform = `translateX(${activeTab.offsetLeft}px)`;\n }\n }, []);\n\n // Radix scrolls a tab into view when it takes focus, and mount is not focus, so\n // URL-driven state can land on a tab that is off to the right with nothing on\n // screen to say so: no indicator, and tab one showing as though it were active.\n // Assigns `scrollLeft` rather than calling `scrollIntoView`, which would also\n // scroll every ancestor and the page with it. Only ever scrolls further right, so\n // re-running it after the webfont settles corrects a short initial scroll without\n // yanking the row back from wherever the user has since dragged it.\n const revealActiveTab = React.useCallback(() => {\n const list = innerRef.current;\n if (!list || !scrollable || list.dataset.orientation === \"vertical\") return;\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) return;\n const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;\n if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;\n }, [scrollable]);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n revealActiveTab();\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\"],\n childList: true,\n subtree: true,\n });\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (cancelled) return;\n updateIndicator();\n // The tabs are wider once the real font is in, so the mount-time scroll can\n // fall short of the active tab. Recomputed here against the settled layout.\n revealActiveTab();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n };\n }, [updateIndicator, revealActiveTab]);\n\n return (\n <TabsPrimitive.List\n ref={innerRef}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n getLayoutClass(variant, fullWidth, alignLeft),\n // Horizontal only: in the vertical orientation the leading padding is\n // the row's left inset, not a label offset, so zeroing it would pull\n // the first label out of line with the others.\n flushLeft && \"data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0\",\n // `flex-none` is what stops the tabs compressing — without it they\n // share the row and never overflow, so there is nothing to scroll.\n // The scrollbar is hidden in both engines: Firefox reads\n // `scrollbar-width`, WebKit and Blink the pseudo-element.\n scrollable &&\n \"data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none\",\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className=\"pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out\"\n style={{ opacity: 0 }}\n />\n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AAiB,WAAA;AACjB,uBAAe,WAAA;AAAA,MACjB;AAAA,IACF,GAAG,CAAC,iBAAiB,eAAe,CAAC;AAErC,WACE;AAAA,MAAC,cAAc;AAAA,MAAd;AAAA,QACC,KAAK;AAAA,QACL,WAAW;AAAA;AAAA;AAAA;AAAA,UAIT;AAAA,UACA,eAAe,SAAS,WAAW,SAAS;AAAA;AAAA;AAAA;AAAA,UAI5C,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,UAKb,cACE;AAAA,UACF;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAW;AAAA,cACX,WAAU;AAAA,cACV,OAAO,EAAE,SAAS,EAAA;AAAA,YAAE;AAAA,UAAA;AAAA,QACtB;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;"}
|
|
1
|
+
{"version":3,"file":"TabsList.mjs","sources":["../../../src/components/Tabs/TabsList.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Breakpoint values for responsive props. */\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\n/** Visual style of a {@link TabsList}. */\nexport type TabsListAppearance = \"underline\" | \"pill\";\n\n/** Height in pixels of each tab in a pill {@link TabsList}. */\nexport type TabsListPillSize = \"32\" | \"36\";\n\nexport const TabsAppearanceContext = React.createContext<{\n appearance: TabsListAppearance;\n size: TabsListPillSize;\n}>({ appearance: \"underline\", size: \"32\" });\n\ntype TabBox = { left: number; top: number; width: number; height: number };\n\nconst PILL_EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\nconst PILL_STEP_MS = 360;\nconst PILL_STEP_MS_TOUCH = 200;\nconst PILL_EXTRA_STEP_MS = 220;\nconst PILL_MAX_MS = 1000;\n/** Share of a slide by which the eased pill has covered 80% of the way, so the label recolours under it. */\nconst PILL_ARRIVAL_SHARE = 0.27;\n\nfunction pillStepMs(canHover: boolean) {\n return canHover ? PILL_STEP_MS : PILL_STEP_MS_TOUCH;\n}\n\nfunction pillSlideMs(distance: number, canHover: boolean) {\n if (!canHover) return PILL_STEP_MS_TOUCH;\n return Math.min(PILL_STEP_MS + Math.max(distance - 1, 0) * PILL_EXTRA_STEP_MS, PILL_MAX_MS);\n}\n\nconst prefersReducedMotion = () =>\n window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches ?? false;\n\nfunction pillTarget(list: HTMLElement, hovered: HTMLElement | null, activeTab: HTMLElement) {\n return (\n list.querySelector<HTMLElement>('[role=\"tab\"][aria-expanded=\"true\"]') ??\n (hovered?.isConnected ? hovered : activeTab)\n );\n}\n\nfunction measureTabs(list: HTMLElement, observer: ResizeObserver | null) {\n const boxes = new Map<Element, TabBox>();\n const order = new Map<Element, number>();\n for (const tab of list.querySelectorAll<HTMLElement>('[role=\"tab\"]')) {\n observer?.observe(tab);\n order.set(tab, order.size);\n boxes.set(tab, {\n left: tab.offsetLeft,\n top: tab.offsetTop,\n width: tab.offsetWidth,\n height: tab.offsetHeight,\n });\n }\n return { boxes, order };\n}\n\nfunction slideFromPrevious(\n list: HTMLElement,\n previous: Map<Element, TabBox>,\n next: Map<Element, TabBox>,\n durationMs: number,\n) {\n const moved: HTMLElement[] = [];\n for (const [tab, box] of next) {\n const before = previous.get(tab);\n if (!before || before.left === box.left || !(tab instanceof HTMLElement)) continue;\n tab.style.transition = \"none\";\n tab.style.transform = `translateX(${before.left - box.left}px)`;\n moved.push(tab);\n }\n if (moved.length === 0) return;\n list.getBoundingClientRect();\n for (const tab of moved) {\n tab.style.transition = `transform ${durationMs}ms var(--pill-ease)`;\n tab.style.transform = \"\";\n const settle = (event: TransitionEvent) => {\n if (event.propertyName !== \"transform\") return;\n tab.style.transition = \"\";\n tab.removeEventListener(\"transitionend\", settle);\n };\n tab.addEventListener(\"transitionend\", settle);\n }\n}\n\nconst alignLeftClasses: Record<Breakpoint | \"always\", string> = {\n always: \"[&>[role=tab]]:flex-initial\",\n sm: \"[&>[role=tab]]:sm:flex-initial\",\n md: \"[&>[role=tab]]:md:flex-initial\",\n lg: \"[&>[role=tab]]:lg:flex-initial\",\n xl: \"[&>[role=tab]]:xl:flex-initial\",\n};\n\nfunction getLayoutClass(\n variant: \"fill\" | \"hug\" | undefined,\n fullWidth: boolean,\n alignLeft?: boolean | Breakpoint,\n): string {\n if (variant === \"hug\") return \"inline-flex\";\n if (variant === \"fill\") return \"flex w-full [&>[role=tab]]:flex-1\";\n\n if (!fullWidth) return \"inline-flex\";\n\n const base = \"flex w-full [&>[role=tab]]:flex-1\";\n if (alignLeft === true) return `${base} ${alignLeftClasses.always}`;\n if (typeof alignLeft === \"string\") return `${base} ${alignLeftClasses[alignLeft]}`;\n return base;\n}\n\n/** Props for the {@link TabsList} component. */\nexport type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & {\n /** When `true` (the default), the tab list spans the full width of its container and each tab grows equally. Set to `false` for inline sizing. */\n fullWidth?: boolean;\n /**\n * Controls tab alignment within a full-width container.\n * - `false` (default): tabs spread evenly\n * - `true`: tabs left-aligned, sized to content\n * - `\"md\"` (breakpoint): spread on mobile, left-aligned at breakpoint and up\n */\n alignLeft?: boolean | Breakpoint;\n /** Explicit layout variant. `\"hug\"` sizes the list to its content; `\"fill\"` stretches it full-width with equal-width tabs. Takes precedence over `fullWidth`/`alignLeft`. */\n variant?: \"fill\" | \"hug\";\n /**\n * Drops the leading padding on the first tab so its label sits flush with the\n * list's left edge, lining it up with page content above or below the bar\n * (a heading, for instance) rather than being indented by the tab's own\n * padding. Spacing between tabs is unaffected. Pair with `alignLeft` or\n * `variant=\"hug\"`. @default false\n */\n flushLeft?: boolean;\n /**\n * Scrolls the row horizontally when the tabs don't fit, instead of letting\n * them compress. By default a tab may shrink until its label ellipsises,\n * which on a narrow viewport can truncate every label at once; here each tab\n * keeps its natural width and the overflow scrolls. The scrollbar itself is\n * hidden — the clipped tab at the edge is the affordance.\n *\n * Because the tabs are content-sized, they no longer spread to fill the row:\n * a set that does fit sits left-aligned, as with `alignLeft`.\n *\n * Horizontal orientation only: a vertical list already grows downwards.\n * @default false\n */\n scrollable?: boolean;\n /**\n * `\"underline\"` marks the active tab with a line under the row. `\"pill\"` sits\n * the tabs in a rounded track, sized to its tabs, and slides a filled pill\n * behind the active one. A pill list is horizontal and ignores `fullWidth`,\n * `alignLeft`, `variant` and `flushLeft`; it scrolls when it doesn't fit.\n * @default \"underline\"\n */\n appearance?: TabsListAppearance;\n /** Height of each tab in a pill list. Ignored by the underline appearance. @default \"32\" */\n size?: TabsListPillSize;\n /**\n * Pill only: the pill follows the mouse across the tabs and settles back on the\n * selected one when the pointer leaves. Mouse only, and off when the user prefers\n * reduced motion. @default false\n */\n followHover?: boolean;\n};\n\n/** Container for {@link TabsTrigger} elements. Renders a sliding active-tab indicator that animates between tabs. */\nexport const TabsList = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.List>,\n TabsListProps\n>(\n (\n {\n className,\n children,\n fullWidth = true,\n alignLeft,\n variant,\n flushLeft = false,\n scrollable = false,\n appearance = \"underline\",\n size = \"32\",\n followHover = false,\n onPointerOver,\n onPointerLeave,\n style,\n ...props\n },\n ref,\n ) => {\n const innerRef = React.useRef<HTMLDivElement>(null);\n const indicatorRef = React.useRef<HTMLSpanElement>(null);\n\n React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement);\n\n const tabBoxes = React.useRef(new Map<Element, TabBox>());\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\n const listWidth = React.useRef<number | null>(null);\n const hoveredTab = React.useRef<HTMLElement | null>(null);\n const pillTab = React.useRef<HTMLElement | null>(null);\n const tabOrder = React.useRef(new Map<Element, number>());\n const canHover = React.useRef(false);\n\n const placePill = React.useCallback((tab: HTMLElement) => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n const box = tabBoxes.current.get(tab);\n if (!box) return;\n const from = pillTab.current;\n pillTab.current = tab;\n const distance =\n from && from !== tab\n ? Math.abs((tabOrder.current.get(tab) ?? 0) - (tabOrder.current.get(from) ?? 0))\n : 0;\n const slideMs = pillSlideMs(distance, canHover.current);\n list.style.setProperty(\"--pill-slide\", `${slideMs}ms`);\n list.style.setProperty(\"--pill-arrive\", `${Math.round(slideMs * PILL_ARRIVAL_SHARE)}ms`);\n indicator.style.width = `${box.width}px`;\n indicator.style.height = `${box.height}px`;\n indicator.style.transform = `translate(${box.left}px, ${box.top}px)`;\n for (const marked of list.querySelectorAll(\"[data-pill]\")) {\n if (marked !== tab) marked.removeAttribute(\"data-pill\");\n }\n tab.setAttribute(\"data-pill\", \"\");\n }, []);\n\n const layoutPill = React.useCallback(\n (list: HTMLElement, indicator: HTMLElement, activeTab: HTMLElement) => {\n indicator.style.background = \"var(--color-content-primary)\";\n indicator.style.inset = \"0 auto auto 0\";\n const previous = tabBoxes.current;\n const rowResized = listWidth.current !== null && listWidth.current !== list.offsetWidth;\n listWidth.current = list.offsetWidth;\n const { boxes, order } = measureTabs(list, resizeObserverRef.current);\n tabBoxes.current = boxes;\n tabOrder.current = order;\n if (!rowResized && previous.size > 0 && !prefersReducedMotion()) {\n slideFromPrevious(list, previous, boxes, pillStepMs(canHover.current));\n }\n placePill(pillTarget(list, hoveredTab.current, activeTab));\n },\n [placePill],\n );\n\n const updateIndicator = React.useCallback(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) {\n indicator.style.opacity = \"0\";\n list.querySelector(\"[data-pill]\")?.removeAttribute(\"data-pill\");\n return;\n }\n\n const isVertical = list.dataset.orientation === \"vertical\";\n\n indicator.style.opacity = \"1\";\n\n if (appearance === \"pill\") {\n layoutPill(list, indicator, activeTab);\n } else if (isVertical) {\n indicator.style.background =\n \"linear-gradient(180deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = `0 -1px auto auto`;\n indicator.style.width = \"1px\";\n indicator.style.height = `${activeTab.offsetHeight}px`;\n indicator.style.transform = `translateY(${activeTab.offsetTop}px)`;\n } else {\n indicator.style.background =\n \"linear-gradient(90deg, var(--color-buttons-tertiary-default) 0%, var(--color-tab-active) 50%, var(--color-buttons-tertiary-default) 100%)\";\n indicator.style.inset = \"auto auto 0 0\";\n indicator.style.height = \"1px\";\n indicator.style.width = `${activeTab.offsetWidth}px`;\n indicator.style.transform = `translateX(${activeTab.offsetLeft}px)`;\n }\n }, [appearance, layoutPill]);\n\n const followsHover = appearance === \"pill\" && followHover;\n\n const handlePointerOver = (event: React.PointerEvent<HTMLDivElement>) => {\n onPointerOver?.(event);\n if (!followsHover || event.pointerType !== \"mouse\") return;\n if (prefersReducedMotion()) return;\n const tab = (event.target as Element).closest<HTMLElement>('[role=\"tab\"]');\n if (!tab || tab === hoveredTab.current || !event.currentTarget.contains(tab)) return;\n hoveredTab.current = tab;\n placePill(pillTarget(event.currentTarget, tab, tab));\n };\n\n const handlePointerLeave = (event: React.PointerEvent<HTMLDivElement>) => {\n onPointerLeave?.(event);\n if (!hoveredTab.current) return;\n hoveredTab.current = null;\n const list = innerRef.current;\n const activeTab = list?.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (list && activeTab) placePill(pillTarget(list, null, activeTab));\n };\n\n // Radix scrolls a tab into view when it takes focus, and mount is not focus, so\n // URL-driven state can land on a tab that is off to the right with nothing on\n // screen to say so: no indicator, and tab one showing as though it were active.\n // Assigns `scrollLeft` rather than calling `scrollIntoView`, which would also\n // scroll every ancestor and the page with it. Only ever scrolls further right, so\n // re-running it after the webfont settles corrects a short initial scroll without\n // yanking the row back from wherever the user has since dragged it.\n const revealActiveTab = React.useCallback(() => {\n const list = innerRef.current;\n const scrolls = scrollable || appearance === \"pill\";\n if (!list || !scrolls || list.dataset.orientation === \"vertical\") return;\n const activeTab = list.querySelector<HTMLElement>('[data-state=\"active\"]');\n if (!activeTab) return;\n const overshoot = activeTab.offsetLeft + activeTab.offsetWidth - list.clientWidth;\n if (overshoot > list.scrollLeft) list.scrollLeft = overshoot;\n }, [scrollable, appearance]);\n\n React.useLayoutEffect(() => {\n const list = innerRef.current;\n const indicator = indicatorRef.current;\n if (!list || !indicator) return;\n\n canHover.current = window.matchMedia?.(\"(hover: hover)\").matches ?? false;\n\n const resizeObserver = new ResizeObserver(updateIndicator);\n resizeObserver.observe(list);\n resizeObserverRef.current = resizeObserver;\n\n indicator.style.transitionDuration = \"0s\";\n updateIndicator();\n indicator.getBoundingClientRect();\n indicator.style.transitionDuration = \"\";\n revealActiveTab();\n\n const mutationObserver = new MutationObserver(updateIndicator);\n mutationObserver.observe(list, {\n attributes: true,\n attributeFilter: [\"data-state\", \"aria-expanded\"],\n childList: true,\n subtree: true,\n });\n\n let cancelled = false;\n if (document.fonts?.status !== \"loaded\") {\n document.fonts?.ready.then(() => {\n if (cancelled) return;\n updateIndicator();\n // The tabs are wider once the real font is in, so the mount-time scroll can\n // fall short of the active tab. Recomputed here against the settled layout.\n revealActiveTab();\n });\n }\n\n return () => {\n cancelled = true;\n mutationObserver.disconnect();\n resizeObserver.disconnect();\n resizeObserverRef.current = null;\n };\n }, [updateIndicator, revealActiveTab]);\n\n const isPill = appearance === \"pill\";\n const listStyle: React.CSSProperties & { \"--pill-ease\"?: string } = isPill\n ? { \"--pill-ease\": PILL_EASE, ...style }\n : { ...style };\n\n return (\n <TabsAppearanceContext.Provider value={{ appearance, size }}>\n <TabsPrimitive.List\n ref={innerRef}\n onPointerOver={handlePointerOver}\n onPointerLeave={handlePointerLeave}\n style={listStyle}\n className={cn(\n // `isolate` scopes the active indicator's `z-10` to a local stacking\n // context. Without it, `relative` alone creates no stacking context, so\n // the indicator escapes and paints above page chrome (e.g. the header).\n \"relative isolate\",\n isPill\n ? \"inline-flex w-fit max-w-full items-center gap-1 overflow-x-auto rounded-full bg-background-secondary p-1 shadow-md [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n : [\n getLayoutClass(variant, fullWidth, alignLeft),\n // Horizontal only: in the vertical orientation the leading padding is\n // the row's left inset, not a label offset, so zeroing it would pull\n // the first label out of line with the others.\n flushLeft && \"data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0\",\n // `flex-none` is what stops the tabs compressing — without it they\n // share the row and never overflow, so there is nothing to scroll.\n // The scrollbar is hidden in both engines: Firefox reads\n // `scrollbar-width`, WebKit and Blink the pseudo-element.\n scrollable &&\n \"data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:[scrollbar-width:none] data-[orientation=horizontal]:[&::-webkit-scrollbar]:hidden data-[orientation=horizontal]:[&>[role=tab]]:flex-none\",\n \"data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]\",\n \"data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]\",\n ],\n className,\n )}\n {...props}\n >\n {children}\n <span\n ref={indicatorRef}\n aria-hidden\n className={cn(\n \"pointer-events-none absolute rounded-full motion-safe:transition-[transform,width,height]\",\n isPill\n ? \"z-5 motion-safe:duration-(--pill-slide) motion-safe:ease-(--pill-ease)\"\n : \"z-10 motion-safe:duration-200 motion-safe:ease-in-out\",\n )}\n style={{ opacity: 0 }}\n />\n </TabsPrimitive.List>\n </TabsAppearanceContext.Provider>\n );\n },\n);\n\nTabsList.displayName = \"TabsList\";\n"],"names":[],"mappings":";;;;;AAaO,MAAM,wBAAwB,MAAM,cAGxC,EAAE,YAAY,aAAa,MAAM,MAAM;AAI1C,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,cAAc;AAEpB,MAAM,qBAAqB;AAE3B,SAAS,WAAW,UAAm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
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "../../utils/cn.mjs";
|
|
5
|
+
import { DropdownMenuItem } from "../DropdownMenu/DropdownMenuItem.mjs";
|
|
6
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from "../DropdownMenu/DropdownMenuRoot.mjs";
|
|
7
|
+
import { ChevronDownIcon } from "../Icons/ChevronDownIcon.mjs";
|
|
8
|
+
import { TabsValueContext, OVERFLOW_TAB_VALUE } from "./Tabs.mjs";
|
|
9
|
+
import { TabsTrigger } from "./TabsTrigger.mjs";
|
|
10
|
+
const OPEN_KEYS = /* @__PURE__ */ new Set(["Enter", " ", "ArrowDown"]);
|
|
11
|
+
const TabsOverflowItem = React.forwardRef(
|
|
12
|
+
({ value, ...props }, ref) => {
|
|
13
|
+
const selection = React.useContext(TabsValueContext);
|
|
14
|
+
const isActive = selection.value === value;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
DropdownMenuItem,
|
|
17
|
+
{
|
|
18
|
+
ref,
|
|
19
|
+
role: "menuitemradio",
|
|
20
|
+
"aria-checked": isActive,
|
|
21
|
+
selected: isActive,
|
|
22
|
+
onSelect: () => selection.select(value),
|
|
23
|
+
...props
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
TabsOverflowItem.displayName = "TabsOverflowItem";
|
|
29
|
+
const TabsOverflow = React.forwardRef(
|
|
30
|
+
({ children, ...props }, ref) => {
|
|
31
|
+
const items = React.Children.toArray(children).filter(
|
|
32
|
+
(child) => React.isValidElement(child)
|
|
33
|
+
);
|
|
34
|
+
if (items.length === 0) return null;
|
|
35
|
+
return /* @__PURE__ */ jsx(OverflowMenu, { ref, items, ...props, children });
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
TabsOverflow.displayName = "TabsOverflow";
|
|
39
|
+
const OverflowMenu = React.forwardRef(({ items, label, children, className, onKeyDown, onMouseDown, ...props }, ref) => {
|
|
40
|
+
const { value } = React.useContext(TabsValueContext);
|
|
41
|
+
const [open, setOpen] = React.useState(false);
|
|
42
|
+
const lastInput = React.useRef("keyboard");
|
|
43
|
+
const activeItem = items.find((item) => item.props.value === value);
|
|
44
|
+
return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, children: [
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
TabsTrigger,
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
asChild: true,
|
|
50
|
+
value: activeItem ? activeItem.props.value : OVERFLOW_TAB_VALUE,
|
|
51
|
+
...!activeItem && { "aria-controls": void 0 },
|
|
52
|
+
className,
|
|
53
|
+
onMouseDown: (event) => {
|
|
54
|
+
onMouseDown?.(event);
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
},
|
|
57
|
+
onKeyDown: (event) => {
|
|
58
|
+
onKeyDown?.(event);
|
|
59
|
+
if (event.defaultPrevented) return;
|
|
60
|
+
if (OPEN_KEYS.has(event.key)) {
|
|
61
|
+
lastInput.current = "keyboard";
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
setOpen(true);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
...props,
|
|
67
|
+
children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
|
|
68
|
+
activeItem ? activeItem.props.children : label,
|
|
69
|
+
/* @__PURE__ */ jsx(
|
|
70
|
+
ChevronDownIcon,
|
|
71
|
+
{
|
|
72
|
+
size: 16,
|
|
73
|
+
className: cn("motion-safe:transition-transform", open && "rotate-180")
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
] }) })
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
/* @__PURE__ */ jsx(
|
|
80
|
+
DropdownMenuContent,
|
|
81
|
+
{
|
|
82
|
+
align: "end",
|
|
83
|
+
"aria-label": typeof label === "string" ? label : void 0,
|
|
84
|
+
onPointerDownCapture: () => {
|
|
85
|
+
lastInput.current = "pointer";
|
|
86
|
+
},
|
|
87
|
+
onKeyDownCapture: () => {
|
|
88
|
+
lastInput.current = "keyboard";
|
|
89
|
+
},
|
|
90
|
+
onPointerDownOutside: () => {
|
|
91
|
+
lastInput.current = "pointer";
|
|
92
|
+
},
|
|
93
|
+
onCloseAutoFocus: (event) => {
|
|
94
|
+
if (lastInput.current === "pointer") event.preventDefault();
|
|
95
|
+
},
|
|
96
|
+
children
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
] });
|
|
100
|
+
});
|
|
101
|
+
OverflowMenu.displayName = "OverflowMenu";
|
|
102
|
+
export {
|
|
103
|
+
TabsOverflow,
|
|
104
|
+
TabsOverflowItem
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=TabsOverflow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TabsOverflow.mjs","sources":["../../../src/components/Tabs/TabsOverflow.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { DropdownMenuItem, type DropdownMenuItemProps } from \"../DropdownMenu/DropdownMenuItem\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuTrigger,\n} from \"../DropdownMenu/DropdownMenuRoot\";\nimport { ChevronDownIcon } from \"../Icons/ChevronDownIcon\";\nimport { OVERFLOW_TAB_VALUE, TabsValueContext } from \"./Tabs\";\nimport { TabsTrigger, type TabsTriggerProps } from \"./TabsTrigger\";\n\nconst OPEN_KEYS = new Set([\"Enter\", \" \", \"ArrowDown\"]);\n\n/** Props for the {@link TabsOverflow} component. */\nexport interface TabsOverflowProps\n extends Omit<TabsTriggerProps, \"value\" | \"children\" | \"asChild\"> {\n /** Text shown on the tab while none of its items is active, e.g. \"More\". */\n label: React.ReactNode;\n /** {@link TabsOverflowItem} elements, one per tab that doesn't fit the row. */\n children?: React.ReactNode;\n}\n\n/** Props for the {@link TabsOverflowItem} component. */\nexport type TabsOverflowItemProps = Omit<DropdownMenuItemProps, \"selected\" | \"onSelect\"> & {\n /** The tab's value, as on a {@link TabsTrigger}. */\n value: string;\n};\n\n/**\n * A tab listed in a {@link TabsOverflow} menu. The active one takes the menu's\n * selected style and is announced as the checked option.\n */\nexport const TabsOverflowItem = React.forwardRef<HTMLDivElement, TabsOverflowItemProps>(\n ({ value, ...props }, ref) => {\n const selection = React.useContext(TabsValueContext);\n const isActive = selection.value === value;\n return (\n <DropdownMenuItem\n ref={ref}\n role=\"menuitemradio\"\n aria-checked={isActive}\n selected={isActive}\n onSelect={() => selection.select(value)}\n {...props}\n />\n );\n },\n);\n\nTabsOverflowItem.displayName = \"TabsOverflowItem\";\n\n/**\n * The last tab in a {@link TabsList}, opening a menu of the tabs that don't fit\n * the row. It sits in the row's arrow-key order, opens with click, Enter, Space\n * or ArrowDown, and never selects anything itself. While one of its items is\n * active it shows that item's label and is the selected tab.\n *\n * Reads and sets the value of the surrounding {@link Tabs}, controlled or not.\n * Renders nothing when it has no items.\n *\n * @example\n * ```tsx\n * <Tabs value={tab} onValueChange={setTab}>\n * <TabsList appearance=\"pill\">\n * <TabsTrigger value=\"all\">All</TabsTrigger>\n * <TabsOverflow label=\"More\">\n * <TabsOverflowItem value=\"tips\">Tips</TabsOverflowItem>\n * </TabsOverflow>\n * </TabsList>\n * </Tabs>\n * ```\n */\nexport const TabsOverflow = React.forwardRef<HTMLButtonElement, TabsOverflowProps>(\n ({ children, ...props }, ref) => {\n const items = React.Children.toArray(children).filter(\n (child): child is React.ReactElement<TabsOverflowItemProps> => React.isValidElement(child),\n );\n if (items.length === 0) return null;\n return (\n <OverflowMenu ref={ref} items={items} {...props}>\n {children}\n </OverflowMenu>\n );\n },\n);\n\nTabsOverflow.displayName = \"TabsOverflow\";\n\nconst OverflowMenu = React.forwardRef<\n HTMLButtonElement,\n TabsOverflowProps & { items: React.ReactElement<TabsOverflowItemProps>[] }\n>(({ items, label, children, className, onKeyDown, onMouseDown, ...props }, ref) => {\n const { value } = React.useContext(TabsValueContext);\n const [open, setOpen] = React.useState(false);\n\n const lastInput = React.useRef<\"pointer\" | \"keyboard\">(\"keyboard\");\n\n const activeItem = items.find((item) => item.props.value === value);\n\n return (\n <DropdownMenu open={open} onOpenChange={setOpen}>\n <TabsTrigger\n ref={ref}\n asChild\n value={activeItem ? activeItem.props.value : OVERFLOW_TAB_VALUE}\n {...(!activeItem && { \"aria-controls\": undefined })}\n className={className}\n onMouseDown={(event) => {\n onMouseDown?.(event);\n event.preventDefault();\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n if (OPEN_KEYS.has(event.key)) {\n lastInput.current = \"keyboard\";\n event.preventDefault();\n setOpen(true);\n }\n }}\n {...props}\n >\n <DropdownMenuTrigger>\n <span className=\"flex items-center gap-2\">\n {activeItem ? activeItem.props.children : label}\n <ChevronDownIcon\n size={16}\n className={cn(\"motion-safe:transition-transform\", open && \"rotate-180\")}\n />\n </span>\n </DropdownMenuTrigger>\n </TabsTrigger>\n <DropdownMenuContent\n align=\"end\"\n aria-label={typeof label === \"string\" ? label : undefined}\n onPointerDownCapture={() => {\n lastInput.current = \"pointer\";\n }}\n onKeyDownCapture={() => {\n lastInput.current = \"keyboard\";\n }}\n onPointerDownOutside={() => {\n lastInput.current = \"pointer\";\n }}\n onCloseAutoFocus={(event) => {\n if (lastInput.current === \"pointer\") event.preventDefault();\n }}\n >\n {children}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n});\n\nOverflowMenu.displayName = \"OverflowMenu\";\n"],"names":[],"mappings":";;;;;;;;;AAYA,MAAM,YAAY,oBAAI,IAAI,CAAC,SAAS,KAAK,WAAW,CAAC;AAqB9C,MAAM,mBAAmB,MAAM;AAAA,EACpC,CAAC,EAAE,OAAO,GAAG,MAAA,GAAS,QAAQ;AAC5B,UAAM,YAAY,MAAM,WAAW,gBAAgB;AACnD,UAAM,WAAW,UAAU,UAAU;AACrC,WACE;AAAA,MAAC;AAAA,MAAA;AAA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G;AAC5B,sBAAU,UAAU;AACpB,kBAAM,eAAA;AACN,oBAAQ,IAAI;AAAA,UACd;AAAA,QACF;AAAA,QACC,GAAG;AAAA,QAEJ,UAAA,oBAAC,qBAAA,EACC,UAAA,qBAAC,QAAA,EAAK,WAAU,2BACb,UAAA;AAAA,UAAA,aAAa,WAAW,MAAM,WAAW;AAAA,UAC1C;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,MAAM;AAAA,cACN,WAAW,GAAG,oCAAoC,QAAQ,YAAY;AAAA,YAAA;AAAA,UAAA;AAAA,QACxE,EAAA,CACF,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAM;AAAA,QACN,cAAY,OAAO,UAAU,WAAW,QAAQ;AAAA,QAChD,sBAAsB,MAAM;AAC1B,oBAAU,UAAU;AAAA,QACtB;AAAA,QACA,kBAAkB,MAAM;AACtB,oBAAU,UAAU;AAAA,QACtB;AAAA,QACA,sBAAsB,MAAM;AAC1B,oBAAU,UAAU;AAAA,QACtB;AAAA,QACA,kBAAkB,CAAC,UAAU;AAC3B,cAAI,UAAU,YAAY,UAAW,OAAM,eAAA;AAAA,QAC7C;AAAA,QAEC;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GACF;AAEJ,CAAC;AAED,aAAa,cAAc;"}
|
|
@@ -3,12 +3,15 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { cn } from "../../utils/cn.mjs";
|
|
6
|
+
import { TabsAppearanceContext } from "./TabsList.mjs";
|
|
6
7
|
const TabsTrigger = React.forwardRef(({ className, children, asChild, ...props }, ref) => {
|
|
7
|
-
const
|
|
8
|
+
const { appearance, size } = React.useContext(TabsAppearanceContext);
|
|
9
|
+
const labelClassName = cn("min-w-0 truncate", appearance === "pill" && "flex items-center gap-2");
|
|
10
|
+
const label = /* @__PURE__ */ jsx("span", { className: labelClassName, children });
|
|
8
11
|
const content = asChild && React.isValidElement(children) ? React.cloneElement(
|
|
9
12
|
children,
|
|
10
13
|
void 0,
|
|
11
|
-
/* @__PURE__ */ jsx("span", { className:
|
|
14
|
+
/* @__PURE__ */ jsx("span", { className: labelClassName, children: children.props.children })
|
|
12
15
|
) : label;
|
|
13
16
|
return /* @__PURE__ */ jsx(
|
|
14
17
|
TabsPrimitive.Trigger,
|
|
@@ -16,21 +19,31 @@ const TabsTrigger = React.forwardRef(({ className, children, asChild, ...props }
|
|
|
16
19
|
ref,
|
|
17
20
|
asChild,
|
|
18
21
|
className: cn(
|
|
19
|
-
"inline-flex min-w-0 items-center justify-center",
|
|
20
|
-
"typography-body-default-16px-semibold cursor-pointer",
|
|
22
|
+
"inline-flex min-w-0 cursor-pointer items-center justify-center",
|
|
21
23
|
"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out",
|
|
22
|
-
"data-[orientation=horizontal]:px-4 data-[orientation=horizontal]:py-3",
|
|
23
|
-
"data-[orientation=vertical]:justify-start data-[orientation=vertical]:px-4 data-[orientation=vertical]:py-3",
|
|
24
|
-
"data-[state=active]:text-content-primary",
|
|
25
|
-
"data-[state=inactive]:text-content-tertiary",
|
|
26
|
-
"data-[state=active]:hover:text-content-primary/70",
|
|
27
|
-
"data-[state=inactive]:hover:text-content-primary",
|
|
28
|
-
"data-[state=active]:active:text-content-primary/70",
|
|
29
|
-
"data-[state=inactive]:active:text-content-primary",
|
|
30
24
|
"data-disabled:pointer-events-none",
|
|
31
|
-
"data-disabled:data-[state=active]:text-content-tertiary",
|
|
32
|
-
"data-disabled:data-[state=inactive]:text-neutral-alphas-200",
|
|
33
25
|
"focus-visible:shadow-focus-ring focus-visible:outline-none",
|
|
26
|
+
appearance === "pill" ? [
|
|
27
|
+
"relative z-0 shrink-0 gap-2 rounded-full px-4 data-pill:z-10",
|
|
28
|
+
size === "36" ? "h-9" : "h-8",
|
|
29
|
+
"typography-body-small-14px-semibold",
|
|
30
|
+
"motion-safe:duration-[160ms] data-pill:motion-safe:delay-(--pill-arrive)",
|
|
31
|
+
"text-content-secondary data-pill:text-content-primary-inverted",
|
|
32
|
+
"not-data-pill:hover:text-content-primary",
|
|
33
|
+
"data-disabled:data-[state=inactive]:text-neutral-alphas-200"
|
|
34
|
+
] : [
|
|
35
|
+
"typography-body-default-16px-semibold",
|
|
36
|
+
"data-[orientation=horizontal]:px-4 data-[orientation=horizontal]:py-3",
|
|
37
|
+
"data-[orientation=vertical]:justify-start data-[orientation=vertical]:px-4 data-[orientation=vertical]:py-3",
|
|
38
|
+
"data-[state=active]:text-content-primary",
|
|
39
|
+
"data-[state=inactive]:text-content-tertiary",
|
|
40
|
+
"data-[state=active]:hover:text-content-primary/70",
|
|
41
|
+
"data-[state=inactive]:hover:text-content-primary",
|
|
42
|
+
"data-[state=active]:active:text-content-primary/70",
|
|
43
|
+
"data-[state=inactive]:active:text-content-primary",
|
|
44
|
+
"data-disabled:data-[state=active]:text-content-tertiary",
|
|
45
|
+
"data-disabled:data-[state=inactive]:text-neutral-alphas-200"
|
|
46
|
+
],
|
|
34
47
|
className
|
|
35
48
|
),
|
|
36
49
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabsTrigger.mjs","sources":["../../../src/components/Tabs/TabsTrigger.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\n\n/** Props for the {@link TabsTrigger} button component. */\nexport type TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>;\n\n/**\n * An interactive tab that activates its associated {@link TabsContent} panel.\n *\n * Renders a `<button>` by default. Pass `asChild` to render the tab as another\n * element — e.g. a router link for navigation tabs (`<TabsTrigger asChild><Link\n * href=\"…\">…</Link></TabsTrigger>`). With `asChild` the child element becomes\n * the tab itself (receiving `role=\"tab\"` and focus management), so the tab\n * stays a single interactive control rather than nesting one inside the other.\n */\nexport const TabsTrigger = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.Trigger>,\n TabsTriggerProps\n>(({ className, children, asChild, ...props }, ref) => {\n const
|
|
1
|
+
{"version":3,"file":"TabsTrigger.mjs","sources":["../../../src/components/Tabs/TabsTrigger.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { TabsAppearanceContext } from \"./TabsList\";\n\n/** Props for the {@link TabsTrigger} button component. */\nexport type TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>;\n\n/**\n * An interactive tab that activates its associated {@link TabsContent} panel.\n *\n * Renders a `<button>` by default. Pass `asChild` to render the tab as another\n * element — e.g. a router link for navigation tabs (`<TabsTrigger asChild><Link\n * href=\"…\">…</Link></TabsTrigger>`). With `asChild` the child element becomes\n * the tab itself (receiving `role=\"tab\"` and focus management), so the tab\n * stays a single interactive control rather than nesting one inside the other.\n *\n * Inside a `TabsList appearance=\"pill\"` the tab takes the pill styling.\n */\nexport const TabsTrigger = React.forwardRef<\n React.ComponentRef<typeof TabsPrimitive.Trigger>,\n TabsTriggerProps\n>(({ className, children, asChild, ...props }, ref) => {\n const { appearance, size } = React.useContext(TabsAppearanceContext);\n const labelClassName = cn(\"min-w-0 truncate\", appearance === \"pill\" && \"flex items-center gap-2\");\n const label = <span className={labelClassName}>{children}</span>;\n\n // The `min-w-0 truncate` span keeps long labels ellipsised. With `asChild`\n // the consumer's element becomes the tab, so wrap *its* children in that\n // span (rather than wrapping the element) — the tab stays a single\n // interactive control (no nested link/button) while behaviour matches the\n // default button tab.\n const content =\n asChild && React.isValidElement(children)\n ? React.cloneElement(\n children,\n undefined,\n <span className={labelClassName}>\n {(children.props as { children?: React.ReactNode }).children}\n </span>,\n )\n : label;\n\n return (\n <TabsPrimitive.Trigger\n ref={ref}\n asChild={asChild}\n className={cn(\n \"inline-flex min-w-0 cursor-pointer items-center justify-center\",\n \"motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-in-out\",\n \"data-disabled:pointer-events-none\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n appearance === \"pill\"\n ? [\n \"relative z-0 shrink-0 gap-2 rounded-full px-4 data-pill:z-10\",\n size === \"36\" ? \"h-9\" : \"h-8\",\n \"typography-body-small-14px-semibold\",\n \"motion-safe:duration-[160ms] data-pill:motion-safe:delay-(--pill-arrive)\",\n \"text-content-secondary data-pill:text-content-primary-inverted\",\n \"not-data-pill:hover:text-content-primary\",\n \"data-disabled:data-[state=inactive]:text-neutral-alphas-200\",\n ]\n : [\n \"typography-body-default-16px-semibold\",\n \"data-[orientation=horizontal]:px-4 data-[orientation=horizontal]:py-3\",\n \"data-[orientation=vertical]:justify-start data-[orientation=vertical]:px-4 data-[orientation=vertical]:py-3\",\n \"data-[state=active]:text-content-primary\",\n \"data-[state=inactive]:text-content-tertiary\",\n \"data-[state=active]:hover:text-content-primary/70\",\n \"data-[state=inactive]:hover:text-content-primary\",\n \"data-[state=active]:active:text-content-primary/70\",\n \"data-[state=inactive]:active:text-content-primary\",\n \"data-disabled:data-[state=active]:text-content-tertiary\",\n \"data-disabled:data-[state=inactive]:text-neutral-alphas-200\",\n ],\n className,\n )}\n {...props}\n >\n {content}\n </TabsPrimitive.Trigger>\n );\n});\n\nTabsTrigger.displayName = \"TabsTrigger\";\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc,MAAM,WAG/B,CAAC,EAAE,WAAW,UAAU,SAAS,GAAG,MAAA,GAAS,QAAQ;AACrD,QAAM,EAAE,YAAY,KAAA,IAAS,MAAM,WAAW,qBAAqB;AACnE,QAAM,iBAAiB,GAAG,oBAAoB,eAAe,UAAU,yBAAyB;AAChG,QAAM,QAAQ,oBAAC,QAAA,EAAK,WAAW,gBAAiB,UAAS;AAOzD,QAAM,UACJ,WAAW,MAAM,eAAe,QAAQ,IACpC,MAAM;AAAA,IACJ;AAAA,IACA;AAAA,wBACC,QAAA,EAAK,WAAW,gBACb,UAAA,SAAS,MAAyC,SAAA,CACtD;AAAA,EAAA,IAEF;AAEN,SACE;AAAA,IAAC,cAAc;AAAA,IAAd;AAAA,MACC;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe,SACX;AAAA,UACE;AAAA,UACA,SAAS,OAAO,QAAQ;AAAA,UACxB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QAAA,IAEF;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAAA,QAEN;AAAA,MAAA;AAAA,MAED,GAAG;AAAA,MAEH,UAAA;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;AAED,YAAY,cAAc;"}
|