@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/link.tsx
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links, and the separators, progress bars and meters that need no state.
|
|
3
|
+
*
|
|
4
|
+
* A link is a press away from a button, and the difference is what the two
|
|
5
|
+
* mean: a link goes somewhere, a button does something. Assistive technology
|
|
6
|
+
* reports them differently, and Enter activates a link where Enter and Space
|
|
7
|
+
* both activate a button — which is why the press hook has to know which it is
|
|
8
|
+
* looking at rather than treating every activation the same.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { cells, getContext, Show, type Accessor, type Child } from "@barqjs/core";
|
|
12
|
+
import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
|
|
13
|
+
import { focusRing } from "./focus.ts";
|
|
14
|
+
import { focusable, type FocusableOptions } from "./interactions/focusable.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";
|
|
22
|
+
import { press, type ElementRef, type PressEvent } from "./interactions/press.ts";
|
|
23
|
+
import { label as labelHook } from "./label.ts";
|
|
24
|
+
import { ProgressBarContext } from "./progress-bar-context.ts";
|
|
25
|
+
|
|
26
|
+
import { numberFormatter } from "./i18n.ts";
|
|
27
|
+
import {
|
|
28
|
+
access,
|
|
29
|
+
clamp,
|
|
30
|
+
type DOMProps,
|
|
31
|
+
filterDOMProps,
|
|
32
|
+
fromProps,
|
|
33
|
+
type MaybeAccessor,
|
|
34
|
+
mergeProps,
|
|
35
|
+
type StyleProps,
|
|
36
|
+
styleProps,
|
|
37
|
+
triggerSlot,
|
|
38
|
+
} from "./utils.ts";
|
|
39
|
+
|
|
40
|
+
export interface LinkOptions extends FocusableOptions {
|
|
41
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
42
|
+
/** @default "a" */
|
|
43
|
+
elementType?: MaybeAccessor<string | undefined>;
|
|
44
|
+
href?: MaybeAccessor<string | undefined>;
|
|
45
|
+
target?: MaybeAccessor<string | undefined>;
|
|
46
|
+
rel?: MaybeAccessor<string | undefined>;
|
|
47
|
+
download?: MaybeAccessor<boolean | string | undefined>;
|
|
48
|
+
ping?: MaybeAccessor<string | undefined>;
|
|
49
|
+
referrerPolicy?: MaybeAccessor<string | undefined>;
|
|
50
|
+
/** Handed to the router in scope along with the href. */
|
|
51
|
+
routerOptions?: MaybeAccessor<RouterOptions>;
|
|
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>;
|
|
57
|
+
"aria-label"?: MaybeAccessor<string | undefined>;
|
|
58
|
+
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
59
|
+
"aria-describedby"?: MaybeAccessor<string | undefined>;
|
|
60
|
+
onPress?: (event: PressEvent) => void;
|
|
61
|
+
onPressStart?: (event: PressEvent) => void;
|
|
62
|
+
onPressEnd?: (event: PressEvent) => void;
|
|
63
|
+
onPressChange?: (isPressed: boolean) => void;
|
|
64
|
+
onClick?: (event: MouseEvent) => void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface LinkResult {
|
|
68
|
+
linkProps: DOMProps;
|
|
69
|
+
isPressed: Accessor<boolean>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function link(options: LinkOptions, ref?: ElementRef): LinkResult {
|
|
73
|
+
const elementType = (): string => access(options.elementType) ?? "a";
|
|
74
|
+
const isDisabled = (): boolean => access(options.isDisabled) === true;
|
|
75
|
+
|
|
76
|
+
const { pressProps, isPressed } = press({ ...options, ref });
|
|
77
|
+
const { focusableProps } = focusable(options, ref);
|
|
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
|
+
);
|
|
102
|
+
|
|
103
|
+
const roleProps: DOMProps = {
|
|
104
|
+
// Anything that is not an `<a href>` has to say what it is, and be
|
|
105
|
+
// reachable by Tab, which a `<span>` is not.
|
|
106
|
+
role: () => (elementType() === "a" ? undefined : "link"),
|
|
107
|
+
tabIndex: () => (elementType() === "a" || isDisabled() ? undefined : 0),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
isPressed,
|
|
112
|
+
linkProps: mergeProps(
|
|
113
|
+
filterDOMProps(options, { labelable: true, isLink: true }),
|
|
114
|
+
// The `data-href` shape, so a non-anchor element can still be opened by
|
|
115
|
+
// the router or by a middle click.
|
|
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
|
+
},
|
|
124
|
+
focusableProps,
|
|
125
|
+
pressProps,
|
|
126
|
+
roleProps,
|
|
127
|
+
{
|
|
128
|
+
// A disabled link must not navigate, and `<a>` has no `disabled`.
|
|
129
|
+
href: () => (isDisabled() ? undefined : routedHref()),
|
|
130
|
+
"aria-disabled": () => isDisabled() || undefined,
|
|
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"]),
|
|
135
|
+
onClick: (event: MouseEvent) => {
|
|
136
|
+
handleLinkClick(event, access(options.href), navigate, access(options.routerOptions));
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Separator
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
export interface SeparatorOptions {
|
|
148
|
+
/** @default "horizontal" */
|
|
149
|
+
orientation?: MaybeAccessor<"horizontal" | "vertical" | undefined>;
|
|
150
|
+
/** @default "hr" */
|
|
151
|
+
elementType?: MaybeAccessor<string | undefined>;
|
|
152
|
+
"aria-label"?: MaybeAccessor<string | undefined>;
|
|
153
|
+
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A divider between groups of content.
|
|
158
|
+
*
|
|
159
|
+
* `<hr>` already has the role and a horizontal orientation, so nothing is
|
|
160
|
+
* written for it. Anything else needs both — and `aria-orientation` only when
|
|
161
|
+
* it is vertical, since horizontal is the role's default.
|
|
162
|
+
*/
|
|
163
|
+
export function separator(options: SeparatorOptions): { separatorProps: DOMProps } {
|
|
164
|
+
const domProps = filterDOMProps(options, { labelable: true });
|
|
165
|
+
|
|
166
|
+
if ((access(options.elementType) ?? "hr") === "hr") return { separatorProps: domProps };
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
separatorProps: mergeProps(domProps, {
|
|
170
|
+
role: "separator",
|
|
171
|
+
"aria-orientation": () =>
|
|
172
|
+
access(options.orientation) === "vertical" ? "vertical" : undefined,
|
|
173
|
+
}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Progress and meter
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
export interface ProgressBarOptions {
|
|
182
|
+
/** @default 0 */
|
|
183
|
+
value?: MaybeAccessor<number | undefined>;
|
|
184
|
+
/** @default 0 */
|
|
185
|
+
minValue?: MaybeAccessor<number | undefined>;
|
|
186
|
+
/** @default 100 */
|
|
187
|
+
maxValue?: MaybeAccessor<number | undefined>;
|
|
188
|
+
/** Progress that is happening but cannot be measured. */
|
|
189
|
+
isIndeterminate?: MaybeAccessor<boolean | undefined>;
|
|
190
|
+
/** What to say instead of the formatted percentage, e.g. "1 of 4". */
|
|
191
|
+
valueLabel?: MaybeAccessor<string | undefined>;
|
|
192
|
+
/** @default { style: "percent" } */
|
|
193
|
+
formatOptions?: Intl.NumberFormatOptions;
|
|
194
|
+
label?: MaybeAccessor<unknown>;
|
|
195
|
+
id?: MaybeAccessor<string | undefined>;
|
|
196
|
+
"aria-label"?: MaybeAccessor<string | undefined>;
|
|
197
|
+
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface ProgressBarResult {
|
|
201
|
+
progressBarProps: DOMProps;
|
|
202
|
+
labelProps: DOMProps;
|
|
203
|
+
/** What a screen reader will read for the value. */
|
|
204
|
+
valueText: Accessor<string | undefined>;
|
|
205
|
+
percentage: Accessor<number>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A progress bar.
|
|
210
|
+
*
|
|
211
|
+
* `aria-valuetext` is what a screen reader actually reads; `aria-valuenow`
|
|
212
|
+
* alone is announced as a bare number with no unit, which for a percentage is
|
|
213
|
+
* wrong in most locales. An indeterminate bar has neither: a value it does not
|
|
214
|
+
* know is worse than no value.
|
|
215
|
+
*/
|
|
216
|
+
export function progressBar(options: ProgressBarOptions): ProgressBarResult {
|
|
217
|
+
const formatOptions = options.formatOptions ?? { style: "percent" as const };
|
|
218
|
+
const format = numberFormatter(formatOptions);
|
|
219
|
+
|
|
220
|
+
const { labelProps, fieldProps } = labelHook({
|
|
221
|
+
...options,
|
|
222
|
+
// A progressbar is not a labelable element.
|
|
223
|
+
labelElementType: "span",
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const min = (): number => access(options.minValue) ?? 0;
|
|
227
|
+
const max = (): number => access(options.maxValue) ?? 100;
|
|
228
|
+
const value = (): number => clamp(access(options.value) ?? 0, min(), max());
|
|
229
|
+
const isIndeterminate = (): boolean => access(options.isIndeterminate) === true;
|
|
230
|
+
|
|
231
|
+
const percentage = (): number => {
|
|
232
|
+
const range = max() - min();
|
|
233
|
+
return range === 0 ? 0 : (value() - min()) / range;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const valueText = (): string | undefined => {
|
|
237
|
+
if (isIndeterminate()) return undefined;
|
|
238
|
+
const given = access(options.valueLabel);
|
|
239
|
+
if (given !== undefined) return given;
|
|
240
|
+
return format().format(formatOptions.style === "percent" ? percentage() : value());
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
percentage,
|
|
245
|
+
valueText,
|
|
246
|
+
labelProps,
|
|
247
|
+
progressBarProps: mergeProps(filterDOMProps(options, { labelable: true }), fieldProps, {
|
|
248
|
+
role: "progressbar",
|
|
249
|
+
"aria-valuenow": () => (isIndeterminate() ? undefined : value()),
|
|
250
|
+
"aria-valuemin": min,
|
|
251
|
+
"aria-valuemax": max,
|
|
252
|
+
"aria-valuetext": valueText,
|
|
253
|
+
}),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* A meter: a quantity within a known range, not progress towards completion.
|
|
259
|
+
*
|
|
260
|
+
* `role="meter progressbar"` is a fallback list, and the reason is browser
|
|
261
|
+
* support: Chrome degrades from `meter` on its own, Firefox does not implement
|
|
262
|
+
* it at all, and `progressbar` is what those two announce instead.
|
|
263
|
+
*/
|
|
264
|
+
export function meter(options: Omit<ProgressBarOptions, "isIndeterminate">): ProgressBarResult {
|
|
265
|
+
const result = progressBar(options);
|
|
266
|
+
return {
|
|
267
|
+
...result,
|
|
268
|
+
progressBarProps: mergeProps(result.progressBarProps, { role: "meter progressbar" }),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
// Components
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
|
|
276
|
+
export interface LinkComponentProps extends StyleProps {
|
|
277
|
+
children?: Child;
|
|
278
|
+
href?: string;
|
|
279
|
+
target?: string;
|
|
280
|
+
rel?: string;
|
|
281
|
+
download?: boolean | string;
|
|
282
|
+
ping?: string;
|
|
283
|
+
referrerPolicy?: string;
|
|
284
|
+
routerOptions?: RouterOptions;
|
|
285
|
+
isDisabled?: boolean;
|
|
286
|
+
autoFocus?: boolean;
|
|
287
|
+
"aria-label"?: string;
|
|
288
|
+
"aria-labelledby"?: string;
|
|
289
|
+
"aria-current"?: boolean | string;
|
|
290
|
+
ref?: RefTarget<HTMLAnchorElement | HTMLSpanElement>;
|
|
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;
|
|
300
|
+
onClick?: (event: MouseEvent) => void;
|
|
301
|
+
}
|
|
302
|
+
|
|
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
|
+
*
|
|
308
|
+
* ```tsx
|
|
309
|
+
* <Link href="/about">About</Link>
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
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),
|
|
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
|
+
);
|
|
354
|
+
|
|
355
|
+
const ref = mergeRefs(domRef.set, slot.ref, props.ref);
|
|
356
|
+
return (
|
|
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>
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface SeparatorComponentProps extends StyleProps {
|
|
373
|
+
orientation?: "horizontal" | "vertical";
|
|
374
|
+
/**
|
|
375
|
+
* Drawn and not announced: a rule that divides nothing a screen reader
|
|
376
|
+
* needs told about, such as the line between two toolbar buttons.
|
|
377
|
+
*/
|
|
378
|
+
decorative?: boolean;
|
|
379
|
+
"aria-label"?: string;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function Separator(props: SeparatorComponentProps) {
|
|
383
|
+
const options = fromProps(cells(props));
|
|
384
|
+
const { separatorProps } = separator({ ...(options as SeparatorOptions), elementType: "hr" });
|
|
385
|
+
|
|
386
|
+
const elementProps = mergeProps(
|
|
387
|
+
separatorProps,
|
|
388
|
+
filterDOMProps(options, { global: true }),
|
|
389
|
+
styleProps(cells(props)),
|
|
390
|
+
{
|
|
391
|
+
role: () => (props.decorative === true ? "none" : undefined),
|
|
392
|
+
"data-orientation": () => props.orientation ?? "horizontal",
|
|
393
|
+
"aria-orientation": () =>
|
|
394
|
+
props.orientation === "vertical" && props.decorative !== true ? "vertical" : undefined,
|
|
395
|
+
"data-testid": () => props["data-testid"],
|
|
396
|
+
},
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
return <hr {...elementProps} />;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface ProgressBarComponentProps extends StyleProps {
|
|
403
|
+
children?: Child;
|
|
404
|
+
label?: Child;
|
|
405
|
+
value?: number;
|
|
406
|
+
minValue?: number;
|
|
407
|
+
maxValue?: number;
|
|
408
|
+
isIndeterminate?: boolean;
|
|
409
|
+
valueLabel?: string;
|
|
410
|
+
formatOptions?: Intl.NumberFormatOptions;
|
|
411
|
+
"aria-label"?: string;
|
|
412
|
+
"aria-labelledby"?: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* ```tsx
|
|
417
|
+
* <ProgressBar label="Uploading" value={progress()} />
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* The bar itself is the caller's: `data-percentage` carries the fraction so a
|
|
421
|
+
* stylesheet can size a child without a `style` attribute.
|
|
422
|
+
*/
|
|
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
|
+
});
|
|
431
|
+
|
|
432
|
+
const elementProps = mergeProps(
|
|
433
|
+
progressBarProps,
|
|
434
|
+
filterDOMProps(options, { global: true }),
|
|
435
|
+
styleProps(cells(props)),
|
|
436
|
+
{
|
|
437
|
+
"data-indeterminate": () => props.isIndeterminate === true,
|
|
438
|
+
"data-percentage": () => (props.isIndeterminate === true ? undefined : percentage()),
|
|
439
|
+
"data-testid": () => props["data-testid"],
|
|
440
|
+
},
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
return (
|
|
444
|
+
<div {...elementProps}>
|
|
445
|
+
<span {...labelProps}>{props.label}</span>
|
|
446
|
+
{props.children}
|
|
447
|
+
<span aria-hidden="true">{valueText}</span>
|
|
448
|
+
</div>
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface MeterComponentProps extends Omit<ProgressBarComponentProps, "isIndeterminate"> {}
|
|
453
|
+
|
|
454
|
+
export function Meter(props: MeterComponentProps) {
|
|
455
|
+
const options = fromProps(cells(props));
|
|
456
|
+
const { progressBarProps, labelProps, percentage, valueText } = meter(
|
|
457
|
+
options as ProgressBarOptions,
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
const elementProps = mergeProps(
|
|
461
|
+
progressBarProps,
|
|
462
|
+
filterDOMProps(options, { global: true }),
|
|
463
|
+
styleProps(cells(props)),
|
|
464
|
+
{
|
|
465
|
+
"data-percentage": percentage,
|
|
466
|
+
"data-testid": () => props["data-testid"],
|
|
467
|
+
},
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
return (
|
|
471
|
+
<div {...elementProps}>
|
|
472
|
+
<span {...labelProps}>{props.label}</span>
|
|
473
|
+
{props.children}
|
|
474
|
+
<span aria-hidden="true">{valueText}</span>
|
|
475
|
+
</div>
|
|
476
|
+
);
|
|
477
|
+
}
|