@fanvue/ui 3.41.0 → 3.42.1

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.
@@ -1,7 +1,31 @@
1
1
  "use client";
2
+ import { jsx } from "react/jsx-runtime";
2
3
  import * as TabsPrimitive from "@radix-ui/react-tabs";
3
- const Tabs = TabsPrimitive.Root;
4
+ import * as React from "react";
5
+ const OVERFLOW_TAB_VALUE = "fanvue-ui-tabs-overflow";
6
+ const TabsValueContext = React.createContext({ value: void 0, select: () => {
7
+ } });
8
+ const Tabs = React.forwardRef(
9
+ ({ value: valueProp, defaultValue, onValueChange, ...props }, ref) => {
10
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
11
+ const isControlled = valueProp !== void 0;
12
+ const value = isControlled ? valueProp : uncontrolledValue;
13
+ const select = React.useCallback(
14
+ (next) => {
15
+ if (next === OVERFLOW_TAB_VALUE) return;
16
+ if (!isControlled) setUncontrolledValue(next);
17
+ onValueChange?.(next);
18
+ },
19
+ [isControlled, onValueChange]
20
+ );
21
+ const context = React.useMemo(() => ({ value, select }), [value, select]);
22
+ return /* @__PURE__ */ jsx(TabsValueContext.Provider, { value: context, children: /* @__PURE__ */ jsx(TabsPrimitive.Root, { ref, value: value ?? "", onValueChange: select, ...props }) });
23
+ }
24
+ );
25
+ Tabs.displayName = "Tabs";
4
26
  export {
5
- Tabs
27
+ OVERFLOW_TAB_VALUE,
28
+ Tabs,
29
+ TabsValueContext
6
30
  };
7
31
  //# sourceMappingURL=Tabs.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tabs.mjs","sources":["../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport type * as React from \"react\";\n\n/** Props for the {@link Tabs} root component. Extends Radix `Tabs.Root` props. */\nexport type TabsProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Root>;\n\n/**\n * Root container for a tabbed interface. Manages the active tab state and\n * coordinates {@link TabsList}, {@link TabsTrigger}, and {@link TabsContent}.\n *\n * Built on Radix UI `Tabs`.\n *\n * @example\n * ```tsx\n * <Tabs defaultValue=\"tab1\">\n * <TabsList>\n * <TabsTrigger value=\"tab1\">Tab 1</TabsTrigger>\n * <TabsTrigger value=\"tab2\">Tab 2</TabsTrigger>\n * </TabsList>\n * <TabsContent value=\"tab1\">Content 1</TabsContent>\n * <TabsContent value=\"tab2\">Content 2</TabsContent>\n * </Tabs>\n * ```\n */\nexport const Tabs = TabsPrimitive.Root;\n"],"names":[],"mappings":";;AAwBO,MAAM,OAAO,cAAc;"}
1
+ {"version":3,"file":"Tabs.mjs","sources":["../../../src/components/Tabs/Tabs.tsx"],"sourcesContent":["import * as TabsPrimitive from \"@radix-ui/react-tabs\";\nimport * as React from \"react\";\n\n/**\n * Value a {@link TabsOverflow} tab carries while none of its items is active.\n * {@link Tabs} never reports or stores it, so focusing More under automatic\n * activation selects nothing.\n */\nexport const OVERFLOW_TAB_VALUE = \"fanvue-ui-tabs-overflow\";\n\n/** Props for the {@link Tabs} root component. Extends Radix `Tabs.Root` props. */\nexport type TabsProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Root>;\n\n/**\n * Root container for a tabbed interface. Manages the active tab state and\n * coordinates {@link TabsList}, {@link TabsTrigger}, and {@link TabsContent}.\n *\n * Built on Radix UI `Tabs`.\n *\n * @example\n * ```tsx\n * <Tabs defaultValue=\"tab1\">\n * <TabsList>\n * <TabsTrigger value=\"tab1\">Tab 1</TabsTrigger>\n * <TabsTrigger value=\"tab2\">Tab 2</TabsTrigger>\n * </TabsList>\n * <TabsContent value=\"tab1\">Content 1</TabsContent>\n * <TabsContent value=\"tab2\">Content 2</TabsContent>\n * </Tabs>\n * ```\n */\nexport const TabsValueContext = React.createContext<{\n value: string | undefined;\n select: (value: string) => void;\n}>({ value: undefined, select: () => {} });\n\nexport const Tabs = React.forwardRef<React.ComponentRef<typeof TabsPrimitive.Root>, TabsProps>(\n ({ value: valueProp, defaultValue, onValueChange, ...props }, ref) => {\n const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);\n const isControlled = valueProp !== undefined;\n const value = isControlled ? valueProp : uncontrolledValue;\n\n const select = React.useCallback(\n (next: string) => {\n if (next === OVERFLOW_TAB_VALUE) return;\n if (!isControlled) setUncontrolledValue(next);\n onValueChange?.(next);\n },\n [isControlled, onValueChange],\n );\n\n const context = React.useMemo(() => ({ value, select }), [value, select]);\n\n return (\n <TabsValueContext.Provider value={context}>\n <TabsPrimitive.Root ref={ref} value={value ?? \"\"} onValueChange={select} {...props} />\n </TabsValueContext.Provider>\n );\n },\n);\n\nTabs.displayName = \"Tabs\";\n"],"names":[],"mappings":";;;;AAQO,MAAM,qBAAqB;AAuB3B,MAAM,mBAAmB,MAAM,cAGnC,EAAE,OAAO,QAAW,QAAQ,MAAM;AAAC,EAAA,CAAG;AAElC,MAAM,OAAO,MAAM;AAAA,EACxB,CAAC,EAAE,OAAO,WAAW,cAAc,eAAe,GAAG,MAAA,GAAS,QAAQ;AACpE,UAAM,CAAC,mBAAmB,oBAAoB,IAAI,MAAM,SAAS,YAAY;AAC7E,UAAM,eAAe,cAAc;AACnC,UAAM,QAAQ,eAAe,YAAY;AAEzC,UAAM,SAAS,MAAM;AAAA,MACnB,CAAC,SAAiB;AAChB,YAAI,SAAS,mBAAoB;AACjC,YAAI,CAAC,aAAc,sBAAqB,IAAI;AAC5C,wBAAgB,IAAI;AAAA,MACtB;AAAA,MACA,CAAC,cAAc,aAAa;AAAA,IAAA;AAG9B,UAAM,UAAU,MAAM,QAAQ,OAAO,EAAE,OAAO,OAAA,IAAW,CAAC,OAAO,MAAM,CAAC;AAExE,+BACG,iBAAiB,UAAjB,EAA0B,OAAO,SAChC,8BAAC,cAAc,MAAd,EAAmB,KAAU,OAAO,SAAS,IAAI,eAAe,QAAS,GAAG,OAAO,GACtF;AAAA,EAEJ;AACF;AAEA,KAAK,cAAc;"}
@@ -1,8 +1,63 @@
1
1
  "use client";
2
- import { jsxs, jsx } from "react/jsx-runtime";
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 (isVertical) {
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
- if (!list || !scrollable || list.dataset.orientation === "vertical") return;
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
- return /* @__PURE__ */ jsxs(
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
- getLayoutClass(variant, fullWidth, alignLeft),
111
- // Horizontal only: in the vertical orientation the leading padding is
112
- // the row's left inset, not a label offset, so zeroing it would pull
113
- // the first label out of line with the others.
114
- flushLeft && "data-[orientation=horizontal]:[&>[role=tab]:first-child]:pl-0",
115
- // `flex-none` is what stops the tabs compressing — without it they
116
- // share the row and never overflow, so there is nothing to scroll.
117
- // The scrollbar is hidden in both engines: Firefox reads
118
- // `scrollbar-width`, WebKit and Blink the pseudo-element.
119
- 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",
120
- "data-[orientation=horizontal]:items-center data-[orientation=horizontal]:shadow-[inset_0_-1px_0_0_var(--color-border-primary)]",
121
- "data-[orientation=vertical]:flex-col data-[orientation=vertical]:shadow-[inset_-1px_0_0_0_var(--color-border-primary)]",
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: "pointer-events-none absolute z-10 rounded-full motion-safe:transition-[transform,width,height] motion-safe:duration-200 motion-safe:ease-in-out",
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 </TabsPrimitive.List>\n );\n },\n);\n\nTabsList.displayName = \"TabsList\";\n"],"names":[],"mappings":";;;;;AAOA,MAAM,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;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,UAAmB;AACrC,SAAO,WAAW,eAAe;AACnC;AAEA,SAAS,YAAY,UAAkB,UAAmB;AACxD,MAAI,CAAC,SAAU,QAA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AAI,UAAW;AACf,0BAAA;AAGA,0BAAA;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO,MAAM;AACX,oBAAY;AACZ,yBAAiB,WAAA;AACjB,uBAAe,WAAA;AACf,0BAAkB,UAAU;AAAA,MAC9B;AAAA,IACF,GAAG,CAAC,iBAAiB,eAAe,CAAC;AAErC,UAAM,SAAS,eAAe;AAC9B,UAAM,YAA8D,SAChE,EAAE,eAAe,WAAW,GAAG,MAAA,IAC/B,EAAE,GAAG,MAAA;AAET,WACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,YAAY,QACnD,UAAA;AAAA,MAAC,cAAc;AAAA,MAAd;AAAA,QACC,KAAK;AAAA,QACL,eAAe;AAAA,QACf,gBAAgB;AAAA,QAChB,OAAO;AAAA,QACP,WAAW;AAAA;AAAA;AAAA;AAAA,UAIT;AAAA,UACA,SACI,4KACA;AAAA,YACE,eAAe,SAAS,WAAW,SAAS;AAAA;AAAA;AAAA;AAAA,YAI5C,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,YAKb,cACE;AAAA,YACF;AAAA,YACA;AAAA,UAAA;AAAA,UAEN;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA;AAAA,UACD;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,KAAK;AAAA,cACL,eAAW;AAAA,cACX,WAAW;AAAA,gBACT;AAAA,gBACA,SACI,2EACA;AAAA,cAAA;AAAA,cAEN,OAAO,EAAE,SAAS,EAAA;AAAA,YAAE;AAAA,UAAA;AAAA,QACtB;AAAA,MAAA;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;AAEA,SAAS,cAAc;"}
@@ -0,0 +1,129 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ 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 isOpen = React.useRef(false);
43
+ const [labelValue, setLabelValue] = React.useState(null);
44
+ const lastInput = React.useRef("keyboard");
45
+ const activeItem = items.find((item) => item.props.value === value);
46
+ const labelItem = labelValue ? items.find((item) => item.props.value === labelValue.value) : activeItem;
47
+ const handleOpenChange = (nextOpen) => {
48
+ if (nextOpen && !open) setLabelValue({ value });
49
+ isOpen.current = nextOpen;
50
+ setOpen(nextOpen);
51
+ };
52
+ return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: handleOpenChange, children: [
53
+ /* @__PURE__ */ jsx(
54
+ TabsTrigger,
55
+ {
56
+ ref,
57
+ asChild: true,
58
+ value: activeItem ? activeItem.props.value : OVERFLOW_TAB_VALUE,
59
+ ...!activeItem && { "aria-controls": void 0 },
60
+ className,
61
+ onMouseDown: (event) => {
62
+ onMouseDown?.(event);
63
+ event.preventDefault();
64
+ },
65
+ onKeyDown: (event) => {
66
+ onKeyDown?.(event);
67
+ if (event.defaultPrevented) return;
68
+ if (OPEN_KEYS.has(event.key)) {
69
+ lastInput.current = "keyboard";
70
+ event.preventDefault();
71
+ handleOpenChange(true);
72
+ }
73
+ },
74
+ ...props,
75
+ children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
76
+ labelItem ? labelItem.props.children : label,
77
+ /* @__PURE__ */ jsx(
78
+ ChevronDownIcon,
79
+ {
80
+ size: 16,
81
+ className: cn("motion-safe:transition-transform", open && "rotate-180")
82
+ }
83
+ )
84
+ ] }) })
85
+ }
86
+ ),
87
+ /* @__PURE__ */ jsxs(
88
+ DropdownMenuContent,
89
+ {
90
+ align: "end",
91
+ "aria-label": typeof label === "string" ? label : void 0,
92
+ onPointerDownCapture: () => {
93
+ lastInput.current = "pointer";
94
+ },
95
+ onKeyDownCapture: () => {
96
+ lastInput.current = "keyboard";
97
+ },
98
+ onPointerDownOutside: () => {
99
+ lastInput.current = "pointer";
100
+ },
101
+ onCloseAutoFocus: (event) => {
102
+ if (lastInput.current === "pointer") event.preventDefault();
103
+ },
104
+ children: [
105
+ /* @__PURE__ */ jsx(ReleaseOnUnmount, { release: setLabelValue, isOpen }),
106
+ children
107
+ ]
108
+ }
109
+ )
110
+ ] });
111
+ });
112
+ OverflowMenu.displayName = "OverflowMenu";
113
+ function ReleaseOnUnmount({
114
+ release,
115
+ isOpen
116
+ }) {
117
+ React.useEffect(
118
+ () => () => {
119
+ if (!isOpen.current) release(null);
120
+ },
121
+ [release, isOpen]
122
+ );
123
+ return null;
124
+ }
125
+ export {
126
+ TabsOverflow,
127
+ TabsOverflowItem
128
+ };
129
+ //# 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 const isOpen = React.useRef(false);\n const [labelValue, setLabelValue] = React.useState<{ value: string | undefined } | null>(null);\n\n const lastInput = React.useRef<\"pointer\" | \"keyboard\">(\"keyboard\");\n\n const activeItem = items.find((item) => item.props.value === value);\n const labelItem = labelValue\n ? items.find((item) => item.props.value === labelValue.value)\n : activeItem;\n\n const handleOpenChange = (nextOpen: boolean) => {\n if (nextOpen && !open) setLabelValue({ value });\n isOpen.current = nextOpen;\n setOpen(nextOpen);\n };\n\n return (\n <DropdownMenu open={open} onOpenChange={handleOpenChange}>\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 handleOpenChange(true);\n }\n }}\n {...props}\n >\n <DropdownMenuTrigger>\n <span className=\"flex items-center gap-2\">\n {labelItem ? labelItem.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 <ReleaseOnUnmount release={setLabelValue} isOpen={isOpen} />\n {children}\n </DropdownMenuContent>\n </DropdownMenu>\n );\n});\n\nOverflowMenu.displayName = \"OverflowMenu\";\n\n/**\n * Hands the trigger's label back to the live selection once the menu content\n * unmounts, which Radix delays until its exit animation has finished. Holding\n * the label until then keeps the trigger's width, so the closing menu, anchored\n * to it, doesn't shift as it fades. Only a closed menu releases it: StrictMode\n * also unmounts the content once while the menu is still open.\n */\nfunction ReleaseOnUnmount({\n release,\n isOpen,\n}: {\n release: React.Dispatch<React.SetStateAction<{ value: string | undefined } | null>>;\n isOpen: React.RefObject<boolean>;\n}) {\n React.useEffect(\n () => () => {\n if (!isOpen.current) release(null);\n },\n [release, isOpen],\n );\n return null;\n}\n"],"names":[],"mappings":";;;;;;;;;AAYA,MAAM,YAAY,oBAAI,IAAI,CAAC,SAAS,KAAK,WAAW,CAAC;AAqB9C,M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eAAA;AAAA,QAC7C;AAAA,QAEA,UAAA;AAAA,UAAA,oBAAC,kBAAA,EAAiB,SAAS,eAAe,OAAA,CAAgB;AAAA,UACzD;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACH,GACF;AAEJ,CAAC;AAED,aAAa,cAAc;AAS3B,SAAS,iBAAiB;AAAA,EACxB;AAAA,EACA;AACF,GAGG;AACD,QAAM;AAAA,IACJ,MAAM,MAAM;AACV,UAAI,CAAC,OAAO,QAAS,SAAQ,IAAI;AAAA,IACnC;AAAA,IACA,CAAC,SAAS,MAAM;AAAA,EAAA;AAElB,SAAO;AACT;"}
@@ -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 label = /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children });
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: "min-w-0 truncate", children: children.props.children })
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,