@42-central/ui-react 0.25.0 → 0.26.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.
Files changed (159) hide show
  1. package/dist/{chunk-LHUWOA2U.js → chunk-276RL7FX.js} +5 -5
  2. package/dist/{chunk-LHUWOA2U.js.map → chunk-276RL7FX.js.map} +1 -1
  3. package/dist/{chunk-6UIQJJNJ.js → chunk-2NTCQIRP.js} +4 -4
  4. package/dist/{chunk-6UIQJJNJ.js.map → chunk-2NTCQIRP.js.map} +1 -1
  5. package/dist/{chunk-T44RW5DW.js → chunk-2TZU4LSX.js} +4 -4
  6. package/dist/{chunk-T44RW5DW.js.map → chunk-2TZU4LSX.js.map} +1 -1
  7. package/dist/{chunk-QZ4N5LYG.js → chunk-7B44J3CF.js} +3 -3
  8. package/dist/{chunk-QZ4N5LYG.js.map → chunk-7B44J3CF.js.map} +1 -1
  9. package/dist/{chunk-XUFCI262.js → chunk-7OGZT7U2.js} +12 -4
  10. package/dist/chunk-7OGZT7U2.js.map +1 -0
  11. package/dist/{chunk-N5M4PDBK.js → chunk-DMI4KS32.js} +3 -3
  12. package/dist/{chunk-N5M4PDBK.js.map → chunk-DMI4KS32.js.map} +1 -1
  13. package/dist/{chunk-UDCCOUWR.js → chunk-DSZF2TW6.js} +5 -5
  14. package/dist/{chunk-UDCCOUWR.js.map → chunk-DSZF2TW6.js.map} +1 -1
  15. package/dist/{chunk-N66NC6QK.js → chunk-E3XLWMEB.js} +3 -3
  16. package/dist/{chunk-N66NC6QK.js.map → chunk-E3XLWMEB.js.map} +1 -1
  17. package/dist/{chunk-HRNWWL3Y.js → chunk-J2NW7JID.js} +61 -29
  18. package/dist/chunk-J2NW7JID.js.map +1 -0
  19. package/dist/{chunk-FZSLSUSX.js → chunk-JDPVD2YE.js} +3 -3
  20. package/dist/{chunk-FZSLSUSX.js.map → chunk-JDPVD2YE.js.map} +1 -1
  21. package/dist/{chunk-6II2DVYR.js → chunk-JFB6O7IY.js} +4 -4
  22. package/dist/{chunk-6II2DVYR.js.map → chunk-JFB6O7IY.js.map} +1 -1
  23. package/dist/chunk-LJVIZNPE.js +9 -0
  24. package/dist/chunk-LJVIZNPE.js.map +1 -0
  25. package/dist/{chunk-HQPU73WV.js → chunk-LYGOFMXJ.js} +3 -3
  26. package/dist/{chunk-HQPU73WV.js.map → chunk-LYGOFMXJ.js.map} +1 -1
  27. package/dist/{chunk-AHKMN3YQ.js → chunk-N42EFOML.js} +3 -3
  28. package/dist/{chunk-AHKMN3YQ.js.map → chunk-N42EFOML.js.map} +1 -1
  29. package/dist/{chunk-7HZBD4YZ.js → chunk-NF2PBGD3.js} +36 -23
  30. package/dist/chunk-NF2PBGD3.js.map +1 -0
  31. package/dist/{chunk-MW42XVPD.js → chunk-PBSVX5DB.js} +15 -5
  32. package/dist/chunk-PBSVX5DB.js.map +1 -0
  33. package/dist/{chunk-PI7X5YFJ.js → chunk-PT22KEVD.js} +4 -4
  34. package/dist/{chunk-PI7X5YFJ.js.map → chunk-PT22KEVD.js.map} +1 -1
  35. package/dist/{chunk-36NWC4GV.js → chunk-QEAF57ZQ.js} +3 -3
  36. package/dist/{chunk-36NWC4GV.js.map → chunk-QEAF57ZQ.js.map} +1 -1
  37. package/dist/{chunk-SAXWCGWR.js → chunk-SOUDKESO.js} +14 -7
  38. package/dist/chunk-SOUDKESO.js.map +1 -0
  39. package/dist/{chunk-54W6VAI3.js → chunk-THGJLR5S.js} +5 -5
  40. package/dist/{chunk-54W6VAI3.js.map → chunk-THGJLR5S.js.map} +1 -1
  41. package/dist/{chunk-LMCUGYHT.js → chunk-YMVUQ2L7.js} +3 -3
  42. package/dist/{chunk-LMCUGYHT.js.map → chunk-YMVUQ2L7.js.map} +1 -1
  43. package/dist/components/ambient-background/index.js +9 -23
  44. package/dist/components/ambient-background/index.js.map +1 -1
  45. package/dist/components/ambient-background/starfield.d.ts.map +1 -1
  46. package/dist/components/app-shell/app-shell.d.ts +55 -10
  47. package/dist/components/app-shell/app-shell.d.ts.map +1 -1
  48. package/dist/components/app-shell/index.d.ts +1 -1
  49. package/dist/components/app-shell/index.d.ts.map +1 -1
  50. package/dist/components/app-shell/index.js +297 -36
  51. package/dist/components/app-shell/index.js.map +1 -1
  52. package/dist/components/autocomplete/index.js +3 -3
  53. package/dist/components/avatar/avatar.d.ts +1 -1
  54. package/dist/components/avatar/avatar.d.ts.map +1 -1
  55. package/dist/components/avatar/index.js +10 -1
  56. package/dist/components/avatar/index.js.map +1 -1
  57. package/dist/components/button-group/button-group.d.ts +10 -2
  58. package/dist/components/button-group/button-group.d.ts.map +1 -1
  59. package/dist/components/button-group/index.js +1 -1
  60. package/dist/components/button-multi-select/index.js +2 -2
  61. package/dist/components/button-select/button-select-control.d.ts +4 -1
  62. package/dist/components/button-select/button-select-control.d.ts.map +1 -1
  63. package/dist/components/button-select/button-select.d.ts +4 -1
  64. package/dist/components/button-select/button-select.d.ts.map +1 -1
  65. package/dist/components/button-select/index.js +2 -2
  66. package/dist/components/camera/index.js +5 -5
  67. package/dist/components/code-block/chrome.js +3 -3
  68. package/dist/components/code-block/index.js +4 -4
  69. package/dist/components/combobox/index.js +3 -3
  70. package/dist/components/combobox-list/index.js +5 -5
  71. package/dist/components/data-table/index.js +13 -13
  72. package/dist/components/date-picker/index.js +7 -7
  73. package/dist/components/drawer/index.js +2 -2
  74. package/dist/components/geodesic/a11y.d.ts +3 -3
  75. package/dist/components/geodesic/a11y.d.ts.map +1 -1
  76. package/dist/components/geodesic/badge-frame.d.ts +13 -1
  77. package/dist/components/geodesic/badge-frame.d.ts.map +1 -1
  78. package/dist/components/geodesic/exam-badge.d.ts +4 -1
  79. package/dist/components/geodesic/exam-badge.d.ts.map +1 -1
  80. package/dist/components/geodesic/geometry.d.ts +14 -9
  81. package/dist/components/geodesic/geometry.d.ts.map +1 -1
  82. package/dist/components/geodesic/index.js +62 -23
  83. package/dist/components/geodesic/index.js.map +1 -1
  84. package/dist/components/geodesic/status.d.ts +8 -6
  85. package/dist/components/geodesic/status.d.ts.map +1 -1
  86. package/dist/components/geodesic/styles.css +15 -2
  87. package/dist/components/hover-card/index.js +2 -2
  88. package/dist/components/indicator/index.js +23 -8
  89. package/dist/components/indicator/index.js.map +1 -1
  90. package/dist/components/indicator/indicator.d.ts +15 -6
  91. package/dist/components/indicator/indicator.d.ts.map +1 -1
  92. package/dist/components/lightbox/index.js +2 -2
  93. package/dist/components/menu/index.js +3 -3
  94. package/dist/components/modal/index.js +2 -2
  95. package/dist/components/multi-combobox-list/index.js +5 -5
  96. package/dist/components/multi-select/index.js +3 -3
  97. package/dist/components/nav-link/index.js +5 -1
  98. package/dist/components/nav-link/nav-link.d.ts.map +1 -1
  99. package/dist/components/nav-link/tanstack.js +5 -1
  100. package/dist/components/nav-link/tanstack.js.map +1 -1
  101. package/dist/components/number-input/index.js +3 -3
  102. package/dist/components/overlays/index.js +3 -3
  103. package/dist/components/photo-capture/index.js +5 -5
  104. package/dist/components/popover/index.js +2 -2
  105. package/dist/components/schedule/index.js +3 -3
  106. package/dist/components/segment-group/index.js +1 -1
  107. package/dist/components/segment-group/segment-group.d.ts +6 -1
  108. package/dist/components/segment-group/segment-group.d.ts.map +1 -1
  109. package/dist/components/select/index.js +4 -4
  110. package/dist/components/spotlight/index.js +4 -4
  111. package/dist/components/tabs/index.js +1 -1
  112. package/dist/components/tabs/tabs-data.d.ts +4 -1
  113. package/dist/components/tabs/tabs-data.d.ts.map +1 -1
  114. package/dist/components/tabs/tabs.d.ts +4 -1
  115. package/dist/components/tabs/tabs.d.ts.map +1 -1
  116. package/dist/components/tags-input/index.js +2 -2
  117. package/dist/components/time-input/index.js +5 -5
  118. package/dist/components/tree-multi-select/index.js +3 -3
  119. package/dist/components/tree-select/index.js +3 -3
  120. package/dist/lib/sidebar-rail.d.ts +21 -0
  121. package/dist/lib/sidebar-rail.d.ts.map +1 -0
  122. package/dist/theme.css +7 -12
  123. package/package.json +1 -1
  124. package/src/as-child.contract.test.tsx +6 -0
  125. package/src/components/ambient-background/starfield.tsx +14 -41
  126. package/src/components/app-shell/app-shell.test.tsx +430 -5
  127. package/src/components/app-shell/app-shell.tsx +484 -24
  128. package/src/components/app-shell/index.ts +2 -0
  129. package/src/components/avatar/avatar.test.tsx +12 -0
  130. package/src/components/avatar/avatar.tsx +9 -0
  131. package/src/components/button-group/button-group.test.tsx +24 -0
  132. package/src/components/button-group/button-group.tsx +21 -4
  133. package/src/components/button-multi-select/button-multi-select.test.tsx +15 -0
  134. package/src/components/button-select/button-select-control.tsx +5 -0
  135. package/src/components/button-select/button-select.test.tsx +25 -0
  136. package/src/components/button-select/button-select.tsx +13 -2
  137. package/src/components/geodesic/badge-frame.tsx +67 -13
  138. package/src/components/geodesic/exam-badge.tsx +8 -4
  139. package/src/components/geodesic/geometry.ts +8 -6
  140. package/src/components/geodesic/status.test.ts +11 -2
  141. package/src/components/geodesic/status.ts +11 -7
  142. package/src/components/geodesic/styles.css +15 -2
  143. package/src/components/indicator/indicator.test.tsx +45 -0
  144. package/src/components/indicator/indicator.tsx +40 -13
  145. package/src/components/nav-link/nav-link.test.tsx +121 -1
  146. package/src/components/nav-link/nav-link.tsx +78 -29
  147. package/src/components/segment-group/segment-group.test.tsx +22 -0
  148. package/src/components/segment-group/segment-group.tsx +35 -19
  149. package/src/components/tabs/tabs-data.tsx +5 -1
  150. package/src/components/tabs/tabs.test.tsx +28 -0
  151. package/src/components/tabs/tabs.tsx +14 -4
  152. package/src/lib/sidebar-rail.ts +24 -0
  153. package/src/theme.css +7 -12
  154. package/src/theme.test.ts +0 -1
  155. package/dist/chunk-7HZBD4YZ.js.map +0 -1
  156. package/dist/chunk-HRNWWL3Y.js.map +0 -1
  157. package/dist/chunk-MW42XVPD.js.map +0 -1
  158. package/dist/chunk-SAXWCGWR.js.map +0 -1
  159. package/dist/chunk-XUFCI262.js.map +0 -1
@@ -83,12 +83,16 @@ const indicatorVariants = cva(
83
83
  // the "positioned, stack-level 0" step, which paints after `children`'s
84
84
  // step — now the dot (and, tucked behind just its own box, the pulse) is
85
85
  // the thing establishing the context, so it's it that ends up on top.
86
- "absolute z-0 inline-flex items-center justify-center",
86
+ "z-0 inline-flex items-center justify-center",
87
87
  "font-sans font-medium leading-none whitespace-nowrap select-none",
88
88
  "bg-(--c-solid) text-(--c-on-solid)",
89
89
  ],
90
90
  {
91
91
  variants: {
92
+ // Overlaid on `children`, or standing in the flow when there are none.
93
+ // `relative` keeps the dot a positioned box either way, so `z-0` still
94
+ // makes it the stacking context the `processing` pulse relies on.
95
+ placement: { overlay: "absolute", standalone: "relative shrink-0" },
92
96
  shape: { dot: "rounded-full", label: "" },
93
97
  size: { xs: "", sm: "", md: "", lg: "", xl: "" },
94
98
  radius: { xs: "", sm: "", md: "", lg: "", xl: "" },
@@ -110,15 +114,15 @@ const indicatorVariants = cva(
110
114
  { shape: "label", radius: "lg", class: "rounded-lg" },
111
115
  { shape: "label", radius: "xl", class: "rounded-xl" },
112
116
  ],
113
- defaultVariants: { shape: "dot", size: "md", radius: "xl" },
117
+ defaultVariants: { placement: "overlay", shape: "dot", size: "md", radius: "xl" },
114
118
  },
115
119
  )
116
120
 
117
121
  export type IndicatorProps = Omit<ComponentPropsWithoutRef<"div">, "children"> &
118
122
  WithTestId & {
119
- /** Which corner (or edge midpoint) of `children` the dot anchors to, straddling it. Default `"top-end"`. */
123
+ /** Which corner (or edge midpoint) of `children` the dot anchors to, straddling it. Default `"top-end"`. Ignored without `children`. */
120
124
  position?: IndicatorPosition
121
- /** Extra px nudge away from the anchor point — a single number for both axes, or `{ x, y }` independently. Ignored on whichever axis a position has no directional edge for (the `center`/`middle` axis of that position). */
125
+ /** Extra px nudge away from the anchor point — a single number for both axes, or `{ x, y }` independently. Ignored on whichever axis a position has no directional edge for (the `center`/`middle` axis of that position), and without `children`. */
122
126
  offset?: IndicatorOffset
123
127
  /** Dot diameter (no `label`) or badge height, off the kit's shared `xs`–`xl` scale. Default `"md"`. */
124
128
  size?: Size
@@ -146,12 +150,12 @@ export type IndicatorProps = Omit<ComponentPropsWithoutRef<"div">, "children"> &
146
150
  withBorder?: boolean
147
151
  /** Corner rounding of the label badge shape once `label` is set — irrelevant to the bare dot, which is always a circle. Default `"xl"`. */
148
152
  radius?: Size
149
- /** Root renders as a `<span>` with `display: inline-block` instead of the default `<div>`/`block` — for wrapping a run of inline content (a word, an icon) that shouldn't force its own line. The tag itself has to change, not just the display: a `<div>` is flow content and is never valid inside phrasing content (e.g. a `<p>`), regardless of its CSS display. Both modes shrink-wrap to `children`'s own intrinsic size either way (the default adds `width: fit-content` — a plain `display: block` box would otherwise stretch to its container's full width, dragging the corner dot away from a small child like an `Avatar` whenever the parent isn't already a flex/grid context). */
153
+ /** Root renders as a `<span>` with `display: inline-block` instead of the default `<div>`/`block` — for wrapping a run of inline content (a word, an icon) that shouldn't force its own line. Without `children` the root is always an inline `<span>`. The tag itself has to change, not just the display: a `<div>` is flow content and is never valid inside phrasing content (e.g. a `<p>`), regardless of its CSS display. Both modes shrink-wrap to `children`'s own intrinsic size either way (the default adds `width: fit-content` — a plain `display: block` box would otherwise stretch to its container's full width, dragging the corner dot away from a small child like an `Avatar` whenever the parent isn't already a flex/grid context). */
150
154
  inline?: boolean
151
155
  /** Stacking order of the dot/badge overlay. */
152
156
  zIndex?: number
153
- /** The element being decorated. Required — `Indicator` has no meaningful standalone render. */
154
- children: ReactNode
157
+ /** The element being decorated. Omit it for a standalone dot (or badge) that sits in the flow — a status dot before a word, a count beside a label — with `position`/`offset` ignored. */
158
+ children?: ReactNode
155
159
  }
156
160
 
157
161
  /** `offset`'s x/y split, defaulting each axis to 0. */
@@ -199,6 +203,10 @@ const buildOffsetStyle = (
199
203
  * on its own, so `alt` supplies the words ("3 unread messages") as visually
200
204
  * hidden text instead.
201
205
  *
206
+ * Without `children` it's a standalone dot in the flow, for a status before a
207
+ * word. The dot still says nothing on its own: pair it with visible text, or
208
+ * give it an `alt`.
209
+ *
202
210
  * No `asChild` — same reasoning as `Skeleton`: the root must stay a real
203
211
  * wrapping element around *two* things at once (`children` **and** the
204
212
  * absolutely-positioned dot sibling), which is structurally incompatible
@@ -212,6 +220,11 @@ const buildOffsetStyle = (
212
220
  * <Indicator processing color="green" position="bottom-end">
213
221
  * <ActionIcon><Wifi /></ActionIcon>
214
222
  * </Indicator>
223
+ *
224
+ * <span className="inline-flex items-center gap-1.5">
225
+ * <Indicator size="sm" color="pink" />
226
+ * Registered
227
+ * </span>
215
228
  */
216
229
  export const Indicator = ({
217
230
  className,
@@ -254,11 +267,20 @@ export const Indicator = ({
254
267
  // prop's own doc below), so the root tag switches to <span> too — the only
255
268
  // way `inline` actually delivers on wrapping a run of inline text without
256
269
  // the browser closing the paragraph around it.
257
- const Root = inline ? "span" : "div"
270
+ const standalone = children == null
271
+ const Root = inline || standalone ? "span" : "div"
272
+
273
+ // Nothing to decorate and nothing to show: render nothing rather than an
274
+ // empty box that still takes a gap in its parent's flex row.
275
+ if (standalone && !visible) return null
258
276
 
259
277
  return (
260
278
  <Root
261
- className={cn("relative", inline ? "inline-block" : "block w-fit", className)}
279
+ className={cn(
280
+ "relative",
281
+ standalone ? "inline-flex shrink-0 align-middle" : inline ? "inline-block" : "block w-fit",
282
+ className,
283
+ )}
262
284
  style={style}
263
285
  {...dataProps({ "data-testid": testId })}
264
286
  {...rest}
@@ -273,15 +295,20 @@ export const Indicator = ({
273
295
  <span
274
296
  aria-hidden="true"
275
297
  data-part="indicator"
276
- data-position={position}
298
+ data-position={standalone ? undefined : position}
277
299
  data-color={color}
278
300
  className={cn(
279
- indicatorVariants({ shape: hasLabel ? "label" : "dot", size, radius }),
280
- POSITION_CLASS[position],
301
+ indicatorVariants({
302
+ placement: standalone ? "standalone" : "overlay",
303
+ shape: hasLabel ? "label" : "dot",
304
+ size,
305
+ radius,
306
+ }),
307
+ !standalone && POSITION_CLASS[position],
281
308
  withBorder && "border-2 border-(--indicator-border-color)",
282
309
  )}
283
310
  style={{
284
- ...buildOffsetStyle(position, offset),
311
+ ...(standalone ? null : buildOffsetStyle(position, offset)),
285
312
  ...(zIndex !== undefined ? { zIndex } : null),
286
313
  }}
287
314
  >
@@ -1,7 +1,8 @@
1
- import { fireEvent, render, screen } from "@testing-library/react"
1
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react"
2
2
  import type { ReactNode } from "react"
3
3
  import { describe, expect, it, vi } from "vitest"
4
4
  import { LinkComponentProvider } from "../../lib/link-component"
5
+ import { SidebarRailContext } from "../../lib/sidebar-rail"
5
6
  import { NavLink } from "./nav-link"
6
7
 
7
8
  const StubLink = ({
@@ -164,3 +165,122 @@ describe("NavLink translations", () => {
164
165
  )
165
166
  })
166
167
  })
168
+
169
+ describe("NavLink in a sidebar icon rail", () => {
170
+ const Row = () => (
171
+ <NavLink
172
+ label="Dashboard"
173
+ startSlot={<svg data-icon />}
174
+ endSlot={<b>3</b>}
175
+ linkOptions={{ href: "/d" }}
176
+ >
177
+ <NavLink label="Child" linkOptions={{ href: "/c" }} />
178
+ </NavLink>
179
+ )
180
+
181
+ it("renders no tooltip machinery outside a rail-capable sidebar", () => {
182
+ render(<Row />)
183
+ // endSlot's text ("3") is part of the row's name.
184
+ const link = screen.getByRole("link", { name: /^Dashboard/ })
185
+ expect(link.getAttribute("data-scope")).toBeNull()
186
+ })
187
+
188
+ it("keeps the label as the accessible name, hides the rest behind the rail variant", () => {
189
+ render(
190
+ <SidebarRailContext.Provider value={{ active: true }}>
191
+ <Row />
192
+ </SidebarRailContext.Provider>,
193
+ )
194
+ const link = screen.getByRole("link", { name: /^Dashboard/ })
195
+ expect(link.getAttribute("data-scope")).toBe("tooltip")
196
+ expect(screen.getByText("Dashboard").className).toContain("sidebar-rail:sr-only")
197
+ expect(screen.getByText("3").parentElement?.className).toContain("sidebar-rail:hidden")
198
+ expect(screen.getByRole("button", { name: "Expand" }).className).toContain(
199
+ "sidebar-rail:hidden",
200
+ )
201
+ })
202
+
203
+ it("folds nested rows shut on an active rail, keeping the row's own open state", () => {
204
+ const { rerender } = render(
205
+ <SidebarRailContext.Provider value={{ active: true }}>
206
+ <NavLink label="Projects" startSlot={<svg />} linkOptions={{ href: "/p" }} defaultOpen>
207
+ <NavLink label="Libft" linkOptions={{ href: "/p/libft" }} />
208
+ </NavLink>
209
+ </SidebarRailContext.Provider>,
210
+ )
211
+ // Animated shut (grid rows to 0fr) and inert, rather than display: none.
212
+ const folded = screen.getByText("Libft").closest("div.grid") as HTMLElement
213
+ expect(folded.getAttribute("data-state")).toBe("closed")
214
+ expect(folded.className).toContain("grid-rows-[0fr]")
215
+ expect(folded.className).not.toContain("sidebar-rail:hidden")
216
+ // Out of the tab order while folded (jsdom's role queries ignore inert).
217
+ expect(screen.getByRole("link", { name: "Libft" }).closest("[inert]")).not.toBeNull()
218
+
219
+ rerender(
220
+ <SidebarRailContext.Provider value={{ active: false }}>
221
+ <NavLink label="Projects" startSlot={<svg />} linkOptions={{ href: "/p" }} defaultOpen>
222
+ <NavLink label="Libft" linkOptions={{ href: "/p/libft" }} />
223
+ </NavLink>
224
+ </SidebarRailContext.Provider>,
225
+ )
226
+ expect(folded.getAttribute("data-state")).toBe("open")
227
+ expect(screen.getByRole("link", { name: "Libft" }).closest("[inert]")).toBeNull()
228
+ })
229
+
230
+ it("shows the label as a tooltip on focus while the rail is active", async () => {
231
+ render(
232
+ <SidebarRailContext.Provider value={{ active: true }}>
233
+ <NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
234
+ </SidebarRailContext.Provider>,
235
+ )
236
+ // zag opens a tooltip on *keyboard* focus only: Tab first.
237
+ fireEvent.keyDown(document.body, { key: "Tab" })
238
+ fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
239
+ expect((await screen.findByRole("tooltip")).textContent).toBe("Dashboard")
240
+ })
241
+
242
+ it("keeps its expanded geometry on a rail, so icons don't move as it opens", () => {
243
+ render(
244
+ <SidebarRailContext.Provider value={{ active: true }}>
245
+ <NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
246
+ </SidebarRailContext.Provider>,
247
+ )
248
+ // The rail is sized to the row (see AppShell's RAIL_WIDTH): only the label
249
+ // hides, nothing re-lays out the row itself.
250
+ const row = screen.getByRole("link", { name: "Dashboard" })
251
+ expect(row.className).not.toMatch(/sidebar-rail:(p|px|size|justify)/)
252
+ })
253
+
254
+ it("never lets the start slot shrink, so an icon can't squish in a narrow row", () => {
255
+ render(<NavLink label="Dashboard" startSlot={<svg data-icon />} linkOptions={{ href: "/d" }} />)
256
+ const icon = document.querySelector("[data-icon]") as Element
257
+ expect(icon.parentElement?.className).toContain("shrink-0")
258
+ })
259
+
260
+ it("closes an open tooltip as soon as the rail opens", async () => {
261
+ const Rail = ({ active }: { active: boolean }) => (
262
+ <SidebarRailContext.Provider value={{ active }}>
263
+ <NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
264
+ </SidebarRailContext.Provider>
265
+ )
266
+ const { rerender } = render(<Rail active />)
267
+ fireEvent.keyDown(document.body, { key: "Tab" })
268
+ fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
269
+ expect(await screen.findByRole("tooltip")).toBeTruthy()
270
+
271
+ rerender(<Rail active={false} />)
272
+ await waitFor(() => expect(screen.queryByRole("tooltip")).toBeNull())
273
+ })
274
+
275
+ it("keeps the tooltip off once the labels are back", async () => {
276
+ render(
277
+ <SidebarRailContext.Provider value={{ active: false }}>
278
+ <NavLink label="Dashboard" startSlot={<svg />} linkOptions={{ href: "/d" }} />
279
+ </SidebarRailContext.Provider>,
280
+ )
281
+ fireEvent.keyDown(document.body, { key: "Tab" })
282
+ fireEvent.focus(screen.getByRole("link", { name: "Dashboard" }))
283
+ await new Promise((resolve) => setTimeout(resolve, 50))
284
+ expect(screen.queryByRole("tooltip")).toBeNull()
285
+ })
286
+ })
@@ -1,16 +1,18 @@
1
1
  "use client"
2
2
 
3
3
  import { cva } from "class-variance-authority"
4
- import { type ElementType, type ReactNode, useId } from "react"
4
+ import { type ElementType, type ReactNode, useId, useState } from "react"
5
5
  import { cn } from "../../lib/cn"
6
6
  import { focusStyles } from "../../lib/focus-styles"
7
7
  import { useLinkComponent } from "../../lib/link-component"
8
8
  import { props } from "../../lib/props"
9
+ import { useSidebarRail } from "../../lib/sidebar-rail"
9
10
  import type { WithTestId } from "../../lib/test-id"
10
11
  import { TEXT_COLOR_CLASSES } from "../../lib/typography-size"
11
12
  import { useUncontrolled } from "../../lib/use-uncontrolled"
12
13
  import { Collapse } from "../collapse/collapse"
13
14
  import { ChevronIcon } from "../popover/icons"
15
+ import { Tooltip } from "../tooltip/tooltip"
14
16
 
15
17
  /**
16
18
  * NavLink — a single sidebar/nav row: leading `startSlot`, `label`, trailing
@@ -37,6 +39,12 @@ import { ChevronIcon } from "../popover/icons"
37
39
  * `linkComponent` — a router's `Link` would put the `href` straight back.
38
40
  *
39
41
  * <NavLink label="Dashboard" startSlot={<Home />} linkOptions={{ href: "/dashboard" }} />
42
+ * In a sidebar collapsed to an icon rail (`AppShell.Sidebar collapse="icons"`)
43
+ * the row shows `startSlot` alone: the label stays as the accessible name
44
+ * (visually hidden) and shows as a tooltip on hover and focus; `endSlot` and
45
+ * the chevron are hidden, and nested children fold shut (animated, and inert)
46
+ * until the sidebar is expanded or peeking. Give such rows a `startSlot` — a rail row without one is empty.
47
+ *
40
48
  * <NavLink label="Settings" startSlot={<Settings />} defaultOpen>
41
49
  * <NavLink label="Profile" linkOptions={{ href: "/settings/profile" }} />
42
50
  * <NavLink label="Security" linkOptions={{ href: "/settings/security" }} />
@@ -46,6 +54,10 @@ import { ChevronIcon } from "../popover/icons"
46
54
  const navLinkRow = cva(
47
55
  [
48
56
  "flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md px-2.5 py-2 text-start text-sm",
57
+ // The row's expanded height, held on an icon rail too, where the label is
58
+ // visually hidden and would otherwise take its line height with it — the
59
+ // rows would grow 4px each as the rail opens.
60
+ "min-h-9",
49
61
  "outline-none transition-colors",
50
62
  "hover:bg-black/5 dark:hover:bg-white/8",
51
63
  focusStyles(),
@@ -63,7 +75,7 @@ const navLinkRow = cva(
63
75
  )
64
76
 
65
77
  const chevronButton = cn(
66
- "flex shrink-0 cursor-pointer items-center justify-center rounded-md p-2 text-black/50 transition-colors",
78
+ "flex shrink-0 sidebar-rail:hidden cursor-pointer items-center justify-center rounded-md p-2 text-black/50 transition-colors",
67
79
  "hover:bg-black/5 dark:text-white/50 dark:hover:bg-white/8",
68
80
  focusStyles(),
69
81
  )
@@ -72,7 +84,7 @@ const chevron = (open: boolean) => (
72
84
  <span
73
85
  aria-hidden="true"
74
86
  data-state={open ? "open" : "closed"}
75
- className="ms-auto flex shrink-0 transition-transform data-[state=open]:rotate-180 [&_svg]:size-4"
87
+ className="ms-auto flex shrink-0 transition-transform sidebar-rail:hidden data-[state=open]:rotate-180 [&_svg]:size-4"
76
88
  >
77
89
  <ChevronIcon />
78
90
  </span>
@@ -152,12 +164,20 @@ function NavLinkImpl({
152
164
  const isLink = linkOptions != null
153
165
  const Comp = useLinkComponent(linkComponent) ?? "a"
154
166
  const itemsId = `nav-link-items-${useId()}`
167
+ const rail = useSidebarRail()
168
+ // Controlled, so the bubble closes the moment the rail opens: Ark's
169
+ // `disabled` only stops a closed tooltip from opening, it doesn't shut one.
170
+ const [tipOpen, setTipOpen] = useState(false)
155
171
 
156
172
  const content = (
157
173
  <>
158
- {startSlot}
159
- <span className="min-w-0 flex-1 truncate">{label}</span>
160
- {endSlot}
174
+ {/* Never shrinks: only the label gives way when the row is narrow. A
175
+ bare SVG icon is a flex item that would otherwise squeeze — and scale
176
+ its drawing down — as an icon rail widens with the label already
177
+ showing, visibly squishing the icon for a frame or two. */}
178
+ {startSlot != null && <span className="flex shrink-0">{startSlot}</span>}
179
+ <span className="min-w-0 flex-1 truncate sidebar-rail:sr-only">{label}</span>
180
+ {endSlot != null && <span className="contents sidebar-rail:hidden">{endSlot}</span>}
161
181
  </>
162
182
  )
163
183
 
@@ -168,32 +188,56 @@ function NavLinkImpl({
168
188
  "data-testid": testId,
169
189
  })
170
190
 
191
+ const row =
192
+ isLink && disabled ? (
193
+ // No `href`, so no tab stop and nothing for Enter to follow; the
194
+ // explicit role keeps it announced as a (disabled) link.
195
+ <a role="link" {...rowState} className={rowClassName}>
196
+ {content}
197
+ </a>
198
+ ) : isLink ? (
199
+ <Comp {...linkOptions} {...rowState} className={rowClassName}>
200
+ {content}
201
+ </Comp>
202
+ ) : (
203
+ <button
204
+ type="button"
205
+ {...rowState}
206
+ aria-expanded={hasChildren ? isOpen : undefined}
207
+ {...props({ "aria-controls": hasChildren && itemsId })}
208
+ disabled={disabled}
209
+ onClick={() => hasChildren && setOpen(!isOpen)}
210
+ className={rowClassName}
211
+ >
212
+ {content}
213
+ {hasChildren && chevron(isOpen)}
214
+ </button>
215
+ )
216
+
171
217
  return (
172
218
  <div>
173
219
  <div className="flex items-stretch gap-1">
174
- {isLink && disabled ? (
175
- // No `href`, so no tab stop and nothing for Enter to follow; the
176
- // explicit role keeps it announced as a (disabled) link.
177
- <a role="link" {...rowState} className={rowClassName}>
178
- {content}
179
- </a>
180
- ) : isLink ? (
181
- <Comp {...linkOptions} {...rowState} className={rowClassName}>
182
- {content}
183
- </Comp>
184
- ) : (
185
- <button
186
- type="button"
187
- {...rowState}
188
- aria-expanded={hasChildren ? isOpen : undefined}
189
- {...props({ "aria-controls": hasChildren && itemsId })}
190
- disabled={disabled}
191
- onClick={() => hasChildren && setOpen(!isOpen)}
192
- className={rowClassName}
220
+ {rail ? (
221
+ // Only inside a rail-capable sidebar, so a plain NavLink pays for
222
+ // no tooltip machine. Disabled (not unmounted) while the labels
223
+ // show, so expanding never remounts the row under focus.
224
+ <Tooltip
225
+ label={label}
226
+ position="end"
227
+ asChild
228
+ disabled={!rail.active}
229
+ open={tipOpen && rail.active}
230
+ onOpenChange={({ open }) => setTipOpen(open)}
231
+ openDelay={200}
232
+ // Gone at once when the rail opens, rather than fading out over
233
+ // the label that's appearing beneath it. Important: it ties with
234
+ // the bubble's own data-[state=closed] exit animation otherwise.
235
+ classNames={{ content: rail.active ? undefined : "data-[state=closed]:animate-none!" }}
193
236
  >
194
- {content}
195
- {hasChildren && chevron(isOpen)}
196
- </button>
237
+ {row}
238
+ </Tooltip>
239
+ ) : (
240
+ row
197
241
  )}
198
242
  {hasChildren && isLink && (
199
243
  <button
@@ -213,7 +257,12 @@ function NavLinkImpl({
213
257
  )}
214
258
  </div>
215
259
  {hasChildren && (
216
- <Collapse open={isOpen}>
260
+ // Nested rows have no place on a rail, so they fold shut there — the
261
+ // same Collapse animation, not `display: none`, so they slide open as
262
+ // the rail peeks (and shut as it closes) instead of snapping, and stay
263
+ // inert while folded. `isOpen` itself is untouched: the row's own
264
+ // open state comes back with the labels.
265
+ <Collapse open={isOpen && !rail?.active}>
217
266
  <div
218
267
  id={itemsId}
219
268
  className={cn(
@@ -214,4 +214,26 @@ describe("SegmentGroup separators under RTL", () => {
214
214
  const pill = container.querySelector('[data-part="indicator"]') as HTMLElement
215
215
  expect(pill.className).not.toMatch(/(^|\s)z-0(\s|$)/)
216
216
  })
217
+
218
+ it("spans the container with an even share per segment under `grow`", () => {
219
+ render(<SegmentGroup data={ITEMS} testId="g" grow />)
220
+ const tray = screen.getByTestId("g")
221
+ expect(tray.className).toMatch(/(^|\s)w-full(\s|$)/)
222
+ expect(tray.className).not.toContain("max-w-fit")
223
+ const item = screen.getByTestId("item-list")
224
+ expect(item.className).toMatch(/(^|\s)flex-1(\s|$)/)
225
+ const text = item.querySelector('[data-part="item-text"]') as HTMLElement
226
+ expect(text.className).toMatch(/(^|\s)w-full(\s|$)/)
227
+ })
228
+
229
+ it("hugs its labels without `grow`", () => {
230
+ render(<SegmentGroup data={ITEMS} testId="g" />)
231
+ const tray = screen.getByTestId("g")
232
+ expect(tray.className).toContain("max-w-fit")
233
+ expect(tray.className).not.toMatch(/(^|\s)w-full(\s|$)/)
234
+ const item = screen.getByTestId("item-list")
235
+ expect(item.className).not.toMatch(/(^|\s)flex-1(\s|$)/)
236
+ const text = item.querySelector('[data-part="item-text"]') as HTMLElement
237
+ expect(text.className).not.toMatch(/(^|\s)w-full(\s|$)/)
238
+ })
217
239
  })
@@ -103,6 +103,8 @@ const segItem = cva(
103
103
  lg: "flex items-center justify-center px-3 text-lg",
104
104
  xl: "flex items-center justify-center px-4 text-xl",
105
105
  },
106
+ // Fill the (grown) segment so the label centers across its whole share.
107
+ grow: { true: "w-full" },
106
108
  },
107
109
  defaultVariants: { variant: "default", size: "md" },
108
110
  },
@@ -117,22 +119,30 @@ const segItem = cva(
117
119
  * `:nth-child(2)`). It flips from a vertical rule to a horizontal one when the
118
120
  * group is laid out vertically.
119
121
  */
120
- const segItemWrap = cva([
121
- "relative z-1 inline-flex",
122
- "before:absolute before:rounded-full before:bg-brand-900/30 dark:before:bg-white/35",
123
- "group-data-invalid:before:bg-red-500/30",
124
- "before:transition-opacity before:duration-200",
125
- // Horizontal: a vertical rule centered on the leading edge, sitting in the gap. Logical
126
- // (`start`, `-ms-[0.5px]` to center the 1px rule), so under `dir="rtl"` the rule still lands
127
- // between a segment and the one before it instead of on the far side.
128
- "before:top-1/2 before:start-0 before:-ms-[0.5px] before:h-1/2 before:w-px before:-translate-y-1/2",
129
- // Vertical: a horizontal rule centered on the top edge instead (`start-1/4` + `w-1/2` is
130
- // centered in either direction).
131
- "in-data-[orientation=vertical]:before:top-0 in-data-[orientation=vertical]:before:start-1/4 in-data-[orientation=vertical]:before:ms-0 in-data-[orientation=vertical]:before:h-px in-data-[orientation=vertical]:before:w-1/2",
132
- // No separator before the first segment, or flanking the active pill.
133
- "nth-2:before:hidden",
134
- "data-[state=checked]:before:opacity-0 data-[state=checked]:[&+*]:before:opacity-0",
135
- ])
122
+ const segItemWrap = cva(
123
+ [
124
+ "relative z-1 inline-flex",
125
+ "before:absolute before:rounded-full before:bg-brand-900/30 dark:before:bg-white/35",
126
+ "group-data-invalid:before:bg-red-500/30",
127
+ "before:transition-opacity before:duration-200",
128
+ // Horizontal: a vertical rule centered on the leading edge, sitting in the gap. Logical
129
+ // (`start`, `-ms-[0.5px]` to center the 1px rule), so under `dir="rtl"` the rule still lands
130
+ // between a segment and the one before it instead of on the far side.
131
+ "before:top-1/2 before:start-0 before:-ms-[0.5px] before:h-1/2 before:w-px before:-translate-y-1/2",
132
+ // Vertical: a horizontal rule centered on the top edge instead (`start-1/4` + `w-1/2` is
133
+ // centered in either direction).
134
+ "in-data-[orientation=vertical]:before:top-0 in-data-[orientation=vertical]:before:start-1/4 in-data-[orientation=vertical]:before:ms-0 in-data-[orientation=vertical]:before:h-px in-data-[orientation=vertical]:before:w-1/2",
135
+ // No separator before the first segment, or flanking the active pill.
136
+ "nth-2:before:hidden",
137
+ "data-[state=checked]:before:opacity-0 data-[state=checked]:[&+*]:before:opacity-0",
138
+ ],
139
+ {
140
+ variants: {
141
+ // An even share of the tray per segment, like a tab bar.
142
+ grow: { true: "flex-1" },
143
+ },
144
+ },
145
+ )
136
146
 
137
147
  /**
138
148
  * The sliding pill, mirroring each `Button` surface. Its slide + color transition
@@ -213,6 +223,8 @@ const segTray = cva(
213
223
  lg: "gap-0 min-h-10",
214
224
  xl: "gap-0 min-h-12",
215
225
  },
226
+ // Span the container instead of hugging the labels.
227
+ grow: { true: "flex w-full max-w-none" },
216
228
  },
217
229
  defaultVariants: { variant: "default" },
218
230
  },
@@ -331,6 +343,9 @@ export type SegmentGroupProps<Data extends SegmentGroupData = SegmentGroupData>
331
343
  size?: SegmentGroupSize
332
344
  variant?: SegmentGroupVariant
333
345
  color?: Color
346
+ /** Span the container and give every segment an even share of it, like a
347
+ * tab bar. Without it the group hugs its labels. */
348
+ grow?: boolean
334
349
  /** Wires the hidden radio inputs into native form submission. */
335
350
  name?: string
336
351
  /** Explicit id for label association. */
@@ -453,6 +468,7 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
453
468
  size = "md",
454
469
  variant = "default",
455
470
  color,
471
+ grow,
456
472
  name,
457
473
  id,
458
474
  ref,
@@ -513,7 +529,7 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
513
529
  onBlur={onBlur}
514
530
  color={color}
515
531
  testId={testId}
516
- className={cn(segTray({ variant, size }), className, classNames?.root)}
532
+ className={cn(segTray({ variant, size, grow }), className, classNames?.root)}
517
533
  >
518
534
  {/* The sliding pill. Ark sets `position: absolute` + `--left`/`--top`/
519
535
  `--width`/`--height` (the selected segment's rect) inline, so it
@@ -552,11 +568,11 @@ export const SegmentGroup = <const Data extends SegmentGroupData = SegmentGroupD
552
568
  value={item.value}
553
569
  disabled={item.disabled}
554
570
  data-testid={item.testId}
555
- className={cn(segItemWrap(), classNames?.item)}
571
+ className={cn(segItemWrap({ grow }), classNames?.item)}
556
572
  >
557
573
  <Ark.ItemText
558
574
  data-color={item.color}
559
- className={cn(segItem({ size, variant }), classNames?.itemText)}
575
+ className={cn(segItem({ size, variant, grow }), classNames?.itemText)}
560
576
  >
561
577
  {/* `renderItem` owns the label content (with the item's typed payload);
562
578
  the ItemText keeps its sizing, checked color, and pill wiring. */}
@@ -71,6 +71,9 @@ export type TabsProps<Data extends TabsData = TabsData> = Omit<
71
71
  /** Palette for the underline bar + active-trigger text. Scoped to the
72
72
  * strip (it lands on the `List`), so it never tints the panel content. */
73
73
  color?: Color
74
+ /** Give every tab an even share of the strip, like a tab bar. Lands on the
75
+ * `List`. */
76
+ grow?: boolean
74
77
  /** Fires with the selected value (narrowed to the data value union). */
75
78
  onChange?: (value: TabsValue<Data>) => void
76
79
  }
@@ -80,6 +83,7 @@ const TabsComponent = <const Data extends TabsData>({
80
83
  variant,
81
84
  size,
82
85
  color,
86
+ grow,
83
87
  value,
84
88
  defaultValue,
85
89
  onChange,
@@ -92,7 +96,7 @@ const TabsComponent = <const Data extends TabsData>({
92
96
  onValueChange={onChange ? (d) => onChange(d.value as TabsValue<Data>) : undefined}
93
97
  {...root}
94
98
  >
95
- <List variant={variant} size={size} color={color}>
99
+ <List variant={variant} size={size} color={color} grow={grow}>
96
100
  <Indicator />
97
101
  {data.map((item) => (
98
102
  <Trigger
@@ -341,4 +341,32 @@ describe("Tabs", () => {
341
341
  const indicator = container.querySelector('[data-part="indicator"]') as HTMLElement
342
342
  expect(indicator.className).not.toMatch(/(^|\s)z-0(\s|$)/)
343
343
  })
344
+
345
+ it("gives every trigger an even share under `List`'s `grow`", () => {
346
+ render(
347
+ <Root defaultValue="a">
348
+ <List grow>
349
+ <Trigger value="a">A</Trigger>
350
+ <Trigger value="b">B</Trigger>
351
+ </List>
352
+ </Root>,
353
+ )
354
+ for (const tab of screen.getAllByRole("tab")) {
355
+ expect(tab.className).toMatch(/(^|\s)flex-1(\s|$)/)
356
+ }
357
+ })
358
+
359
+ it("passes `grow` through the data-driven Tabs to its List", () => {
360
+ render(<Tabs data={ITEMS} grow />)
361
+ for (const tab of screen.getAllByRole("tab")) {
362
+ expect(tab.className).toMatch(/(^|\s)flex-1(\s|$)/)
363
+ }
364
+ })
365
+
366
+ it("keeps the triggers hugging their labels without `grow`", () => {
367
+ render(<Tabs data={ITEMS} />)
368
+ for (const tab of screen.getAllByRole("tab")) {
369
+ expect(tab.className).not.toMatch(/(^|\s)flex-1(\s|$)/)
370
+ }
371
+ })
344
372
  })