@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.
- package/LICENSE +21 -0
- package/README.md +304 -2
- package/package.json +437 -4
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +297 -0
- package/src/button.tsx +468 -0
- package/src/calendar.tsx +2316 -0
- package/src/checkbox.tsx +732 -0
- package/src/collections.ts +1059 -0
- package/src/color.ts +2119 -0
- package/src/colorpicker.tsx +2023 -0
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +3003 -0
- package/src/command.tsx +1203 -0
- package/src/date.ts +674 -0
- package/src/datefield.tsx +2066 -0
- package/src/datepicker.tsx +907 -0
- package/src/dialog.tsx +1077 -0
- package/src/disclosure.tsx +711 -0
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +703 -0
- package/src/drag-and-drop.tsx +669 -0
- package/src/drawer.ts +674 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/focus.ts +1370 -0
- package/src/form.tsx +94 -0
- package/src/gridlist.tsx +1354 -0
- package/src/group.tsx +146 -0
- package/src/i18n.ts +823 -0
- package/src/index.ts +1672 -0
- package/src/interactions/description.ts +73 -0
- package/src/interactions/flags.ts +35 -0
- package/src/interactions/focus-events.ts +226 -0
- package/src/interactions/focusable.ts +86 -0
- package/src/interactions/hover.ts +213 -0
- package/src/interactions/interact-outside.ts +123 -0
- package/src/interactions/keyboard.ts +298 -0
- package/src/interactions/listeners.ts +78 -0
- package/src/interactions/long-press.ts +160 -0
- package/src/interactions/modality.ts +428 -0
- package/src/interactions/move.ts +257 -0
- package/src/interactions/open-link.ts +226 -0
- package/src/interactions/press.ts +915 -0
- package/src/interactions/prevent-focus.ts +102 -0
- package/src/interactions/scroll-wheel.ts +43 -0
- package/src/interactions/text-selection.ts +77 -0
- package/src/interactions.ts +81 -0
- package/src/label.ts +140 -0
- package/src/link.tsx +477 -0
- package/src/listbox.tsx +1247 -0
- package/src/live.ts +208 -0
- package/src/menu.tsx +2383 -0
- package/src/menubar.tsx +579 -0
- package/src/navigation-tree.tsx +357 -0
- package/src/navigation.ts +735 -0
- package/src/numberfield.tsx +942 -0
- package/src/otp.ts +430 -0
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +1549 -0
- package/src/platform.ts +75 -0
- package/src/presence.ts +164 -0
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +1717 -0
- package/src/radio.tsx +641 -0
- package/src/register-dom.ts +12 -0
- package/src/scroller.ts +1165 -0
- package/src/select.tsx +1745 -0
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +1472 -0
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +1137 -0
- package/src/splitter.ts +1152 -0
- package/src/static-collection.ts +211 -0
- package/src/switch.tsx +212 -0
- package/src/table.tsx +2218 -0
- package/src/tabs.tsx +1127 -0
- package/src/tag.tsx +637 -0
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +483 -0
- package/src/toast-components.tsx +589 -0
- package/src/toast.ts +658 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +86 -0
- package/src/toggle.ts +384 -0
- package/src/togglegroup.ts +365 -0
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +184 -0
- package/src/tooltip.tsx +674 -0
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +787 -0
- package/src/validation.ts +504 -0
- package/src/virtualizer.tsx +837 -0
package/src/group.tsx
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A group: a set of related controls that reads, and styles, as one.
|
|
3
|
+
*
|
|
4
|
+
* An input with a button stuck to it, a date field's segments, a toolbar's
|
|
5
|
+
* cluster of toggles. What the group adds is the state of the WHOLE: whether
|
|
6
|
+
* the pointer is over any of it, and whether focus is anywhere inside, so the
|
|
7
|
+
* border drawn around the set can follow the control the user is in.
|
|
8
|
+
*
|
|
9
|
+
* `role="group"` by default. `region` puts it in the page's landmarks, for a
|
|
10
|
+
* group important enough to be jumped to; `presentation` is for one that is
|
|
11
|
+
* only drawn and means nothing to a screen reader.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { cells, type Accessor, type Child } from "@barqjs/core";
|
|
15
|
+
import { mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
|
|
16
|
+
import { focusRing } from "./focus.ts";
|
|
17
|
+
import { hover, type HoverEvent } from "./interactions/hover.ts";
|
|
18
|
+
import {
|
|
19
|
+
access,
|
|
20
|
+
type DOMProps,
|
|
21
|
+
filterDOMProps,
|
|
22
|
+
fromProps,
|
|
23
|
+
type MaybeAccessor,
|
|
24
|
+
mergeProps,
|
|
25
|
+
type StyleProps,
|
|
26
|
+
styleProps,
|
|
27
|
+
} from "./utils.ts";
|
|
28
|
+
|
|
29
|
+
export type GroupRole = "group" | "region" | "presentation";
|
|
30
|
+
|
|
31
|
+
export interface GroupOptions {
|
|
32
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
33
|
+
isInvalid?: MaybeAccessor<boolean | undefined>;
|
|
34
|
+
isReadOnly?: MaybeAccessor<boolean | undefined>;
|
|
35
|
+
/** @default "group" */
|
|
36
|
+
role?: MaybeAccessor<GroupRole | undefined>;
|
|
37
|
+
"aria-label"?: MaybeAccessor<string | undefined>;
|
|
38
|
+
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
39
|
+
"aria-describedby"?: MaybeAccessor<string | undefined>;
|
|
40
|
+
"aria-details"?: MaybeAccessor<string | undefined>;
|
|
41
|
+
/** Read as `isDisabled` when that is not given, as a caller writing ARIA directly expects. */
|
|
42
|
+
"aria-disabled"?: MaybeAccessor<boolean | "true" | "false" | undefined>;
|
|
43
|
+
/** Read as `isInvalid` when that is not given. */
|
|
44
|
+
"aria-invalid"?: MaybeAccessor<boolean | "true" | "false" | undefined>;
|
|
45
|
+
onHoverStart?: (event: HoverEvent) => void;
|
|
46
|
+
onHoverEnd?: (event: HoverEvent) => void;
|
|
47
|
+
onHoverChange?: (isHovered: boolean) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface GroupResult {
|
|
51
|
+
groupProps: DOMProps;
|
|
52
|
+
isHovered: Accessor<boolean>;
|
|
53
|
+
/** Whether focus is anywhere inside. */
|
|
54
|
+
isFocusWithin: Accessor<boolean>;
|
|
55
|
+
/** Whether focus inside arrived by keyboard. */
|
|
56
|
+
isFocusVisible: Accessor<boolean>;
|
|
57
|
+
isDisabled: Accessor<boolean>;
|
|
58
|
+
isInvalid: Accessor<boolean>;
|
|
59
|
+
isReadOnly: Accessor<boolean>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isTrue(value: boolean | "true" | "false" | undefined): boolean {
|
|
63
|
+
return value === true || value === "true";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function group(options: GroupOptions = {}): GroupResult {
|
|
67
|
+
const isDisabled = (): boolean =>
|
|
68
|
+
access(options.isDisabled) ?? isTrue(access(options["aria-disabled"]));
|
|
69
|
+
const isInvalid = (): boolean =>
|
|
70
|
+
access(options.isInvalid) ?? isTrue(access(options["aria-invalid"]));
|
|
71
|
+
const isReadOnly = (): boolean => access(options.isReadOnly) === true;
|
|
72
|
+
|
|
73
|
+
const { hoverProps, isHovered } = hover({
|
|
74
|
+
isDisabled,
|
|
75
|
+
onHoverStart: options.onHoverStart,
|
|
76
|
+
onHoverEnd: options.onHoverEnd,
|
|
77
|
+
onHoverChange: options.onHoverChange,
|
|
78
|
+
});
|
|
79
|
+
const { focusProps, isFocused, isFocusVisible } = focusRing({ within: true });
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
isHovered,
|
|
83
|
+
isFocusWithin: isFocused,
|
|
84
|
+
isFocusVisible,
|
|
85
|
+
isDisabled,
|
|
86
|
+
isInvalid,
|
|
87
|
+
isReadOnly,
|
|
88
|
+
groupProps: mergeProps(filterDOMProps(options, { labelable: true }), hoverProps, focusProps, {
|
|
89
|
+
role: () => access(options.role) ?? "group",
|
|
90
|
+
"aria-disabled": () => access(options["aria-disabled"]),
|
|
91
|
+
"aria-invalid": () => access(options["aria-invalid"]),
|
|
92
|
+
"data-hovered": isHovered,
|
|
93
|
+
"data-focus-within": isFocused,
|
|
94
|
+
"data-focus-visible": isFocusVisible,
|
|
95
|
+
"data-disabled": isDisabled,
|
|
96
|
+
"data-invalid": isInvalid,
|
|
97
|
+
"data-readonly": isReadOnly,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface GroupComponentProps extends Omit<StyleProps, "role"> {
|
|
103
|
+
children?: Child;
|
|
104
|
+
isDisabled?: boolean;
|
|
105
|
+
isInvalid?: boolean;
|
|
106
|
+
isReadOnly?: boolean;
|
|
107
|
+
/** @default "group" */
|
|
108
|
+
role?: GroupRole;
|
|
109
|
+
"aria-label"?: string;
|
|
110
|
+
"aria-labelledby"?: string;
|
|
111
|
+
"aria-describedby"?: string;
|
|
112
|
+
"aria-details"?: string;
|
|
113
|
+
"aria-disabled"?: boolean | "true" | "false";
|
|
114
|
+
"aria-invalid"?: boolean | "true" | "false";
|
|
115
|
+
ref?: RefTarget<HTMLDivElement>;
|
|
116
|
+
onHoverStart?: (event: HoverEvent) => void;
|
|
117
|
+
onHoverEnd?: (event: HoverEvent) => void;
|
|
118
|
+
onHoverChange?: (isHovered: boolean) => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* ```tsx
|
|
123
|
+
* <Group aria-label="Quantity">
|
|
124
|
+
* <button>-</button>
|
|
125
|
+
* <input />
|
|
126
|
+
* <button>+</button>
|
|
127
|
+
* </Group>
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function Group(props: GroupComponentProps) {
|
|
131
|
+
const options = fromProps(cells(props));
|
|
132
|
+
const { groupProps } = group(options);
|
|
133
|
+
|
|
134
|
+
const elementProps = mergeProps(
|
|
135
|
+
groupProps,
|
|
136
|
+
filterDOMProps(options, { global: true }),
|
|
137
|
+
styleProps(cells(props)),
|
|
138
|
+
{ "data-testid": () => props["data-testid"] },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div {...elementProps} ref={mergeRefs(props.ref)}>
|
|
143
|
+
{props.children}
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|