@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.
- package/README.md +24 -13
- package/package.json +127 -37
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +21 -20
- package/src/button.tsx +151 -25
- package/src/calendar.tsx +1019 -92
- package/src/checkbox.tsx +214 -52
- package/src/collections.ts +88 -5
- package/src/color.ts +1580 -23
- package/src/colorpicker.tsx +698 -153
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +635 -113
- package/src/command.tsx +78 -59
- package/src/date.ts +31 -9
- package/src/datefield.tsx +1451 -336
- package/src/datepicker.tsx +465 -114
- package/src/dialog.tsx +302 -115
- package/src/disclosure.tsx +81 -29
- 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 +3 -6
- package/src/drag-and-drop.tsx +669 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/form.tsx +18 -18
- package/src/gridlist.tsx +912 -121
- package/src/group.tsx +146 -0
- package/src/index.ts +402 -0
- package/src/interactions/focus-events.ts +13 -5
- package/src/interactions/keyboard.ts +195 -2
- package/src/interactions/modality.ts +18 -6
- package/src/interactions/open-link.ts +46 -13
- package/src/interactions/press.ts +35 -18
- package/src/label.ts +18 -6
- package/src/link.tsx +146 -50
- package/src/listbox.tsx +615 -89
- package/src/live.ts +4 -0
- package/src/menu.tsx +182 -89
- package/src/menubar.tsx +21 -17
- package/src/navigation-tree.tsx +357 -0
- package/src/numberfield.tsx +164 -60
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +364 -62
- package/src/platform.ts +2 -1
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +109 -104
- package/src/radio.tsx +101 -27
- package/src/select.tsx +225 -145
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +73 -16
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +139 -44
- package/src/switch.tsx +47 -21
- package/src/table.tsx +0 -0
- package/src/tabs.tsx +198 -89
- package/src/tag.tsx +217 -32
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +103 -37
- package/src/toast-components.tsx +589 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +38 -0
- package/src/toggle.ts +68 -5
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +15 -10
- package/src/tooltip.tsx +46 -29
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +30 -1
- package/src/validation.ts +79 -22
- package/src/virtualizer.tsx +186 -23
package/src/datepicker.tsx
CHANGED
|
@@ -20,24 +20,30 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
|
+
cells,
|
|
23
24
|
type Accessor,
|
|
24
25
|
type Child,
|
|
25
26
|
createContext,
|
|
26
27
|
getContext,
|
|
27
28
|
getOwner,
|
|
28
|
-
type Incoming,
|
|
29
29
|
install,
|
|
30
30
|
} from "@barqjs/core";
|
|
31
31
|
import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
|
|
32
|
-
import { button
|
|
32
|
+
import { button } from "./button.tsx";
|
|
33
33
|
import { Calendar, RangeCalendar, type DateRange } from "./calendar.tsx";
|
|
34
34
|
import { CalendarDate, CalendarDateTime, toCalendarDate, today, type DateValue } from "./date.ts";
|
|
35
|
+
import { StringDictionary, stringFormatter } from "./i18n.ts";
|
|
35
36
|
import { Popover } from "./dialog.tsx";
|
|
36
37
|
import { focusRing } from "./focus.ts";
|
|
37
38
|
import { hover } from "./interactions/hover.ts";
|
|
38
39
|
import type { ElementRef } from "./interactions/press.ts";
|
|
39
40
|
import { field, type FieldOptions } from "./label.ts";
|
|
40
|
-
import
|
|
41
|
+
import {
|
|
42
|
+
fieldValidation,
|
|
43
|
+
type ValidateFunction,
|
|
44
|
+
type ValidationBehavior,
|
|
45
|
+
type ValidationResult,
|
|
46
|
+
} from "./validation.ts";
|
|
41
47
|
import {
|
|
42
48
|
overlayTriggerState,
|
|
43
49
|
type OverlayTriggerState,
|
|
@@ -158,6 +164,7 @@ export function datePicker(options: DatePickerOptions, state: DatePickerState):
|
|
|
158
164
|
const groupId = id();
|
|
159
165
|
const buttonId = id();
|
|
160
166
|
const dialogId = id();
|
|
167
|
+
const messages = stringFormatter(PICKER_STRINGS);
|
|
161
168
|
|
|
162
169
|
const {
|
|
163
170
|
labelProps,
|
|
@@ -182,6 +189,8 @@ export function datePicker(options: DatePickerOptions, state: DatePickerState):
|
|
|
182
189
|
role: "group",
|
|
183
190
|
id: groupId,
|
|
184
191
|
"aria-disabled": () => state.isDisabled() || undefined,
|
|
192
|
+
onKeyDown: (event: KeyboardEvent) =>
|
|
193
|
+
opensOnAltArrow(event, state, state.isDisabled() || state.isReadOnly()),
|
|
185
194
|
}),
|
|
186
195
|
fieldProps: {
|
|
187
196
|
"aria-labelledby": () => access(labelProps.id as MaybeAccessor<string | undefined>),
|
|
@@ -195,7 +204,7 @@ export function datePicker(options: DatePickerOptions, state: DatePickerState):
|
|
|
195
204
|
"aria-controls": () => (state.isOpen() ? dialogId() : undefined),
|
|
196
205
|
// Named by ITSELF and by the field, so it is announced as "Calendar,
|
|
197
206
|
// Departure" rather than as one of a page of identical buttons.
|
|
198
|
-
"aria-label": "
|
|
207
|
+
"aria-label": () => messages().format("calendar"),
|
|
199
208
|
"aria-labelledby": () =>
|
|
200
209
|
`${buttonId()} ${access(labelProps.id as MaybeAccessor<string | undefined>) ?? groupId()}`,
|
|
201
210
|
isDisabled: () => state.isDisabled() || state.isReadOnly(),
|
|
@@ -208,11 +217,29 @@ export function datePicker(options: DatePickerOptions, state: DatePickerState):
|
|
|
208
217
|
access(labelProps.id as MaybeAccessor<string | undefined>) ?? groupId(),
|
|
209
218
|
},
|
|
210
219
|
calendarProps: {
|
|
211
|
-
"aria-label":
|
|
220
|
+
"aria-label": () => messages().format("calendar"),
|
|
212
221
|
},
|
|
213
222
|
};
|
|
214
223
|
}
|
|
215
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Alt with an arrow opens the calendar, from anywhere in the field.
|
|
227
|
+
*
|
|
228
|
+
* The segments leave a modified arrow alone, so it reaches the group whichever
|
|
229
|
+
* segment holds focus.
|
|
230
|
+
*/
|
|
231
|
+
function opensOnAltArrow(
|
|
232
|
+
event: KeyboardEvent,
|
|
233
|
+
overlay: Pick<OverlayTriggerState, "isOpen" | "setOpen">,
|
|
234
|
+
isBlocked = false,
|
|
235
|
+
): void {
|
|
236
|
+
if (!event.altKey || (event.key !== "ArrowDown" && event.key !== "ArrowUp")) return;
|
|
237
|
+
if (isBlocked || overlay.isOpen()) return;
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
event.stopPropagation();
|
|
240
|
+
overlay.setOpen(true);
|
|
241
|
+
}
|
|
242
|
+
|
|
216
243
|
// ---------------------------------------------------------------------------
|
|
217
244
|
// Components
|
|
218
245
|
// ---------------------------------------------------------------------------
|
|
@@ -269,22 +296,22 @@ export interface DatePickerComponentProps extends StyleProps {
|
|
|
269
296
|
* <DatePicker label="Departure" value={date()} onChange={date.set} minValue={today()} />
|
|
270
297
|
* ```
|
|
271
298
|
*/
|
|
272
|
-
export function DatePicker(props:
|
|
299
|
+
export function DatePicker(props: DatePickerComponentProps) {
|
|
273
300
|
const groupRef = makeRef<HTMLDivElement>();
|
|
274
301
|
const triggerRef = makeRef<HTMLButtonElement>();
|
|
275
302
|
|
|
276
303
|
const state = datePickerState({
|
|
277
|
-
value: () => props.value
|
|
278
|
-
defaultValue: () => props.defaultValue
|
|
279
|
-
minValue: () => props.minValue
|
|
280
|
-
maxValue: () => props.maxValue
|
|
281
|
-
granularity: () => props.granularity
|
|
282
|
-
isDisabled: () => props.isDisabled
|
|
283
|
-
isReadOnly: () => props.isReadOnly
|
|
284
|
-
isOpen: () => props.isOpen
|
|
285
|
-
defaultOpen: () => props.defaultOpen
|
|
286
|
-
onChange: (value) => props.onChange?.(
|
|
287
|
-
onOpenChange: (isOpen) => props.onOpenChange?.(
|
|
304
|
+
value: () => props.value,
|
|
305
|
+
defaultValue: () => props.defaultValue,
|
|
306
|
+
minValue: () => props.minValue,
|
|
307
|
+
maxValue: () => props.maxValue,
|
|
308
|
+
granularity: () => props.granularity,
|
|
309
|
+
isDisabled: () => props.isDisabled,
|
|
310
|
+
isReadOnly: () => props.isReadOnly,
|
|
311
|
+
isOpen: () => props.isOpen,
|
|
312
|
+
defaultOpen: () => props.defaultOpen,
|
|
313
|
+
onChange: (value) => props.onChange?.(value),
|
|
314
|
+
onOpenChange: (isOpen) => props.onOpenChange?.(isOpen),
|
|
288
315
|
});
|
|
289
316
|
|
|
290
317
|
const {
|
|
@@ -298,21 +325,21 @@ export function DatePicker(props: Incoming<DatePickerComponentProps>) {
|
|
|
298
325
|
} = datePicker(
|
|
299
326
|
{
|
|
300
327
|
ref: groupRef,
|
|
301
|
-
label: () => props.label
|
|
302
|
-
description: () => props.description
|
|
303
|
-
errorMessage: () => props.errorMessage
|
|
304
|
-
isDisabled: () => props.isDisabled
|
|
305
|
-
isReadOnly: () => props.isReadOnly
|
|
306
|
-
isRequired: () => props.isRequired
|
|
307
|
-
isInvalid: () => props.isInvalid
|
|
308
|
-
"aria-label": () => props["aria-label"]
|
|
309
|
-
"aria-labelledby": () => props["aria-labelledby"]
|
|
328
|
+
label: () => props.label,
|
|
329
|
+
description: () => props.description,
|
|
330
|
+
errorMessage: () => props.errorMessage,
|
|
331
|
+
isDisabled: () => props.isDisabled,
|
|
332
|
+
isReadOnly: () => props.isReadOnly,
|
|
333
|
+
isRequired: () => props.isRequired,
|
|
334
|
+
isInvalid: () => props.isInvalid,
|
|
335
|
+
"aria-label": () => props["aria-label"],
|
|
336
|
+
"aria-labelledby": () => props["aria-labelledby"],
|
|
310
337
|
},
|
|
311
338
|
state,
|
|
312
339
|
);
|
|
313
340
|
|
|
314
341
|
const trigger = button(buttonProps, triggerRef);
|
|
315
|
-
const { hoverProps, isHovered } = hover({ isDisabled: () => props.isDisabled
|
|
342
|
+
const { hoverProps, isHovered } = hover({ isDisabled: () => props.isDisabled });
|
|
316
343
|
const { focusProps, isFocusVisible } = focusRing();
|
|
317
344
|
|
|
318
345
|
const owner = getOwner();
|
|
@@ -320,12 +347,12 @@ export function DatePicker(props: Incoming<DatePickerComponentProps>) {
|
|
|
320
347
|
|
|
321
348
|
const elementProps = mergeProps(
|
|
322
349
|
groupProps,
|
|
323
|
-
filterDOMProps(fromProps(props), { global: true }),
|
|
324
|
-
styleProps(props),
|
|
350
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
351
|
+
styleProps(cells(props)),
|
|
325
352
|
{
|
|
326
353
|
"data-open": state.isOpen,
|
|
327
|
-
"data-disabled": () => props.isDisabled
|
|
328
|
-
"data-testid": () => props["data-testid"]
|
|
354
|
+
"data-disabled": () => props.isDisabled === true,
|
|
355
|
+
"data-testid": () => props["data-testid"],
|
|
329
356
|
},
|
|
330
357
|
);
|
|
331
358
|
|
|
@@ -339,26 +366,27 @@ export function DatePicker(props: Incoming<DatePickerComponentProps>) {
|
|
|
339
366
|
return (
|
|
340
367
|
<>
|
|
341
368
|
<span {...labelProps}>{props.label}</span>
|
|
342
|
-
<div {...elementProps} ref={mergeRefs(groupRef.set, props.ref
|
|
369
|
+
<div {...elementProps} ref={mergeRefs(groupRef.set, props.ref)}>
|
|
343
370
|
{/* Not labelled again: the group around it already carries the
|
|
344
371
|
label, and naming both makes a screen reader say "Departure
|
|
345
372
|
group, Departure group". The segments name themselves. */}
|
|
346
373
|
<DateField
|
|
347
374
|
value={state.value()}
|
|
348
|
-
placeholderValue={props.placeholderValue
|
|
349
|
-
minValue={props.minValue
|
|
350
|
-
maxValue={props.maxValue
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
375
|
+
placeholderValue={props.placeholderValue}
|
|
376
|
+
minValue={props.minValue}
|
|
377
|
+
maxValue={props.maxValue}
|
|
378
|
+
isDateUnavailable={callback<[CalendarDate], boolean>(cells(props).isDateUnavailable)}
|
|
379
|
+
granularity={props.granularity}
|
|
380
|
+
hourCycle={props.hourCycle}
|
|
381
|
+
isDisabled={props.isDisabled}
|
|
382
|
+
isReadOnly={props.isReadOnly}
|
|
383
|
+
isRequired={props.isRequired}
|
|
384
|
+
isInvalid={props.isInvalid}
|
|
357
385
|
validate={callback<[DateValue | null], string | string[] | true | null | undefined>(
|
|
358
|
-
props.validate,
|
|
386
|
+
cells(props).validate,
|
|
359
387
|
)}
|
|
360
|
-
validationBehavior={props.validationBehavior
|
|
361
|
-
name={props.name
|
|
388
|
+
validationBehavior={props.validationBehavior}
|
|
389
|
+
name={props.name}
|
|
362
390
|
onChange={(value) => state.setValue(value)}
|
|
363
391
|
/>
|
|
364
392
|
<button {...triggerElementProps} type="button" ref={triggerRef.set}>
|
|
@@ -369,20 +397,20 @@ export function DatePicker(props: Incoming<DatePickerComponentProps>) {
|
|
|
369
397
|
triggerRef={triggerRef}
|
|
370
398
|
isOpen={state.isOpen()}
|
|
371
399
|
onOpenChange={state.setOpen}
|
|
372
|
-
placement={props.placement
|
|
400
|
+
placement={props.placement ?? "bottom start"}
|
|
373
401
|
>
|
|
374
402
|
<div {...dialogProps}>
|
|
375
403
|
<Calendar
|
|
376
|
-
aria-label={
|
|
404
|
+
aria-label={access(calendarProps["aria-label"] as MaybeAccessor<string>)}
|
|
377
405
|
value={state.dateValue()}
|
|
378
406
|
defaultFocusedValue={
|
|
379
|
-
state.dateValue() ?? toCalendarDate(props.placeholderValue
|
|
407
|
+
state.dateValue() ?? toCalendarDate(props.placeholderValue ?? today())
|
|
380
408
|
}
|
|
381
|
-
minValue={props.minValue
|
|
382
|
-
maxValue={props.maxValue
|
|
383
|
-
isDateUnavailable={callback<[CalendarDate], boolean>(props.isDateUnavailable)}
|
|
384
|
-
isDisabled={props.isDisabled
|
|
385
|
-
isReadOnly={props.isReadOnly
|
|
409
|
+
minValue={props.minValue}
|
|
410
|
+
maxValue={props.maxValue}
|
|
411
|
+
isDateUnavailable={callback<[CalendarDate], boolean>(cells(props).isDateUnavailable)}
|
|
412
|
+
isDisabled={props.isDisabled}
|
|
413
|
+
isReadOnly={props.isReadOnly}
|
|
386
414
|
autoFocus
|
|
387
415
|
onChange={(date) => state.setDateValue(date)}
|
|
388
416
|
/>
|
|
@@ -398,15 +426,48 @@ export function DatePicker(props: Incoming<DatePickerComponentProps>) {
|
|
|
398
426
|
// A range of days
|
|
399
427
|
// ---------------------------------------------------------------------------
|
|
400
428
|
|
|
401
|
-
|
|
429
|
+
/** Two ends, each a day or a day with a time. */
|
|
430
|
+
export interface DateTimeRange<T extends DateValue = DateValue> {
|
|
431
|
+
start: T;
|
|
432
|
+
end: T;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface DateRangePickerComponentProps<T extends DateValue = CalendarDate> extends Omit<
|
|
402
436
|
DatePickerComponentProps,
|
|
403
|
-
"value" | "defaultValue" | "onChange" | "name"
|
|
437
|
+
"value" | "defaultValue" | "onChange" | "name" | "validate"
|
|
404
438
|
> {
|
|
405
|
-
value?:
|
|
406
|
-
defaultValue?:
|
|
439
|
+
value?: DateTimeRange<T> | null;
|
|
440
|
+
defaultValue?: DateTimeRange<T> | null;
|
|
407
441
|
startName?: string;
|
|
408
442
|
endName?: string;
|
|
409
|
-
|
|
443
|
+
/** What the page thinks of the RANGE, checked as it changes. */
|
|
444
|
+
validate?: ValidateFunction<DateTimeRange<T> | null>;
|
|
445
|
+
onChange?: (value: DateTimeRange<T> | null) => void;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** A range whose end comes before its start, which no stay or booking can be. */
|
|
449
|
+
function reversedRange(
|
|
450
|
+
range: DateTimeRange | null,
|
|
451
|
+
message: () => string,
|
|
452
|
+
): ValidationResult | undefined {
|
|
453
|
+
if (range === null || range.end.compare(range.start) >= 0) return undefined;
|
|
454
|
+
return {
|
|
455
|
+
isInvalid: true,
|
|
456
|
+
validationErrors: [message()],
|
|
457
|
+
validationDetails: {
|
|
458
|
+
badInput: false,
|
|
459
|
+
customError: false,
|
|
460
|
+
patternMismatch: false,
|
|
461
|
+
rangeOverflow: true,
|
|
462
|
+
rangeUnderflow: true,
|
|
463
|
+
stepMismatch: false,
|
|
464
|
+
tooLong: false,
|
|
465
|
+
tooShort: false,
|
|
466
|
+
typeMismatch: false,
|
|
467
|
+
valueMissing: false,
|
|
468
|
+
valid: false,
|
|
469
|
+
},
|
|
470
|
+
};
|
|
410
471
|
}
|
|
411
472
|
|
|
412
473
|
/**
|
|
@@ -414,29 +475,61 @@ export interface DateRangePickerComponentProps extends Omit<
|
|
|
414
475
|
*
|
|
415
476
|
* The fields are separate controls — a start and an end are two dates, and one
|
|
416
477
|
* field holding "3 Mar – 7 Mar" is a string nobody can edit a part of — but
|
|
417
|
-
* they share the calendar, where the range is drawn in one gesture.
|
|
478
|
+
* they share the calendar, where the range is drawn in one gesture. What is
|
|
479
|
+
* wrong with the range as a whole, an end before its start, is said once, by
|
|
480
|
+
* the group, rather than by either field.
|
|
418
481
|
*/
|
|
419
|
-
export function DateRangePicker
|
|
482
|
+
export function DateRangePicker<T extends DateValue = CalendarDate>(
|
|
483
|
+
props: DateRangePickerComponentProps<T>,
|
|
484
|
+
) {
|
|
420
485
|
const groupRef = makeRef<HTMLDivElement>();
|
|
421
486
|
const triggerRef = makeRef<HTMLButtonElement>();
|
|
487
|
+
const messages = stringFormatter(PICKER_STRINGS);
|
|
422
488
|
|
|
423
|
-
const [value, setValue] = controllable<
|
|
424
|
-
() => props.value
|
|
425
|
-
() => props.defaultValue
|
|
426
|
-
(next) => props.onChange?.(
|
|
489
|
+
const [value, setValue] = controllable<DateTimeRange<T> | null>(
|
|
490
|
+
() => props.value,
|
|
491
|
+
() => props.defaultValue ?? null,
|
|
492
|
+
(next) => props.onChange?.(next),
|
|
427
493
|
);
|
|
428
494
|
|
|
429
495
|
const overlay = overlayTriggerState({
|
|
430
|
-
isOpen: () => props.isOpen
|
|
431
|
-
defaultOpen: () => props.defaultOpen
|
|
432
|
-
onOpenChange: (isOpen) => props.onOpenChange?.(
|
|
496
|
+
isOpen: () => props.isOpen,
|
|
497
|
+
defaultOpen: () => props.defaultOpen,
|
|
498
|
+
onOpenChange: (isOpen) => props.onOpenChange?.(isOpen),
|
|
433
499
|
});
|
|
434
500
|
|
|
435
|
-
const labelId = id();
|
|
436
501
|
const buttonId = id();
|
|
437
502
|
const dialogId = id();
|
|
438
503
|
|
|
439
|
-
const isDisabled = (): boolean => props.isDisabled
|
|
504
|
+
const isDisabled = (): boolean => props.isDisabled === true;
|
|
505
|
+
|
|
506
|
+
const { isInvalid, errors, errorMessage } = fieldValidation<DateTimeRange<T> | null>({
|
|
507
|
+
value,
|
|
508
|
+
builtinValidation: () => reversedRange(value(), () => messages().format("rangeReversed")),
|
|
509
|
+
validate: callback<[DateTimeRange<T> | null], string | string[] | true | null | undefined>(
|
|
510
|
+
cells(props).validate,
|
|
511
|
+
),
|
|
512
|
+
validationBehavior: () => props.validationBehavior,
|
|
513
|
+
isInvalid: () => props.isInvalid,
|
|
514
|
+
errorMessage: () => props.errorMessage,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const {
|
|
518
|
+
labelProps,
|
|
519
|
+
fieldProps: labelledProps,
|
|
520
|
+
descriptionProps,
|
|
521
|
+
errorMessageProps,
|
|
522
|
+
} = field({
|
|
523
|
+
label: () => props.label,
|
|
524
|
+
description: () => props.description,
|
|
525
|
+
errorMessage,
|
|
526
|
+
isInvalid,
|
|
527
|
+
"aria-label": () => props["aria-label"],
|
|
528
|
+
"aria-labelledby": () => props["aria-labelledby"],
|
|
529
|
+
labelElementType: "span",
|
|
530
|
+
});
|
|
531
|
+
const labelId = (): string | undefined =>
|
|
532
|
+
access(labelProps.id as MaybeAccessor<string | undefined>);
|
|
440
533
|
|
|
441
534
|
const trigger = button(
|
|
442
535
|
{
|
|
@@ -444,72 +537,107 @@ export function DateRangePicker(props: Incoming<DateRangePickerComponentProps>)
|
|
|
444
537
|
"aria-haspopup": "dialog",
|
|
445
538
|
"aria-expanded": () => overlay.isOpen(),
|
|
446
539
|
"aria-controls": () => (overlay.isOpen() ? dialogId() : undefined),
|
|
447
|
-
"aria-label": "
|
|
448
|
-
"aria-labelledby": () => `${buttonId()} ${labelId()}
|
|
449
|
-
isDisabled: () => isDisabled() || props.isReadOnly
|
|
540
|
+
"aria-label": () => messages().format("calendar"),
|
|
541
|
+
"aria-labelledby": () => `${buttonId()} ${labelId() ?? ""}`.trim(),
|
|
542
|
+
isDisabled: () => isDisabled() || props.isReadOnly === true,
|
|
450
543
|
onPress: () => overlay.toggle(),
|
|
451
|
-
}
|
|
544
|
+
},
|
|
452
545
|
triggerRef,
|
|
453
546
|
);
|
|
454
547
|
|
|
455
548
|
const { hoverProps, isHovered } = hover({ isDisabled });
|
|
456
549
|
const { focusProps, isFocusVisible } = focusRing();
|
|
457
550
|
|
|
458
|
-
/**
|
|
459
|
-
|
|
551
|
+
/**
|
|
552
|
+
* One end changed. The other is kept, so the range is edited rather than
|
|
553
|
+
* reset, and each end keeps the time typed into it.
|
|
554
|
+
*/
|
|
555
|
+
const setEnd = (which: "start" | "end", reported: DateValue | null): void => {
|
|
460
556
|
const current = value();
|
|
461
|
-
if (
|
|
557
|
+
if (reported === null) {
|
|
462
558
|
setValue(null);
|
|
463
559
|
return;
|
|
464
560
|
}
|
|
465
|
-
|
|
561
|
+
// The field reports a day or a day with a time as its granularity says,
|
|
562
|
+
// which is the kind the caller's range holds.
|
|
563
|
+
const date = reported as T;
|
|
466
564
|
const other = which === "start" ? current?.end : current?.start;
|
|
467
565
|
if (other === undefined) {
|
|
468
|
-
setValue({ start:
|
|
566
|
+
setValue({ start: date, end: date });
|
|
469
567
|
return;
|
|
470
568
|
}
|
|
471
|
-
setValue(which === "start" ? { start:
|
|
569
|
+
setValue(which === "start" ? { start: date, end: other } : { start: other, end: date });
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/** A range drawn in the calendar, with the times the two ends already held. */
|
|
573
|
+
const fromCalendar = (range: DateRange | null): DateTimeRange<T> | null => {
|
|
574
|
+
if (range === null) return null;
|
|
575
|
+
const current = value();
|
|
576
|
+
// A day chosen in the calendar keeps the time its end already had.
|
|
577
|
+
const keep = (day: CalendarDate, was: T | undefined): T =>
|
|
578
|
+
(was instanceof CalendarDateTime ? CalendarDateTime.from(day, was.time) : day) as T;
|
|
579
|
+
return { start: keep(range.start, current?.start), end: keep(range.end, current?.end) };
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
const days = (): DateRange | null => {
|
|
583
|
+
const current = value();
|
|
584
|
+
if (current === null) return null;
|
|
585
|
+
return { start: toCalendarDate(current.start), end: toCalendarDate(current.end) };
|
|
472
586
|
};
|
|
473
587
|
|
|
474
588
|
const elementProps = mergeProps(
|
|
475
|
-
|
|
476
|
-
|
|
589
|
+
labelledProps,
|
|
590
|
+
filterDOMProps(fromProps(cells(props)), { global: true }),
|
|
591
|
+
styleProps(cells(props)),
|
|
477
592
|
{
|
|
478
593
|
role: "group",
|
|
479
|
-
"aria-labelledby": labelId,
|
|
480
594
|
"aria-disabled": () => isDisabled() || undefined,
|
|
595
|
+
"aria-invalid": () => isInvalid() || undefined,
|
|
481
596
|
"data-open": overlay.isOpen,
|
|
482
|
-
"data-
|
|
597
|
+
"data-invalid": isInvalid,
|
|
598
|
+
"data-testid": () => props["data-testid"],
|
|
599
|
+
onKeyDown: (event: KeyboardEvent) =>
|
|
600
|
+
opensOnAltArrow(event, overlay, isDisabled() || props.isReadOnly === true),
|
|
483
601
|
},
|
|
484
602
|
);
|
|
485
603
|
|
|
486
604
|
return (
|
|
487
605
|
<>
|
|
488
|
-
<span
|
|
489
|
-
<div {...elementProps} ref={mergeRefs(groupRef.set, props.ref
|
|
606
|
+
<span {...labelProps}>{props.label}</span>
|
|
607
|
+
<div {...elementProps} ref={mergeRefs(groupRef.set, props.ref)}>
|
|
490
608
|
<DateField
|
|
491
|
-
aria-label="
|
|
609
|
+
aria-label={messages().format("startDate")}
|
|
492
610
|
value={value()?.start ?? null}
|
|
493
|
-
placeholderValue={props.placeholderValue
|
|
494
|
-
minValue={props.minValue
|
|
495
|
-
maxValue={props.maxValue
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
611
|
+
placeholderValue={props.placeholderValue}
|
|
612
|
+
minValue={props.minValue}
|
|
613
|
+
maxValue={props.maxValue}
|
|
614
|
+
isDateUnavailable={callback<[CalendarDate], boolean>(cells(props).isDateUnavailable)}
|
|
615
|
+
granularity={props.granularity}
|
|
616
|
+
hourCycle={props.hourCycle}
|
|
617
|
+
isDisabled={props.isDisabled}
|
|
618
|
+
isReadOnly={props.isReadOnly}
|
|
619
|
+
isRequired={props.isRequired}
|
|
620
|
+
isInvalid={isInvalid() || undefined}
|
|
621
|
+
validationBehavior={props.validationBehavior}
|
|
622
|
+
name={props.startName}
|
|
500
623
|
onChange={(next) => setEnd("start", next)}
|
|
501
624
|
/>
|
|
502
625
|
<span aria-hidden="true">–</span>
|
|
503
626
|
<DateField
|
|
504
|
-
aria-label="
|
|
627
|
+
aria-label={messages().format("endDate")}
|
|
505
628
|
value={value()?.end ?? null}
|
|
506
|
-
placeholderValue={props.placeholderValue
|
|
507
|
-
minValue={props.minValue
|
|
508
|
-
maxValue={props.maxValue
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
629
|
+
placeholderValue={props.placeholderValue}
|
|
630
|
+
minValue={props.minValue}
|
|
631
|
+
maxValue={props.maxValue}
|
|
632
|
+
isDateUnavailable={callback<[CalendarDate], boolean>(cells(props).isDateUnavailable)}
|
|
633
|
+
granularity={props.granularity}
|
|
634
|
+
hourCycle={props.hourCycle}
|
|
635
|
+
isDisabled={props.isDisabled}
|
|
636
|
+
isReadOnly={props.isReadOnly}
|
|
637
|
+
isRequired={props.isRequired}
|
|
638
|
+
isInvalid={isInvalid() || undefined}
|
|
639
|
+
validationBehavior={props.validationBehavior}
|
|
640
|
+
name={props.endName}
|
|
513
641
|
onChange={(next) => setEnd("end", next)}
|
|
514
642
|
/>
|
|
515
643
|
<button
|
|
@@ -528,29 +656,252 @@ export function DateRangePicker(props: Incoming<DateRangePickerComponentProps>)
|
|
|
528
656
|
triggerRef={triggerRef}
|
|
529
657
|
isOpen={overlay.isOpen()}
|
|
530
658
|
onOpenChange={overlay.setOpen}
|
|
531
|
-
placement={props.placement
|
|
659
|
+
placement={props.placement ?? "bottom start"}
|
|
532
660
|
>
|
|
533
|
-
<div
|
|
661
|
+
<div
|
|
662
|
+
id={dialogId}
|
|
663
|
+
role="dialog"
|
|
664
|
+
aria-labelledby={`${buttonId()} ${labelId() ?? ""}`.trim()}
|
|
665
|
+
>
|
|
534
666
|
<RangeCalendar
|
|
535
|
-
aria-label="
|
|
536
|
-
value={
|
|
537
|
-
defaultFocusedValue={
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
isDisabled={props.isDisabled?.()}
|
|
544
|
-
isReadOnly={props.isReadOnly?.()}
|
|
667
|
+
aria-label={messages().format("calendar")}
|
|
668
|
+
value={days()}
|
|
669
|
+
defaultFocusedValue={days()?.start ?? toCalendarDate(props.placeholderValue ?? today())}
|
|
670
|
+
minValue={props.minValue}
|
|
671
|
+
maxValue={props.maxValue}
|
|
672
|
+
isDateUnavailable={callback<[CalendarDate], boolean>(cells(props).isDateUnavailable)}
|
|
673
|
+
isDisabled={props.isDisabled}
|
|
674
|
+
isReadOnly={props.isReadOnly}
|
|
545
675
|
autoFocus
|
|
546
676
|
onChange={(range) => {
|
|
547
|
-
setValue(range);
|
|
677
|
+
setValue(fromCalendar(range));
|
|
548
678
|
overlay.close();
|
|
549
679
|
}}
|
|
550
680
|
/>
|
|
551
681
|
</div>
|
|
552
682
|
</Popover>
|
|
553
|
-
<span>{props.description}</span>
|
|
683
|
+
<span {...descriptionProps}>{props.description}</span>
|
|
684
|
+
<span {...errorMessageProps}>
|
|
685
|
+
{() => {
|
|
686
|
+
const given = props.errorMessage;
|
|
687
|
+
if (given !== undefined && given !== null && given !== "") return given;
|
|
688
|
+
const found = errors();
|
|
689
|
+
return found.length === 0 ? null : found.join(" ");
|
|
690
|
+
}}
|
|
691
|
+
</span>
|
|
554
692
|
</>
|
|
555
693
|
);
|
|
556
694
|
}
|
|
695
|
+
|
|
696
|
+
// ---------------------------------------------------------------------------
|
|
697
|
+
// Strings
|
|
698
|
+
// ---------------------------------------------------------------------------
|
|
699
|
+
|
|
700
|
+
type PickerKey = "calendar" | "startDate" | "endDate" | "rangeReversed";
|
|
701
|
+
|
|
702
|
+
const PICKER_STRINGS = new StringDictionary<PickerKey>({
|
|
703
|
+
"en-US": {
|
|
704
|
+
calendar: "Calendar",
|
|
705
|
+
startDate: "Start date",
|
|
706
|
+
endDate: "End date",
|
|
707
|
+
rangeReversed: "The start date is after the end date.",
|
|
708
|
+
},
|
|
709
|
+
"ar-AE": {
|
|
710
|
+
calendar: "التقويم",
|
|
711
|
+
startDate: "تاريخ البدء",
|
|
712
|
+
endDate: "تاريخ الانتهاء",
|
|
713
|
+
rangeReversed: "تاريخ البدء يجب أن يكون قبل تاريخ الانتهاء.",
|
|
714
|
+
},
|
|
715
|
+
"bg-BG": {
|
|
716
|
+
calendar: "Календар",
|
|
717
|
+
startDate: "Начална дата",
|
|
718
|
+
endDate: "Крайна дата",
|
|
719
|
+
rangeReversed: "Началната дата трябва да е преди крайната.",
|
|
720
|
+
},
|
|
721
|
+
"cs-CZ": {
|
|
722
|
+
calendar: "Kalendář",
|
|
723
|
+
startDate: "Počáteční datum",
|
|
724
|
+
endDate: "Konečné datum",
|
|
725
|
+
rangeReversed: "Datum zahájení musí předcházet datu ukončení.",
|
|
726
|
+
},
|
|
727
|
+
"da-DK": {
|
|
728
|
+
calendar: "Kalender",
|
|
729
|
+
startDate: "Startdato",
|
|
730
|
+
endDate: "Slutdato",
|
|
731
|
+
rangeReversed: "Startdatoen skal være før slutdatoen.",
|
|
732
|
+
},
|
|
733
|
+
"de-DE": {
|
|
734
|
+
calendar: "Kalender",
|
|
735
|
+
startDate: "Startdatum",
|
|
736
|
+
endDate: "Enddatum",
|
|
737
|
+
rangeReversed: "Das Startdatum muss vor dem Enddatum liegen.",
|
|
738
|
+
},
|
|
739
|
+
"el-GR": {
|
|
740
|
+
calendar: "Ημερολόγιο",
|
|
741
|
+
startDate: "Ημερομηνία έναρξης",
|
|
742
|
+
endDate: "Ημερομηνία λήξης",
|
|
743
|
+
rangeReversed: "Η ημερομηνία έναρξης πρέπει να είναι πριν από την ημερομηνία λήξης.",
|
|
744
|
+
},
|
|
745
|
+
"es-ES": {
|
|
746
|
+
calendar: "Calendario",
|
|
747
|
+
startDate: "Fecha de inicio",
|
|
748
|
+
endDate: "Fecha final",
|
|
749
|
+
rangeReversed: "La fecha de inicio debe ser anterior a la fecha de finalización.",
|
|
750
|
+
},
|
|
751
|
+
"et-EE": {
|
|
752
|
+
calendar: "Kalender",
|
|
753
|
+
startDate: "Alguskuupäev",
|
|
754
|
+
endDate: "Lõppkuupäev",
|
|
755
|
+
rangeReversed: "Alguskuupäev peab olema enne lõppkuupäeva.",
|
|
756
|
+
},
|
|
757
|
+
"fi-FI": {
|
|
758
|
+
calendar: "Kalenteri",
|
|
759
|
+
startDate: "Alkamispäivä",
|
|
760
|
+
endDate: "Päättymispäivä",
|
|
761
|
+
rangeReversed: "Aloituspäivän on oltava ennen lopetuspäivää.",
|
|
762
|
+
},
|
|
763
|
+
"fr-FR": {
|
|
764
|
+
calendar: "Calendrier",
|
|
765
|
+
startDate: "Date de début",
|
|
766
|
+
endDate: "Date de fin",
|
|
767
|
+
rangeReversed: "La date de début doit être antérieure à la date de fin.",
|
|
768
|
+
},
|
|
769
|
+
"he-IL": {
|
|
770
|
+
calendar: "לוח שנה",
|
|
771
|
+
startDate: "תאריך התחלה",
|
|
772
|
+
endDate: "תאריך סיום",
|
|
773
|
+
rangeReversed: "תאריך ההתחלה חייב להיות לפני תאריך הסיום.",
|
|
774
|
+
},
|
|
775
|
+
"hr-HR": {
|
|
776
|
+
calendar: "Kalendar",
|
|
777
|
+
startDate: "Datum početka",
|
|
778
|
+
endDate: "Datum završetka",
|
|
779
|
+
rangeReversed: "Datum početka mora biti prije datuma završetka.",
|
|
780
|
+
},
|
|
781
|
+
"hu-HU": {
|
|
782
|
+
calendar: "Naptár",
|
|
783
|
+
startDate: "Kezdő dátum",
|
|
784
|
+
endDate: "Befejező dátum",
|
|
785
|
+
rangeReversed: "A kezdő dátumnak a befejező dátumnál korábbinak kell lennie.",
|
|
786
|
+
},
|
|
787
|
+
"it-IT": {
|
|
788
|
+
calendar: "Calendario",
|
|
789
|
+
startDate: "Data iniziale",
|
|
790
|
+
endDate: "Data finale",
|
|
791
|
+
rangeReversed: "La data di inizio deve essere antecedente alla data di fine.",
|
|
792
|
+
},
|
|
793
|
+
"ja-JP": {
|
|
794
|
+
calendar: "カレンダー",
|
|
795
|
+
startDate: "開始日",
|
|
796
|
+
endDate: "終了日",
|
|
797
|
+
rangeReversed: "開始日は終了日より前にする必要があります。",
|
|
798
|
+
},
|
|
799
|
+
"ko-KR": {
|
|
800
|
+
calendar: "달력",
|
|
801
|
+
startDate: "시작일",
|
|
802
|
+
endDate: "종료일",
|
|
803
|
+
rangeReversed: "시작일은 종료일 이전이어야 합니다.",
|
|
804
|
+
},
|
|
805
|
+
"lt-LT": {
|
|
806
|
+
calendar: "Kalendorius",
|
|
807
|
+
startDate: "Pradžios data",
|
|
808
|
+
endDate: "Pabaigos data",
|
|
809
|
+
rangeReversed: "Pradžios data turi būti ankstesnė nei pabaigos data.",
|
|
810
|
+
},
|
|
811
|
+
"lv-LV": {
|
|
812
|
+
calendar: "Kalendārs",
|
|
813
|
+
startDate: "Sākuma datums",
|
|
814
|
+
endDate: "Beigu datums",
|
|
815
|
+
rangeReversed: "Sākuma datumam ir jābūt pirms beigu datuma.",
|
|
816
|
+
},
|
|
817
|
+
"nb-NO": {
|
|
818
|
+
calendar: "Kalender",
|
|
819
|
+
startDate: "Startdato",
|
|
820
|
+
endDate: "Sluttdato",
|
|
821
|
+
rangeReversed: "Startdatoen må være før sluttdatoen.",
|
|
822
|
+
},
|
|
823
|
+
"nl-NL": {
|
|
824
|
+
calendar: "Kalender",
|
|
825
|
+
startDate: "Startdatum",
|
|
826
|
+
endDate: "Einddatum",
|
|
827
|
+
rangeReversed: "De startdatum moet voor de einddatum liggen.",
|
|
828
|
+
},
|
|
829
|
+
"pl-PL": {
|
|
830
|
+
calendar: "Kalendarz",
|
|
831
|
+
startDate: "Data początkowa",
|
|
832
|
+
endDate: "Data końcowa",
|
|
833
|
+
rangeReversed: "Data rozpoczęcia musi być wcześniejsza niż data zakończenia.",
|
|
834
|
+
},
|
|
835
|
+
"pt-BR": {
|
|
836
|
+
calendar: "Calendário",
|
|
837
|
+
startDate: "Data inicial",
|
|
838
|
+
endDate: "Data final",
|
|
839
|
+
rangeReversed: "A data inicial deve ser anterior à data final.",
|
|
840
|
+
},
|
|
841
|
+
"pt-PT": {
|
|
842
|
+
calendar: "Calendário",
|
|
843
|
+
startDate: "Data de Início",
|
|
844
|
+
endDate: "Data de Término",
|
|
845
|
+
rangeReversed: "A data de início deve ser anterior à data de fim.",
|
|
846
|
+
},
|
|
847
|
+
"ro-RO": {
|
|
848
|
+
calendar: "Calendar",
|
|
849
|
+
startDate: "Dată început",
|
|
850
|
+
endDate: "Dată final",
|
|
851
|
+
rangeReversed: "Data de început trebuie să fie anterioară datei de sfârșit.",
|
|
852
|
+
},
|
|
853
|
+
"ru-RU": {
|
|
854
|
+
calendar: "Календарь",
|
|
855
|
+
startDate: "Дата начала",
|
|
856
|
+
endDate: "Дата окончания",
|
|
857
|
+
rangeReversed: "Дата начала должна предшествовать дате окончания.",
|
|
858
|
+
},
|
|
859
|
+
"sk-SK": {
|
|
860
|
+
calendar: "Kalendár",
|
|
861
|
+
startDate: "Dátum začatia",
|
|
862
|
+
endDate: "Dátum ukončenia",
|
|
863
|
+
rangeReversed: "Dátum začiatku musí byť skorší ako dátum konca.",
|
|
864
|
+
},
|
|
865
|
+
"sl-SI": {
|
|
866
|
+
calendar: "Koledar",
|
|
867
|
+
startDate: "Datum začetka",
|
|
868
|
+
endDate: "Datum konca",
|
|
869
|
+
rangeReversed: "Začetni datum mora biti pred končnim datumom.",
|
|
870
|
+
},
|
|
871
|
+
"sr-SP": {
|
|
872
|
+
calendar: "Kalendar",
|
|
873
|
+
startDate: "Datum početka",
|
|
874
|
+
endDate: "Datum završetka",
|
|
875
|
+
rangeReversed: "Datum početka mora biti pre datuma završetka.",
|
|
876
|
+
},
|
|
877
|
+
"sv-SE": {
|
|
878
|
+
calendar: "Kalender",
|
|
879
|
+
startDate: "Startdatum",
|
|
880
|
+
endDate: "Slutdatum",
|
|
881
|
+
rangeReversed: "Startdatumet måste vara före slutdatumet.",
|
|
882
|
+
},
|
|
883
|
+
"tr-TR": {
|
|
884
|
+
calendar: "Takvim",
|
|
885
|
+
startDate: "Başlangıç Tarihi",
|
|
886
|
+
endDate: "Bitiş Tarihi",
|
|
887
|
+
rangeReversed: "Başlangıç tarihi bitiş tarihinden önce olmalıdır.",
|
|
888
|
+
},
|
|
889
|
+
"uk-UA": {
|
|
890
|
+
calendar: "Календар",
|
|
891
|
+
startDate: "Дата початку",
|
|
892
|
+
endDate: "Дата завершення",
|
|
893
|
+
rangeReversed: "Дата початку має передувати даті завершення.",
|
|
894
|
+
},
|
|
895
|
+
"zh-CN": {
|
|
896
|
+
calendar: "日历",
|
|
897
|
+
startDate: "开始日期",
|
|
898
|
+
endDate: "结束日期",
|
|
899
|
+
rangeReversed: "开始日期必须早于结束日期。",
|
|
900
|
+
},
|
|
901
|
+
"zh-TW": {
|
|
902
|
+
calendar: "日曆",
|
|
903
|
+
startDate: "開始日期",
|
|
904
|
+
endDate: "結束日期",
|
|
905
|
+
rangeReversed: "開始日期必須在結束日期之前。",
|
|
906
|
+
},
|
|
907
|
+
});
|