@eifi1/ui-kit 0.9.0 → 0.10.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 (176) hide show
  1. package/README.md +21 -11
  2. package/dist/components/alert-banner.d.ts +32 -5
  3. package/dist/components/alert-banner.js +57 -14
  4. package/dist/components/alert-banner.js.map +1 -1
  5. package/dist/components/amount-input.d.ts +4 -0
  6. package/dist/components/breadcrumbs.d.ts +60 -0
  7. package/dist/components/breadcrumbs.js +88 -0
  8. package/dist/components/breadcrumbs.js.map +1 -0
  9. package/dist/components/bulk-action-bar.d.ts +66 -0
  10. package/dist/components/bulk-action-bar.js +149 -0
  11. package/dist/components/bulk-action-bar.js.map +1 -0
  12. package/dist/components/calculator.d.ts +4 -0
  13. package/dist/components/chip.d.ts +31 -5
  14. package/dist/components/chip.js +85 -5
  15. package/dist/components/chip.js.map +1 -1
  16. package/dist/components/copy-button.d.ts +13 -4
  17. package/dist/components/copy-button.js +17 -4
  18. package/dist/components/copy-button.js.map +1 -1
  19. package/dist/components/date-picker.d.ts +22 -2
  20. package/dist/components/date-picker.js +11 -3
  21. package/dist/components/date-picker.js.map +1 -1
  22. package/dist/components/description-list.d.ts +43 -6
  23. package/dist/components/description-list.js +91 -11
  24. package/dist/components/description-list.js.map +1 -1
  25. package/dist/components/dialog-frame.d.ts +7 -0
  26. package/dist/components/dialog-frame.js.map +1 -1
  27. package/dist/components/disclosure.d.ts +57 -2
  28. package/dist/components/disclosure.js +24 -12
  29. package/dist/components/disclosure.js.map +1 -1
  30. package/dist/components/file-dropzone.d.ts +3 -4
  31. package/dist/components/file-dropzone.js +2 -1
  32. package/dist/components/file-dropzone.js.map +1 -1
  33. package/dist/components/full-bleed-dialog.d.ts +23 -4
  34. package/dist/components/full-bleed-dialog.js +11 -2
  35. package/dist/components/full-bleed-dialog.js.map +1 -1
  36. package/dist/components/list.d.ts +174 -0
  37. package/dist/components/list.js +215 -0
  38. package/dist/components/list.js.map +1 -0
  39. package/dist/components/menu-item.d.ts +99 -0
  40. package/dist/components/menu-item.js +83 -0
  41. package/dist/components/menu-item.js.map +1 -0
  42. package/dist/components/modal.d.ts +23 -1
  43. package/dist/components/modal.js +36 -10
  44. package/dist/components/modal.js.map +1 -1
  45. package/dist/components/number-field.d.ts +4 -0
  46. package/dist/components/number-input.d.ts +4 -0
  47. package/dist/components/numpad-sheet.d.ts +4 -0
  48. package/dist/components/page-contents.js +1 -2
  49. package/dist/components/page-contents.js.map +1 -1
  50. package/dist/components/page-header.d.ts +37 -0
  51. package/dist/components/page-header.js +36 -0
  52. package/dist/components/page-header.js.map +1 -0
  53. package/dist/components/series-chart-labels.d.ts +3 -0
  54. package/dist/components/series-chart-labels.js +2 -1
  55. package/dist/components/series-chart-labels.js.map +1 -1
  56. package/dist/components/series-chart.d.ts +16 -0
  57. package/dist/components/series-chart.js +137 -3
  58. package/dist/components/series-chart.js.map +1 -1
  59. package/dist/components/status-dot.d.ts +49 -0
  60. package/dist/components/status-dot.js +52 -0
  61. package/dist/components/status-dot.js.map +1 -0
  62. package/dist/components/table.d.ts +39 -6
  63. package/dist/components/table.js +43 -4
  64. package/dist/components/table.js.map +1 -1
  65. package/dist/components/text.d.ts +63 -0
  66. package/dist/components/text.js +23 -0
  67. package/dist/components/text.js.map +1 -0
  68. package/dist/components/toast.d.ts +167 -0
  69. package/dist/components/toast.js +226 -0
  70. package/dist/components/toast.js.map +1 -0
  71. package/dist/components/toggle-group.d.ts +29 -1
  72. package/dist/components/toggle-group.js +52 -3
  73. package/dist/components/toggle-group.js.map +1 -1
  74. package/dist/components/tooltip.d.ts +38 -15
  75. package/dist/components/tooltip.js +85 -47
  76. package/dist/components/tooltip.js.map +1 -1
  77. package/dist/components/ui.d.ts +104 -4
  78. package/dist/components/ui.js +112 -8
  79. package/dist/components/ui.js.map +1 -1
  80. package/dist/hooks/use-close-transition.d.ts +7 -1
  81. package/dist/hooks/use-close-transition.js +5 -2
  82. package/dist/hooks/use-close-transition.js.map +1 -1
  83. package/dist/hooks/use-copy-to-clipboard.js +1 -1
  84. package/dist/hooks/use-copy-to-clipboard.js.map +1 -1
  85. package/dist/i18n/defaults.d.ts +4 -0
  86. package/dist/i18n/defaults.js +9 -1
  87. package/dist/i18n/defaults.js.map +1 -1
  88. package/dist/i18n/kit-labels.d.ts +8 -0
  89. package/dist/i18n/kit-labels.js.map +1 -1
  90. package/dist/i18n/locales/de-CH-informal.d.ts +4 -0
  91. package/dist/i18n/locales/de-CH.d.ts +4 -0
  92. package/dist/i18n/locales/de-informal.d.ts +4 -0
  93. package/dist/i18n/locales/de.d.ts +4 -0
  94. package/dist/i18n/locales/de.js +21 -1
  95. package/dist/i18n/locales/de.js.map +1 -1
  96. package/dist/i18n/locales/es.d.ts +4 -0
  97. package/dist/i18n/locales/es.js +21 -1
  98. package/dist/i18n/locales/es.js.map +1 -1
  99. package/dist/i18n/locales/fr.d.ts +4 -0
  100. package/dist/i18n/locales/fr.js +21 -1
  101. package/dist/i18n/locales/fr.js.map +1 -1
  102. package/dist/i18n/locales/hu.d.ts +4 -0
  103. package/dist/i18n/locales/hu.js +21 -1
  104. package/dist/i18n/locales/hu.js.map +1 -1
  105. package/dist/i18n/locales/it.d.ts +4 -0
  106. package/dist/i18n/locales/it.js +21 -1
  107. package/dist/i18n/locales/it.js.map +1 -1
  108. package/dist/i18n/locales/zh.d.ts +4 -0
  109. package/dist/i18n/locales/zh.js +21 -1
  110. package/dist/i18n/locales/zh.js.map +1 -1
  111. package/dist/index.d.ts +15 -7
  112. package/dist/index.js +12 -0
  113. package/dist/index.js.map +1 -1
  114. package/dist/lib/clipping.d.ts +9 -0
  115. package/dist/lib/clipping.js +14 -0
  116. package/dist/lib/clipping.js.map +1 -0
  117. package/dist/search/command-palette.d.ts +19 -2
  118. package/dist/search/command-palette.js +16 -5
  119. package/dist/search/command-palette.js.map +1 -1
  120. package/dist/search/global-search.d.ts +26 -1
  121. package/dist/search/global-search.js +29 -13
  122. package/dist/search/global-search.js.map +1 -1
  123. package/dist/search.d.ts +1 -1
  124. package/dist/wizard/stepper-nav.js +1 -1
  125. package/dist/wizard/stepper-nav.js.map +1 -1
  126. package/dist/wizard/types.d.ts +2 -2
  127. package/dist/wizard/types.js.map +1 -1
  128. package/dist/wizard/use-wizard.js +1 -1
  129. package/dist/wizard/use-wizard.js.map +1 -1
  130. package/dist/wizard/wizard-summary.js +3 -3
  131. package/dist/wizard/wizard-summary.js.map +1 -1
  132. package/package.json +16 -12
  133. package/src/components/alert-banner.tsx +117 -18
  134. package/src/components/breadcrumbs.tsx +168 -0
  135. package/src/components/bulk-action-bar.tsx +256 -0
  136. package/src/components/chip.tsx +128 -7
  137. package/src/components/copy-button.tsx +29 -7
  138. package/src/components/date-picker.tsx +49 -1
  139. package/src/components/description-list.tsx +168 -15
  140. package/src/components/dialog-frame.tsx +7 -0
  141. package/src/components/disclosure.tsx +93 -21
  142. package/src/components/file-dropzone.tsx +9 -10
  143. package/src/components/full-bleed-dialog.tsx +42 -5
  144. package/src/components/list.tsx +417 -0
  145. package/src/components/menu-item.tsx +214 -0
  146. package/src/components/modal.tsx +80 -17
  147. package/src/components/page-contents.tsx +4 -4
  148. package/src/components/page-header.tsx +68 -0
  149. package/src/components/series-chart-labels.ts +4 -0
  150. package/src/components/series-chart.tsx +253 -3
  151. package/src/components/status-dot.tsx +99 -0
  152. package/src/components/table.tsx +91 -6
  153. package/src/components/text.tsx +89 -0
  154. package/src/components/toast.tsx +441 -0
  155. package/src/components/toggle-group.tsx +82 -3
  156. package/src/components/tooltip.tsx +186 -100
  157. package/src/components/ui.tsx +237 -8
  158. package/src/hooks/use-close-transition.ts +14 -5
  159. package/src/hooks/use-copy-to-clipboard.ts +1 -1
  160. package/src/i18n/defaults.ts +8 -0
  161. package/src/i18n/kit-labels.tsx +8 -0
  162. package/src/i18n/locales/de.ts +20 -0
  163. package/src/i18n/locales/es.ts +20 -0
  164. package/src/i18n/locales/fr.ts +20 -0
  165. package/src/i18n/locales/hu.ts +20 -0
  166. package/src/i18n/locales/it.ts +20 -0
  167. package/src/i18n/locales/zh.ts +20 -0
  168. package/src/index.ts +26 -0
  169. package/src/lib/clipping.ts +16 -0
  170. package/src/search/command-palette.tsx +42 -5
  171. package/src/search/global-search.tsx +59 -18
  172. package/src/wizard/stepper-nav.tsx +2 -1
  173. package/src/wizard/types.ts +2 -2
  174. package/src/wizard/use-wizard.ts +3 -3
  175. package/src/wizard/wizard-summary.tsx +14 -10
  176. package/tokens.css +97 -0
@@ -1,12 +1,18 @@
1
1
  import type { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
2
- import { AlertTriangle, ChevronRight, Info, X } from "lucide-react";
2
+ import { AlertTriangle, CheckCircle2, ChevronRight, Info, X } from "lucide-react";
3
3
  import { cn } from "../lib/cn";
4
4
  import { DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels";
5
5
 
6
6
  /** `info` (0.8.0) is the sky family, for news that is neither good nor bad: keksdose's
7
7
  * preview and beta-performance banners, which borrowed `warning` for want of it and
8
8
  * so told every user of the preview build that something was wrong. */
9
- export type AlertTone = "danger" | "warning" | "info" | "neutral";
9
+ export type AlertTone = "danger" | "warning" | "info" | "success" | "neutral";
10
+
11
+ /** `sm` (0.10.0): 12px type and a 14px glyph — the hint line under a field or a total
12
+ * that keksdose spells `text-xs text-amber-700 dark:text-amber-400` by hand
13
+ * (accounts-page's missing-rate note, import-map-step, guest-key-control's two
14
+ * key states, goal-form). At body size those read as a second heading. */
15
+ export type AlertSize = "sm" | "md";
10
16
 
11
17
  /** Border + surface per tone, WITHOUT a radius or padding, so a caller that owns
12
18
  * its own box (a Card, say) can take the tone alone. Single source for both
@@ -25,9 +31,26 @@ const TONE_FRAME: Record<AlertTone, string> = {
25
31
  danger: "border-2 border-[var(--danger-border)] bg-[var(--danger-bg)]",
26
32
  warning: "border-2 border-[var(--warning-border)] bg-[var(--warning-bg)]",
27
33
  info: "border-2 border-[var(--info-border)] bg-[var(--info-bg)]",
34
+ success: "border-2 border-[var(--success-border)] bg-[var(--success-bg)]",
28
35
  neutral: "border border-[var(--border)]",
29
36
  };
30
37
 
38
+ /** `elevated`: the same frame on an OPAQUE surface. The dark tone washes are
39
+ * translucent (a 20–25 % tint), which is right on a page and wrong on anything that
40
+ * floats over one — keksdose's server-wake notice (#209) let the page's own text
41
+ * show through the one message whose job is to be read when nothing else makes
42
+ * sense. So the surface becomes `--bg-surface` and the tone's wash is layered on it
43
+ * as a background IMAGE (a flat gradient), which keeps the exact tint in both themes
44
+ * without a second, opaque copy of every `-bg` token. */
45
+ const TONE_ELEVATED: Record<AlertTone, string> = {
46
+ danger: "bg-[image:linear-gradient(var(--danger-bg),var(--danger-bg))]",
47
+ warning: "bg-[image:linear-gradient(var(--warning-bg),var(--warning-bg))]",
48
+ info: "bg-[image:linear-gradient(var(--info-bg),var(--info-bg))]",
49
+ success: "bg-[image:linear-gradient(var(--success-bg),var(--success-bg))]",
50
+ neutral: "",
51
+ };
52
+ const ELEVATED = "bg-[var(--bg-surface)] shadow-lg";
53
+
31
54
  /** The tone's border + surface on their own — for a caller that already has a box
32
55
  * with its own radius and padding (e.g. a Card). Remember to shave 1px off that
33
56
  * padding for the colored tones, whose border is 2px wide. */
@@ -38,15 +61,34 @@ export function toneFrameClass(tone: AlertTone): string {
38
61
  /** Single source for the warning-callout frame (feedback #277): the tone's border
39
62
  * and surface plus this component's own radius and padding, the latter
40
63
  * compensating the 2px colored border so toggling tones never shifts layout. */
41
- export function alertFrameClass(tone: AlertTone): string {
42
- const box = tone === "neutral" ? "rounded-md p-3" : "rounded-md p-[11px]";
64
+ export function alertFrameClass(tone: AlertTone, size: AlertSize = "md"): string {
65
+ const box =
66
+ size === "sm"
67
+ ? tone === "neutral"
68
+ ? "rounded-md px-2.5 py-1.5"
69
+ : "rounded-md px-[9px] py-[5px]"
70
+ : tone === "neutral"
71
+ ? "rounded-md p-3"
72
+ : "rounded-md p-[11px]";
43
73
  return `${box} ${TONE_FRAME[tone]}`;
44
74
  }
45
75
 
76
+ /** The `strip` frame: the tone's surface edge to edge, no radius, and only the BOTTOM
77
+ * border, 1px — a strip is a band across the top of a page, and its one visible edge
78
+ * is the line it draws under itself. kastlan's trial, past-due and tour banners. */
79
+ function stripFrameClass(tone: AlertTone, size: AlertSize): string {
80
+ return cn(
81
+ TONE_FRAME[tone],
82
+ "rounded-none border-0 border-b",
83
+ size === "sm" ? "px-4 py-1.5" : "px-4 py-2",
84
+ );
85
+ }
86
+
46
87
  const TONE_TEXT: Record<AlertTone, string> = {
47
88
  danger: "text-[var(--danger)]",
48
89
  warning: "text-[var(--warning)]",
49
90
  info: "text-[var(--info)]",
91
+ success: "text-[var(--success)]",
50
92
  neutral: "text-[var(--text-secondary)]",
51
93
  };
52
94
 
@@ -54,6 +96,7 @@ const TONE_ICON: Record<AlertTone, string> = {
54
96
  danger: "text-[var(--danger)]",
55
97
  warning: "text-[var(--warning)]",
56
98
  info: "text-[var(--info)]",
99
+ success: "text-[var(--success)]",
57
100
  neutral: "text-[var(--text-muted)]",
58
101
  };
59
102
 
@@ -66,6 +109,7 @@ const TONE_GLYPH: Record<AlertTone, typeof AlertTriangle> = {
66
109
  danger: AlertTriangle,
67
110
  warning: AlertTriangle,
68
111
  info: Info,
112
+ success: CheckCircle2,
69
113
  neutral: Info,
70
114
  };
71
115
 
@@ -86,8 +130,30 @@ interface AlertBannerBaseProps extends Omit<ComponentPropsWithoutRef<"div">, "on
86
130
  * otherwise never hears. The box stays role-less as it always was: it is usually
87
131
  * page furniture present at load, and an alert that fires on every navigation is
88
132
  * noise. Either way a `role` you pass wins.
133
+ *
134
+ * `strip` (0.10.0): a band across the top of a page or a panel — edge to edge, no
135
+ * radius, only a bottom border, content centred on one line, and usually an
136
+ * {@link action}. kastlan's billing trial-banner and past-due-banner and its tours
137
+ * tour-banner each built this by hand in amber or red Tailwind classes, with a
138
+ * separate dark: spelling apiece. Role-less like the box: it is page furniture.
89
139
  */
90
- variant?: "box" | "inline";
140
+ variant?: "box" | "inline" | "strip";
141
+ /** See {@link AlertSize}. Default `md`. */
142
+ size?: AlertSize;
143
+ /**
144
+ * An opaque, raised surface (a shadow, and no translucency in dark mode) for a
145
+ * notice that floats over the page — see {@link TONE_ELEVATED}. `box` and `strip`
146
+ * only; an inline message has no surface to raise.
147
+ */
148
+ elevated?: boolean;
149
+ /**
150
+ * A trailing control — the "Update payment method" button on kastlan's trial and
151
+ * past-due strips, the "Exit" on its tour strip. Sits at the end of the row,
152
+ * vertically centred, and never shrinks. On a whole-row banner (`href`/`onClick`)
153
+ * it is rendered BESIDE the row's own link or button, as the × is, because
154
+ * interactive content may not nest.
155
+ */
156
+ action?: ReactNode;
91
157
  /** Replaces the tone's glyph — a `<Spinner label={null} />` for "Solving…", say.
92
158
  * `null` draws none. Always decorative; the text carries the message. */
93
159
  icon?: ReactNode;
@@ -133,6 +199,9 @@ export type AlertBannerProps = AlertBannerBaseProps &
133
199
  export function AlertBanner({
134
200
  tone = "danger",
135
201
  variant = "box",
202
+ size = "md",
203
+ elevated = false,
204
+ action,
136
205
  icon,
137
206
  onDismiss,
138
207
  dismissLabel,
@@ -145,22 +214,40 @@ export function AlertBanner({
145
214
  }: AlertBannerProps) {
146
215
  const common = useKitLabels("common", DEFAULT_COMMON_LABELS, { dismiss: dismissLabel });
147
216
  const inline = variant === "inline";
217
+ const strip = variant === "strip";
218
+ const sm = size === "sm";
148
219
  const interactive = href !== undefined || onClick !== undefined;
149
220
  const resolvedRole = role ?? (inline ? (tone === "danger" ? "alert" : "status") : undefined);
150
221
 
151
222
  const Glyph = TONE_GLYPH[tone];
223
+ // Onto the first line of a box's text: 2px at 14px/20px, 1px at 12px/16px.
224
+ const nudge = inline || strip ? undefined : sm ? "mt-px" : "mt-0.5";
152
225
  const glyph =
153
226
  icon === null ? null : icon !== undefined ? (
154
- <span aria-hidden className={cn("flex shrink-0 [&_svg]:size-4", !inline && "mt-0.5", TONE_ICON[tone])}>
227
+ <span
228
+ aria-hidden
229
+ className={cn("flex shrink-0", sm ? "[&_svg]:size-3.5" : "[&_svg]:size-4", nudge, TONE_ICON[tone])}
230
+ >
155
231
  {icon}
156
232
  </span>
157
233
  ) : (
158
- <Glyph aria-hidden className={cn("size-4 shrink-0", !inline && "mt-0.5", TONE_ICON[tone])} />
234
+ <Glyph aria-hidden className={cn(sm ? "size-3.5" : "size-4", "shrink-0", nudge, TONE_ICON[tone])} />
159
235
  );
160
236
 
161
- // The row layout, shared by every shape below.
162
- const row = inline ? "inline-flex items-center gap-1.5 text-sm" : "flex items-start gap-2 text-sm";
163
- const frame = inline ? "" : alertFrameClass(tone);
237
+ // The row layout, shared by every shape below. A strip centres, and WRAPS: on a
238
+ // phone a long message plus an action would otherwise squeeze the text into a narrow
239
+ // column, so the action drops under it instead. A box may wrap its text, so it
240
+ // top-aligns and nudges the glyph onto the first line.
241
+ const row = cn(
242
+ inline ? "inline-flex items-center" : strip ? "flex flex-wrap items-center gap-y-1" : "flex items-start",
243
+ sm ? "gap-1.5 text-xs" : inline ? "gap-1.5 text-sm" : "gap-2 text-sm",
244
+ );
245
+ const frame = inline
246
+ ? ""
247
+ : cn(
248
+ strip ? stripFrameClass(tone, size) : alertFrameClass(tone, size),
249
+ elevated && cn(ELEVATED, TONE_ELEVATED[tone]),
250
+ );
164
251
  const focusRing =
165
252
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--bg-surface)]";
166
253
 
@@ -171,7 +258,7 @@ export function AlertBanner({
171
258
  {interactive && (
172
259
  <ChevronRight
173
260
  aria-hidden
174
- className={cn("size-4 shrink-0 opacity-70 rtl:-scale-x-100", !inline && "mt-0.5")}
261
+ className={cn(sm ? "size-3.5" : "size-4", "shrink-0 opacity-70 rtl:-scale-x-100", nudge)}
175
262
  />
176
263
  )}
177
264
  </>
@@ -198,6 +285,14 @@ export function AlertBanner({
198
285
  </button>
199
286
  ) : null;
200
287
 
288
+ // `relative z-10` so it stays clickable over a whole-row banner's stretched target.
289
+ const trailing =
290
+ action !== undefined && action !== null ? (
291
+ <div className={cn("relative z-10 flex shrink-0 items-center gap-2", !strip && !inline && "self-center", strip && "ms-auto")}>
292
+ {action}
293
+ </div>
294
+ ) : null;
295
+
201
296
  if (!interactive) {
202
297
  return (
203
298
  <div
@@ -210,6 +305,7 @@ export function AlertBanner({
210
305
  className={cn(row, frame, TONE_TEXT[tone], className)}
211
306
  >
212
307
  {content}
308
+ {trailing}
213
309
  {dismiss}
214
310
  </div>
215
311
  );
@@ -218,12 +314,14 @@ export function AlertBanner({
218
314
  const hover = "cursor-pointer transition-[filter] hover:brightness-[0.97] dark:hover:brightness-110";
219
315
  // With a dismiss the frame is a wrapper and the row element is stretched over it;
220
316
  // without one the row element IS the frame.
221
- const split = dismiss !== null;
317
+ const split = dismiss !== null || trailing !== null;
222
318
  const actionClass = split
223
319
  ? cn(
224
- "flex min-w-0 flex-1 gap-2 text-start",
225
- inline ? "items-center" : "items-start",
226
- "outline-none after:absolute after:inset-0 after:rounded-md after:content-['']",
320
+ "flex min-w-0 flex-1 text-start",
321
+ sm ? "gap-1.5" : "gap-2",
322
+ inline || strip ? "items-center" : "items-start",
323
+ "outline-none after:absolute after:inset-0 after:content-['']",
324
+ strip ? "after:rounded-none" : "after:rounded-md",
227
325
  "focus-visible:after:ring-2 focus-visible:after:ring-[var(--brand)]",
228
326
  )
229
327
  : cn(row, !inline && "w-full", frame, TONE_TEXT[tone], hover, focusRing, className);
@@ -232,7 +330,7 @@ export function AlertBanner({
232
330
  // NOT carried over — a button or a link that is also a `status` is neither.
233
331
  const actionRest = split ? {} : rest;
234
332
 
235
- const action =
333
+ const rowAction =
236
334
  href !== undefined ? (
237
335
  <a
238
336
  {...(actionRest as ComponentPropsWithoutRef<"a">)}
@@ -252,14 +350,15 @@ export function AlertBanner({
252
350
  </button>
253
351
  );
254
352
 
255
- if (!split) return action;
353
+ if (!split) return rowAction;
256
354
  return (
257
355
  <div
258
356
  {...rest}
259
357
  role={resolvedRole}
260
358
  className={cn("relative", row, frame, TONE_TEXT[tone], hover, className)}
261
359
  >
262
- {action}
360
+ {rowAction}
361
+ {trailing}
263
362
  {dismiss}
264
363
  </div>
265
364
  );
@@ -0,0 +1,168 @@
1
+ import { Fragment, useEffect, useRef, useState } from "react";
2
+ import type { ComponentPropsWithoutRef, ReactElement, ReactNode } from "react";
3
+ import { ChevronRight, MoreHorizontal } from "lucide-react";
4
+ import { cn } from "../lib/cn";
5
+ import { useKitLabels } from "../i18n/kit-labels";
6
+
7
+ export interface BreadcrumbsLabels {
8
+ /** The `nav` landmark's name — what a screen reader lists it as. */
9
+ label: string;
10
+ /** The "…" button that reveals the levels collapsed away on a phone. */
11
+ showAll: string;
12
+ }
13
+
14
+ export const DEFAULT_BREADCRUMBS_LABELS: BreadcrumbsLabels = {
15
+ label: "Breadcrumb",
16
+ showAll: "Show full path",
17
+ };
18
+
19
+ export interface BreadcrumbItem {
20
+ label: ReactNode;
21
+ /** Where the crumb leads. A crumb without one is text (a level with no page of its
22
+ * own). The LAST crumb is the current page and is text whether or not it has one. */
23
+ href?: string;
24
+ /** A stable React key, when `label` is not a string. */
25
+ key?: string;
26
+ }
27
+
28
+ /** What {@link BreadcrumbsProps.renderLink} is handed. Spread it onto your router's
29
+ * link — `({ href, ...p }) => <Link to={href} {...p} />`. */
30
+ export interface BreadcrumbLinkProps {
31
+ href: string;
32
+ className: string;
33
+ children: ReactNode;
34
+ }
35
+
36
+ export interface BreadcrumbsProps extends Omit<ComponentPropsWithoutRef<"nav">, "children"> {
37
+ items: BreadcrumbItem[];
38
+ /** Your router's link. Default `<a>`. The API `Chip`, `StatTile` and `ListItem` share. */
39
+ renderLink?: (props: BreadcrumbLinkProps) => ReactElement;
40
+ /**
41
+ * The mark between crumbs. Default a chevron, mirrored in RTL — a chevron pointing
42
+ * right in a right-to-left trail points back toward where you came from. Supply your
43
+ * own and it is drawn as given (a "/" needs no mirroring).
44
+ */
45
+ separator?: ReactNode;
46
+ /**
47
+ * Collapse the middle on phones (below the `md` breakpoint) into a "…" button, keeping
48
+ * the first crumb and the last {@link keepEnd}. Default `true`. kastlan's trail
49
+ * scrolled sideways on a phone instead, which hides the current page — the one crumb
50
+ * that must never be off-screen.
51
+ */
52
+ collapse?: boolean;
53
+ /** How many crumbs at the end stay visible when collapsed — the current page and its
54
+ * parent by default (2), because "up one level" is what a phone user reaches for. */
55
+ keepEnd?: number;
56
+ /** Overrides the {@link UiKitProvider}'s `breadcrumbs` labels. */
57
+ labels?: Partial<BreadcrumbsLabels>;
58
+ }
59
+
60
+ /**
61
+ * The trail from the app's root to this page.
62
+ *
63
+ * `nav` + `ol` + `aria-current="page"` on the last crumb: the WAI breadcrumb pattern,
64
+ * which kastlan's (shared/components/layout/breadcrumbs.tsx) nearly was — a `nav` of
65
+ * `span`s, so a screen reader heard no list, no count, and nothing marking where you
66
+ * are. The collapse is CSS (`hidden md:flex`), so it costs no media-query listener and
67
+ * the server's first paint is already right.
68
+ */
69
+ export function Breadcrumbs({
70
+ items,
71
+ renderLink,
72
+ separator,
73
+ collapse = true,
74
+ keepEnd = 2,
75
+ labels: labelsProp,
76
+ className,
77
+ "aria-label": ariaLabel,
78
+ ...rest
79
+ }: BreadcrumbsProps) {
80
+ const labels = useKitLabels("breadcrumbs", DEFAULT_BREADCRUMBS_LABELS, labelsProp);
81
+ const [expanded, setExpanded] = useState(false);
82
+ // The "…" button vanishes when pressed; focus goes to the first crumb it revealed,
83
+ // not back to the top of the document.
84
+ const revealedRef = useRef<HTMLLIElement>(null);
85
+ const focusRevealed = useRef(false);
86
+ useEffect(() => {
87
+ if (!expanded || !focusRevealed.current) return;
88
+ focusRevealed.current = false;
89
+ const li = revealedRef.current;
90
+ (li?.querySelector<HTMLElement>("a[href]") ?? li)?.focus();
91
+ }, [expanded]);
92
+ if (items.length === 0) return null;
93
+
94
+ const end = Math.max(1, keepEnd);
95
+ // Crumbs [1, firstKept) are the collapsible middle. Collapsing a single crumb into a
96
+ // "…" saves nothing, so it takes two.
97
+ const firstKept = Math.max(1, items.length - end);
98
+ const collapsible = collapse && !expanded && firstKept - 1 >= 2;
99
+ const isHidden = (i: number) => collapsible && i >= 1 && i < firstKept;
100
+
101
+ const sep = (
102
+ <span aria-hidden className="flex shrink-0 items-center text-[var(--text-placeholder)]">
103
+ {separator ?? <ChevronRight className="size-3.5 rtl:-scale-x-100" />}
104
+ </span>
105
+ );
106
+ const linkClass =
107
+ "block max-w-[14rem] truncate rounded-sm hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]";
108
+
109
+ return (
110
+ <nav {...rest} aria-label={ariaLabel ?? labels.label} className={cn("min-w-0 text-sm", className)}>
111
+ <ol className="m-0 flex min-w-0 list-none flex-wrap items-center gap-x-1.5 gap-y-1 p-0 text-[var(--text-muted)]">
112
+ {items.map((item, i) => {
113
+ const last = i === items.length - 1;
114
+ const key = item.key ?? (typeof item.label === "string" ? `${i}-${item.label}` : String(i));
115
+ let content: ReactNode;
116
+ if (last) {
117
+ content = (
118
+ <span aria-current="page" className="block max-w-[16rem] truncate font-medium text-[var(--text-primary)]">
119
+ {item.label}
120
+ </span>
121
+ );
122
+ } else if (item.href !== undefined) {
123
+ const props: BreadcrumbLinkProps = { href: item.href, className: linkClass, children: item.label };
124
+ content = renderLink ? (
125
+ renderLink(props)
126
+ ) : (
127
+ <a href={props.href} className={props.className}>
128
+ {props.children}
129
+ </a>
130
+ );
131
+ } else {
132
+ content = <span className="block max-w-[14rem] truncate">{item.label}</span>;
133
+ }
134
+ return (
135
+ <Fragment key={key}>
136
+ {collapsible && i === 1 && (
137
+ <li className="flex items-center gap-1.5 md:hidden">
138
+ {sep}
139
+ <button
140
+ type="button"
141
+ onClick={() => {
142
+ focusRevealed.current = true;
143
+ setExpanded(true);
144
+ }}
145
+ aria-label={labels.showAll}
146
+ aria-expanded={false}
147
+ className="flex items-center rounded-sm px-0.5 hover:text-[var(--text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--brand)]"
148
+ >
149
+ <MoreHorizontal className="size-4" aria-hidden />
150
+ </button>
151
+ </li>
152
+ )}
153
+ <li
154
+ ref={i === 1 ? revealedRef : undefined}
155
+ // Focusable only as the landing place for a revealed crumb with no link.
156
+ tabIndex={i === 1 && expanded && item.href === undefined ? -1 : undefined}
157
+ className={cn("flex min-w-0 items-center gap-1.5 outline-none", isHidden(i) && "hidden md:flex")}
158
+ >
159
+ {i > 0 && sep}
160
+ {content}
161
+ </li>
162
+ </Fragment>
163
+ );
164
+ })}
165
+ </ol>
166
+ </nav>
167
+ );
168
+ }