@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
package/src/link.tsx CHANGED
@@ -8,14 +8,21 @@
8
8
  * looking at rather than treating every activation the same.
9
9
  */
10
10
 
11
- import { type Accessor, type Child, type Incoming } from "@barqjs/core";
11
+ import { cells, getContext, Show, type Accessor, type Child } from "@barqjs/core";
12
12
  import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
13
13
  import { focusRing } from "./focus.ts";
14
14
  import { focusable, type FocusableOptions } from "./interactions/focusable.ts";
15
- import { hover } from "./interactions/hover.ts";
16
- import { handleLinkClick, router, syntheticLinkProps } from "./interactions/open-link.ts";
15
+ import { hover, type HoverEvent } from "./interactions/hover.ts";
16
+ import {
17
+ handleLinkClick,
18
+ router,
19
+ type RouterOptions,
20
+ syntheticLinkProps,
21
+ } from "./interactions/open-link.ts";
17
22
  import { press, type ElementRef, type PressEvent } from "./interactions/press.ts";
18
23
  import { label as labelHook } from "./label.ts";
24
+ import { ProgressBarContext } from "./progress-bar-context.ts";
25
+
19
26
  import { numberFormatter } from "./i18n.ts";
20
27
  import {
21
28
  access,
@@ -27,6 +34,7 @@ import {
27
34
  mergeProps,
28
35
  type StyleProps,
29
36
  styleProps,
37
+ triggerSlot,
30
38
  } from "./utils.ts";
31
39
 
32
40
  export interface LinkOptions extends FocusableOptions {
@@ -39,7 +47,13 @@ export interface LinkOptions extends FocusableOptions {
39
47
  download?: MaybeAccessor<boolean | string | undefined>;
40
48
  ping?: MaybeAccessor<string | undefined>;
41
49
  referrerPolicy?: MaybeAccessor<string | undefined>;
50
+ /** Handed to the router in scope along with the href. */
51
+ routerOptions?: MaybeAccessor<RouterOptions>;
42
52
  "aria-current"?: MaybeAccessor<boolean | string | undefined>;
53
+ /** From a trigger the link stands in for: a preview, a menu. */
54
+ "aria-haspopup"?: MaybeAccessor<boolean | string | undefined>;
55
+ "aria-expanded"?: MaybeAccessor<boolean | undefined>;
56
+ "aria-controls"?: MaybeAccessor<string | undefined>;
43
57
  "aria-label"?: MaybeAccessor<string | undefined>;
44
58
  "aria-labelledby"?: MaybeAccessor<string | undefined>;
45
59
  "aria-describedby"?: MaybeAccessor<string | undefined>;
@@ -62,6 +76,29 @@ export function link(options: LinkOptions, ref?: ElementRef): LinkResult {
62
76
  const { pressProps, isPressed } = press({ ...options, ref });
63
77
  const { focusableProps } = focusable(options, ref);
64
78
  const navigate = router();
79
+ // The href a client router renders for the path: a base path, a locale
80
+ // prefix. The click still hands the router the path it was given.
81
+ const routedHref = (): string | undefined => {
82
+ const href = access(options.href);
83
+ return href === undefined ? undefined : navigate.href(href);
84
+ };
85
+ // The link's `data-*` shape, for an element that is not an anchor: none on
86
+ // an anchor, which has the real attributes, and none while disabled, which
87
+ // must not navigate.
88
+ const synthetic = (): Record<string, unknown> =>
89
+ elementType() === "a" || isDisabled()
90
+ ? {}
91
+ : syntheticLinkProps(
92
+ {
93
+ href: access(options.href),
94
+ target: access(options.target),
95
+ rel: access(options.rel),
96
+ download: access(options.download),
97
+ ping: access(options.ping),
98
+ referrerPolicy: access(options.referrerPolicy),
99
+ },
100
+ navigate,
101
+ );
65
102
 
66
103
  const roleProps: DOMProps = {
67
104
  // Anything that is not an `<a href>` has to say what it is, and be
@@ -76,17 +113,27 @@ export function link(options: LinkOptions, ref?: ElementRef): LinkResult {
76
113
  filterDOMProps(options, { labelable: true, isLink: true }),
77
114
  // The `data-href` shape, so a non-anchor element can still be opened by
78
115
  // the router or by a middle click.
79
- elementType() === "a" ? {} : syntheticLinkProps(options as never),
116
+ {
117
+ "data-href": () => synthetic()["data-href"],
118
+ "data-target": () => synthetic()["data-target"],
119
+ "data-rel": () => synthetic()["data-rel"],
120
+ "data-download": () => synthetic()["data-download"],
121
+ "data-ping": () => synthetic()["data-ping"],
122
+ "data-referrer-policy": () => synthetic()["data-referrer-policy"],
123
+ },
80
124
  focusableProps,
81
125
  pressProps,
82
126
  roleProps,
83
127
  {
84
128
  // A disabled link must not navigate, and `<a>` has no `disabled`.
85
- href: () => (isDisabled() ? undefined : access(options.href)),
129
+ href: () => (isDisabled() ? undefined : routedHref()),
86
130
  "aria-disabled": () => isDisabled() || undefined,
87
131
  "aria-current": () => access(options["aria-current"]),
132
+ "aria-haspopup": () => access(options["aria-haspopup"]),
133
+ "aria-expanded": () => access(options["aria-expanded"]),
134
+ "aria-controls": () => access(options["aria-controls"]),
88
135
  onClick: (event: MouseEvent) => {
89
- handleLinkClick(event, access(options.href), navigate);
136
+ handleLinkClick(event, access(options.href), navigate, access(options.routerOptions));
90
137
  },
91
138
  },
92
139
  ),
@@ -232,45 +279,93 @@ export interface LinkComponentProps extends StyleProps {
232
279
  target?: string;
233
280
  rel?: string;
234
281
  download?: boolean | string;
282
+ ping?: string;
283
+ referrerPolicy?: string;
284
+ routerOptions?: RouterOptions;
235
285
  isDisabled?: boolean;
236
286
  autoFocus?: boolean;
237
287
  "aria-label"?: string;
238
288
  "aria-labelledby"?: string;
239
289
  "aria-current"?: boolean | string;
240
- ref?: RefTarget<HTMLAnchorElement>;
290
+ ref?: RefTarget<HTMLAnchorElement | HTMLSpanElement>;
241
291
  onPress?: (event: PressEvent) => void;
292
+ onPressStart?: (event: PressEvent) => void;
293
+ onPressEnd?: (event: PressEvent) => void;
294
+ onPressChange?: (isPressed: boolean) => void;
295
+ onHoverStart?: (event: HoverEvent) => void;
296
+ onHoverEnd?: (event: HoverEvent) => void;
297
+ onHoverChange?: (isHovered: boolean) => void;
298
+ onFocus?: (event: FocusEvent) => void;
299
+ onBlur?: (event: FocusEvent) => void;
242
300
  onClick?: (event: MouseEvent) => void;
243
301
  }
244
302
 
245
303
  /**
304
+ * An `<a>` while it has somewhere to go; a `<span role="link">` with no href
305
+ * or while disabled, since an anchor without an href is neither a link to
306
+ * assistive technology nor reachable by Tab.
307
+ *
246
308
  * ```tsx
247
309
  * <Link href="/about">About</Link>
248
310
  * ```
249
311
  */
250
- export function Link(props: Incoming<LinkComponentProps>) {
251
- const domRef = makeRef<HTMLAnchorElement>();
252
- const options = fromProps(props);
253
-
254
- const { linkProps, isPressed } = link(options, domRef);
255
- const { hoverProps, isHovered } = hover({ isDisabled: options.isDisabled });
256
- const { focusProps, isFocused, isFocusVisible } = focusRing();
257
- // `link()` delivers `onClick` itself; bound on the element as well, a
258
- // caller's handler runs twice for every mouse click.
259
- const { onClick: _, ...forwarded } = filterDOMProps(options, { global: true });
260
-
261
- const elementProps = mergeProps(linkProps, hoverProps, focusProps, forwarded, styleProps(props), {
262
- "data-pressed": isPressed,
263
- "data-hovered": isHovered,
264
- "data-focused": isFocused,
265
- "data-focus-visible": isFocusVisible,
266
- "data-disabled": () => props.isDisabled?.() === true,
267
- "data-testid": () => props["data-testid"]?.(),
312
+ export function Link(props: LinkComponentProps) {
313
+ const domRef = makeRef<HTMLAnchorElement | HTMLSpanElement>();
314
+ // A trigger the link is written inside (a FileTrigger, a PreviewTrigger)
315
+ // hands its press, its ARIA and its ref through the slot, as it does to a
316
+ // Button.
317
+ const slot = triggerSlot();
318
+ const options = mergeProps(fromProps(cells(props)), slot.props) as LinkOptions;
319
+ const elementType = (): "a" | "span" =>
320
+ props.href !== undefined && props.isDisabled !== true ? "a" : "span";
321
+
322
+ const { linkProps, isPressed } = link({ ...options, elementType }, domRef);
323
+ const { hoverProps, isHovered } = hover({
324
+ isDisabled: options.isDisabled,
325
+ onHoverStart: (event) => props.onHoverStart?.(event),
326
+ onHoverEnd: (event) => props.onHoverEnd?.(event),
327
+ onHoverChange: (hovered) => props.onHoverChange?.(hovered),
268
328
  });
329
+ const { focusProps, isFocused, isFocusVisible } = focusRing();
330
+ // `link()` delivers `onClick`, `onFocus` and `onBlur` itself; bound on the
331
+ // element as well, a caller's handler runs twice.
332
+ const {
333
+ onClick: _click,
334
+ onFocus: _focus,
335
+ onBlur: _blur,
336
+ ...forwarded
337
+ } = filterDOMProps(options, { global: true });
338
+
339
+ const elementProps = mergeProps(
340
+ linkProps,
341
+ hoverProps,
342
+ focusProps,
343
+ forwarded,
344
+ styleProps(cells(props)),
345
+ {
346
+ "data-pressed": isPressed,
347
+ "data-hovered": isHovered,
348
+ "data-focused": isFocused,
349
+ "data-focus-visible": isFocusVisible,
350
+ "data-disabled": () => props.isDisabled === true,
351
+ "data-testid": () => props["data-testid"],
352
+ },
353
+ );
269
354
 
355
+ const ref = mergeRefs(domRef.set, slot.ref, props.ref);
270
356
  return (
271
- <a {...elementProps} ref={mergeRefs(domRef.set, props.ref?.())}>
272
- {props.children}
273
- </a>
357
+ <Show
358
+ when={elementType() === "a"}
359
+ fallback={
360
+ <span {...elementProps} ref={ref}>
361
+ {props.children}
362
+ </span>
363
+ }
364
+ >
365
+ <a {...elementProps} ref={ref}>
366
+ {props.children}
367
+ </a>
368
+ </Show>
274
369
  );
275
370
  }
276
371
 
@@ -284,22 +379,20 @@ export interface SeparatorComponentProps extends StyleProps {
284
379
  "aria-label"?: string;
285
380
  }
286
381
 
287
- export function Separator(props: Incoming<SeparatorComponentProps>) {
288
- const options = fromProps(props);
382
+ export function Separator(props: SeparatorComponentProps) {
383
+ const options = fromProps(cells(props));
289
384
  const { separatorProps } = separator({ ...(options as SeparatorOptions), elementType: "hr" });
290
385
 
291
386
  const elementProps = mergeProps(
292
387
  separatorProps,
293
388
  filterDOMProps(options, { global: true }),
294
- styleProps(props),
389
+ styleProps(cells(props)),
295
390
  {
296
- role: () => (props.decorative?.() === true ? "none" : undefined),
297
- "data-orientation": () => props.orientation?.() ?? "horizontal",
391
+ role: () => (props.decorative === true ? "none" : undefined),
392
+ "data-orientation": () => props.orientation ?? "horizontal",
298
393
  "aria-orientation": () =>
299
- props.orientation?.() === "vertical" && props.decorative?.() !== true
300
- ? "vertical"
301
- : undefined,
302
- "data-testid": () => props["data-testid"]?.(),
394
+ props.orientation === "vertical" && props.decorative !== true ? "vertical" : undefined,
395
+ "data-testid": () => props["data-testid"],
303
396
  },
304
397
  );
305
398
 
@@ -327,20 +420,23 @@ export interface ProgressBarComponentProps extends StyleProps {
327
420
  * The bar itself is the caller's: `data-percentage` carries the fraction so a
328
421
  * stylesheet can size a child without a `style` attribute.
329
422
  */
330
- export function ProgressBar(props: Incoming<ProgressBarComponentProps>) {
331
- const options = fromProps(props);
332
- const { progressBarProps, labelProps, percentage, valueText } = progressBar(
333
- options as ProgressBarOptions,
334
- );
423
+ export function ProgressBar(props: ProgressBarComponentProps) {
424
+ const options = fromProps(cells(props));
425
+ const context = getContext(ProgressBarContext);
426
+ const { progressBarProps, labelProps, percentage, valueText } = progressBar({
427
+ ...(options as ProgressBarOptions),
428
+ id: () =>
429
+ access((options as ProgressBarOptions).id) ?? (context ? access(context.id) : undefined),
430
+ });
335
431
 
336
432
  const elementProps = mergeProps(
337
433
  progressBarProps,
338
434
  filterDOMProps(options, { global: true }),
339
- styleProps(props),
435
+ styleProps(cells(props)),
340
436
  {
341
- "data-indeterminate": () => props.isIndeterminate?.() === true,
342
- "data-percentage": () => (props.isIndeterminate?.() === true ? undefined : percentage()),
343
- "data-testid": () => props["data-testid"]?.(),
437
+ "data-indeterminate": () => props.isIndeterminate === true,
438
+ "data-percentage": () => (props.isIndeterminate === true ? undefined : percentage()),
439
+ "data-testid": () => props["data-testid"],
344
440
  },
345
441
  );
346
442
 
@@ -355,8 +451,8 @@ export function ProgressBar(props: Incoming<ProgressBarComponentProps>) {
355
451
 
356
452
  export interface MeterComponentProps extends Omit<ProgressBarComponentProps, "isIndeterminate"> {}
357
453
 
358
- export function Meter(props: Incoming<MeterComponentProps>) {
359
- const options = fromProps(props);
454
+ export function Meter(props: MeterComponentProps) {
455
+ const options = fromProps(cells(props));
360
456
  const { progressBarProps, labelProps, percentage, valueText } = meter(
361
457
  options as ProgressBarOptions,
362
458
  );
@@ -364,10 +460,10 @@ export function Meter(props: Incoming<MeterComponentProps>) {
364
460
  const elementProps = mergeProps(
365
461
  progressBarProps,
366
462
  filterDOMProps(options, { global: true }),
367
- styleProps(props),
463
+ styleProps(cells(props)),
368
464
  {
369
465
  "data-percentage": percentage,
370
- "data-testid": () => props["data-testid"]?.(),
466
+ "data-testid": () => props["data-testid"],
371
467
  },
372
468
  );
373
469