@barqjs/aria 0.0.0-stage → 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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +304 -2
  3. package/package.json +437 -4
  4. package/src/autocomplete.tsx +581 -0
  5. package/src/breadcrumbs.tsx +297 -0
  6. package/src/button.tsx +468 -0
  7. package/src/calendar.tsx +2316 -0
  8. package/src/checkbox.tsx +732 -0
  9. package/src/collections.ts +1059 -0
  10. package/src/color.ts +2119 -0
  11. package/src/colorpicker.tsx +2023 -0
  12. package/src/colorswatchpicker.tsx +240 -0
  13. package/src/combobox.tsx +3003 -0
  14. package/src/command.tsx +1203 -0
  15. package/src/date.ts +674 -0
  16. package/src/datefield.tsx +2066 -0
  17. package/src/datepicker.tsx +907 -0
  18. package/src/dialog.tsx +1077 -0
  19. package/src/disclosure.tsx +711 -0
  20. package/src/dnd/clipboard.ts +125 -0
  21. package/src/dnd/collection.ts +1265 -0
  22. package/src/dnd/data.ts +409 -0
  23. package/src/dnd/drag-drop.ts +801 -0
  24. package/src/dnd/index.ts +133 -0
  25. package/src/dnd/manager.ts +639 -0
  26. package/src/dnd/strings.ts +1279 -0
  27. package/src/dnd/targets.ts +726 -0
  28. package/src/dnd/types.ts +212 -0
  29. package/src/dom.ts +703 -0
  30. package/src/drag-and-drop.tsx +669 -0
  31. package/src/drawer.ts +674 -0
  32. package/src/dropzone.tsx +208 -0
  33. package/src/file-trigger.tsx +103 -0
  34. package/src/focus.ts +1370 -0
  35. package/src/form.tsx +94 -0
  36. package/src/gridlist.tsx +1354 -0
  37. package/src/group.tsx +146 -0
  38. package/src/i18n.ts +823 -0
  39. package/src/index.ts +1672 -0
  40. package/src/interactions/description.ts +73 -0
  41. package/src/interactions/flags.ts +35 -0
  42. package/src/interactions/focus-events.ts +226 -0
  43. package/src/interactions/focusable.ts +86 -0
  44. package/src/interactions/hover.ts +213 -0
  45. package/src/interactions/interact-outside.ts +123 -0
  46. package/src/interactions/keyboard.ts +298 -0
  47. package/src/interactions/listeners.ts +78 -0
  48. package/src/interactions/long-press.ts +160 -0
  49. package/src/interactions/modality.ts +428 -0
  50. package/src/interactions/move.ts +257 -0
  51. package/src/interactions/open-link.ts +226 -0
  52. package/src/interactions/press.ts +915 -0
  53. package/src/interactions/prevent-focus.ts +102 -0
  54. package/src/interactions/scroll-wheel.ts +43 -0
  55. package/src/interactions/text-selection.ts +77 -0
  56. package/src/interactions.ts +81 -0
  57. package/src/label.ts +140 -0
  58. package/src/link.tsx +477 -0
  59. package/src/listbox.tsx +1247 -0
  60. package/src/live.ts +208 -0
  61. package/src/menu.tsx +2383 -0
  62. package/src/menubar.tsx +579 -0
  63. package/src/navigation-tree.tsx +357 -0
  64. package/src/navigation.ts +735 -0
  65. package/src/numberfield.tsx +942 -0
  66. package/src/otp.ts +430 -0
  67. package/src/overlay-arrow.tsx +157 -0
  68. package/src/overlays.ts +1549 -0
  69. package/src/platform.ts +75 -0
  70. package/src/presence.ts +164 -0
  71. package/src/preview-trigger.tsx +582 -0
  72. package/src/progress-bar-context.ts +15 -0
  73. package/src/questionnaire.tsx +1717 -0
  74. package/src/radio.tsx +641 -0
  75. package/src/register-dom.ts +12 -0
  76. package/src/scroller.ts +1165 -0
  77. package/src/select.tsx +1745 -0
  78. package/src/selection-indicator.tsx +74 -0
  79. package/src/selection.ts +1472 -0
  80. package/src/shared-element-transition.tsx +316 -0
  81. package/src/sheet.tsx +1461 -0
  82. package/src/slider.tsx +1137 -0
  83. package/src/splitter.ts +1152 -0
  84. package/src/static-collection.ts +211 -0
  85. package/src/switch.tsx +212 -0
  86. package/src/table.tsx +2218 -0
  87. package/src/tabs.tsx +1127 -0
  88. package/src/tag.tsx +637 -0
  89. package/src/textarea.tsx +186 -0
  90. package/src/textfield.tsx +483 -0
  91. package/src/toast-components.tsx +589 -0
  92. package/src/toast.ts +658 -0
  93. package/src/toggle-button-group.tsx +175 -0
  94. package/src/toggle-input.tsx +86 -0
  95. package/src/toggle.ts +384 -0
  96. package/src/togglegroup.ts +365 -0
  97. package/src/tokenfield.tsx +1673 -0
  98. package/src/toolbar.tsx +184 -0
  99. package/src/tooltip.tsx +674 -0
  100. package/src/tree.tsx +2075 -0
  101. package/src/utils.ts +787 -0
  102. package/src/validation.ts +504 -0
  103. package/src/virtualizer.tsx +837 -0
package/src/form.tsx ADDED
@@ -0,0 +1,94 @@
1
+ /**
2
+ * A form, and the validation that belongs to the whole of it rather than to
3
+ * one field.
4
+ *
5
+ * Three things a `<form>` cannot do on its own:
6
+ *
7
+ * - **Hand a submission's errors back to the fields they belong to.** A server
8
+ * answering "that address is already taken" knows the field name and nothing
9
+ * else; `<Form validationErrors={…}>` puts each message where its field can
10
+ * find it, and the field clears it the moment the user edits the value.
11
+ * - **Choose one validation behaviour for everything inside.** Setting
12
+ * `validationBehavior` per field is how a form ends up half native and half
13
+ * ARIA, which means half of it blocks submission and half does not.
14
+ * - **Give a submit handler the values.** `onSubmit` here is called with a
15
+ * `FormData`, and the default is prevented, because a form that both calls a
16
+ * handler AND navigates does both.
17
+ */
18
+
19
+ import { cells, type Child } from "@barqjs/core";
20
+ import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
21
+ import {
22
+ provideValidationBehavior,
23
+ provideValidationErrors,
24
+ type ValidationBehavior,
25
+ type ValidationErrors,
26
+ } from "./validation.ts";
27
+ import { filterDOMProps, fromProps, mergeProps, type StyleProps, styleProps } from "./utils.ts";
28
+
29
+ export interface FormComponentProps extends StyleProps {
30
+ children?: Child;
31
+ /** Errors a submission came back with, by field name. */
32
+ validationErrors?: ValidationErrors;
33
+ /** @default "aria" */
34
+ validationBehavior?: ValidationBehavior;
35
+ action?: string;
36
+ method?: "get" | "post" | "dialog";
37
+ encType?: string;
38
+ target?: string;
39
+ autoComplete?: "on" | "off";
40
+ /** Turn off the browser's own validation UI. */
41
+ noValidate?: boolean;
42
+ "aria-label"?: string;
43
+ "aria-labelledby"?: string;
44
+ ref?: RefTarget<HTMLFormElement>;
45
+ onSubmit?: (data: FormData, event: SubmitEvent) => void;
46
+ onReset?: (event: Event) => void;
47
+ }
48
+
49
+ /**
50
+ * ```tsx
51
+ * <Form validationErrors={errors()} onSubmit={(data) => save(data)}>
52
+ * <TextField label="Email" name="email" type="email" isRequired />
53
+ * <Button type="submit">Save</Button>
54
+ * </Form>
55
+ * ```
56
+ */
57
+ export function Form(props: FormComponentProps) {
58
+ const domRef = makeRef<HTMLFormElement>();
59
+
60
+ provideValidationErrors(() => props.validationErrors ?? {});
61
+ provideValidationBehavior(() => props.validationBehavior);
62
+
63
+ const onSubmit = (event: SubmitEvent): void => {
64
+ const handler = props.onSubmit;
65
+ if (handler === undefined) return;
66
+ // Both calling a handler and navigating is doing the thing twice.
67
+ event.preventDefault();
68
+ handler(new FormData(event.currentTarget as HTMLFormElement), event);
69
+ };
70
+
71
+ const elementProps = mergeProps(
72
+ filterDOMProps(fromProps(cells(props)), { global: true }),
73
+ styleProps(cells(props)),
74
+ {
75
+ action: () => props.action,
76
+ method: () => props.method,
77
+ enctype: () => props.encType,
78
+ target: () => props.target,
79
+ autocomplete: () => props.autoComplete,
80
+ novalidate: () => props.noValidate === true || undefined,
81
+ "aria-label": () => props["aria-label"],
82
+ "aria-labelledby": () => props["aria-labelledby"],
83
+ "data-testid": () => props["data-testid"],
84
+ onSubmit,
85
+ onReset: (event: Event) => props.onReset?.(event),
86
+ },
87
+ );
88
+
89
+ return (
90
+ <form {...elementProps} ref={mergeRefs(domRef.set, props.ref)}>
91
+ {props.children}
92
+ </form>
93
+ );
94
+ }