@barqjs/aria 0.2.0-next.0 → 0.2.0-next.1

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 (78) hide show
  1. package/README.md +24 -13
  2. package/package.json +127 -37
  3. package/src/autocomplete.tsx +581 -0
  4. package/src/breadcrumbs.tsx +21 -20
  5. package/src/button.tsx +151 -25
  6. package/src/calendar.tsx +1019 -92
  7. package/src/checkbox.tsx +214 -52
  8. package/src/collections.ts +88 -5
  9. package/src/color.ts +1580 -23
  10. package/src/colorpicker.tsx +698 -153
  11. package/src/colorswatchpicker.tsx +240 -0
  12. package/src/combobox.tsx +635 -113
  13. package/src/command.tsx +78 -59
  14. package/src/date.ts +31 -9
  15. package/src/datefield.tsx +1451 -336
  16. package/src/datepicker.tsx +465 -114
  17. package/src/dialog.tsx +302 -115
  18. package/src/disclosure.tsx +81 -29
  19. package/src/dnd/clipboard.ts +125 -0
  20. package/src/dnd/collection.ts +1265 -0
  21. package/src/dnd/data.ts +409 -0
  22. package/src/dnd/drag-drop.ts +801 -0
  23. package/src/dnd/index.ts +133 -0
  24. package/src/dnd/manager.ts +639 -0
  25. package/src/dnd/strings.ts +1279 -0
  26. package/src/dnd/targets.ts +726 -0
  27. package/src/dnd/types.ts +212 -0
  28. package/src/dom.ts +3 -6
  29. package/src/drag-and-drop.tsx +669 -0
  30. package/src/dropzone.tsx +208 -0
  31. package/src/file-trigger.tsx +103 -0
  32. package/src/form.tsx +18 -18
  33. package/src/gridlist.tsx +912 -121
  34. package/src/group.tsx +146 -0
  35. package/src/index.ts +402 -0
  36. package/src/interactions/focus-events.ts +13 -5
  37. package/src/interactions/keyboard.ts +195 -2
  38. package/src/interactions/modality.ts +18 -6
  39. package/src/interactions/open-link.ts +46 -13
  40. package/src/interactions/press.ts +35 -18
  41. package/src/label.ts +18 -6
  42. package/src/link.tsx +146 -50
  43. package/src/listbox.tsx +615 -89
  44. package/src/live.ts +4 -0
  45. package/src/menu.tsx +182 -89
  46. package/src/menubar.tsx +21 -17
  47. package/src/navigation-tree.tsx +357 -0
  48. package/src/numberfield.tsx +164 -60
  49. package/src/overlay-arrow.tsx +157 -0
  50. package/src/overlays.ts +364 -62
  51. package/src/platform.ts +2 -1
  52. package/src/preview-trigger.tsx +582 -0
  53. package/src/progress-bar-context.ts +15 -0
  54. package/src/questionnaire.tsx +109 -104
  55. package/src/radio.tsx +101 -27
  56. package/src/select.tsx +225 -145
  57. package/src/selection-indicator.tsx +74 -0
  58. package/src/selection.ts +73 -16
  59. package/src/shared-element-transition.tsx +316 -0
  60. package/src/sheet.tsx +1461 -0
  61. package/src/slider.tsx +139 -44
  62. package/src/switch.tsx +47 -21
  63. package/src/table.tsx +0 -0
  64. package/src/tabs.tsx +198 -89
  65. package/src/tag.tsx +217 -32
  66. package/src/textarea.tsx +186 -0
  67. package/src/textfield.tsx +103 -37
  68. package/src/toast-components.tsx +589 -0
  69. package/src/toggle-button-group.tsx +175 -0
  70. package/src/toggle-input.tsx +38 -0
  71. package/src/toggle.ts +68 -5
  72. package/src/tokenfield.tsx +1673 -0
  73. package/src/toolbar.tsx +15 -10
  74. package/src/tooltip.tsx +46 -29
  75. package/src/tree.tsx +2075 -0
  76. package/src/utils.ts +30 -1
  77. package/src/validation.ts +79 -22
  78. package/src/virtualizer.tsx +186 -23
@@ -0,0 +1,589 @@
1
+ /**
2
+ * The toast region and its parts, headless, over the queue in `toast.ts`.
3
+ *
4
+ * The queue decides what is shown and for how long; what is here is what a
5
+ * screen reader and a keyboard make of it:
6
+ *
7
+ * - **The region is a landmark**, named by how many notifications it holds,
8
+ * and it is only in the document while it holds one. It is marked top layer,
9
+ * so a modal opened later neither hides it nor counts a press on it as a
10
+ * press outside.
11
+ * - **Each toast is a non-modal `alertdialog`** that can be tabbed to, named by
12
+ * its title and described by its description. Its content is a
13
+ * `role="alert"`, hidden for the first render and shown after it: NVDA
14
+ * announces an alert only when it APPEARS in the tree, not when it is
15
+ * rendered there already visible.
16
+ * - **The clocks stop while the user is in the region**, pointer or focus. A
17
+ * toast that expires while being read or while its button is focused was
18
+ * never available to the user.
19
+ * - **Focus is never stranded.** A focused toast that goes hands focus to its
20
+ * neighbour, newer first; the last one going gives focus back to where it
21
+ * was before the region took it.
22
+ */
23
+
24
+ import {
25
+ cells,
26
+ type Accessor,
27
+ type Child,
28
+ createContext,
29
+ createEffect,
30
+ createSignal,
31
+ For,
32
+ getContext,
33
+ isBlock,
34
+ omit,
35
+ onCleanup,
36
+ onSettled,
37
+ provide,
38
+ Show,
39
+ untrack,
40
+ } from "@barqjs/core";
41
+ import { isServer, Portal } from "@barqjs/web";
42
+ import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
43
+ import { Button, type ButtonComponentProps } from "./button.tsx";
44
+ import { focusWithoutScrolling, targetElement } from "./dom.ts";
45
+ import { focusRing } from "./focus.ts";
46
+ import { useLocale } from "./i18n.ts";
47
+ import { focusWithin } from "./interactions/focus-events.ts";
48
+ import { hover } from "./interactions/hover.ts";
49
+ import { getInteractionModality } from "./interactions/modality.ts";
50
+ import type { ElementRef, PressEvent } from "./interactions/press.ts";
51
+ import { portalContainer, topLayerProps, usePortalTarget } from "./overlays.ts";
52
+ import type { Toast as QueuedToast, ToastId, ToastQueue } from "./toast.ts";
53
+ import {
54
+ access,
55
+ type DOMProps,
56
+ filterDOMProps,
57
+ fromProps,
58
+ id,
59
+ type MaybeAccessor,
60
+ mergeProps,
61
+ type StyleProps,
62
+ styleProps,
63
+ } from "./utils.ts";
64
+
65
+ const PAUSE_POINTER = "pointer";
66
+ const PAUSE_FOCUS = "focus";
67
+
68
+ function notifications(count: number): string {
69
+ return count === 1 ? "1 notification." : `${count} notifications.`;
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // The region
74
+ // ---------------------------------------------------------------------------
75
+
76
+ export interface ToastRegionOptions {
77
+ ref: ElementRef;
78
+ /** @default "N notifications." */
79
+ "aria-label"?: MaybeAccessor<string | undefined>;
80
+ "aria-labelledby"?: MaybeAccessor<string | undefined>;
81
+ "aria-describedby"?: MaybeAccessor<string | undefined>;
82
+ }
83
+
84
+ export interface ToastRegionResult {
85
+ regionProps: DOMProps;
86
+ /** Whether the pointer is over the region. */
87
+ isHovered: Accessor<boolean>;
88
+ }
89
+
90
+ export function toastRegion<D>(
91
+ options: ToastRegionOptions,
92
+ queue: ToastQueue<D>,
93
+ ): ToastRegionResult {
94
+ const count = (): number => queue.toasts().length;
95
+
96
+ const { hoverProps, isHovered } = hover({
97
+ onHoverStart: () => queue.pause(PAUSE_POINTER),
98
+ onHoverEnd: () => queue.resume(PAUSE_POINTER),
99
+ });
100
+
101
+ // Where focus was before it came into the region, to give it back to.
102
+ let lastFocused: HTMLElement | null = null;
103
+ // Which toast, by its place in the list, holds focus; -1 for none.
104
+ let focusedIndex = -1;
105
+
106
+ const giveBack = (): void => {
107
+ const element = lastFocused;
108
+ lastFocused = null;
109
+ if (element === null || !element.isConnected) return;
110
+ if (getInteractionModality() === "pointer") focusWithoutScrolling(element);
111
+ else element.focus();
112
+ };
113
+
114
+ const { focusWithinProps } = focusWithin({
115
+ onFocusWithin: (event) => {
116
+ queue.pause(PAUSE_FOCUS);
117
+ lastFocused = event.relatedTarget instanceof HTMLElement ? event.relatedTarget : null;
118
+ },
119
+ onBlurWithin: () => {
120
+ queue.resume(PAUSE_FOCUS);
121
+ lastFocused = null;
122
+ focusedIndex = -1;
123
+ },
124
+ });
125
+
126
+ const toastElements = (): HTMLElement[] => {
127
+ const region = untrack(() => access(options.ref)) as HTMLElement | null;
128
+ return region === null ? [] : [...region.querySelectorAll<HTMLElement>('[role="alertdialog"]')];
129
+ };
130
+
131
+ if (!isServer) {
132
+ let previous: readonly ToastId[] = untrack(() => queue.toasts().map((each) => each.id));
133
+ createEffect(
134
+ () => queue.toasts().map((each) => each.id),
135
+ (ids) => {
136
+ const before = previous;
137
+ previous = ids;
138
+ if (ids.length === 0) {
139
+ // The last one went while the user was in the region.
140
+ if (focusedIndex !== -1) giveBack();
141
+ focusedIndex = -1;
142
+ return;
143
+ }
144
+ if (focusedIndex === -1) return;
145
+ const focusedId = before[focusedIndex];
146
+ if (focusedId === undefined || ids.includes(focusedId)) return;
147
+
148
+ // A pointer user is somewhere else entirely; focus held in the region
149
+ // would hold every clock in it stopped.
150
+ if (getInteractionModality() === "pointer" && lastFocused?.isConnected === true) {
151
+ giveBack();
152
+ return;
153
+ }
154
+ // The queue keeps the newest last, and the newer neighbour is the one
155
+ // to land on: it is the one most likely still being read.
156
+ const elements = toastElements();
157
+ let newer: number | null = null;
158
+ for (let at = focusedIndex + 1; at < before.length; at++) {
159
+ const kept = before[at];
160
+ if (kept !== undefined && ids.includes(kept)) {
161
+ newer = ids.indexOf(kept);
162
+ break;
163
+ }
164
+ }
165
+ let older: number | null = null;
166
+ for (let at = focusedIndex - 1; at >= 0; at--) {
167
+ const kept = before[at];
168
+ if (kept !== undefined && ids.includes(kept)) {
169
+ older = ids.indexOf(kept);
170
+ break;
171
+ }
172
+ }
173
+ const next = elements[newer ?? older ?? 0];
174
+ if (next !== undefined) focusWithoutScrolling(next);
175
+ },
176
+ );
177
+
178
+ // The region leaving with focus in it, when its owner unmounts it.
179
+ onCleanup(() => {
180
+ if (focusedIndex !== -1) giveBack();
181
+ });
182
+ }
183
+
184
+ return {
185
+ isHovered,
186
+ regionProps: mergeProps(hoverProps, focusWithinProps, topLayerProps(), {
187
+ role: "region",
188
+ tabIndex: -1,
189
+ "aria-label": () => access(options["aria-label"]) ?? notifications(count()),
190
+ "aria-labelledby": () => access(options["aria-labelledby"]),
191
+ "aria-describedby": () => access(options["aria-describedby"]),
192
+ // Every focus change, not only the first: focus-within fires once on
193
+ // the way in.
194
+ onFocusIn: (event: FocusEvent) => {
195
+ const target = targetElement(event)?.closest('[role="alertdialog"]') ?? null;
196
+ focusedIndex = target === null ? -1 : toastElements().indexOf(target as HTMLElement);
197
+ },
198
+ }),
199
+ };
200
+ }
201
+
202
+ // ---------------------------------------------------------------------------
203
+ // A toast
204
+ //
205
+ // `ToastRoot` and `ToastBody` rather than React Aria's `Toast` and
206
+ // `ToastContent`: `toast.ts` already exports those two names as the types of a
207
+ // queued toast and of its text.
208
+ // ---------------------------------------------------------------------------
209
+
210
+ export interface ToastRootOptions<D> {
211
+ toast: MaybeAccessor<QueuedToast<D>>;
212
+ "aria-label"?: MaybeAccessor<string | undefined>;
213
+ "aria-labelledby"?: MaybeAccessor<string | undefined>;
214
+ "aria-describedby"?: MaybeAccessor<string | undefined>;
215
+ }
216
+
217
+ export interface ToastRootResult {
218
+ /** The toast: a non-modal alert dialog. */
219
+ toastProps: DOMProps;
220
+ /** Its message: the live alert. */
221
+ contentProps: DOMProps;
222
+ titleProps: DOMProps;
223
+ descriptionProps: DOMProps;
224
+ /** Options for a `<Button>`, not props for an element. */
225
+ closeButtonProps: DOMProps;
226
+ /** Call from a description element while it is mounted, so the toast points at it. */
227
+ describe(has: boolean): void;
228
+ }
229
+
230
+ export function toastRoot<D>(options: ToastRootOptions<D>, queue: ToastQueue<D>): ToastRootResult {
231
+ const titleId = id();
232
+ const descriptionId = id();
233
+ const [described, setDescribed] = createSignal(false, { ownedWrite: true });
234
+ const [isVisible, setVisible] = createSignal(false, { ownedWrite: true });
235
+ onSettled(() => {
236
+ setVisible(true);
237
+ });
238
+
239
+ return {
240
+ describe: setDescribed,
241
+ toastProps: mergeProps(filterDOMProps(options, { labelable: true }), {
242
+ role: "alertdialog",
243
+ "aria-modal": "false",
244
+ "aria-labelledby": () => access(options["aria-labelledby"]) ?? titleId(),
245
+ "aria-describedby": () =>
246
+ access(options["aria-describedby"]) ?? (described() ? descriptionId() : undefined),
247
+ tabIndex: 0,
248
+ }),
249
+ contentProps: {
250
+ role: "alert",
251
+ "aria-atomic": "true",
252
+ "aria-hidden": () => (isVisible() ? undefined : "true"),
253
+ },
254
+ titleProps: { id: titleId },
255
+ descriptionProps: { id: descriptionId },
256
+ closeButtonProps: {
257
+ "aria-label": "Close",
258
+ onPress: () => queue.dismiss(access(options.toast).id),
259
+ },
260
+ };
261
+ }
262
+
263
+ // ---------------------------------------------------------------------------
264
+ // Components
265
+ // ---------------------------------------------------------------------------
266
+
267
+ interface RegionValue {
268
+ queue: ToastQueue;
269
+ }
270
+
271
+ interface ToastValue {
272
+ toast: Accessor<QueuedToast>;
273
+ contentProps: DOMProps;
274
+ titleProps: DOMProps;
275
+ descriptionProps: DOMProps;
276
+ closeButtonProps: DOMProps;
277
+ describe(has: boolean): void;
278
+ }
279
+
280
+ const RegionContext = createContext<RegionValue | null>(null);
281
+ const ToastRootContext = createContext<ToastValue | null>(null);
282
+
283
+ function useRegion(): RegionValue {
284
+ const value = getContext(RegionContext);
285
+ if (value === null || value === undefined) {
286
+ throw new Error("This must be rendered inside a ToastRegion.");
287
+ }
288
+ return value;
289
+ }
290
+
291
+ /** The enclosing {@link ToastRoot}'s toast and the props its parts carry. */
292
+ export function useToastRoot(): ToastValue {
293
+ const value = getContext(ToastRootContext);
294
+ if (value === null || value === undefined) {
295
+ throw new Error("This must be rendered inside a ToastRoot.");
296
+ }
297
+ return value;
298
+ }
299
+
300
+ type ToastRender<D> = (toast: QueuedToast<D>) => Child;
301
+
302
+ export interface ToastRegionComponentProps<D> extends StyleProps {
303
+ queue: ToastQueue<D>;
304
+ /** How one toast renders, or a {@link ToastList} with that callback inside other markup. */
305
+ children: ToastRender<D> | Child;
306
+ /** @default "N notifications." */
307
+ "aria-label"?: string;
308
+ "aria-labelledby"?: string;
309
+ "aria-describedby"?: string;
310
+ ref?: RefTarget<HTMLDivElement>;
311
+ }
312
+
313
+ /** The callback among the children, when they are one rather than markup. */
314
+ function renderCallback<D>(children: unknown): ToastRender<D> | null {
315
+ if (typeof children !== "function") return null;
316
+ if (children.length > 0) return children as ToastRender<D>;
317
+ if (isBlock(children)) return null;
318
+ const inner: unknown = (children as () => unknown)();
319
+ return typeof inner === "function" && inner.length > 0 ? (inner as ToastRender<D>) : null;
320
+ }
321
+
322
+ /**
323
+ * The toast as its callback sees it: each field read from the queue's current
324
+ * copy, so an update in place reaches the markup without building it again.
325
+ */
326
+ function liveToast(current: Accessor<QueuedToast>): QueuedToast {
327
+ return new Proxy({} as QueuedToast, {
328
+ get: (_target, key) => (current() as unknown as Record<PropertyKey, unknown>)[key],
329
+ has: (_target, key) => key in current(),
330
+ ownKeys: () => Reflect.ownKeys(current()),
331
+ getOwnPropertyDescriptor: (_target, key) => {
332
+ const descriptor = Reflect.getOwnPropertyDescriptor(current(), key);
333
+ return descriptor === undefined ? undefined : { ...descriptor, configurable: true };
334
+ },
335
+ });
336
+ }
337
+
338
+ /**
339
+ * ```tsx
340
+ * const queue = toastQueue<{ title: string }>();
341
+ * <ToastRegion queue={queue}>
342
+ * {(toast) => (
343
+ * <ToastRoot toast={toast}>
344
+ * <ToastBody>
345
+ * <ToastTitle>{toast.title}</ToastTitle>
346
+ * </ToastBody>
347
+ * <ToastCloseButton>×</ToastCloseButton>
348
+ * </ToastRoot>
349
+ * )}
350
+ * </ToastRegion>
351
+ * ```
352
+ */
353
+ export function ToastRegion<D>(props: ToastRegionComponentProps<D>) {
354
+ const target = usePortalTarget();
355
+ const queue = props.queue as ToastQueue;
356
+ const value: RegionValue = { queue };
357
+
358
+ return (
359
+ <Show when={queue.toasts().length > 0}>
360
+ <Portal mount={portalContainer(target)}>
361
+ <RegionProvider value={value}>
362
+ <RegionBody {...props} />
363
+ </RegionProvider>
364
+ </Portal>
365
+ </Show>
366
+ );
367
+ }
368
+
369
+ function RegionProvider(props: { value: RegionValue; children?: Child }) {
370
+ return provide(
371
+ RegionContext,
372
+ () => props.value,
373
+ () => props.children as unknown,
374
+ );
375
+ }
376
+
377
+ /** Inside the `<Show>`, so leaving the document is what disposes it. */
378
+ function RegionBody<D>(props: ToastRegionComponentProps<D>) {
379
+ const domRef = makeRef<HTMLDivElement>();
380
+ const { queue } = useRegion();
381
+ const locale = useLocale();
382
+ const { regionProps, isHovered } = toastRegion(
383
+ {
384
+ ref: domRef,
385
+ "aria-label": () => props["aria-label"],
386
+ "aria-labelledby": () => props["aria-labelledby"],
387
+ "aria-describedby": () => props["aria-describedby"],
388
+ },
389
+ queue,
390
+ );
391
+ const { focusProps, isFocused, isFocusVisible } = focusRing();
392
+ const render = renderCallback<unknown>(cells(props).children);
393
+
394
+ const elementProps = mergeProps(
395
+ regionProps,
396
+ focusProps,
397
+ filterDOMProps(fromProps(cells(props)), { global: true }),
398
+ styleProps(cells(props)),
399
+ {
400
+ dir: () => locale().direction,
401
+ "data-hovered": isHovered,
402
+ "data-focused": isFocused,
403
+ "data-focus-visible": isFocusVisible,
404
+ "data-testid": () => props["data-testid"],
405
+ },
406
+ );
407
+
408
+ return (
409
+ <div {...elementProps} ref={mergeRefs(domRef.set, props.ref)}>
410
+ {render === null ? (
411
+ props.children
412
+ ) : (
413
+ <ToastList style={{ display: "contents" }}>{render}</ToastList>
414
+ )}
415
+ </div>
416
+ );
417
+ }
418
+
419
+ export interface ToastListComponentProps<D> extends StyleProps {
420
+ children: ToastRender<D>;
421
+ ref?: RefTarget<HTMLOListElement>;
422
+ }
423
+
424
+ /** The toasts, newest last, as a list. */
425
+ export function ToastList<D>(props: ToastListComponentProps<D>) {
426
+ const { queue } = useRegion();
427
+ const { hoverProps, isHovered } = hover({});
428
+ const render = renderCallback<unknown>(cells(props).children);
429
+
430
+ const elementProps = mergeProps(
431
+ hoverProps,
432
+ filterDOMProps(fromProps(cells(props)), { global: true }),
433
+ styleProps(cells(props)),
434
+ { "data-hovered": isHovered, "data-testid": () => props["data-testid"] },
435
+ );
436
+
437
+ return (
438
+ <ol {...elementProps} ref={mergeRefs(props.ref)}>
439
+ <For each={queue.toasts()} keyed={(each: QueuedToast) => each.id}>
440
+ {(each: Accessor<QueuedToast>) => (
441
+ <li style={{ display: "contents" }}>{render?.(liveToast(each))}</li>
442
+ )}
443
+ </For>
444
+ </ol>
445
+ );
446
+ }
447
+
448
+ export interface ToastRootComponentProps<D> extends StyleProps {
449
+ toast: QueuedToast<D>;
450
+ children?: Child;
451
+ "aria-label"?: string;
452
+ "aria-labelledby"?: string;
453
+ "aria-describedby"?: string;
454
+ ref?: RefTarget<HTMLDivElement>;
455
+ }
456
+
457
+ /** One toast: a non-modal alert dialog that can be tabbed to. */
458
+ export function ToastRoot<D>(props: ToastRootComponentProps<D>) {
459
+ const { queue } = useRegion();
460
+ const result = toastRoot<unknown>(
461
+ {
462
+ toast: () => props.toast,
463
+ "aria-label": () => props["aria-label"],
464
+ "aria-labelledby": () => props["aria-labelledby"],
465
+ "aria-describedby": () => props["aria-describedby"],
466
+ },
467
+ queue,
468
+ );
469
+ const { focusProps, isFocused, isFocusVisible } = focusRing();
470
+
471
+ const value: ToastValue = {
472
+ toast: () => props.toast,
473
+ contentProps: result.contentProps,
474
+ titleProps: result.titleProps,
475
+ descriptionProps: result.descriptionProps,
476
+ closeButtonProps: result.closeButtonProps,
477
+ describe: (has) => result.describe(has),
478
+ };
479
+
480
+ const elementProps = mergeProps(
481
+ result.toastProps,
482
+ focusProps,
483
+ filterDOMProps(fromProps(cells(props)), { global: true }),
484
+ styleProps(cells(props)),
485
+ {
486
+ "data-focused": isFocused,
487
+ "data-focus-visible": isFocusVisible,
488
+ "data-kind": () => props.toast.kind,
489
+ "data-leaving": () => props.toast.isLeaving === true,
490
+ "data-testid": () => props["data-testid"],
491
+ },
492
+ );
493
+
494
+ return (
495
+ <div {...elementProps} ref={mergeRefs(props.ref)}>
496
+ <ToastRootProvider value={value}>{props.children}</ToastRootProvider>
497
+ </div>
498
+ );
499
+ }
500
+
501
+ function ToastRootProvider(props: { value: ToastValue; children?: Child }) {
502
+ return provide(
503
+ ToastRootContext,
504
+ () => props.value,
505
+ () => props.children as unknown,
506
+ );
507
+ }
508
+
509
+ export interface ToastPartComponentProps extends StyleProps {
510
+ children?: Child;
511
+ ref?: RefTarget<HTMLDivElement>;
512
+ }
513
+
514
+ /** The message: what is announced when the toast appears. */
515
+ export function ToastBody(props: ToastPartComponentProps) {
516
+ const held = useToastRoot();
517
+ return (
518
+ <div
519
+ {...mergeProps(
520
+ held.contentProps,
521
+ filterDOMProps(fromProps(cells(props)), { global: true }),
522
+ styleProps(cells(props)),
523
+ { "data-testid": () => props["data-testid"] },
524
+ )}
525
+ ref={mergeRefs(props.ref)}
526
+ >
527
+ {props.children}
528
+ </div>
529
+ );
530
+ }
531
+
532
+ /** What names the toast. */
533
+ export function ToastTitle(props: ToastPartComponentProps) {
534
+ const held = useToastRoot();
535
+ return (
536
+ <div
537
+ {...mergeProps(
538
+ held.titleProps,
539
+ filterDOMProps(fromProps(cells(props)), { global: true, id: false }),
540
+ styleProps(cells(props)),
541
+ { "data-testid": () => props["data-testid"] },
542
+ )}
543
+ ref={mergeRefs(props.ref)}
544
+ >
545
+ {props.children}
546
+ </div>
547
+ );
548
+ }
549
+
550
+ /** What describes it. Rendering one is what makes the toast point at it. */
551
+ export function ToastDescription(props: ToastPartComponentProps) {
552
+ const held = useToastRoot();
553
+ held.describe(true);
554
+ onCleanup(() => held.describe(false));
555
+ return (
556
+ <div
557
+ {...mergeProps(
558
+ held.descriptionProps,
559
+ filterDOMProps(fromProps(cells(props)), { global: true, id: false }),
560
+ styleProps(cells(props)),
561
+ { "data-testid": () => props["data-testid"] },
562
+ )}
563
+ ref={mergeRefs(props.ref)}
564
+ >
565
+ {props.children}
566
+ </div>
567
+ );
568
+ }
569
+
570
+ export interface ToastCloseButtonComponentProps extends Omit<ButtonComponentProps, "onPress"> {
571
+ /** Told after the toast is dismissed. */
572
+ onPress?: ButtonComponentProps["onPress"];
573
+ }
574
+
575
+ /** A button that dismisses the enclosing toast. Named "Close" unless told otherwise. */
576
+ export function ToastCloseButton(props: ToastCloseButtonComponentProps) {
577
+ const held = useToastRoot();
578
+ const { queue } = useRegion();
579
+ return (
580
+ <Button
581
+ {...omit(props, "onPress", "aria-label")}
582
+ aria-label={props["aria-label"] ?? "Close"}
583
+ onPress={(event: PressEvent) => {
584
+ queue.dismiss(held.toast().id);
585
+ props.onPress?.(event);
586
+ }}
587
+ />
588
+ );
589
+ }