@eifi1/ui-kit 0.9.0 → 0.11.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 (243) hide show
  1. package/README.md +37 -23
  2. package/dist/components/alert-banner.d.ts +57 -5
  3. package/dist/components/alert-banner.js +63 -17
  4. package/dist/components/alert-banner.js.map +1 -1
  5. package/dist/components/amount-input.d.ts +6 -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 +112 -0
  10. package/dist/components/bulk-action-bar.js +196 -0
  11. package/dist/components/bulk-action-bar.js.map +1 -0
  12. package/dist/components/button-group.d.ts +58 -3
  13. package/dist/components/button-group.js +56 -5
  14. package/dist/components/button-group.js.map +1 -1
  15. package/dist/components/calculator.d.ts +6 -0
  16. package/dist/components/calendar-heatmap.d.ts +124 -0
  17. package/dist/components/calendar-heatmap.js +295 -0
  18. package/dist/components/calendar-heatmap.js.map +1 -0
  19. package/dist/components/chip.d.ts +31 -5
  20. package/dist/components/chip.js +85 -5
  21. package/dist/components/chip.js.map +1 -1
  22. package/dist/components/choice-card.d.ts +34 -2
  23. package/dist/components/choice-card.js +49 -0
  24. package/dist/components/choice-card.js.map +1 -1
  25. package/dist/components/copy-button.d.ts +14 -4
  26. package/dist/components/copy-button.js +17 -4
  27. package/dist/components/copy-button.js.map +1 -1
  28. package/dist/components/data-table.js +2 -0
  29. package/dist/components/data-table.js.map +1 -1
  30. package/dist/components/date-picker.d.ts +22 -2
  31. package/dist/components/date-picker.js +11 -3
  32. package/dist/components/date-picker.js.map +1 -1
  33. package/dist/components/description-list.d.ts +43 -6
  34. package/dist/components/description-list.js +91 -11
  35. package/dist/components/description-list.js.map +1 -1
  36. package/dist/components/dialog-frame.d.ts +7 -0
  37. package/dist/components/dialog-frame.js.map +1 -1
  38. package/dist/components/disclosure.d.ts +57 -2
  39. package/dist/components/disclosure.js +24 -12
  40. package/dist/components/disclosure.js.map +1 -1
  41. package/dist/components/field.d.ts +43 -0
  42. package/dist/components/field.js +52 -0
  43. package/dist/components/field.js.map +1 -0
  44. package/dist/components/file-button.d.ts +1 -0
  45. package/dist/components/file-dropzone.d.ts +4 -4
  46. package/dist/components/file-dropzone.js +2 -1
  47. package/dist/components/file-dropzone.js.map +1 -1
  48. package/dist/components/floating-panel.d.ts +147 -4
  49. package/dist/components/floating-panel.js +188 -28
  50. package/dist/components/floating-panel.js.map +1 -1
  51. package/dist/components/full-bleed-dialog.d.ts +23 -4
  52. package/dist/components/full-bleed-dialog.js +11 -2
  53. package/dist/components/full-bleed-dialog.js.map +1 -1
  54. package/dist/components/list.d.ts +187 -0
  55. package/dist/components/list.js +221 -0
  56. package/dist/components/list.js.map +1 -0
  57. package/dist/components/menu-item.d.ts +109 -0
  58. package/dist/components/menu-item.js +88 -0
  59. package/dist/components/menu-item.js.map +1 -0
  60. package/dist/components/mini-calendar.d.ts +70 -5
  61. package/dist/components/mini-calendar.js +166 -62
  62. package/dist/components/mini-calendar.js.map +1 -1
  63. package/dist/components/modal.d.ts +23 -1
  64. package/dist/components/modal.js +36 -10
  65. package/dist/components/modal.js.map +1 -1
  66. package/dist/components/nav-pills.d.ts +66 -0
  67. package/dist/components/nav-pills.js +65 -0
  68. package/dist/components/nav-pills.js.map +1 -0
  69. package/dist/components/number-field.d.ts +6 -0
  70. package/dist/components/number-input.d.ts +6 -0
  71. package/dist/components/numpad-sheet.d.ts +6 -0
  72. package/dist/components/page-contents.js +1 -2
  73. package/dist/components/page-contents.js.map +1 -1
  74. package/dist/components/page-header.d.ts +37 -0
  75. package/dist/components/page-header.js +36 -0
  76. package/dist/components/page-header.js.map +1 -0
  77. package/dist/components/progress-bar.d.ts +31 -2
  78. package/dist/components/progress-bar.js +73 -7
  79. package/dist/components/progress-bar.js.map +1 -1
  80. package/dist/components/series-chart-labels.d.ts +3 -0
  81. package/dist/components/series-chart-labels.js +2 -1
  82. package/dist/components/series-chart-labels.js.map +1 -1
  83. package/dist/components/series-chart.d.ts +32 -0
  84. package/dist/components/series-chart.js +141 -4
  85. package/dist/components/series-chart.js.map +1 -1
  86. package/dist/components/settings-fields.d.ts +1 -0
  87. package/dist/components/status-dot.d.ts +53 -0
  88. package/dist/components/status-dot.js +57 -0
  89. package/dist/components/status-dot.js.map +1 -0
  90. package/dist/components/table.d.ts +78 -13
  91. package/dist/components/table.js +84 -11
  92. package/dist/components/table.js.map +1 -1
  93. package/dist/components/text.d.ts +70 -0
  94. package/dist/components/text.js +24 -0
  95. package/dist/components/text.js.map +1 -0
  96. package/dist/components/time-input.d.ts +1 -0
  97. package/dist/components/toast.d.ts +167 -0
  98. package/dist/components/toast.js +226 -0
  99. package/dist/components/toast.js.map +1 -0
  100. package/dist/components/toggle-group.d.ts +44 -1
  101. package/dist/components/toggle-group.js +73 -4
  102. package/dist/components/toggle-group.js.map +1 -1
  103. package/dist/components/tooltip.d.ts +46 -15
  104. package/dist/components/tooltip.js +87 -47
  105. package/dist/components/tooltip.js.map +1 -1
  106. package/dist/components/ui.d.ts +158 -7
  107. package/dist/components/ui.js +191 -10
  108. package/dist/components/ui.js.map +1 -1
  109. package/dist/components/user-avatar.d.ts +25 -3
  110. package/dist/components/user-avatar.js +32 -3
  111. package/dist/components/user-avatar.js.map +1 -1
  112. package/dist/hooks/use-close-transition.d.ts +7 -1
  113. package/dist/hooks/use-close-transition.js +5 -2
  114. package/dist/hooks/use-close-transition.js.map +1 -1
  115. package/dist/hooks/use-copy-to-clipboard.js +1 -1
  116. package/dist/hooks/use-copy-to-clipboard.js.map +1 -1
  117. package/dist/hooks/use-file-drop.d.ts +1 -0
  118. package/dist/i18n/defaults.d.ts +6 -0
  119. package/dist/i18n/defaults.js +11 -1
  120. package/dist/i18n/defaults.js.map +1 -1
  121. package/dist/i18n/kit-labels.d.ts +11 -0
  122. package/dist/i18n/kit-labels.js.map +1 -1
  123. package/dist/i18n/locales/de-CH-informal.d.ts +6 -0
  124. package/dist/i18n/locales/de-CH.d.ts +6 -0
  125. package/dist/i18n/locales/de-informal.d.ts +6 -0
  126. package/dist/i18n/locales/de.d.ts +6 -0
  127. package/dist/i18n/locales/de.js +30 -2
  128. package/dist/i18n/locales/de.js.map +1 -1
  129. package/dist/i18n/locales/es.d.ts +6 -0
  130. package/dist/i18n/locales/es.js +30 -2
  131. package/dist/i18n/locales/es.js.map +1 -1
  132. package/dist/i18n/locales/fr.d.ts +6 -0
  133. package/dist/i18n/locales/fr.js +30 -2
  134. package/dist/i18n/locales/fr.js.map +1 -1
  135. package/dist/i18n/locales/hu.d.ts +6 -0
  136. package/dist/i18n/locales/hu.js +30 -2
  137. package/dist/i18n/locales/hu.js.map +1 -1
  138. package/dist/i18n/locales/it.d.ts +6 -0
  139. package/dist/i18n/locales/it.js +30 -2
  140. package/dist/i18n/locales/it.js.map +1 -1
  141. package/dist/i18n/locales/zh.d.ts +6 -0
  142. package/dist/i18n/locales/zh.js +30 -2
  143. package/dist/i18n/locales/zh.js.map +1 -1
  144. package/dist/index.d.ts +27 -15
  145. package/dist/index.js +15 -0
  146. package/dist/index.js.map +1 -1
  147. package/dist/lib/clipping.d.ts +25 -0
  148. package/dist/lib/clipping.js +17 -0
  149. package/dist/lib/clipping.js.map +1 -0
  150. package/dist/lib/dates.d.ts +17 -1
  151. package/dist/lib/dates.js +19 -0
  152. package/dist/lib/dates.js.map +1 -1
  153. package/dist/rhf/form.d.ts +1 -0
  154. package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
  155. package/dist/rhf/use-rhf-wizard-step.js +38 -0
  156. package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
  157. package/dist/rhf.d.ts +2 -0
  158. package/dist/rhf.js +1 -0
  159. package/dist/rhf.js.map +1 -1
  160. package/dist/search/command-palette.d.ts +19 -2
  161. package/dist/search/command-palette.js +16 -5
  162. package/dist/search/command-palette.js.map +1 -1
  163. package/dist/search/global-search.d.ts +26 -1
  164. package/dist/search/global-search.js +29 -13
  165. package/dist/search/global-search.js.map +1 -1
  166. package/dist/search.d.ts +1 -1
  167. package/dist/shell/topbar-action-menu.d.ts +73 -3
  168. package/dist/shell/topbar-action-menu.js +100 -27
  169. package/dist/shell/topbar-action-menu.js.map +1 -1
  170. package/dist/shell.d.ts +2 -1
  171. package/dist/wizard/stepper-nav.d.ts +1 -0
  172. package/dist/wizard/stepper-nav.js +1 -1
  173. package/dist/wizard/stepper-nav.js.map +1 -1
  174. package/dist/wizard/types.d.ts +2 -2
  175. package/dist/wizard/types.js.map +1 -1
  176. package/dist/wizard/use-wizard.js +1 -1
  177. package/dist/wizard/use-wizard.js.map +1 -1
  178. package/dist/wizard/wizard-context.d.ts +7 -1
  179. package/dist/wizard/wizard-context.js +4 -0
  180. package/dist/wizard/wizard-context.js.map +1 -1
  181. package/dist/wizard/wizard-summary.js +3 -3
  182. package/dist/wizard/wizard-summary.js.map +1 -1
  183. package/dist/wizard.d.ts +2 -1
  184. package/package.json +16 -12
  185. package/src/components/alert-banner.tsx +149 -21
  186. package/src/components/breadcrumbs.tsx +168 -0
  187. package/src/components/bulk-action-bar.tsx +362 -0
  188. package/src/components/button-group.tsx +124 -4
  189. package/src/components/calendar-heatmap.tsx +504 -0
  190. package/src/components/chip.tsx +128 -7
  191. package/src/components/choice-card.tsx +97 -1
  192. package/src/components/copy-button.tsx +29 -7
  193. package/src/components/data-table.tsx +7 -0
  194. package/src/components/date-picker.tsx +49 -1
  195. package/src/components/description-list.tsx +168 -15
  196. package/src/components/dialog-frame.tsx +7 -0
  197. package/src/components/disclosure.tsx +93 -21
  198. package/src/components/field.tsx +137 -0
  199. package/src/components/file-dropzone.tsx +9 -10
  200. package/src/components/floating-panel.tsx +366 -15
  201. package/src/components/full-bleed-dialog.tsx +42 -5
  202. package/src/components/list.tsx +443 -0
  203. package/src/components/menu-item.tsx +235 -0
  204. package/src/components/mini-calendar.tsx +245 -54
  205. package/src/components/modal.tsx +80 -17
  206. package/src/components/nav-pills.tsx +145 -0
  207. package/src/components/page-contents.tsx +4 -4
  208. package/src/components/page-header.tsx +68 -0
  209. package/src/components/progress-bar.tsx +129 -11
  210. package/src/components/series-chart-labels.ts +4 -0
  211. package/src/components/series-chart.tsx +274 -3
  212. package/src/components/status-dot.tsx +107 -0
  213. package/src/components/table.tsx +176 -17
  214. package/src/components/text.tsx +97 -0
  215. package/src/components/toast.tsx +441 -0
  216. package/src/components/toggle-group.tsx +128 -4
  217. package/src/components/tooltip.tsx +200 -100
  218. package/src/components/ui.tsx +381 -14
  219. package/src/components/user-avatar.tsx +57 -3
  220. package/src/hooks/use-close-transition.ts +14 -5
  221. package/src/hooks/use-copy-to-clipboard.ts +1 -1
  222. package/src/i18n/defaults.ts +10 -0
  223. package/src/i18n/kit-labels.tsx +10 -0
  224. package/src/i18n/locales/de.ts +29 -0
  225. package/src/i18n/locales/es.ts +29 -0
  226. package/src/i18n/locales/fr.ts +29 -0
  227. package/src/i18n/locales/hu.ts +29 -0
  228. package/src/i18n/locales/it.ts +29 -0
  229. package/src/i18n/locales/zh.ts +29 -0
  230. package/src/index.ts +31 -0
  231. package/src/lib/clipping.ts +34 -0
  232. package/src/lib/dates.ts +37 -0
  233. package/src/rhf/use-rhf-wizard-step.ts +113 -0
  234. package/src/rhf.ts +2 -0
  235. package/src/search/command-palette.tsx +42 -5
  236. package/src/search/global-search.tsx +59 -18
  237. package/src/shell/topbar-action-menu.tsx +239 -49
  238. package/src/wizard/stepper-nav.tsx +2 -1
  239. package/src/wizard/types.ts +2 -2
  240. package/src/wizard/use-wizard.ts +3 -3
  241. package/src/wizard/wizard-context.tsx +9 -0
  242. package/src/wizard/wizard-summary.tsx +14 -10
  243. 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,55 @@ 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.
139
+ */
140
+ variant?: "box" | "inline" | "strip";
141
+ /** See {@link AlertSize}. Default `md`. */
142
+ size?: AlertSize;
143
+ /**
144
+ * `inline` only (0.11.0): lay the message out as a BLOCK — a full-width `flex` row,
145
+ * the glyph on the text's FIRST line when it wraps — instead of the `inline-flex`,
146
+ * centred line it is by default. keksdose writes `className="flex"` on nearly every
147
+ * inline banner it has (accounts-page:564, holdings-panel:631, import-map-step:66/314,
148
+ * guest-key-control:84) to get a line of its own under a total or a field, and a
149
+ * two-line hint there then centres its glyph between the lines.
150
+ *
151
+ * An option rather than the new default, because the inline-flex is load-bearing for
152
+ * the callers the variant was made for: lenkbank's corner-motion toolbar
153
+ * (corner-motion.tsx:178) sets it as a `shrink-0` item beside the controls, kastlan's
154
+ * import page and keksdose's rules page place it in a run of content — a block would
155
+ * take the whole row in the second kind, and top-align the first against a taller
156
+ * control. Ignored by `box` and `strip`, which are blocks already.
89
157
  */
90
- variant?: "box" | "inline";
158
+ block?: boolean;
159
+ /**
160
+ * `false` opts an inline banner out of its live region (no `role="alert"` /
161
+ * `role="status"`), for a message that is static page content rather than the answer
162
+ * to something the user just did: keksdose's CAMT review step (camt-review-step:214)
163
+ * renders "unresolved rows block the import" as part of the step, and as
164
+ * `role="alert"` a screen reader interrupted with it on every mount. A `role` you pass
165
+ * still wins. Default `true`; the box and the strip are role-less either way.
166
+ */
167
+ live?: boolean;
168
+ /**
169
+ * An opaque, raised surface (a shadow, and no translucency in dark mode) for a
170
+ * notice that floats over the page — see {@link TONE_ELEVATED}. `box` and `strip`
171
+ * only; an inline message has no surface to raise.
172
+ */
173
+ elevated?: boolean;
174
+ /**
175
+ * A trailing control — the "Update payment method" button on kastlan's trial and
176
+ * past-due strips, the "Exit" on its tour strip. Sits at the end of the row,
177
+ * vertically centred, and never shrinks. On a whole-row banner (`href`/`onClick`)
178
+ * it is rendered BESIDE the row's own link or button, as the × is, because
179
+ * interactive content may not nest.
180
+ */
181
+ action?: ReactNode;
91
182
  /** Replaces the tone's glyph — a `<Spinner label={null} />` for "Solving…", say.
92
183
  * `null` draws none. Always decorative; the text carries the message. */
93
184
  icon?: ReactNode;
@@ -133,6 +224,11 @@ export type AlertBannerProps = AlertBannerBaseProps &
133
224
  export function AlertBanner({
134
225
  tone = "danger",
135
226
  variant = "box",
227
+ size = "md",
228
+ block = false,
229
+ live = true,
230
+ elevated = false,
231
+ action,
136
232
  icon,
137
233
  onDismiss,
138
234
  dismissLabel,
@@ -145,33 +241,53 @@ export function AlertBanner({
145
241
  }: AlertBannerProps) {
146
242
  const common = useKitLabels("common", DEFAULT_COMMON_LABELS, { dismiss: dismissLabel });
147
243
  const inline = variant === "inline";
244
+ const strip = variant === "strip";
245
+ const sm = size === "sm";
148
246
  const interactive = href !== undefined || onClick !== undefined;
149
- const resolvedRole = role ?? (inline ? (tone === "danger" ? "alert" : "status") : undefined);
247
+ // A block-laid inline banner behaves like a box for layout: a row that may wrap.
248
+ const inlineRow = inline && !block;
249
+ const resolvedRole = role ?? (inline && live ? (tone === "danger" ? "alert" : "status") : undefined);
150
250
 
151
251
  const Glyph = TONE_GLYPH[tone];
252
+ // Onto the first line of a box's text: 2px at 14px/20px, 1px at 12px/16px.
253
+ const nudge = inlineRow || strip ? undefined : sm ? "mt-px" : "mt-0.5";
152
254
  const glyph =
153
255
  icon === null ? null : icon !== undefined ? (
154
- <span aria-hidden className={cn("flex shrink-0 [&_svg]:size-4", !inline && "mt-0.5", TONE_ICON[tone])}>
256
+ <span
257
+ aria-hidden
258
+ className={cn("flex shrink-0", sm ? "[&_svg]:size-3.5" : "[&_svg]:size-4", nudge, TONE_ICON[tone])}
259
+ >
155
260
  {icon}
156
261
  </span>
157
262
  ) : (
158
- <Glyph aria-hidden className={cn("size-4 shrink-0", !inline && "mt-0.5", TONE_ICON[tone])} />
263
+ <Glyph aria-hidden className={cn(sm ? "size-3.5" : "size-4", "shrink-0", nudge, TONE_ICON[tone])} />
159
264
  );
160
265
 
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);
266
+ // The row layout, shared by every shape below. A strip centres, and WRAPS: on a
267
+ // phone a long message plus an action would otherwise squeeze the text into a narrow
268
+ // column, so the action drops under it instead. A box may wrap its text, so it
269
+ // top-aligns and nudges the glyph onto the first line.
270
+ const row = cn(
271
+ inlineRow ? "inline-flex items-center" : strip ? "flex flex-wrap items-center gap-y-1" : "flex items-start",
272
+ sm ? "gap-1.5 text-xs" : inline ? "gap-1.5 text-sm" : "gap-2 text-sm",
273
+ );
274
+ const frame = inline
275
+ ? ""
276
+ : cn(
277
+ strip ? stripFrameClass(tone, size) : alertFrameClass(tone, size),
278
+ elevated && cn(ELEVATED, TONE_ELEVATED[tone]),
279
+ );
164
280
  const focusRing =
165
281
  "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
282
 
167
283
  const content = (
168
284
  <>
169
285
  {glyph}
170
- <span className={cn(!inline && "flex-1", "min-w-0 text-start")}>{children}</span>
286
+ <span className={cn(!inlineRow && "flex-1", "min-w-0 text-start")}>{children}</span>
171
287
  {interactive && (
172
288
  <ChevronRight
173
289
  aria-hidden
174
- className={cn("size-4 shrink-0 opacity-70 rtl:-scale-x-100", !inline && "mt-0.5")}
290
+ className={cn(sm ? "size-3.5" : "size-4", "shrink-0 opacity-70 rtl:-scale-x-100", nudge)}
175
291
  />
176
292
  )}
177
293
  </>
@@ -198,6 +314,14 @@ export function AlertBanner({
198
314
  </button>
199
315
  ) : null;
200
316
 
317
+ // `relative z-10` so it stays clickable over a whole-row banner's stretched target.
318
+ const trailing =
319
+ action !== undefined && action !== null ? (
320
+ <div className={cn("relative z-10 flex shrink-0 items-center gap-2", !strip && !inlineRow && "self-center", strip && "ms-auto")}>
321
+ {action}
322
+ </div>
323
+ ) : null;
324
+
201
325
  if (!interactive) {
202
326
  return (
203
327
  <div
@@ -210,6 +334,7 @@ export function AlertBanner({
210
334
  className={cn(row, frame, TONE_TEXT[tone], className)}
211
335
  >
212
336
  {content}
337
+ {trailing}
213
338
  {dismiss}
214
339
  </div>
215
340
  );
@@ -218,21 +343,23 @@ export function AlertBanner({
218
343
  const hover = "cursor-pointer transition-[filter] hover:brightness-[0.97] dark:hover:brightness-110";
219
344
  // With a dismiss the frame is a wrapper and the row element is stretched over it;
220
345
  // without one the row element IS the frame.
221
- const split = dismiss !== null;
346
+ const split = dismiss !== null || trailing !== null;
222
347
  const actionClass = split
223
348
  ? 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-['']",
349
+ "flex min-w-0 flex-1 text-start",
350
+ sm ? "gap-1.5" : "gap-2",
351
+ inlineRow || strip ? "items-center" : "items-start",
352
+ "outline-none after:absolute after:inset-0 after:content-['']",
353
+ strip ? "after:rounded-none" : "after:rounded-md",
227
354
  "focus-visible:after:ring-2 focus-visible:after:ring-[var(--brand)]",
228
355
  )
229
- : cn(row, !inline && "w-full", frame, TONE_TEXT[tone], hover, focusRing, className);
356
+ : cn(row, !inlineRow && "w-full", frame, TONE_TEXT[tone], hover, focusRing, className);
230
357
  // The div's attributes are the row element's: an `id`, a test id or an
231
358
  // `aria-describedby` belongs on the thing that takes focus. The live-region role is
232
359
  // NOT carried over — a button or a link that is also a `status` is neither.
233
360
  const actionRest = split ? {} : rest;
234
361
 
235
- const action =
362
+ const rowAction =
236
363
  href !== undefined ? (
237
364
  <a
238
365
  {...(actionRest as ComponentPropsWithoutRef<"a">)}
@@ -252,14 +379,15 @@ export function AlertBanner({
252
379
  </button>
253
380
  );
254
381
 
255
- if (!split) return action;
382
+ if (!split) return rowAction;
256
383
  return (
257
384
  <div
258
385
  {...rest}
259
386
  role={resolvedRole}
260
387
  className={cn("relative", row, frame, TONE_TEXT[tone], hover, className)}
261
388
  >
262
- {action}
389
+ {rowAction}
390
+ {trailing}
263
391
  {dismiss}
264
392
  </div>
265
393
  );
@@ -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
+ }