cursedbelt 5.32.0 → 5.34.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 (195) hide show
  1. package/dist/react/Toast.d.ts +1 -1
  2. package/dist/react/Toast.d.ts.map +1 -1
  3. package/dist/react/Toast.js +19 -4
  4. package/dist/react/Toast.js.map +1 -1
  5. package/dist/react/components/Button.d.ts +16 -1
  6. package/dist/react/components/Button.d.ts.map +1 -1
  7. package/dist/react/components/Button.js +34 -5
  8. package/dist/react/components/Button.js.map +1 -1
  9. package/dist/react/components/ChoiceGroup.d.ts +20 -1
  10. package/dist/react/components/ChoiceGroup.d.ts.map +1 -1
  11. package/dist/react/components/ChoiceGroup.js +15 -2
  12. package/dist/react/components/ChoiceGroup.js.map +1 -1
  13. package/dist/react/components/CopyButton.d.ts +10 -1
  14. package/dist/react/components/CopyButton.d.ts.map +1 -1
  15. package/dist/react/components/CopyButton.js +2 -2
  16. package/dist/react/components/CopyButton.js.map +1 -1
  17. package/dist/react/components/DataTable/DataTable.d.ts +27 -2
  18. package/dist/react/components/DataTable/DataTable.d.ts.map +1 -1
  19. package/dist/react/components/DataTable/DataTable.js +168 -44
  20. package/dist/react/components/DataTable/DataTable.js.map +1 -1
  21. package/dist/react/components/DataTable/RowActions.d.ts +4 -1
  22. package/dist/react/components/DataTable/RowActions.d.ts.map +1 -1
  23. package/dist/react/components/DataTable/RowActions.js +2 -2
  24. package/dist/react/components/DataTable/RowActions.js.map +1 -1
  25. package/dist/react/components/DataTable/columnPriority.d.ts +30 -0
  26. package/dist/react/components/DataTable/columnPriority.d.ts.map +1 -0
  27. package/dist/react/components/DataTable/columnPriority.js +45 -0
  28. package/dist/react/components/DataTable/columnPriority.js.map +1 -0
  29. package/dist/react/components/DataTable/types.d.ts +14 -0
  30. package/dist/react/components/DataTable/types.d.ts.map +1 -1
  31. package/dist/react/components/DataTable/types.js.map +1 -1
  32. package/dist/react/components/EmptyState.d.ts.map +1 -1
  33. package/dist/react/components/EmptyState.js +2 -2
  34. package/dist/react/components/EmptyState.js.map +1 -1
  35. package/dist/react/components/ErrorCard.d.ts +13 -1
  36. package/dist/react/components/ErrorCard.d.ts.map +1 -1
  37. package/dist/react/components/ErrorCard.js +3 -2
  38. package/dist/react/components/ErrorCard.js.map +1 -1
  39. package/dist/react/components/Field.d.ts +37 -12
  40. package/dist/react/components/Field.d.ts.map +1 -1
  41. package/dist/react/components/Field.js +19 -8
  42. package/dist/react/components/Field.js.map +1 -1
  43. package/dist/react/components/Menu.d.ts +58 -0
  44. package/dist/react/components/Menu.d.ts.map +1 -0
  45. package/dist/react/components/Menu.js +86 -0
  46. package/dist/react/components/Menu.js.map +1 -0
  47. package/dist/react/components/Modal.d.ts +1 -0
  48. package/dist/react/components/Modal.d.ts.map +1 -1
  49. package/dist/react/components/Modal.js +3 -2
  50. package/dist/react/components/Modal.js.map +1 -1
  51. package/dist/react/components/SaveIndicator.d.ts +36 -0
  52. package/dist/react/components/SaveIndicator.d.ts.map +1 -0
  53. package/dist/react/components/SaveIndicator.js +48 -0
  54. package/dist/react/components/SaveIndicator.js.map +1 -0
  55. package/dist/react/components/SelectionBar.d.ts +26 -0
  56. package/dist/react/components/SelectionBar.d.ts.map +1 -0
  57. package/dist/react/components/SelectionBar.js +21 -0
  58. package/dist/react/components/SelectionBar.js.map +1 -0
  59. package/dist/react/components/Switch.d.ts +16 -2
  60. package/dist/react/components/Switch.d.ts.map +1 -1
  61. package/dist/react/components/Switch.js +10 -3
  62. package/dist/react/components/Switch.js.map +1 -1
  63. package/dist/react/components/Tooltip.d.ts +1 -1
  64. package/dist/react/components/Tooltip.d.ts.map +1 -1
  65. package/dist/react/components/Tooltip.js +14 -1
  66. package/dist/react/components/Tooltip.js.map +1 -1
  67. package/dist/react/components/TooltipImpl.d.ts.map +1 -1
  68. package/dist/react/components/TooltipImpl.js +37 -7
  69. package/dist/react/components/TooltipImpl.js.map +1 -1
  70. package/dist/react/components/UnstyledButton.d.ts +37 -0
  71. package/dist/react/components/UnstyledButton.d.ts.map +1 -0
  72. package/dist/react/components/UnstyledButton.js +46 -0
  73. package/dist/react/components/UnstyledButton.js.map +1 -0
  74. package/dist/react/components/auth/SignInCard.d.ts +15 -1
  75. package/dist/react/components/auth/SignInCard.d.ts.map +1 -1
  76. package/dist/react/components/auth/SignInCard.js +6 -2
  77. package/dist/react/components/auth/SignInCard.js.map +1 -1
  78. package/dist/react/components/dialog.d.ts.map +1 -1
  79. package/dist/react/components/dialog.js +35 -3
  80. package/dist/react/components/dialog.js.map +1 -1
  81. package/dist/react/hooks/useCopyToClipboard.d.ts +10 -2
  82. package/dist/react/hooks/useCopyToClipboard.d.ts.map +1 -1
  83. package/dist/react/hooks/useCopyToClipboard.js +13 -4
  84. package/dist/react/hooks/useCopyToClipboard.js.map +1 -1
  85. package/dist/react/icons.d.ts +12 -1
  86. package/dist/react/icons.d.ts.map +1 -1
  87. package/dist/react/icons.js +12 -22
  88. package/dist/react/icons.js.map +1 -1
  89. package/dist/react/index.d.ts +8 -4
  90. package/dist/react/index.d.ts.map +1 -1
  91. package/dist/react/index.js +7 -3
  92. package/dist/react/index.js.map +1 -1
  93. package/dist/react/lib/hoverIntent.d.ts +21 -0
  94. package/dist/react/lib/hoverIntent.d.ts.map +1 -1
  95. package/dist/react/lib/hoverIntent.js +24 -0
  96. package/dist/react/lib/hoverIntent.js.map +1 -1
  97. package/dist/react/lib/openDialogs.d.ts +5 -0
  98. package/dist/react/lib/openDialogs.d.ts.map +1 -0
  99. package/dist/react/lib/openDialogs.js +45 -0
  100. package/dist/react/lib/openDialogs.js.map +1 -0
  101. package/dist/styles-areas/analytics.css +16 -16
  102. package/dist/styles-areas/calendar.css +7 -7
  103. package/dist/styles-areas/chat.css +9 -10
  104. package/dist/styles-areas/core.css +69 -62
  105. package/dist/styles-areas/data-table.css +16 -16
  106. package/dist/styles-areas/disk-usage.css +7 -7
  107. package/dist/styles-areas/emoji.css +3 -3
  108. package/dist/styles-areas/fields.css +10 -10
  109. package/dist/styles-areas/filter-rail.css +7 -8
  110. package/dist/styles-areas/layout-engine.css +5 -6
  111. package/dist/styles-areas/master-detail.css +6 -7
  112. package/dist/styles-areas/media-gallery.css +2 -2
  113. package/dist/styles-areas/media.css +2 -2
  114. package/dist/styles-areas/nav.css +17 -18
  115. package/dist/styles-areas/notifications.css +5 -5
  116. package/dist/styles-areas/overlays.css +5 -5
  117. package/dist/styles-areas/sharing.css +2 -2
  118. package/dist/styles-areas/stats.css +4 -4
  119. package/dist/styles-areas/wizard.css +3 -3
  120. package/dist/styles-areas/workbench.css +18 -19
  121. package/dist/styles-utilities.css +72 -0
  122. package/dist/testing/tooltip.d.ts.map +1 -1
  123. package/dist/testing/tooltip.js +8 -18
  124. package/dist/testing/tooltip.js.map +1 -1
  125. package/package.json +81 -3
  126. package/scripts/guardrails-baseline.json +1 -1
  127. package/scripts/styleAreas.ts +4 -0
  128. package/src/react/Toast.spec.tsx +17 -1
  129. package/src/react/Toast.tsx +20 -3
  130. package/src/react/components/Button.spec.tsx +49 -1
  131. package/src/react/components/Button.tsx +63 -6
  132. package/src/react/components/ChoiceGroup.spec.tsx +32 -0
  133. package/src/react/components/ChoiceGroup.tsx +78 -23
  134. package/src/react/components/CopyButton.spec.tsx +35 -0
  135. package/src/react/components/CopyButton.tsx +11 -2
  136. package/src/react/components/DataTable/DataTable.spec.tsx +16 -0
  137. package/src/react/components/DataTable/DataTable.tsx +266 -37
  138. package/src/react/components/DataTable/RowActions.tsx +5 -2
  139. package/src/react/components/DataTable/columnPriority.spec.ts +97 -0
  140. package/src/react/components/DataTable/columnPriority.ts +54 -0
  141. package/src/react/components/DataTable/types.ts +14 -0
  142. package/src/react/components/DataTable/virtualize.spec.tsx +47 -2
  143. package/src/react/components/EmptyState.spec.tsx +7 -0
  144. package/src/react/components/EmptyState.tsx +3 -0
  145. package/src/react/components/ErrorCard.spec.tsx +32 -0
  146. package/src/react/components/ErrorCard.tsx +17 -1
  147. package/src/react/components/Field.spec.tsx +61 -0
  148. package/src/react/components/Field.tsx +84 -27
  149. package/src/react/components/Menu.spec.tsx +90 -0
  150. package/src/react/components/Menu.tsx +204 -0
  151. package/src/react/components/Modal.spec.tsx +84 -0
  152. package/src/react/components/Modal.tsx +4 -1
  153. package/src/react/components/SaveIndicator.spec.tsx +35 -0
  154. package/src/react/components/SaveIndicator.tsx +85 -0
  155. package/src/react/components/SelectionBar.spec.tsx +32 -0
  156. package/src/react/components/SelectionBar.tsx +49 -0
  157. package/src/react/components/Switch.spec.tsx +25 -0
  158. package/src/react/components/Switch.tsx +49 -4
  159. package/src/react/components/Tooltip.spec.tsx +183 -2
  160. package/src/react/components/Tooltip.tsx +14 -2
  161. package/src/react/components/TooltipImpl.tsx +42 -8
  162. package/src/react/components/UnstyledButton.spec.tsx +61 -0
  163. package/src/react/components/UnstyledButton.tsx +83 -0
  164. package/src/react/components/auth/SignInCard.spec.tsx +34 -0
  165. package/src/react/components/auth/SignInCard.tsx +36 -3
  166. package/src/react/components/dialog.tsx +49 -9
  167. package/src/react/hooks/useCopyToClipboard.ts +17 -4
  168. package/src/react/icons.spec.ts +32 -1
  169. package/src/react/icons.tsx +59 -0
  170. package/src/react/index.ts +23 -2
  171. package/src/react/lib/hoverIntent.ts +28 -0
  172. package/src/react/lib/openDialogs.ts +48 -0
  173. package/src/styles-areas/analytics.css +16 -16
  174. package/src/styles-areas/calendar.css +7 -7
  175. package/src/styles-areas/chat.css +9 -10
  176. package/src/styles-areas/core.css +69 -62
  177. package/src/styles-areas/data-table.css +16 -16
  178. package/src/styles-areas/disk-usage.css +7 -7
  179. package/src/styles-areas/emoji.css +3 -3
  180. package/src/styles-areas/fields.css +10 -10
  181. package/src/styles-areas/filter-rail.css +7 -8
  182. package/src/styles-areas/layout-engine.css +5 -6
  183. package/src/styles-areas/master-detail.css +6 -7
  184. package/src/styles-areas/media-gallery.css +2 -2
  185. package/src/styles-areas/media.css +2 -2
  186. package/src/styles-areas/nav.css +17 -18
  187. package/src/styles-areas/notifications.css +5 -5
  188. package/src/styles-areas/overlays.css +5 -5
  189. package/src/styles-areas/sharing.css +2 -2
  190. package/src/styles-areas/stats.css +4 -4
  191. package/src/styles-areas/wizard.css +3 -3
  192. package/src/styles-areas/workbench.css +18 -19
  193. package/src/styles-utilities.css +72 -0
  194. package/src/testing/tooltip.spec.ts +19 -0
  195. package/src/testing/tooltip.ts +17 -1
@@ -1,7 +1,15 @@
1
1
  import { Slot } from '@radix-ui/react-slot';
2
2
  import { cva, type VariantProps } from 'class-variance-authority';
3
3
  import { Check, Loader2 } from 'lucide-react';
4
- import { type ButtonHTMLAttributes, type MouseEvent, type ReactNode, type Ref, useRef, useState } from 'react';
4
+ import {
5
+ type ButtonHTMLAttributes,
6
+ type KeyboardEvent,
7
+ type MouseEvent,
8
+ type ReactNode,
9
+ type Ref,
10
+ useRef,
11
+ useState,
12
+ } from 'react';
5
13
  import { toast } from 'sonner';
6
14
  import { cn } from '../lib/cn.js';
7
15
  import { Tooltip, type TooltipMobile, type TooltipPlacement } from './Tooltip.js';
@@ -29,6 +37,12 @@ export const buttonVariants = cva(
29
37
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background',
30
38
  // Disabled = muted surface + faded + inert (never color-alone): clearly off, not a low-contrast haze.
31
39
  'disabled:pointer-events-none disabled:opacity-50 disabled:border-transparent disabled:bg-muted disabled:text-muted-foreground',
40
+ // REFUSED (`unavailableReason`) is drawn like disabled but keeps its pointer events:
41
+ // it has to be hoverable and focusable to deliver the reason it exists to give.
42
+ 'aria-disabled:cursor-not-allowed aria-disabled:opacity-50',
43
+ // A toggle that is ON (`aria-pressed`) reads as selected in every variant — the
44
+ // accent border and text over a faint accent wash, never colour alone (the border).
45
+ 'aria-pressed:border aria-pressed:border-accent aria-pressed:bg-accent/10 aria-pressed:text-accent',
32
46
  '[&_svg]:size-4 [&_svg]:shrink-0',
33
47
  ],
34
48
  {
@@ -159,6 +173,21 @@ export interface ButtonProps
159
173
  /** Toast shown when `onAsyncClick` rejects. `true` (default) → the thrown
160
174
  * error's message; a string → that message instead; `false` → no toast. */
161
175
  errorMessage?: boolean | string;
176
+ /**
177
+ * Why this control cannot work HERE — and supplying it refuses the press.
178
+ *
179
+ * The owner's rule for a control that cannot work on this host: visible, disabled,
180
+ * and the reason on hover. `disabled` cannot carry that, because a disabled button
181
+ * leaves the tab order and fires no pointer events, so the one sentence that explains
182
+ * it is unreachable by keyboard. A refused button is `aria-disabled` instead —
183
+ * announced as disabled, drawn as disabled, turned away on click and on Enter/Space,
184
+ * and still focusable and hoverable, which is what the ARIA practices guide
185
+ * recommends. Its hint is the reason (it replaces `tooltip` while set). `disabled`
186
+ * wins when both are given: a momentarily inert control is simply inert.
187
+ *
188
+ * Came from desk's own Button (forge task 2410), which had carried it since its file 80.
189
+ */
190
+ unavailableReason?: string;
162
191
  /** How long the post-completion checkmark flash shows (ms). Default 1200. */
163
192
  resetMs?: number;
164
193
  children?: ReactNode;
@@ -189,6 +218,8 @@ export function Button({
189
218
  children,
190
219
  disabled,
191
220
  onClick,
221
+ onKeyDown,
222
+ unavailableReason,
192
223
  ...props
193
224
  }: ButtonProps) {
194
225
  const classes = cn(buttonVariants({ variant, size }), className);
@@ -222,6 +253,28 @@ export function Button({
222
253
  : onClick;
223
254
 
224
255
  const isLoading = loading || pending;
256
+ const reason = unavailableReason?.trim() || undefined;
257
+ const refused = reason !== undefined && !disabled;
258
+
259
+ // The half `disabled` would do for free, done before anything else runs so a caller's
260
+ // handler (or `onAsyncClick`) can never fire behind a refusal.
261
+ const refuseClick = (e: MouseEvent<HTMLButtonElement>) => {
262
+ if (refused) {
263
+ e.preventDefault();
264
+ e.stopPropagation();
265
+ return;
266
+ }
267
+ handleClick?.(e);
268
+ };
269
+ // Enter and Space are a button's click; a focusable refused control turns them away too,
270
+ // or the keyboard route it was just given becomes the one way through it.
271
+ const refuseKey = (e: KeyboardEvent<HTMLButtonElement>) => {
272
+ if (refused && (e.key === 'Enter' || e.key === ' ')) {
273
+ e.preventDefault();
274
+ return;
275
+ }
276
+ onKeyDown?.(e);
277
+ };
225
278
 
226
279
  // asChild: hand styling to the consumer's single element (no spinner/label wrapper —
227
280
  // that extra <span> would defeat the Slot merge, per the note above). `type` is a
@@ -231,7 +284,7 @@ export function Button({
231
284
  const variantAttr = variant ?? 'secondary';
232
285
 
233
286
  const el = asChild ? (
234
- <Slot className={classes} data-cb-variant={variantAttr} onClick={onClick} {...props}>
287
+ <Slot className={classes} data-cb-variant={variantAttr} onClick={onClick} onKeyDown={onKeyDown} {...props}>
235
288
  {children}
236
289
  </Slot>
237
290
  ) : (
@@ -242,10 +295,12 @@ export function Button({
242
295
  type={type ?? 'button'}
243
296
  className={classes}
244
297
  data-cb-variant={variantAttr}
245
- disabled={disabled || isLoading || undefined}
246
- aria-busy={isLoading || undefined}
247
- onClick={handleClick}
248
298
  {...props}
299
+ disabled={(disabled || (isLoading && !refused)) || undefined}
300
+ aria-disabled={refused ? true : props['aria-disabled']}
301
+ aria-busy={isLoading || undefined}
302
+ onClick={refuseClick}
303
+ onKeyDown={refuseKey}
249
304
  >
250
305
  {isLoading ? <Loader2 className='absolute size-4 animate-spin' aria-hidden /> : null}
251
306
  {!isLoading && justSucceeded ? <Check className='absolute size-4' aria-hidden /> : null}
@@ -258,8 +313,10 @@ export function Button({
258
313
  );
259
314
 
260
315
  // The single "button with a tooltip" seam: wrap once, here, so no call site re-implements it.
316
+ // `multiline`: a hint that is a sentence ("Nothing to restore — the trash is empty") wraps
317
+ // inside a capped bubble instead of running off a narrow pane; a short one is unchanged.
261
318
  return (
262
- <Tooltip content={tooltip} side={tooltipSide} mobile={tooltipMobile}>
319
+ <Tooltip content={refused ? reason : tooltip} side={tooltipSide} mobile={tooltipMobile} multiline>
263
320
  {el}
264
321
  </Tooltip>
265
322
  );
@@ -75,4 +75,36 @@ describe('ChoiceGroup', () => {
75
75
  );
76
76
  expect(queryByText('Only curators.')).toBeNull();
77
77
  });
78
+
79
+ describe("layout='picture'", () => {
80
+ const PICTURES: ChoiceOption[] = [
81
+ { value: 'first', label: 'Whichever is first' },
82
+ { value: 'p1', label: 'Nan at the beach', image: <img alt='' src='/p1.jpg' /> },
83
+ { value: 'p2', label: <b>Grandad</b>, 'aria-label': 'Use Grandad as the cover', image: <img alt='' src='/p2.jpg' /> },
84
+ ];
85
+
86
+ test('each picture is a radio named by its label, and a picture-less option shows its words', () => {
87
+ const { getAllByRole } = render(
88
+ <ChoiceGroup layout='picture' aria-label='Cover' options={PICTURES} value='p1' onChange={() => {}} />,
89
+ );
90
+ const radios = getAllByRole('radio');
91
+ expect(radios.map((r) => r.getAttribute('aria-label') ?? r.textContent)).toEqual([
92
+ 'Whichever is first',
93
+ 'Nan at the beach',
94
+ 'Use Grandad as the cover',
95
+ ]);
96
+ expect(radios[1]?.getAttribute('aria-checked')).toBe('true');
97
+ expect(radios[1]?.querySelector('img')).not.toBeNull();
98
+ expect((radios[0] as HTMLElement).style.width).toBe('64px');
99
+ });
100
+
101
+ test('pressing a tile reports its value', () => {
102
+ const chosen: string[] = [];
103
+ const { getAllByRole } = render(
104
+ <ChoiceGroup layout='picture' aria-label='Cover' options={PICTURES} value='p1' onChange={(v) => chosen.push(v)} />,
105
+ );
106
+ fireEvent.click(getAllByRole('radio')[0] as HTMLElement);
107
+ expect(chosen).toEqual(['first']);
108
+ });
109
+ });
78
110
  });
@@ -2,6 +2,7 @@ import * as RadioGroup from '@radix-ui/react-radio-group';
2
2
  import { type ReactNode, useId } from 'react';
3
3
  import { cn } from '../lib/cn.js';
4
4
  import { TAP_TARGET } from '../lib/tapTarget.js';
5
+ import { Tooltip } from './Tooltip.js';
5
6
 
6
7
  export interface ChoiceOption<T extends string = string> {
7
8
  /** Stable value reported by `onChange`. */
@@ -11,6 +12,15 @@ export interface ChoiceOption<T extends string = string> {
11
12
  /** A quieter second line under the label. */
12
13
  description?: ReactNode;
13
14
  disabled?: boolean;
15
+ /**
16
+ * `layout='picture'` only: the picture that IS the option — a thumbnail filling the
17
+ * tile. The `label` then becomes the tile's hover tooltip, and its accessible name
18
+ * when it is a string (pass `aria-label` when it is not). An option with no `image`
19
+ * shows its `label` inside the tile instead ("Whichever is first").
20
+ */
21
+ image?: ReactNode;
22
+ /** Accessible name for a picture tile whose `label` is not a plain string. */
23
+ 'aria-label'?: string;
14
24
  }
15
25
 
16
26
  export interface ChoiceGroupProps<T extends string = string> {
@@ -29,6 +39,15 @@ export interface ChoiceGroupProps<T extends string = string> {
29
39
  disabledReason?: ReactNode;
30
40
  /** Form field name, for a group inside a `<form>`. */
31
41
  name?: string;
42
+ /**
43
+ * `text` (default): a wrapping row of worded options. `picture`: one strip of
44
+ * square thumbnail tiles, checked by an accent ring — a cover picker, an avatar
45
+ * picker. The strip does not wrap; put the group in a `ScrollArea axis='x'` when
46
+ * it can be longer than its container.
47
+ */
48
+ layout?: 'text' | 'picture';
49
+ /** `layout='picture'` tile edge in px. Default 64. */
50
+ tileSize?: number;
32
51
  className?: string;
33
52
  }
34
53
 
@@ -41,6 +60,7 @@ export interface ChoiceGroupProps<T extends string = string> {
41
60
  * - a short view/mode switch on one line → `SegmentedControl`
42
61
  * - a long or data-driven list → `SelectField` / `ChoiceMenu`
43
62
  * - a colour → `SwatchPicker`
63
+ * - one picture out of several (a cover, an avatar) → THIS, `layout='picture'`
44
64
  * - a handful of answers that each need words → THIS
45
65
  *
46
66
  * ── 🔴 Why this exists: the hidden-radio trap (family, 2026-09-26) ──────────
@@ -71,6 +91,8 @@ export function ChoiceGroup<T extends string = string>({
71
91
  disabled = false,
72
92
  disabledReason,
73
93
  name,
94
+ layout = 'text',
95
+ tileSize = 64,
74
96
  className,
75
97
  }: ChoiceGroupProps<T>) {
76
98
  const id = useId();
@@ -94,30 +116,34 @@ export function ChoiceGroup<T extends string = string>({
94
116
  onValueChange={(next) => onChange(next as T)}
95
117
  disabled={disabled}
96
118
  name={name}
97
- className='relative flex min-w-0 flex-wrap gap-1.5'
119
+ className={cn('relative flex min-w-0', layout === 'picture' ? 'gap-2' : 'flex-wrap gap-1.5')}
98
120
  >
99
- {options.map((option) => (
100
- <RadioGroup.Item
101
- key={option.value}
102
- value={option.value}
103
- disabled={option.disabled}
104
- className={cn(
105
- 'flex min-w-0 max-w-full flex-col items-start rounded-md border border-border bg-transparent px-2.5 py-1.5 text-left text-sm text-foreground transition-colors',
106
- 'hover:border-accent',
107
- 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
108
- 'data-[state=checked]:border-accent data-[state=checked]:bg-accent/10 data-[state=checked]:font-medium',
109
- 'disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-border',
110
- TAP_TARGET,
111
- )}
112
- >
113
- <span className='min-w-0 break-words'>{option.label}</span>
114
- {option.description != null ? (
115
- <span className='min-w-0 break-words text-xs font-normal text-muted-foreground'>
116
- {option.description}
117
- </span>
118
- ) : null}
119
- </RadioGroup.Item>
120
- ))}
121
+ {options.map((option) =>
122
+ layout === 'picture' ? (
123
+ <PictureTile key={option.value} option={option} size={tileSize} />
124
+ ) : (
125
+ <RadioGroup.Item
126
+ key={option.value}
127
+ value={option.value}
128
+ disabled={option.disabled}
129
+ className={cn(
130
+ 'flex min-w-0 max-w-full flex-col items-start rounded-md border border-border bg-transparent px-2.5 py-1.5 text-left text-sm text-foreground transition-colors',
131
+ 'hover:border-accent',
132
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
133
+ 'data-[state=checked]:border-accent data-[state=checked]:bg-accent/10 data-[state=checked]:font-medium',
134
+ 'disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-border',
135
+ TAP_TARGET,
136
+ )}
137
+ >
138
+ <span className='min-w-0 break-words'>{option.label}</span>
139
+ {option.description != null ? (
140
+ <span className='min-w-0 break-words text-xs font-normal text-muted-foreground'>
141
+ {option.description}
142
+ </span>
143
+ ) : null}
144
+ </RadioGroup.Item>
145
+ ),
146
+ )}
121
147
  </RadioGroup.Root>
122
148
  {reasonId ? (
123
149
  <p id={reasonId} className='text-xs text-muted-foreground'>
@@ -132,3 +158,32 @@ export function ChoiceGroup<T extends string = string>({
132
158
  </div>
133
159
  );
134
160
  }
161
+
162
+ /**
163
+ * One square tile of a `layout='picture'` group. Still a Radix radio item — roving
164
+ * tabindex, arrow keys and `aria-checked` come from the group, exactly as for a text
165
+ * option — so a picture picker is never a row of hand-rolled `role="radio"` buttons
166
+ * again (family's cover picker was, until task 2402).
167
+ */
168
+ function PictureTile<T extends string>({ option, size }: { option: ChoiceOption<T>; size: number }) {
169
+ const name = option['aria-label'] ?? (typeof option.label === 'string' ? option.label : undefined);
170
+ const item = (
171
+ <RadioGroup.Item
172
+ value={option.value}
173
+ disabled={option.disabled}
174
+ aria-label={option.image != null ? name : undefined}
175
+ style={{ width: size, height: size }}
176
+ className={cn(
177
+ 'flex shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-card text-center text-caption leading-tight text-foreground transition-colors',
178
+ 'hover:border-accent',
179
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
180
+ 'data-[state=checked]:border-accent data-[state=checked]:ring-2 data-[state=checked]:ring-accent',
181
+ option.image == null && 'px-1 data-[state=checked]:bg-accent/10',
182
+ 'disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-border',
183
+ )}
184
+ >
185
+ {option.image ?? option.label}
186
+ </RadioGroup.Item>
187
+ );
188
+ return option.image != null ? <Tooltip content={option.label}>{item}</Tooltip> : item;
189
+ }
@@ -48,4 +48,39 @@ describe('CopyButton', () => {
48
48
  expect(success).not.toHaveBeenCalled();
49
49
  success.mockRestore();
50
50
  });
51
+
52
+ test('`onCopy` owns the write — the clipboard is never touched, and the ✓ and toast still fire', async () => {
53
+ const writeText = stubClipboard();
54
+ const success = spyOn(toast, 'success').mockImplementation(() => '1');
55
+ const onCopy = mock((_: string) => Promise.resolve(true));
56
+ const onCopied = mock((_: string) => {});
57
+
58
+ const { getByRole } = render(
59
+ <CopyButton value='s3cret' label='Copy notes' onCopy={onCopy} onCopied={onCopied} confirmToast='Copied — clears in 45s' />,
60
+ );
61
+ fireEvent.click(getByRole('button'));
62
+
63
+ await waitFor(() => expect(onCopied).toHaveBeenCalledWith('s3cret'));
64
+ expect(onCopy).toHaveBeenCalledWith('s3cret');
65
+ expect(writeText).not.toHaveBeenCalled();
66
+ expect(success).toHaveBeenCalledWith('Copied — clears in 45s');
67
+ expect(getByRole('button').getAttribute('aria-label')).toBe('Copied');
68
+ success.mockRestore();
69
+ });
70
+
71
+ test('`onCopy` resolving false is a failed copy — onError, no toast, no ✓', async () => {
72
+ stubClipboard();
73
+ const success = spyOn(toast, 'success').mockImplementation(() => '1');
74
+ const onError = mock(() => {});
75
+
76
+ const { getByRole } = render(
77
+ <CopyButton value='x' label='Copy notes' onCopy={() => Promise.resolve(false)} onError={onError} />,
78
+ );
79
+ fireEvent.click(getByRole('button'));
80
+
81
+ await waitFor(() => expect(onError).toHaveBeenCalled());
82
+ expect(success).not.toHaveBeenCalled();
83
+ expect(getByRole('button').getAttribute('aria-label')).toBe('Copy notes');
84
+ success.mockRestore();
85
+ });
51
86
  });
@@ -1,7 +1,7 @@
1
1
  import { Check, Copy } from 'lucide-react';
2
2
  import type { MouseEvent, ReactNode } from 'react';
3
3
  import { toast } from 'sonner';
4
- import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
4
+ import { type ClipboardWriter, useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
5
5
  import { cn } from '../lib/cn.js';
6
6
  import { Button } from './Button.js';
7
7
  import type { TooltipPlacement } from './Tooltip.js';
@@ -29,6 +29,14 @@ export interface CopyButtonProps {
29
29
  copyIcon?: ReactNode;
30
30
  copiedIcon?: ReactNode;
31
31
  iconSize?: number;
32
+ /**
33
+ * Take over the clipboard write — resolve `false` for a failed copy. The ✓, the
34
+ * toast, `onCopied` and `onError` all still happen here. The vault copies a secret
35
+ * through a writer that wipes the clipboard ~45s later, which is why it can use
36
+ * this button instead of a hand-rolled one (task 2402; `SecretInput` has the same
37
+ * `onCopy` seam).
38
+ */
39
+ onCopy?: ClipboardWriter;
32
40
  onCopied?: (text: string) => void;
33
41
  onError?: () => void;
34
42
  /** Stop the click bubbling (e.g. inside a clickable row). */
@@ -55,6 +63,7 @@ export function CopyButton({
55
63
  copyIcon,
56
64
  copiedIcon,
57
65
  iconSize = 16,
66
+ onCopy,
58
67
  onCopied,
59
68
  onError,
60
69
  stopPropagation,
@@ -64,7 +73,7 @@ export function CopyButton({
64
73
  className,
65
74
  disabled,
66
75
  }: CopyButtonProps) {
67
- const { copied, copy } = useCopyToClipboard(resetMs);
76
+ const { copied, copy } = useCopyToClipboard(resetMs, onCopy);
68
77
 
69
78
  const onClick = async (e: MouseEvent<HTMLButtonElement>) => {
70
79
  if (stopPropagation) e.stopPropagation();
@@ -203,6 +203,22 @@ describe('DataTable', () => {
203
203
  expect(getAllByRole('button', { name: 'Row actions' }).length).toBe(6);
204
204
  });
205
205
 
206
+ test('rowMenuLabel names each row\'s kebab after its row, in every layer', () => {
207
+ const cols: ColDef<Record<string, unknown>>[] = [{ key: 'task', label: 'Task', type: 'text' }];
208
+ const { getAllByRole, queryAllByRole } = render(
209
+ <DataTable
210
+ columns={cols}
211
+ data={[{ task: 't1' }, { task: 't2' }]}
212
+ rowMenu={() => [{ key: 'view', label: 'View details', onClick: () => {} }]}
213
+ rowMenuLabel={(row) => `More for ${row.task}`}
214
+ />,
215
+ );
216
+ // grid + tablet list + phone cards.
217
+ expect(getAllByRole('button', { name: 'More for t1' }).length).toBe(3);
218
+ expect(getAllByRole('button', { name: 'More for t2' }).length).toBe(3);
219
+ expect(queryAllByRole('button', { name: 'Row actions' }).length).toBe(0);
220
+ });
221
+
206
222
  test('mono-id cells mid-truncate long ids and keep the full value on the tooltip', async () => {
207
223
  const id = 'tsk_01KXFRZ7RP1A4F7J993HJXETKJ';
208
224
  const cols: ColDef<Record<string, unknown>>[] = [{ key: 'id', label: 'Id', type: 'mono-id' }];