@proyecto-viviana/solidaria 0.2.4 → 0.2.8
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/dist/actiongroup/createActionGroup.d.ts +29 -0
- package/dist/actiongroup/createActionGroup.d.ts.map +1 -0
- package/dist/actiongroup/index.d.ts +2 -0
- package/dist/actiongroup/index.d.ts.map +1 -0
- package/dist/autocomplete/createAutocomplete.d.ts +6 -2
- package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
- package/dist/breadcrumbs/createBreadcrumbs.d.ts +2 -0
- package/dist/breadcrumbs/createBreadcrumbs.d.ts.map +1 -1
- package/dist/button/createToggleButtonGroup.d.ts +32 -0
- package/dist/button/createToggleButtonGroup.d.ts.map +1 -0
- package/dist/button/index.d.ts +2 -0
- package/dist/button/index.d.ts.map +1 -1
- package/dist/calendar/createCalendarCell.d.ts +2 -0
- package/dist/calendar/createCalendarCell.d.ts.map +1 -1
- package/dist/calendar/createCalendarGrid.d.ts.map +1 -1
- package/dist/calendar/createRangeCalendarCell.d.ts +3 -1
- package/dist/calendar/createRangeCalendarCell.d.ts.map +1 -1
- package/dist/checkbox/createCheckboxGroup.d.ts +5 -1
- package/dist/checkbox/createCheckboxGroup.d.ts.map +1 -1
- package/dist/collections/index.d.ts +56 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/color/createColorArea.d.ts.map +1 -1
- package/dist/color/createColorSlider.d.ts.map +1 -1
- package/dist/color/createColorWheel.d.ts.map +1 -1
- package/dist/combobox/createComboBox.d.ts +6 -0
- package/dist/combobox/createComboBox.d.ts.map +1 -1
- package/dist/datepicker/createDatePicker.d.ts +6 -0
- package/dist/datepicker/createDatePicker.d.ts.map +1 -1
- package/dist/datepicker/createDateRangePicker.d.ts +40 -0
- package/dist/datepicker/createDateRangePicker.d.ts.map +1 -0
- package/dist/datepicker/createDateSegment.d.ts +1 -1
- package/dist/datepicker/createDateSegment.d.ts.map +1 -1
- package/dist/datepicker/createTimeSegment.d.ts +29 -0
- package/dist/datepicker/createTimeSegment.d.ts.map +1 -0
- package/dist/datepicker/index.d.ts +2 -0
- package/dist/datepicker/index.d.ts.map +1 -1
- package/dist/disclosure/createDisclosureGroup.d.ts +2 -1
- package/dist/disclosure/createDisclosureGroup.d.ts.map +1 -1
- package/dist/dnd/createDrag.d.ts.map +1 -1
- package/dist/dnd/createDraggableCollection.d.ts +4 -0
- package/dist/dnd/createDraggableCollection.d.ts.map +1 -1
- package/dist/dnd/createDraggableItem.d.ts.map +1 -1
- package/dist/dnd/createDrop.d.ts.map +1 -1
- package/dist/dnd/createDroppableCollection.d.ts +32 -1
- package/dist/dnd/createDroppableCollection.d.ts.map +1 -1
- package/dist/dnd/createDroppableItem.d.ts.map +1 -1
- package/dist/dnd/index.d.ts +1 -1
- package/dist/dnd/index.d.ts.map +1 -1
- package/dist/grid/createGrid.d.ts.map +1 -1
- package/dist/gridlist/createGridList.d.ts.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4659 -3452
- package/dist/index.js.map +1 -7
- package/dist/index.ssr.js +4659 -3452
- package/dist/index.ssr.js.map +1 -7
- package/dist/interactions/createFocus.d.ts.map +1 -1
- package/dist/interactions/createFocusWithin.d.ts.map +1 -1
- package/dist/link/createLink.d.ts +10 -0
- package/dist/link/createLink.d.ts.map +1 -1
- package/dist/listbox/createListBox.d.ts +1 -0
- package/dist/listbox/createListBox.d.ts.map +1 -1
- package/dist/listbox/createOption.d.ts.map +1 -1
- package/dist/menu/createMenu.d.ts +1 -0
- package/dist/menu/createMenu.d.ts.map +1 -1
- package/dist/meter/createMeter.d.ts.map +1 -1
- package/dist/numberfield/createNumberField.d.ts +18 -0
- package/dist/numberfield/createNumberField.d.ts.map +1 -1
- package/dist/overlays/createModal.d.ts +16 -0
- package/dist/overlays/createModal.d.ts.map +1 -1
- package/dist/overlays/createOverlay.d.ts.map +1 -1
- package/dist/overlays/index.d.ts +1 -1
- package/dist/overlays/index.d.ts.map +1 -1
- package/dist/popover/createOverlayPosition.d.ts.map +1 -1
- package/dist/popover/createPopover.d.ts.map +1 -1
- package/dist/progress/createProgressBar.d.ts.map +1 -1
- package/dist/radio/createRadioGroup.d.ts +2 -2
- package/dist/radio/createRadioGroup.d.ts.map +1 -1
- package/dist/searchfield/createSearchField.d.ts.map +1 -1
- package/dist/select/createHiddenSelect.d.ts.map +1 -1
- package/dist/select/createSelect.d.ts.map +1 -1
- package/dist/slider/createSlider.d.ts.map +1 -1
- package/dist/table/createTable.d.ts.map +1 -1
- package/dist/tabs/createTabs.d.ts +1 -1
- package/dist/tabs/createTabs.d.ts.map +1 -1
- package/dist/tag/createTag.d.ts.map +1 -1
- package/dist/tag/createTagGroup.d.ts.map +1 -1
- package/dist/toast/createToast.d.ts +4 -0
- package/dist/toast/createToast.d.ts.map +1 -1
- package/dist/toast/createToastRegion.d.ts.map +1 -1
- package/dist/toolbar/createToolbar.d.ts.map +1 -1
- package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
- package/dist/tree/createTree.d.ts.map +1 -1
- package/dist/tree/createTreeItem.d.ts.map +1 -1
- package/dist/tree/types.d.ts +4 -0
- package/dist/tree/types.d.ts.map +1 -1
- package/dist/utils/env.d.ts +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/visually-hidden/createVisuallyHidden.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/actiongroup/createActionGroup.ts +324 -0
- package/src/actiongroup/index.ts +8 -0
- package/src/autocomplete/createAutocomplete.ts +32 -9
- package/src/breadcrumbs/createBreadcrumbs.ts +10 -15
- package/src/button/createButton.ts +1 -1
- package/src/button/createToggleButtonGroup.ts +128 -0
- package/src/button/index.ts +9 -0
- package/src/calendar/createCalendarCell.ts +6 -4
- package/src/calendar/createCalendarGrid.ts +27 -18
- package/src/calendar/createRangeCalendarCell.ts +26 -9
- package/src/checkbox/createCheckboxGroup.ts +21 -4
- package/src/collections/index.ts +242 -0
- package/src/color/createColorArea.ts +380 -314
- package/src/color/createColorField.ts +137 -137
- package/src/color/createColorSlider.ts +286 -197
- package/src/color/createColorSwatch.ts +40 -40
- package/src/color/createColorWheel.ts +218 -208
- package/src/color/index.ts +24 -24
- package/src/color/types.ts +116 -116
- package/src/combobox/createComboBox.ts +670 -647
- package/src/combobox/index.ts +6 -6
- package/src/datepicker/createDatePicker.ts +54 -16
- package/src/datepicker/createDateRangePicker.ts +246 -0
- package/src/datepicker/createDateSegment.ts +185 -31
- package/src/datepicker/createTimeSegment.ts +370 -0
- package/src/datepicker/index.ts +14 -0
- package/src/dialog/createDialog.ts +120 -120
- package/src/dialog/index.ts +2 -2
- package/src/dialog/types.ts +19 -19
- package/src/disclosure/createDisclosureGroup.ts +5 -2
- package/src/dnd/createDrag.ts +224 -209
- package/src/dnd/createDraggableCollection.ts +96 -63
- package/src/dnd/createDraggableItem.ts +259 -243
- package/src/dnd/createDrop.ts +322 -321
- package/src/dnd/createDroppableCollection.ts +682 -293
- package/src/dnd/createDroppableItem.ts +215 -213
- package/src/dnd/index.ts +55 -47
- package/src/dnd/types.ts +89 -89
- package/src/dnd/utils.ts +294 -294
- package/src/focus/createAutoFocus.ts +321 -321
- package/src/focus/createFocusRestore.ts +313 -313
- package/src/focus/createVirtualFocus.ts +396 -396
- package/src/form/createFormValidation.ts +224 -224
- package/src/form/index.ts +11 -11
- package/src/grid/createGrid.ts +3 -1
- package/src/gridlist/createGridList.ts +16 -0
- package/src/gridlist/createGridListItem.ts +1 -1
- package/src/i18n/NumberFormatter.ts +266 -266
- package/src/i18n/createCollator.ts +79 -79
- package/src/i18n/createDateFormatter.ts +83 -83
- package/src/i18n/createFilter.ts +131 -131
- package/src/i18n/createNumberFormatter.ts +52 -52
- package/src/i18n/index.ts +40 -40
- package/src/i18n/locale.tsx +188 -188
- package/src/i18n/utils.ts +99 -99
- package/src/index.ts +51 -0
- package/src/interactions/createFocus.ts +6 -5
- package/src/interactions/createFocusWithin.ts +6 -5
- package/src/interactions/createLongPress.ts +174 -174
- package/src/interactions/createMove.ts +289 -289
- package/src/interactions/createPress.ts +5 -5
- package/src/landmark/createLandmark.ts +377 -377
- package/src/landmark/index.ts +8 -8
- package/src/link/createLink.ts +23 -8
- package/src/listbox/createListBox.ts +308 -269
- package/src/listbox/createOption.ts +162 -151
- package/src/listbox/index.ts +12 -12
- package/src/live-announcer/announce.ts +322 -322
- package/src/live-announcer/index.ts +9 -9
- package/src/menu/createMenu.ts +405 -396
- package/src/menu/createMenuItem.ts +149 -149
- package/src/menu/createMenuTrigger.ts +88 -88
- package/src/menu/index.ts +18 -18
- package/src/meter/createMeter.ts +1 -6
- package/src/numberfield/createNumberField.ts +311 -268
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/ariaHideOutside.ts +219 -219
- package/src/overlays/createInteractOutside.ts +149 -149
- package/src/overlays/createModal.tsx +238 -202
- package/src/overlays/createOverlay.ts +165 -155
- package/src/overlays/createOverlayTrigger.ts +85 -85
- package/src/overlays/createPreventScroll.ts +266 -266
- package/src/overlays/index.ts +48 -44
- package/src/popover/calculatePosition.ts +6 -6
- package/src/popover/createOverlayPosition.ts +7 -4
- package/src/popover/createPopover.ts +21 -7
- package/src/progress/createProgressBar.ts +6 -1
- package/src/radio/createRadioGroup.ts +88 -14
- package/src/searchfield/createSearchField.ts +241 -186
- package/src/searchfield/index.ts +2 -2
- package/src/select/createHiddenSelect.tsx +263 -236
- package/src/select/createSelect.ts +373 -395
- package/src/select/index.ts +14 -14
- package/src/slider/createSlider.ts +364 -349
- package/src/slider/index.ts +2 -2
- package/src/ssr/index.tsx +370 -370
- package/src/table/createTable.ts +3 -1
- package/src/table/createTableColumnHeader.ts +1 -1
- package/src/table/createTableRow.ts +1 -1
- package/src/tabs/createTabs.ts +80 -51
- package/src/tag/createTag.ts +135 -6
- package/src/tag/createTagGroup.ts +7 -2
- package/src/toast/createToast.ts +8 -2
- package/src/toast/createToastRegion.ts +0 -1
- package/src/toolbar/createToolbar.ts +75 -1
- package/src/tooltip/createTooltip.ts +79 -79
- package/src/tooltip/createTooltipTrigger.ts +226 -222
- package/src/tooltip/index.ts +6 -6
- package/src/tree/createTree.ts +261 -246
- package/src/tree/createTreeItem.ts +282 -233
- package/src/tree/createTreeSelectionCheckbox.ts +68 -68
- package/src/tree/index.ts +16 -16
- package/src/tree/types.ts +91 -87
- package/src/utils/env.ts +55 -54
- package/src/utils/platform.ts +16 -6
- package/src/visually-hidden/createVisuallyHidden.ts +139 -124
- package/src/visually-hidden/index.ts +6 -6
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createTimeSegment hook for Solidaria
|
|
3
|
+
*
|
|
4
|
+
* Provides the behavior and accessibility implementation for a time segment.
|
|
5
|
+
* Based on @react-aria/datepicker useDateSegment semantics (time-field scope).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createMemo, createSignal } from 'solid-js';
|
|
9
|
+
import { useLocale } from '../i18n';
|
|
10
|
+
import { access, type MaybeAccessor } from '../utils/reactivity';
|
|
11
|
+
import type { TimeFieldState, TimeSegment, TimeSegmentType } from '@proyecto-viviana/solid-stately';
|
|
12
|
+
|
|
13
|
+
// ============================================
|
|
14
|
+
// TYPES
|
|
15
|
+
// ============================================
|
|
16
|
+
|
|
17
|
+
export interface AriaTimeSegmentProps {
|
|
18
|
+
/** The segment data. */
|
|
19
|
+
segment: TimeSegment;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TimeSegmentAria {
|
|
23
|
+
/** Props for the segment element. */
|
|
24
|
+
segmentProps: Record<string, unknown>;
|
|
25
|
+
/** Whether the segment is focused. */
|
|
26
|
+
isFocused: boolean;
|
|
27
|
+
/** Whether the segment is editable. */
|
|
28
|
+
isEditable: boolean;
|
|
29
|
+
/** Whether the segment is a placeholder. */
|
|
30
|
+
isPlaceholder: boolean;
|
|
31
|
+
/** The text to display. */
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ============================================
|
|
36
|
+
// IMPLEMENTATION
|
|
37
|
+
// ============================================
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Provides the behavior and accessibility implementation for a time segment.
|
|
41
|
+
*/
|
|
42
|
+
export function createTimeSegment<T extends TimeFieldState>(
|
|
43
|
+
props: MaybeAccessor<AriaTimeSegmentProps>,
|
|
44
|
+
state: T,
|
|
45
|
+
ref?: () => HTMLElement | null
|
|
46
|
+
): TimeSegmentAria {
|
|
47
|
+
const getProps = () => access(props);
|
|
48
|
+
const [isFocused, setIsFocused] = createSignal(false);
|
|
49
|
+
const [enteredKeys, setEnteredKeys] = createSignal('');
|
|
50
|
+
const [isComposing, setIsComposing] = createSignal(false);
|
|
51
|
+
const locale = useLocale();
|
|
52
|
+
|
|
53
|
+
const segment = createMemo(() => getProps().segment);
|
|
54
|
+
|
|
55
|
+
const isEditable = createMemo(() => {
|
|
56
|
+
const seg = segment();
|
|
57
|
+
return seg.isEditable && !state.isDisabled() && !state.isReadOnly();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const focusSegment = (target: 'first' | 'last' | 'prev' | 'next') => {
|
|
61
|
+
const el = ref?.();
|
|
62
|
+
if (!el) return;
|
|
63
|
+
|
|
64
|
+
const container = el.parentElement;
|
|
65
|
+
if (!container) return;
|
|
66
|
+
|
|
67
|
+
const segments = Array.from(
|
|
68
|
+
container.querySelectorAll<HTMLElement>('[role="spinbutton"]')
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (segments.length === 0) return;
|
|
72
|
+
|
|
73
|
+
if (target === 'first') {
|
|
74
|
+
segments[0]?.focus();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (target === 'last') {
|
|
79
|
+
segments[segments.length - 1]?.focus();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const currentIndex = segments.indexOf(el);
|
|
84
|
+
if (currentIndex < 0) return;
|
|
85
|
+
|
|
86
|
+
const nextIndex = target === 'next' ? currentIndex + 1 : currentIndex - 1;
|
|
87
|
+
if (nextIndex >= 0 && nextIndex < segments.length) {
|
|
88
|
+
segments[nextIndex]?.focus();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const clearCurrentSegment = (type: TimeSegmentType) => {
|
|
93
|
+
state.clearSegment(type);
|
|
94
|
+
setEnteredKeys('');
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleNumericInput = (
|
|
98
|
+
key: string,
|
|
99
|
+
type: TimeSegmentType,
|
|
100
|
+
seg: TimeSegment
|
|
101
|
+
) => {
|
|
102
|
+
const newKeys = enteredKeys() + key;
|
|
103
|
+
const numValue = parseInt(newKeys, 10);
|
|
104
|
+
const maxValue = seg.maxValue ?? 99;
|
|
105
|
+
const minValue = seg.minValue ?? 0;
|
|
106
|
+
const maxDigits = String(maxValue).length;
|
|
107
|
+
|
|
108
|
+
if (numValue <= maxValue) {
|
|
109
|
+
state.setSegment(type, numValue);
|
|
110
|
+
|
|
111
|
+
const potentialNextValue = parseInt(newKeys + '0', 10);
|
|
112
|
+
if (potentialNextValue > maxValue || newKeys.length >= maxDigits) {
|
|
113
|
+
setEnteredKeys('');
|
|
114
|
+
focusSegment('next');
|
|
115
|
+
} else {
|
|
116
|
+
setEnteredKeys(newKeys);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const singleValue = parseInt(key, 10);
|
|
120
|
+
if (singleValue >= minValue && singleValue <= maxValue) {
|
|
121
|
+
state.setSegment(type, singleValue);
|
|
122
|
+
const potentialNextValue = parseInt(key + '0', 10);
|
|
123
|
+
if (potentialNextValue > maxValue || key.length >= maxDigits) {
|
|
124
|
+
setEnteredKeys('');
|
|
125
|
+
focusSegment('next');
|
|
126
|
+
} else {
|
|
127
|
+
setEnteredKeys(key);
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
setEnteredKeys('');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
136
|
+
if (!isEditable()) return;
|
|
137
|
+
if (isComposing()) return;
|
|
138
|
+
|
|
139
|
+
const seg = segment();
|
|
140
|
+
const type = seg.type;
|
|
141
|
+
|
|
142
|
+
if (type === 'literal') return;
|
|
143
|
+
|
|
144
|
+
switch (e.key) {
|
|
145
|
+
case 'ArrowRight':
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
focusSegment(locale().direction === 'rtl' ? 'prev' : 'next');
|
|
148
|
+
break;
|
|
149
|
+
case 'ArrowLeft':
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
focusSegment(locale().direction === 'rtl' ? 'next' : 'prev');
|
|
152
|
+
break;
|
|
153
|
+
case 'ArrowUp':
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
state.incrementSegment(type);
|
|
156
|
+
break;
|
|
157
|
+
case 'ArrowDown':
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
state.decrementSegment(type);
|
|
160
|
+
break;
|
|
161
|
+
case 'Home':
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
focusSegment('first');
|
|
164
|
+
break;
|
|
165
|
+
case 'End':
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
focusSegment('last');
|
|
168
|
+
break;
|
|
169
|
+
case 'Backspace':
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
if (seg.isPlaceholder) {
|
|
172
|
+
focusSegment('prev');
|
|
173
|
+
} else {
|
|
174
|
+
clearCurrentSegment(type);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
case 'Delete':
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
clearCurrentSegment(type);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
const normalizedDigit = normalizeDigit(e.key);
|
|
183
|
+
if (normalizedDigit) {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
handleNumericInput(normalizedDigit, type, seg);
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const handleBeforeInput = (e: InputEvent) => {
|
|
192
|
+
if (!isEditable()) return;
|
|
193
|
+
if (isComposing()) return;
|
|
194
|
+
|
|
195
|
+
const seg = segment();
|
|
196
|
+
if (seg.type === 'literal') return;
|
|
197
|
+
|
|
198
|
+
if (e.inputType === 'deleteContentBackward' || e.inputType === 'deleteContentForward') {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
clearCurrentSegment(seg.type);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (e.inputType === 'insertText' && e.data) {
|
|
205
|
+
const normalizedDigit = normalizeDigit(e.data);
|
|
206
|
+
if (!normalizedDigit) return;
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
handleNumericInput(normalizedDigit, seg.type, seg);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const handleCompositionStart = () => {
|
|
213
|
+
if (!isEditable()) return;
|
|
214
|
+
setIsComposing(true);
|
|
215
|
+
setEnteredKeys('');
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const handleCompositionEnd = (e: CompositionEvent) => {
|
|
219
|
+
if (!isEditable()) return;
|
|
220
|
+
setIsComposing(false);
|
|
221
|
+
|
|
222
|
+
const seg = segment();
|
|
223
|
+
if (seg.type === 'literal') return;
|
|
224
|
+
|
|
225
|
+
const digits = extractNormalizedDigits(e.data ?? '');
|
|
226
|
+
if (digits.length === 0) return;
|
|
227
|
+
|
|
228
|
+
for (const digit of digits) {
|
|
229
|
+
handleNumericInput(digit, seg.type, seg);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const handleFocus = () => {
|
|
234
|
+
setIsFocused(true);
|
|
235
|
+
setEnteredKeys('');
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const handleBlur = () => {
|
|
239
|
+
setIsFocused(false);
|
|
240
|
+
setEnteredKeys('');
|
|
241
|
+
|
|
242
|
+
const maybeState = state as unknown as { confirmPlaceholder?: () => void };
|
|
243
|
+
maybeState.confirmPlaceholder?.();
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const segmentProps = createMemo(() => {
|
|
247
|
+
const seg = segment();
|
|
248
|
+
const type = seg.type;
|
|
249
|
+
|
|
250
|
+
if (type === 'literal') {
|
|
251
|
+
return {
|
|
252
|
+
'aria-hidden': true,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
role: 'spinbutton',
|
|
258
|
+
tabIndex: isEditable() ? 0 : -1,
|
|
259
|
+
'aria-label': getSegmentLabel(type, locale().locale),
|
|
260
|
+
'aria-valuenow': seg.value,
|
|
261
|
+
'aria-valuemin': seg.minValue,
|
|
262
|
+
'aria-valuemax': seg.maxValue,
|
|
263
|
+
'aria-valuetext': seg.isPlaceholder ? seg.placeholder : seg.text,
|
|
264
|
+
'aria-readonly': state.isReadOnly() || undefined,
|
|
265
|
+
'aria-disabled': state.isDisabled() || undefined,
|
|
266
|
+
'aria-invalid': state.isInvalid() || undefined,
|
|
267
|
+
contentEditable: isEditable(),
|
|
268
|
+
suppressContentEditableWarning: true,
|
|
269
|
+
inputMode: 'numeric' as const,
|
|
270
|
+
autoCorrect: 'off',
|
|
271
|
+
enterKeyHint: 'next' as const,
|
|
272
|
+
spellCheck: false,
|
|
273
|
+
onKeyDown: handleKeyDown,
|
|
274
|
+
onFocus: handleFocus,
|
|
275
|
+
onBlur: handleBlur,
|
|
276
|
+
onBeforeInput: handleBeforeInput,
|
|
277
|
+
onCompositionStart: handleCompositionStart,
|
|
278
|
+
onCompositionEnd: handleCompositionEnd,
|
|
279
|
+
onMouseDown: (e: MouseEvent) => {
|
|
280
|
+
e.preventDefault();
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const text = createMemo(() => {
|
|
286
|
+
const seg = segment();
|
|
287
|
+
return seg.isPlaceholder ? seg.placeholder : seg.text;
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
get segmentProps() {
|
|
292
|
+
return segmentProps();
|
|
293
|
+
},
|
|
294
|
+
get isFocused() {
|
|
295
|
+
return isFocused();
|
|
296
|
+
},
|
|
297
|
+
get isEditable() {
|
|
298
|
+
return isEditable();
|
|
299
|
+
},
|
|
300
|
+
get isPlaceholder() {
|
|
301
|
+
return segment().isPlaceholder;
|
|
302
|
+
},
|
|
303
|
+
get text() {
|
|
304
|
+
return text();
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ============================================
|
|
310
|
+
// HELPERS
|
|
311
|
+
// ============================================
|
|
312
|
+
|
|
313
|
+
type EditableTimeSegmentType = Exclude<TimeSegmentType, 'literal'>;
|
|
314
|
+
|
|
315
|
+
const SEGMENT_LABELS: Record<string, Record<EditableTimeSegmentType, string>> = {
|
|
316
|
+
en: {
|
|
317
|
+
hour: 'Hour',
|
|
318
|
+
minute: 'Minute',
|
|
319
|
+
second: 'Second',
|
|
320
|
+
dayPeriod: 'AM/PM',
|
|
321
|
+
},
|
|
322
|
+
es: {
|
|
323
|
+
hour: 'Hora',
|
|
324
|
+
minute: 'Minuto',
|
|
325
|
+
second: 'Segundo',
|
|
326
|
+
dayPeriod: 'AM/PM',
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
function getSegmentLabel(type: TimeSegmentType, locale: string): string {
|
|
331
|
+
if (type === 'literal') return '';
|
|
332
|
+
|
|
333
|
+
const language = locale.toLowerCase().split('-')[0] ?? 'en';
|
|
334
|
+
const labels = SEGMENT_LABELS[language] ?? SEGMENT_LABELS.en;
|
|
335
|
+
return labels[type];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function normalizeDigit(input: string): string | null {
|
|
339
|
+
if (/^[0-9]$/.test(input)) {
|
|
340
|
+
return input;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const code = input.codePointAt(0);
|
|
344
|
+
if (code === undefined) return null;
|
|
345
|
+
|
|
346
|
+
if (code >= 0x0660 && code <= 0x0669) {
|
|
347
|
+
return String(code - 0x0660);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (code >= 0x06f0 && code <= 0x06f9) {
|
|
351
|
+
return String(code - 0x06f0);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (code >= 0xff10 && code <= 0xff19) {
|
|
355
|
+
return String(code - 0xff10);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function extractNormalizedDigits(input: string): string[] {
|
|
362
|
+
const digits: string[] = [];
|
|
363
|
+
for (const char of input) {
|
|
364
|
+
const normalized = normalizeDigit(char);
|
|
365
|
+
if (normalized) {
|
|
366
|
+
digits.push(normalized);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return digits;
|
|
370
|
+
}
|
package/src/datepicker/index.ts
CHANGED
|
@@ -19,6 +19,13 @@ export {
|
|
|
19
19
|
type TimeFieldAria,
|
|
20
20
|
} from './createTimeField';
|
|
21
21
|
|
|
22
|
+
// Time Segment
|
|
23
|
+
export {
|
|
24
|
+
createTimeSegment,
|
|
25
|
+
type AriaTimeSegmentProps,
|
|
26
|
+
type TimeSegmentAria,
|
|
27
|
+
} from './createTimeSegment';
|
|
28
|
+
|
|
22
29
|
// Date Picker
|
|
23
30
|
export {
|
|
24
31
|
createDatePicker,
|
|
@@ -26,3 +33,10 @@ export {
|
|
|
26
33
|
type DatePickerAria,
|
|
27
34
|
type DatePickerState,
|
|
28
35
|
} from './createDatePicker';
|
|
36
|
+
|
|
37
|
+
// Date Range Picker
|
|
38
|
+
export {
|
|
39
|
+
createDateRangePicker,
|
|
40
|
+
type AriaDateRangePickerProps,
|
|
41
|
+
type DateRangePickerAria,
|
|
42
|
+
} from './createDateRangePicker';
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Ported from React Aria:
|
|
15
|
-
* https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/dialog/src/useDialog.ts
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { Accessor, createEffect, createMemo, createSignal, createUniqueId, onCleanup } from 'solid-js'
|
|
19
|
-
import { filterDOMProps, focusSafely } from '../utils'
|
|
20
|
-
import type { AriaLabelingProps, DOMProps } from './types'
|
|
21
|
-
|
|
22
|
-
export interface AriaDialogProps extends DOMProps, AriaLabelingProps {
|
|
23
|
-
/**
|
|
24
|
-
* The role of the dialog element.
|
|
25
|
-
* @default 'dialog'
|
|
26
|
-
*/
|
|
27
|
-
role?: 'dialog' | 'alertdialog'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface DialogAria {
|
|
31
|
-
/** Props for the dialog container element. */
|
|
32
|
-
dialogProps: Accessor<Record<string, any>>
|
|
33
|
-
|
|
34
|
-
/** Props for the dialog title element. */
|
|
35
|
-
titleProps: Accessor<Record<string, any>>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Provides the behavior and accessibility implementation for a dialog component.
|
|
40
|
-
* A dialog is an overlay shown above other content in an application.
|
|
41
|
-
*/
|
|
42
|
-
export function createDialog(
|
|
43
|
-
props: AriaDialogProps | Accessor<AriaDialogProps>,
|
|
44
|
-
ref: Accessor<HTMLElement | undefined>
|
|
45
|
-
): DialogAria {
|
|
46
|
-
// Support both direct props and accessor pattern
|
|
47
|
-
const getProps = typeof props === 'function' ? props : () => props
|
|
48
|
-
|
|
49
|
-
const role = () => getProps().role ?? 'dialog'
|
|
50
|
-
const generatedTitleId = createUniqueId()
|
|
51
|
-
const [isRefocusing, setIsRefocusing] = createSignal(false)
|
|
52
|
-
|
|
53
|
-
const titleId = createMemo(() => {
|
|
54
|
-
const p = getProps()
|
|
55
|
-
// Use provided aria-labelledby, or generated ID if no aria-label
|
|
56
|
-
if (p['aria-labelledby']) return undefined
|
|
57
|
-
return p['aria-label'] ? undefined : generatedTitleId
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
// Focus the dialog itself on mount, unless a child element is already focused.
|
|
61
|
-
// Only run on the client (SSR-safe)
|
|
62
|
-
createEffect(() => {
|
|
63
|
-
// Guard against SSR - document is not available on the server
|
|
64
|
-
if (typeof document === 'undefined') return
|
|
65
|
-
|
|
66
|
-
const dialogEl = ref()
|
|
67
|
-
if (dialogEl && !dialogEl.contains(document.activeElement)) {
|
|
68
|
-
focusSafely(dialogEl)
|
|
69
|
-
|
|
70
|
-
// Safari on iOS does not move the VoiceOver cursor to the dialog
|
|
71
|
-
// or announce that it has opened until it has rendered. A workaround
|
|
72
|
-
// is to wait for half a second, then blur and re-focus the dialog.
|
|
73
|
-
const timeout = setTimeout(() => {
|
|
74
|
-
// Check that the dialog is still focused, or focused was lost to the body.
|
|
75
|
-
if (document.activeElement === dialogEl || document.activeElement === document.body) {
|
|
76
|
-
setIsRefocusing(true)
|
|
77
|
-
dialogEl.blur()
|
|
78
|
-
focusSafely(dialogEl)
|
|
79
|
-
setIsRefocusing(false)
|
|
80
|
-
}
|
|
81
|
-
}, 500)
|
|
82
|
-
|
|
83
|
-
onCleanup(() => {
|
|
84
|
-
clearTimeout(timeout)
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
// Note: Focus containment is typically handled by createModal at a higher level
|
|
90
|
-
// For standalone dialogs, focus containment should be managed by the overlay system
|
|
91
|
-
|
|
92
|
-
const dialogProps = createMemo(() => {
|
|
93
|
-
const p = getProps()
|
|
94
|
-
return {
|
|
95
|
-
...filterDOMProps(p),
|
|
96
|
-
role: role(),
|
|
97
|
-
tabIndex: -1,
|
|
98
|
-
'aria-label': p['aria-label'],
|
|
99
|
-
'aria-labelledby': p['aria-labelledby'] || titleId(),
|
|
100
|
-
'aria-describedby': p['aria-describedby'],
|
|
101
|
-
// Prevent blur events from reaching createOverlay, which may cause
|
|
102
|
-
// popovers to close. Since focus is contained within the dialog,
|
|
103
|
-
// we don't want this to occur due to the above createEffect.
|
|
104
|
-
onBlur: (e: FocusEvent) => {
|
|
105
|
-
if (isRefocusing()) {
|
|
106
|
-
e.stopPropagation()
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
const titlePropsValue = createMemo(() => ({
|
|
113
|
-
id: titleId()
|
|
114
|
-
}))
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
dialogProps,
|
|
118
|
-
titleProps: titlePropsValue
|
|
119
|
-
}
|
|
120
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Ported from React Aria:
|
|
15
|
+
* https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/dialog/src/useDialog.ts
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Accessor, createEffect, createMemo, createSignal, createUniqueId, onCleanup } from 'solid-js'
|
|
19
|
+
import { filterDOMProps, focusSafely } from '../utils'
|
|
20
|
+
import type { AriaLabelingProps, DOMProps } from './types'
|
|
21
|
+
|
|
22
|
+
export interface AriaDialogProps extends DOMProps, AriaLabelingProps {
|
|
23
|
+
/**
|
|
24
|
+
* The role of the dialog element.
|
|
25
|
+
* @default 'dialog'
|
|
26
|
+
*/
|
|
27
|
+
role?: 'dialog' | 'alertdialog'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DialogAria {
|
|
31
|
+
/** Props for the dialog container element. */
|
|
32
|
+
dialogProps: Accessor<Record<string, any>>
|
|
33
|
+
|
|
34
|
+
/** Props for the dialog title element. */
|
|
35
|
+
titleProps: Accessor<Record<string, any>>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Provides the behavior and accessibility implementation for a dialog component.
|
|
40
|
+
* A dialog is an overlay shown above other content in an application.
|
|
41
|
+
*/
|
|
42
|
+
export function createDialog(
|
|
43
|
+
props: AriaDialogProps | Accessor<AriaDialogProps>,
|
|
44
|
+
ref: Accessor<HTMLElement | undefined>
|
|
45
|
+
): DialogAria {
|
|
46
|
+
// Support both direct props and accessor pattern
|
|
47
|
+
const getProps = typeof props === 'function' ? props : () => props
|
|
48
|
+
|
|
49
|
+
const role = () => getProps().role ?? 'dialog'
|
|
50
|
+
const generatedTitleId = createUniqueId()
|
|
51
|
+
const [isRefocusing, setIsRefocusing] = createSignal(false)
|
|
52
|
+
|
|
53
|
+
const titleId = createMemo(() => {
|
|
54
|
+
const p = getProps()
|
|
55
|
+
// Use provided aria-labelledby, or generated ID if no aria-label
|
|
56
|
+
if (p['aria-labelledby']) return undefined
|
|
57
|
+
return p['aria-label'] ? undefined : generatedTitleId
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Focus the dialog itself on mount, unless a child element is already focused.
|
|
61
|
+
// Only run on the client (SSR-safe)
|
|
62
|
+
createEffect(() => {
|
|
63
|
+
// Guard against SSR - document is not available on the server
|
|
64
|
+
if (typeof document === 'undefined') return
|
|
65
|
+
|
|
66
|
+
const dialogEl = ref()
|
|
67
|
+
if (dialogEl && !dialogEl.contains(document.activeElement)) {
|
|
68
|
+
focusSafely(dialogEl)
|
|
69
|
+
|
|
70
|
+
// Safari on iOS does not move the VoiceOver cursor to the dialog
|
|
71
|
+
// or announce that it has opened until it has rendered. A workaround
|
|
72
|
+
// is to wait for half a second, then blur and re-focus the dialog.
|
|
73
|
+
const timeout = setTimeout(() => {
|
|
74
|
+
// Check that the dialog is still focused, or focused was lost to the body.
|
|
75
|
+
if (document.activeElement === dialogEl || document.activeElement === document.body) {
|
|
76
|
+
setIsRefocusing(true)
|
|
77
|
+
dialogEl.blur()
|
|
78
|
+
focusSafely(dialogEl)
|
|
79
|
+
setIsRefocusing(false)
|
|
80
|
+
}
|
|
81
|
+
}, 500)
|
|
82
|
+
|
|
83
|
+
onCleanup(() => {
|
|
84
|
+
clearTimeout(timeout)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Note: Focus containment is typically handled by createModal at a higher level
|
|
90
|
+
// For standalone dialogs, focus containment should be managed by the overlay system
|
|
91
|
+
|
|
92
|
+
const dialogProps = createMemo(() => {
|
|
93
|
+
const p = getProps()
|
|
94
|
+
return {
|
|
95
|
+
...filterDOMProps(p),
|
|
96
|
+
role: role(),
|
|
97
|
+
tabIndex: -1,
|
|
98
|
+
'aria-label': p['aria-label'],
|
|
99
|
+
'aria-labelledby': p['aria-labelledby'] || titleId(),
|
|
100
|
+
'aria-describedby': p['aria-describedby'],
|
|
101
|
+
// Prevent blur events from reaching createOverlay, which may cause
|
|
102
|
+
// popovers to close. Since focus is contained within the dialog,
|
|
103
|
+
// we don't want this to occur due to the above createEffect.
|
|
104
|
+
onBlur: (e: FocusEvent) => {
|
|
105
|
+
if (isRefocusing()) {
|
|
106
|
+
e.stopPropagation()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const titlePropsValue = createMemo(() => ({
|
|
113
|
+
id: titleId()
|
|
114
|
+
}))
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
dialogProps,
|
|
118
|
+
titleProps: titlePropsValue
|
|
119
|
+
}
|
|
120
|
+
}
|
package/src/dialog/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createDialog } from './createDialog'
|
|
2
|
-
export type { AriaDialogProps, DialogAria } from './createDialog'
|
|
1
|
+
export { createDialog } from './createDialog'
|
|
2
|
+
export type { AriaDialogProps, DialogAria } from './createDialog'
|
package/src/dialog/types.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for dialog accessibility hooks
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface DOMProps {
|
|
6
|
-
/** The element's unique identifier. */
|
|
7
|
-
id?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface AriaLabelingProps {
|
|
11
|
-
/** Defines a string value that labels the current element. */
|
|
12
|
-
'aria-label'?: string;
|
|
13
|
-
/** Identifies the element (or elements) that labels the current element. */
|
|
14
|
-
'aria-labelledby'?: string;
|
|
15
|
-
/** Identifies the element (or elements) that describes the object. */
|
|
16
|
-
'aria-describedby'?: string;
|
|
17
|
-
/** Identifies the element (or elements) that provide a detailed, extended description for the object. */
|
|
18
|
-
'aria-details'?: string;
|
|
19
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for dialog accessibility hooks
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface DOMProps {
|
|
6
|
+
/** The element's unique identifier. */
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AriaLabelingProps {
|
|
11
|
+
/** Defines a string value that labels the current element. */
|
|
12
|
+
'aria-label'?: string;
|
|
13
|
+
/** Identifies the element (or elements) that labels the current element. */
|
|
14
|
+
'aria-labelledby'?: string;
|
|
15
|
+
/** Identifies the element (or elements) that describes the object. */
|
|
16
|
+
'aria-describedby'?: string;
|
|
17
|
+
/** Identifies the element (or elements) that provide a detailed, extended description for the object. */
|
|
18
|
+
'aria-details'?: string;
|
|
19
|
+
}
|