@eifi1/ui-kit 0.10.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 (162) hide show
  1. package/README.md +20 -16
  2. package/dist/components/alert-banner.d.ts +26 -1
  3. package/dist/components/alert-banner.js +10 -7
  4. package/dist/components/alert-banner.js.map +1 -1
  5. package/dist/components/amount-input.d.ts +2 -0
  6. package/dist/components/bulk-action-bar.d.ts +51 -5
  7. package/dist/components/bulk-action-bar.js +88 -41
  8. package/dist/components/bulk-action-bar.js.map +1 -1
  9. package/dist/components/button-group.d.ts +58 -3
  10. package/dist/components/button-group.js +56 -5
  11. package/dist/components/button-group.js.map +1 -1
  12. package/dist/components/calculator.d.ts +2 -0
  13. package/dist/components/calendar-heatmap.d.ts +124 -0
  14. package/dist/components/calendar-heatmap.js +295 -0
  15. package/dist/components/calendar-heatmap.js.map +1 -0
  16. package/dist/components/choice-card.d.ts +34 -2
  17. package/dist/components/choice-card.js +49 -0
  18. package/dist/components/choice-card.js.map +1 -1
  19. package/dist/components/copy-button.d.ts +1 -0
  20. package/dist/components/data-table.js +2 -0
  21. package/dist/components/data-table.js.map +1 -1
  22. package/dist/components/field.d.ts +43 -0
  23. package/dist/components/field.js +52 -0
  24. package/dist/components/field.js.map +1 -0
  25. package/dist/components/file-button.d.ts +1 -0
  26. package/dist/components/file-dropzone.d.ts +1 -0
  27. package/dist/components/floating-panel.d.ts +147 -4
  28. package/dist/components/floating-panel.js +188 -28
  29. package/dist/components/floating-panel.js.map +1 -1
  30. package/dist/components/list.d.ts +14 -1
  31. package/dist/components/list.js +7 -1
  32. package/dist/components/list.js.map +1 -1
  33. package/dist/components/menu-item.d.ts +11 -1
  34. package/dist/components/menu-item.js +6 -1
  35. package/dist/components/menu-item.js.map +1 -1
  36. package/dist/components/mini-calendar.d.ts +70 -5
  37. package/dist/components/mini-calendar.js +166 -62
  38. package/dist/components/mini-calendar.js.map +1 -1
  39. package/dist/components/nav-pills.d.ts +66 -0
  40. package/dist/components/nav-pills.js +65 -0
  41. package/dist/components/nav-pills.js.map +1 -0
  42. package/dist/components/number-field.d.ts +2 -0
  43. package/dist/components/number-input.d.ts +2 -0
  44. package/dist/components/numpad-sheet.d.ts +2 -0
  45. package/dist/components/progress-bar.d.ts +31 -2
  46. package/dist/components/progress-bar.js +73 -7
  47. package/dist/components/progress-bar.js.map +1 -1
  48. package/dist/components/series-chart.d.ts +16 -0
  49. package/dist/components/series-chart.js +4 -1
  50. package/dist/components/series-chart.js.map +1 -1
  51. package/dist/components/settings-fields.d.ts +1 -0
  52. package/dist/components/status-dot.d.ts +6 -2
  53. package/dist/components/status-dot.js +6 -1
  54. package/dist/components/status-dot.js.map +1 -1
  55. package/dist/components/table.d.ts +40 -8
  56. package/dist/components/table.js +41 -7
  57. package/dist/components/table.js.map +1 -1
  58. package/dist/components/text.d.ts +8 -1
  59. package/dist/components/text.js +1 -0
  60. package/dist/components/text.js.map +1 -1
  61. package/dist/components/time-input.d.ts +1 -0
  62. package/dist/components/toggle-group.d.ts +15 -0
  63. package/dist/components/toggle-group.js +23 -3
  64. package/dist/components/toggle-group.js.map +1 -1
  65. package/dist/components/tooltip.d.ts +11 -3
  66. package/dist/components/tooltip.js +2 -0
  67. package/dist/components/tooltip.js.map +1 -1
  68. package/dist/components/ui.d.ts +55 -4
  69. package/dist/components/ui.js +84 -7
  70. package/dist/components/ui.js.map +1 -1
  71. package/dist/components/user-avatar.d.ts +25 -3
  72. package/dist/components/user-avatar.js +32 -3
  73. package/dist/components/user-avatar.js.map +1 -1
  74. package/dist/hooks/use-file-drop.d.ts +1 -0
  75. package/dist/i18n/defaults.d.ts +2 -0
  76. package/dist/i18n/defaults.js +2 -0
  77. package/dist/i18n/defaults.js.map +1 -1
  78. package/dist/i18n/kit-labels.d.ts +3 -0
  79. package/dist/i18n/kit-labels.js.map +1 -1
  80. package/dist/i18n/locales/de-CH-informal.d.ts +2 -0
  81. package/dist/i18n/locales/de-CH.d.ts +2 -0
  82. package/dist/i18n/locales/de-informal.d.ts +2 -0
  83. package/dist/i18n/locales/de.d.ts +2 -0
  84. package/dist/i18n/locales/de.js +9 -1
  85. package/dist/i18n/locales/de.js.map +1 -1
  86. package/dist/i18n/locales/es.d.ts +2 -0
  87. package/dist/i18n/locales/es.js +9 -1
  88. package/dist/i18n/locales/es.js.map +1 -1
  89. package/dist/i18n/locales/fr.d.ts +2 -0
  90. package/dist/i18n/locales/fr.js +9 -1
  91. package/dist/i18n/locales/fr.js.map +1 -1
  92. package/dist/i18n/locales/hu.d.ts +2 -0
  93. package/dist/i18n/locales/hu.js +9 -1
  94. package/dist/i18n/locales/hu.js.map +1 -1
  95. package/dist/i18n/locales/it.d.ts +2 -0
  96. package/dist/i18n/locales/it.js +9 -1
  97. package/dist/i18n/locales/it.js.map +1 -1
  98. package/dist/i18n/locales/zh.d.ts +2 -0
  99. package/dist/i18n/locales/zh.js +9 -1
  100. package/dist/i18n/locales/zh.js.map +1 -1
  101. package/dist/index.d.ts +14 -10
  102. package/dist/index.js +3 -0
  103. package/dist/index.js.map +1 -1
  104. package/dist/lib/clipping.d.ts +21 -5
  105. package/dist/lib/clipping.js +3 -0
  106. package/dist/lib/clipping.js.map +1 -1
  107. package/dist/lib/dates.d.ts +17 -1
  108. package/dist/lib/dates.js +19 -0
  109. package/dist/lib/dates.js.map +1 -1
  110. package/dist/rhf/form.d.ts +1 -0
  111. package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
  112. package/dist/rhf/use-rhf-wizard-step.js +38 -0
  113. package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
  114. package/dist/rhf.d.ts +2 -0
  115. package/dist/rhf.js +1 -0
  116. package/dist/rhf.js.map +1 -1
  117. package/dist/shell/topbar-action-menu.d.ts +73 -3
  118. package/dist/shell/topbar-action-menu.js +100 -27
  119. package/dist/shell/topbar-action-menu.js.map +1 -1
  120. package/dist/shell.d.ts +2 -1
  121. package/dist/wizard/stepper-nav.d.ts +1 -0
  122. package/dist/wizard/wizard-context.d.ts +7 -1
  123. package/dist/wizard/wizard-context.js +4 -0
  124. package/dist/wizard/wizard-context.js.map +1 -1
  125. package/dist/wizard.d.ts +2 -1
  126. package/package.json +1 -1
  127. package/src/components/alert-banner.tsx +36 -7
  128. package/src/components/bulk-action-bar.tsx +163 -57
  129. package/src/components/button-group.tsx +124 -4
  130. package/src/components/calendar-heatmap.tsx +504 -0
  131. package/src/components/choice-card.tsx +97 -1
  132. package/src/components/data-table.tsx +7 -0
  133. package/src/components/field.tsx +137 -0
  134. package/src/components/floating-panel.tsx +366 -15
  135. package/src/components/list.tsx +28 -2
  136. package/src/components/menu-item.tsx +22 -1
  137. package/src/components/mini-calendar.tsx +245 -54
  138. package/src/components/nav-pills.tsx +145 -0
  139. package/src/components/progress-bar.tsx +129 -11
  140. package/src/components/series-chart.tsx +21 -0
  141. package/src/components/status-dot.tsx +10 -2
  142. package/src/components/table.tsx +85 -11
  143. package/src/components/text.tsx +9 -1
  144. package/src/components/toggle-group.tsx +48 -3
  145. package/src/components/tooltip.tsx +17 -3
  146. package/src/components/ui.tsx +149 -11
  147. package/src/components/user-avatar.tsx +57 -3
  148. package/src/i18n/defaults.ts +2 -0
  149. package/src/i18n/kit-labels.tsx +2 -0
  150. package/src/i18n/locales/de.ts +9 -0
  151. package/src/i18n/locales/es.ts +9 -0
  152. package/src/i18n/locales/fr.ts +9 -0
  153. package/src/i18n/locales/hu.ts +9 -0
  154. package/src/i18n/locales/it.ts +9 -0
  155. package/src/i18n/locales/zh.ts +9 -0
  156. package/src/index.ts +5 -0
  157. package/src/lib/clipping.ts +22 -4
  158. package/src/lib/dates.ts +37 -0
  159. package/src/rhf/use-rhf-wizard-step.ts +113 -0
  160. package/src/rhf.ts +2 -0
  161. package/src/shell/topbar-action-menu.tsx +239 -49
  162. package/src/wizard/wizard-context.tsx +9 -0
@@ -140,6 +140,31 @@ interface AlertBannerBaseProps extends Omit<ComponentPropsWithoutRef<"div">, "on
140
140
  variant?: "box" | "inline" | "strip";
141
141
  /** See {@link AlertSize}. Default `md`. */
142
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.
157
+ */
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;
143
168
  /**
144
169
  * An opaque, raised surface (a shadow, and no translucency in dark mode) for a
145
170
  * notice that floats over the page — see {@link TONE_ELEVATED}. `box` and `strip`
@@ -200,6 +225,8 @@ export function AlertBanner({
200
225
  tone = "danger",
201
226
  variant = "box",
202
227
  size = "md",
228
+ block = false,
229
+ live = true,
203
230
  elevated = false,
204
231
  action,
205
232
  icon,
@@ -217,11 +244,13 @@ export function AlertBanner({
217
244
  const strip = variant === "strip";
218
245
  const sm = size === "sm";
219
246
  const interactive = href !== undefined || onClick !== undefined;
220
- 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);
221
250
 
222
251
  const Glyph = TONE_GLYPH[tone];
223
252
  // 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";
253
+ const nudge = inlineRow || strip ? undefined : sm ? "mt-px" : "mt-0.5";
225
254
  const glyph =
226
255
  icon === null ? null : icon !== undefined ? (
227
256
  <span
@@ -239,7 +268,7 @@ export function AlertBanner({
239
268
  // column, so the action drops under it instead. A box may wrap its text, so it
240
269
  // top-aligns and nudges the glyph onto the first line.
241
270
  const row = cn(
242
- inline ? "inline-flex items-center" : strip ? "flex flex-wrap items-center gap-y-1" : "flex items-start",
271
+ inlineRow ? "inline-flex items-center" : strip ? "flex flex-wrap items-center gap-y-1" : "flex items-start",
243
272
  sm ? "gap-1.5 text-xs" : inline ? "gap-1.5 text-sm" : "gap-2 text-sm",
244
273
  );
245
274
  const frame = inline
@@ -254,7 +283,7 @@ export function AlertBanner({
254
283
  const content = (
255
284
  <>
256
285
  {glyph}
257
- <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>
258
287
  {interactive && (
259
288
  <ChevronRight
260
289
  aria-hidden
@@ -288,7 +317,7 @@ export function AlertBanner({
288
317
  // `relative z-10` so it stays clickable over a whole-row banner's stretched target.
289
318
  const trailing =
290
319
  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")}>
320
+ <div className={cn("relative z-10 flex shrink-0 items-center gap-2", !strip && !inlineRow && "self-center", strip && "ms-auto")}>
292
321
  {action}
293
322
  </div>
294
323
  ) : null;
@@ -319,12 +348,12 @@ export function AlertBanner({
319
348
  ? cn(
320
349
  "flex min-w-0 flex-1 text-start",
321
350
  sm ? "gap-1.5" : "gap-2",
322
- inline || strip ? "items-center" : "items-start",
351
+ inlineRow || strip ? "items-center" : "items-start",
323
352
  "outline-none after:absolute after:inset-0 after:content-['']",
324
353
  strip ? "after:rounded-none" : "after:rounded-md",
325
354
  "focus-visible:after:ring-2 focus-visible:after:ring-[var(--brand)]",
326
355
  )
327
- : 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);
328
357
  // The div's attributes are the row element's: an `id`, a test id or an
329
358
  // `aria-describedby` belongs on the thing that takes focus. The live-region role is
330
359
  // NOT carried over — a button or a link that is also a `status` is neither.
@@ -6,6 +6,7 @@ import { cn } from "../lib/cn";
6
6
  import { horizontalStep } from "../lib/direction";
7
7
  import { useKitLabels } from "../i18n/kit-labels";
8
8
  import { useAnnounce } from "../hooks/use-announce";
9
+ import { useMediaQuery } from "../hooks/use-media-query";
9
10
  import { OVERLAY_EXIT_MS, prefersReducedMotion } from "../hooks/use-close-transition";
10
11
  import { Button, IconButton } from "./ui";
11
12
 
@@ -34,16 +35,89 @@ export const DEFAULT_BULK_ACTION_BAR_LABELS: BulkActionBarLabels = {
34
35
  */
35
36
  export type BulkActionBarVariant = "floating" | "sticky" | "inline";
36
37
 
38
+ /**
39
+ * A variant per breakpoint, mobile first — `{ base: "floating", md: "sticky" }` is the
40
+ * phone's floating card below 768px and the desktop's sticky bar from there up. The
41
+ * breakpoints are Tailwind's (sm 640, md 768, lg 1024, xl 1280px), the ones the kit's
42
+ * classes already use. keksdose's payees selection bar (payees-selection-bar.tsx)
43
+ * computes exactly this with its own `useMediaQuery("(min-width: 768px)")`; every bar
44
+ * that is a card on a phone and a strip on a desktop would repeat it.
45
+ *
46
+ * Resolved in JS rather than with `md:` classes because the variants differ in more
47
+ * than classes: the floating bar's clear is an icon at the start, the others' a text
48
+ * button at the end, and the floating bar is positioned by inline style.
49
+ */
50
+ export interface ResponsiveBulkActionBarVariant {
51
+ base: BulkActionBarVariant;
52
+ sm?: BulkActionBarVariant;
53
+ md?: BulkActionBarVariant;
54
+ lg?: BulkActionBarVariant;
55
+ xl?: BulkActionBarVariant;
56
+ }
57
+
58
+ const BREAKPOINTS = [
59
+ ["xl", "(min-width: 1280px)"],
60
+ ["lg", "(min-width: 1024px)"],
61
+ ["md", "(min-width: 768px)"],
62
+ ["sm", "(min-width: 640px)"],
63
+ ] as const;
64
+
65
+ /** The variant in force: the widest breakpoint that matches AND names one, else
66
+ * `base`. The four queries are subscribed unconditionally — hooks cannot be skipped —
67
+ * and a plain string variant simply ignores them. Without `matchMedia` (SSR, tests)
68
+ * every query is false, so the bar renders its `base`, the phone's, first. */
69
+ function useResolvedVariant(variant: BulkActionBarVariant | ResponsiveBulkActionBarVariant): BulkActionBarVariant {
70
+ const matches = {
71
+ xl: useMediaQuery(BREAKPOINTS[0][1], false),
72
+ lg: useMediaQuery(BREAKPOINTS[1][1], false),
73
+ md: useMediaQuery(BREAKPOINTS[2][1], false),
74
+ sm: useMediaQuery(BREAKPOINTS[3][1], false),
75
+ };
76
+ if (typeof variant === "string") return variant;
77
+ for (const [key] of BREAKPOINTS) {
78
+ const v = variant[key];
79
+ if (matches[key] && v !== undefined) return v;
80
+ }
81
+ return variant.base;
82
+ }
83
+
37
84
  export interface BulkActionBarProps extends Omit<ComponentPropsWithoutRef<"div">, "role" | "children"> {
38
- /** How many items are selected. The bar shows only while this is above zero. */
85
+ /** How many items are selected. The bar shows only while this is above zero —
86
+ * unless {@link open} says otherwise. */
39
87
  count: number;
88
+ /**
89
+ * Show the bar regardless of `count` — `true` for SELECTION MODE with nothing picked
90
+ * yet, `false` to hide it with rows still selected. Left out, `count > 0` decides, as
91
+ * before.
92
+ *
93
+ * keksdose's invoice lines (invoice-lines-bulk-bar.tsx) enter selection with a
94
+ * "Select" button, and the bar must be there at "0 selected" to hold the way out and
95
+ * a "Select all" (pass it as a child); gated on the count, the bar appeared only at
96
+ * the first tick, and the user who pressed "Select" saw nothing happen. The exit plays
97
+ * when it closes either way, and the count is still announced on every change.
98
+ */
99
+ open?: boolean;
40
100
  /** Clear the selection / leave selection mode. */
41
101
  onClear: () => void;
42
102
  /** The actions: buttons (`IconButton size="lg"` on a phone, `Button` from md up),
43
103
  * in the caller's order. They are the toolbar's arrow-key stops, after the clear. */
44
104
  children?: ReactNode;
45
- /** Default `floating`. See {@link BulkActionBarVariant}. */
46
- variant?: BulkActionBarVariant;
105
+ /** Default `floating`. See {@link BulkActionBarVariant}; an object picks one per
106
+ * breakpoint, see {@link ResponsiveBulkActionBarVariant}. */
107
+ variant?: BulkActionBarVariant | ResponsiveBulkActionBarVariant;
108
+ /**
109
+ * Content BELOW the toolbar row, inside the same surface — the same floating card or
110
+ * sticky tinted strip — but OUTSIDE the toolbar: its fields keep their own Tab stops
111
+ * and arrow keys, and the toolbar's roving focus never walks into it. keksdose's
112
+ * desktop receipt-line bar (invoice-lines-bulk-bar.tsx) shows its `BulkFields` form —
113
+ * a category picker, an exclude checkbox, Apply — under the count and the clear; a
114
+ * form is not a toolbar's content (`role="toolbar"` promises one arrow-key widget),
115
+ * and set beside the bar it lost the sticky tint and scrolled away from it.
116
+ *
117
+ * On the floating variant the panel scrolls within 60% of the viewport's height, so a
118
+ * long form on a phone cannot push the bar off the top of the screen.
119
+ */
120
+ panel?: ReactNode;
47
121
  /** Default: `bulkActionBar` from the {@link UiKitProvider}, else English. */
48
122
  labels?: Partial<BulkActionBarLabels>;
49
123
  }
@@ -105,7 +179,9 @@ export function BulkActionBar({
105
179
  count,
106
180
  onClear,
107
181
  children,
108
- variant = "floating",
182
+ variant: variantProp = "floating",
183
+ open,
184
+ panel,
109
185
  labels: labelsProp,
110
186
  className,
111
187
  style,
@@ -116,21 +192,22 @@ export function BulkActionBar({
116
192
  const labels = useKitLabels("bulkActionBar", DEFAULT_BULK_ACTION_BAR_LABELS, labelsProp);
117
193
  const { announce, regionProps } = useAnnounce();
118
194
  const barRef = useRef<HTMLDivElement>(null);
119
- const shown = count > 0;
195
+ const variant = useResolvedVariant(variantProp);
196
+ const shown = open ?? count > 0;
120
197
 
121
198
  // The count the bar last SHOWED, so a bar lowering itself after "clear" still reads
122
199
  // "3 selected" on its way out rather than "0 selected". Adjusted during render
123
200
  // (`Collapse`'s pattern), as is the exit below.
124
201
  const [shownCount, setShownCount] = useState(count);
125
202
  const [leaving, setLeaving] = useState(false);
126
- const [prevCount, setPrevCount] = useState(count);
127
- if (count !== prevCount) {
128
- setPrevCount(count);
203
+ const [prev, setPrev] = useState({ count, shown });
204
+ if (count !== prev.count || shown !== prev.shown) {
205
+ setPrev({ count, shown });
129
206
  if (shown) {
130
207
  setShownCount(count);
131
208
  setLeaving(false);
132
- } else {
133
- setLeaving(prevCount > 0 && !prefersReducedMotion());
209
+ } else if (prev.shown) {
210
+ setLeaving(!prefersReducedMotion());
134
211
  }
135
212
  }
136
213
  useEffect(() => {
@@ -145,8 +222,9 @@ export function BulkActionBar({
145
222
  useEffect(() => {
146
223
  if (spoken.current === count) return;
147
224
  spoken.current = count;
148
- announce(count > 0 ? labels.selected(count) : labels.cleared);
149
- }, [count, labels, announce]);
225
+ // In selection mode the bar stays at zero, so zero is a count like any other.
226
+ announce(count > 0 || shown ? labels.selected(count) : labels.cleared);
227
+ }, [count, shown, labels, announce]);
150
228
 
151
229
  // Roving tab stop. The controls are the caller's, so the stop is kept on the DOM
152
230
  // rather than through props: after every render the remembered control (or the
@@ -191,54 +269,82 @@ export function BulkActionBar({
191
269
  </Button>
192
270
  );
193
271
 
272
+ const hasPanel = panel !== undefined && panel !== null && panel !== false;
273
+ // The surface — where the bar sits and what it looks like — and the toolbar row's
274
+ // own layout. Without a panel they are one element, exactly as before 0.11.0; with
275
+ // one the surface wraps the row and the panel, so both share its tint and position.
276
+ const surfaceClass = floating
277
+ ? cn(
278
+ "fixed z-30 rounded-2xl border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
279
+ shown ? "animate-sheet" : "animate-sheet-out",
280
+ )
281
+ : cn(
282
+ variant === "sticky" &&
283
+ "sticky top-0 z-20 border-b border-[var(--border)] bg-[color-mix(in_srgb,var(--brand)_8%,var(--bg-surface))] backdrop-blur",
284
+ shown ? "animate-overlay" : "animate-overlay-out",
285
+ );
286
+ const rowClass = cn("flex items-center", floating ? "gap-1 px-2 py-1" : "gap-2 px-3 py-2");
287
+ const surfaceStyle = floating ? { ...FLOATING_STYLE, ...style } : style;
288
+
289
+ const toolbar = (
290
+ <div
291
+ {...(hasPanel ? null : rest)}
292
+ ref={barRef}
293
+ role="toolbar"
294
+ aria-label={labels.selected(shownCount)}
295
+ aria-orientation="horizontal"
296
+ data-bulk-action-bar={hasPanel ? undefined : variant}
297
+ // Leaving: out of the tab order and the accessibility tree at once, while the
298
+ // bar still animates. The selection it acted on is already gone.
299
+ inert={(!hasPanel && !shown) || undefined}
300
+ onKeyDown={handleKeyDown}
301
+ onFocus={(e) => {
302
+ onFocus?.(e);
303
+ // Clicking a control is using it: the stop follows the pointer too.
304
+ const hit = itemsOf(barRef.current).find((el) => el === e.target);
305
+ if (hit) {
306
+ active.current = hit;
307
+ rove(barRef.current, active);
308
+ }
309
+ }}
310
+ style={hasPanel ? undefined : surfaceStyle}
311
+ className={hasPanel ? rowClass : cn(rowClass, surfaceClass, className)}
312
+ >
313
+ {floating && clear}
314
+ <span className="min-w-0 flex-1 truncate text-sm font-medium text-[var(--text-primary)]">
315
+ {labels.selected(shownCount)}
316
+ </span>
317
+ {/* `contents`, so the caller's controls are flex items of the bar itself. */}
318
+ <div className="contents">{children}</div>
319
+ {!floating && clear}
320
+ </div>
321
+ );
322
+
194
323
  return (
195
324
  <>
196
325
  <span {...regionProps} />
197
- <div
198
- {...rest}
199
- ref={barRef}
200
- role="toolbar"
201
- aria-label={labels.selected(shownCount)}
202
- aria-orientation="horizontal"
203
- data-bulk-action-bar={variant}
204
- // Leaving: out of the tab order and the accessibility tree at once, while the
205
- // bar still animates. The selection it acted on is already gone.
206
- inert={!shown || undefined}
207
- onKeyDown={handleKeyDown}
208
- onFocus={(e) => {
209
- onFocus?.(e);
210
- // Clicking a control is using it: the stop follows the pointer too.
211
- const hit = itemsOf(barRef.current).find((el) => el === e.target);
212
- if (hit) {
213
- active.current = hit;
214
- rove(barRef.current, active);
215
- }
216
- }}
217
- style={floating ? { ...FLOATING_STYLE, ...style } : style}
218
- className={cn(
219
- "flex items-center",
220
- floating
221
- ? cn(
222
- "fixed z-30 gap-1 rounded-2xl border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1 shadow-lg",
223
- shown ? "animate-sheet" : "animate-sheet-out",
224
- )
225
- : cn(
226
- "gap-2 px-3 py-2",
227
- variant === "sticky" &&
228
- "sticky top-0 z-20 border-b border-[var(--border)] bg-[color-mix(in_srgb,var(--brand)_8%,var(--bg-surface))] backdrop-blur",
229
- shown ? "animate-overlay" : "animate-overlay-out",
230
- ),
231
- className,
232
- )}
233
- >
234
- {floating && clear}
235
- <span className="min-w-0 flex-1 truncate text-sm font-medium text-[var(--text-primary)]">
236
- {labels.selected(shownCount)}
237
- </span>
238
- {/* `contents`, so the caller's controls are flex items of the bar itself. */}
239
- <div className="contents">{children}</div>
240
- {!floating && clear}
241
- </div>
326
+ {hasPanel ? (
327
+ <div
328
+ {...rest}
329
+ data-bulk-action-bar={variant}
330
+ inert={!shown || undefined}
331
+ style={surfaceStyle}
332
+ className={cn("flex flex-col", surfaceClass, className)}
333
+ >
334
+ {toolbar}
335
+ <div
336
+ data-bulk-action-bar-panel=""
337
+ className={cn(
338
+ "border-t border-[var(--border)] px-3 py-3",
339
+ floating && "max-h-[60dvh] overflow-y-auto",
340
+ )}
341
+ >
342
+ {panel}
343
+ </div>
344
+ </div>
345
+ ) : (
346
+ toolbar
347
+ )}
242
348
  </>
243
349
  );
244
350
  }
@@ -1,5 +1,6 @@
1
- import type { ComponentPropsWithoutRef } from "react";
1
+ import type { ComponentPropsWithoutRef, MouseEvent, ReactElement, ReactNode, Ref } from "react";
2
2
  import { cn } from "../lib/cn";
3
+ import { buttonClasses, type ButtonSize, type ButtonVariant } from "./ui";
3
4
 
4
5
  // Every class below is spelled out in full rather than assembled from parts: the
5
6
  // consumer's Tailwind build finds classes by scanning this package's source as text,
@@ -8,12 +9,15 @@ import { cn } from "../lib/cn";
8
9
  // Each rule is written twice, once for a direct child and once for a `<button>` one
9
10
  // level down. The second is for a Tooltip-wrapped IconButton — the map zoom's + and −
10
11
  // both carry a tooltip — where the direct child is the tooltip's wrapper span and the
11
- // button that draws the border and the corners sits inside it.
12
+ // button that draws the border and the corners sits inside it. The same again for an
13
+ // `<a>` one level down: a router link member (see {@link ButtonGroupLink}) under a
14
+ // tooltip. A bare link is a direct child and needs nothing extra.
12
15
  const JOINED_COMMON = cn(
13
16
  "inline-flex rounded-md border border-[var(--border)]",
14
17
  // The group draws the frame; each member gives up its own border, radius and shadow.
15
18
  "[&>*]:rounded-none [&>*]:border-0 [&>*]:shadow-none",
16
19
  "[&>*>button]:rounded-none [&>*>button]:border-0 [&>*>button]:shadow-none",
20
+ "[&>*>a]:rounded-none [&>*>a]:border-0 [&>*>a]:shadow-none",
17
21
  "[&>*]:border-[var(--border)]",
18
22
  // A focused member rises above its neighbours so its ring is not painted over by
19
23
  // the next one's background.
@@ -30,6 +34,7 @@ const JOINED: Record<"horizontal" | "vertical", string> = {
30
34
  "[&>*:not(:first-child)]:border-s",
31
35
  "[&>:first-child]:rounded-s-md [&>:last-child]:rounded-e-md",
32
36
  "[&>:first-child>button]:rounded-s-md [&>:last-child>button]:rounded-e-md",
37
+ "[&>:first-child>a]:rounded-s-md [&>:last-child>a]:rounded-e-md",
33
38
  ),
34
39
  // The block axis is top-to-bottom in both reading directions, so top/bottom are
35
40
  // already the logical edges here.
@@ -39,13 +44,47 @@ const JOINED: Record<"horizontal" | "vertical", string> = {
39
44
  "[&>*:not(:first-child)]:border-t",
40
45
  "[&>:first-child]:rounded-t-md [&>:last-child]:rounded-b-md",
41
46
  "[&>:first-child>button]:rounded-t-md [&>:last-child>button]:rounded-b-md",
47
+ "[&>:first-child>a]:rounded-t-md [&>:last-child>a]:rounded-b-md",
42
48
  ),
43
49
  };
44
50
 
51
+ // `gapped`: the members keep their own shape — round overlay discs, each its own
52
+ // border and radius — and sit apart. Nothing is stripped, so there is nothing to
53
+ // restore per edge, and the gap is logical by nature.
54
+ const GAPPED: Record<"horizontal" | "vertical", string> = {
55
+ horizontal: "inline-flex flex-row items-center gap-1",
56
+ vertical: "inline-flex flex-col items-center gap-1",
57
+ };
58
+
59
+ // `elevated`, joined: the frame itself floats — a filled surface under the members (a
60
+ // ghost member would otherwise show the content through it) and the shadow of a
61
+ // control lifted over the page.
62
+ const ELEVATED_JOINED = "bg-[var(--bg-surface)] shadow-lg";
63
+ // `elevated`, gapped: there is no frame, so each disc carries the shadow. Aimed at the
64
+ // control, not the tooltip's square wrapper span, whose shadow would be a box round a
65
+ // round disc.
66
+ const ELEVATED_GAPPED =
67
+ "[&>button]:shadow-md [&>a]:shadow-md [&>*>button]:shadow-md [&>*>a]:shadow-md";
68
+
45
69
  export interface ButtonGroupProps extends Omit<ComponentPropsWithoutRef<"div">, "role"> {
46
70
  /** `horizontal` (default): side by side, in reading order. `vertical`: stacked —
47
71
  * the map's zoom + over −. */
48
72
  orientation?: "horizontal" | "vertical";
73
+ /**
74
+ * `joined` (default): one frame, hairline dividers, outer corners rounded. `gapped`:
75
+ * separate controls with a small gap, each keeping its own shape — the overlay
76
+ * discs of keksdose's receipt preview zoom (scan-file-preview.tsx:362, the − and +
77
+ * `IconButton variant="overlay"` in a hand-made `flex gap-1`), where a joined frame
78
+ * would be a box drawn over the photo.
79
+ */
80
+ variant?: "joined" | "gapped";
81
+ /**
82
+ * Float it: a surface with a shadow, for a toolbar that sits OVER content (a map's
83
+ * zoom, a photo's controls) rather than in the page's flow — keksdose adds
84
+ * `shadow-sm` to each disc on the receipt preview by hand. On a joined group the
85
+ * frame is filled and shadowed; on a gapped one, each member.
86
+ */
87
+ elevated?: boolean;
49
88
  }
50
89
 
51
90
  /**
@@ -63,13 +102,94 @@ export interface ButtonGroupProps extends Omit<ComponentPropsWithoutRef<"div">,
63
102
  * roving, and every member keeps its own tab stop, as plain adjacent buttons do.
64
103
  * For one-of-many selection use `ToggleGroup`, which has the radio semantics.
65
104
  */
66
- export function ButtonGroup({ orientation = "horizontal", className, ...rest }: ButtonGroupProps) {
105
+ export function ButtonGroup({
106
+ orientation = "horizontal",
107
+ variant = "joined",
108
+ elevated = false,
109
+ className,
110
+ ...rest
111
+ }: ButtonGroupProps) {
112
+ const joined = variant === "joined";
67
113
  return (
68
114
  <div
69
115
  {...rest}
70
116
  role="group"
71
117
  data-orientation={orientation}
72
- className={cn(JOINED[orientation], className)}
118
+ data-variant={variant}
119
+ className={cn(
120
+ joined ? JOINED[orientation] : GAPPED[orientation],
121
+ elevated && (joined ? ELEVATED_JOINED : ELEVATED_GAPPED),
122
+ className,
123
+ )}
73
124
  />
74
125
  );
75
126
  }
127
+
128
+ /** What {@link ButtonGroupLinkProps.renderLink} is handed. Spread it onto your router's
129
+ * link, mapping `href` — `renderLink={({ href, ...p }) => <Link to={href} {...p} />}`. */
130
+ export interface ButtonGroupLinkRenderProps {
131
+ href: string;
132
+ /** The button look — keep it, or the member is a bare link in the frame. */
133
+ className: string;
134
+ children: ReactNode;
135
+ ref?: Ref<HTMLAnchorElement>;
136
+ "aria-current"?: "page";
137
+ onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
138
+ [key: `aria-${string}`]: string | boolean | number | undefined;
139
+ [key: `data-${string}`]: unknown;
140
+ }
141
+
142
+ export interface ButtonGroupLinkProps extends Omit<ComponentPropsWithoutRef<"a">, "href" | "className" | "children"> {
143
+ href: string;
144
+ /** The {@link Button} variant it looks like. Default `secondary`, the usual member. */
145
+ variant?: ButtonVariant;
146
+ size?: ButtonSize;
147
+ /** The member for the page you are on: `aria-current="page"` and the "on" look of a
148
+ * pressed member, so a link row reads as a segmented switch between pages. */
149
+ current?: boolean;
150
+ /** Render through your router's `Link` — see {@link ButtonGroupLinkRenderProps}. */
151
+ renderLink?: (props: ButtonGroupLinkRenderProps) => ReactElement;
152
+ className?: string;
153
+ children: ReactNode;
154
+ ref?: Ref<HTMLAnchorElement>;
155
+ }
156
+
157
+ const LINK_CURRENT = "bg-[var(--brand-bg)] text-[var(--brand)] hover:bg-[var(--brand-bg-hover)]";
158
+
159
+ /**
160
+ * A {@link ButtonGroup} member that navigates: a link drawn as a {@link Button}, so it
161
+ * joins the frame like one. A group mixing actions and pages — "Export" beside "Open
162
+ * report" — had to either make the page a button with an `onClick` navigate (no
163
+ * middle-click, no "open in new tab", no link semantics) or style an `<a>` whose
164
+ * corners the group did not know about. Plain `<a>` by default; `renderLink` for the
165
+ * router's `Link`, the kit's usual shape (`Chip`, `MenuItem`, `StatTile`).
166
+ */
167
+ export function ButtonGroupLink({
168
+ href,
169
+ variant = "secondary",
170
+ size,
171
+ current = false,
172
+ renderLink,
173
+ className,
174
+ children,
175
+ ...rest
176
+ }: ButtonGroupLinkProps) {
177
+ const props: ButtonGroupLinkRenderProps = {
178
+ ...rest,
179
+ href,
180
+ "aria-current": current ? "page" : undefined,
181
+ className: buttonClasses(variant, { size, className: cn(current && LINK_CURRENT, className) }),
182
+ children,
183
+ };
184
+ if (renderLink) return <RenderedGroupLink render={renderLink} {...props} />;
185
+ const { children: content, ...anchor } = props;
186
+ return <a {...anchor}>{content}</a>;
187
+ }
188
+
189
+ /** Calls `renderLink` as a component, so the router link's hooks are its own. */
190
+ function RenderedGroupLink({
191
+ render,
192
+ ...props
193
+ }: ButtonGroupLinkRenderProps & { render: (props: ButtonGroupLinkRenderProps) => ReactElement }) {
194
+ return render(props);
195
+ }