@dloizides/ui-forms 1.41.0 → 1.42.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/dist/index.d.mts +54 -6
- package/dist/index.d.ts +54 -6
- package/dist/index.js +1193 -281
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1081 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React37 = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
var uiFeedback = require('@dloizides/ui-feedback');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -12,12 +12,12 @@ var Svg = require('react-native-svg');
|
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var React37__default = /*#__PURE__*/_interopDefault(React37);
|
|
16
16
|
var Svg__default = /*#__PURE__*/_interopDefault(Svg);
|
|
17
17
|
|
|
18
18
|
// src/Field/Field.tsx
|
|
19
19
|
function attachControlId(child, candidateId, describedById) {
|
|
20
|
-
if (!
|
|
20
|
+
if (!React37__default.default.isValidElement(child) || child.type === React37__default.default.Fragment) {
|
|
21
21
|
return { node: child };
|
|
22
22
|
}
|
|
23
23
|
const props = child.props;
|
|
@@ -28,15 +28,15 @@ function attachControlId(child, candidateId, describedById) {
|
|
|
28
28
|
if (describedById !== void 0 && props.describedById === void 0) {
|
|
29
29
|
injected.describedById = describedById;
|
|
30
30
|
}
|
|
31
|
-
return { node:
|
|
31
|
+
return { node: React37__default.default.cloneElement(element, injected), controlId };
|
|
32
32
|
}
|
|
33
33
|
var IS_WEB = reactNative.Platform.OS === "web";
|
|
34
34
|
function isAttributeHost(node) {
|
|
35
35
|
return typeof node === "object" && node !== null && typeof node.setAttribute === "function";
|
|
36
36
|
}
|
|
37
37
|
function useHtmlFor(controlId) {
|
|
38
|
-
const ref =
|
|
39
|
-
|
|
38
|
+
const ref = React37.useRef(null);
|
|
39
|
+
React37.useEffect(() => {
|
|
40
40
|
const node = ref.current;
|
|
41
41
|
if (!IS_WEB || !isAttributeHost(node)) return;
|
|
42
42
|
const target = controlId !== void 0 && controlId !== "" ? node.ownerDocument?.getElementById(controlId) : null;
|
|
@@ -138,15 +138,15 @@ var labelVariantStyles = reactNative.StyleSheet.create({
|
|
|
138
138
|
function resolveLabelVariantStyle(variant) {
|
|
139
139
|
return variant === "control" ? labelVariantStyles.control : labelVariantStyles.field;
|
|
140
140
|
}
|
|
141
|
-
var FormGridContext =
|
|
142
|
-
var GapOwnedContext =
|
|
141
|
+
var FormGridContext = React37__default.default.createContext(null);
|
|
142
|
+
var GapOwnedContext = React37__default.default.createContext(false);
|
|
143
143
|
var FormGridProvider = FormGridContext.Provider;
|
|
144
144
|
var GapOwnedProvider = GapOwnedContext.Provider;
|
|
145
145
|
function useFormGridMetrics() {
|
|
146
|
-
return
|
|
146
|
+
return React37__default.default.useContext(FormGridContext);
|
|
147
147
|
}
|
|
148
148
|
function useIsGapOwned() {
|
|
149
|
-
return
|
|
149
|
+
return React37__default.default.useContext(GapOwnedContext);
|
|
150
150
|
}
|
|
151
151
|
var ERROR_LIGHT_STEPS = ["500", "600", "700"];
|
|
152
152
|
var ERROR_DARK_STEPS = ["300", "200", "400", "100", "500"];
|
|
@@ -169,7 +169,7 @@ var styles = reactNative.StyleSheet.create({
|
|
|
169
169
|
});
|
|
170
170
|
var fieldSeq = 0;
|
|
171
171
|
function useFieldIds() {
|
|
172
|
-
const [ids] =
|
|
172
|
+
const [ids] = React37__default.default.useState(() => {
|
|
173
173
|
fieldSeq += 1;
|
|
174
174
|
const seq = String(fieldSeq);
|
|
175
175
|
return {
|
|
@@ -216,7 +216,7 @@ var Field = ({
|
|
|
216
216
|
const hasLabel = labelText !== "";
|
|
217
217
|
const marker = resolveFieldMarker(required, optional);
|
|
218
218
|
const { hintId, errorId, controlId, labelId } = useFieldIds();
|
|
219
|
-
const themeStyles =
|
|
219
|
+
const themeStyles = React37__default.default.useMemo(
|
|
220
220
|
() => ({
|
|
221
221
|
label: { color: colors.textSecondary },
|
|
222
222
|
requiredMark: { color: errorColor },
|
|
@@ -268,7 +268,7 @@ var FormGrid = ({
|
|
|
268
268
|
style,
|
|
269
269
|
testID
|
|
270
270
|
}) => {
|
|
271
|
-
const metrics =
|
|
271
|
+
const metrics = React37__default.default.useMemo(() => ({ minWidth, basis }), [minWidth, basis]);
|
|
272
272
|
return /* @__PURE__ */ jsxRuntime.jsx(FormGridProvider, { value: metrics, children: /* @__PURE__ */ jsxRuntime.jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles2.grid, { gap }, style], testID, children }) }) });
|
|
273
273
|
};
|
|
274
274
|
var LABEL_LINE_PLACEHOLDER = "\xA0";
|
|
@@ -353,8 +353,8 @@ var InlineFieldRow = ({
|
|
|
353
353
|
}) => {
|
|
354
354
|
const { width } = reactNative.useWindowDimensions();
|
|
355
355
|
const layout = inlineFieldRowLayout(width, fieldMaxWidth, inlineMinWidth);
|
|
356
|
-
const rowStyle =
|
|
357
|
-
const fieldStyle =
|
|
356
|
+
const rowStyle = React37.useMemo(() => [styles4.row, { gap }], [gap]);
|
|
357
|
+
const fieldStyle = React37.useMemo(() => [styles4.field, { maxWidth: layout.fieldMaxWidth }], [layout.fieldMaxWidth]);
|
|
358
358
|
if (!layout.inline)
|
|
359
359
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
360
360
|
field2,
|
|
@@ -535,7 +535,7 @@ var styles9 = reactNative.StyleSheet.create({
|
|
|
535
535
|
});
|
|
536
536
|
var sectionSeq = 0;
|
|
537
537
|
function useSectionLegendId() {
|
|
538
|
-
const [id] =
|
|
538
|
+
const [id] = React37__default.default.useState(() => {
|
|
539
539
|
sectionSeq += 1;
|
|
540
540
|
return `form-section-legend-${String(sectionSeq)}`;
|
|
541
541
|
});
|
|
@@ -793,8 +793,8 @@ function horizontalPlacement(rect2, viewportWidth) {
|
|
|
793
793
|
return { left, width };
|
|
794
794
|
}
|
|
795
795
|
function useAnchorRect(ref, enabled) {
|
|
796
|
-
const [rect2, setRect] =
|
|
797
|
-
|
|
796
|
+
const [rect2, setRect] = React37.useState(null);
|
|
797
|
+
React37.useLayoutEffect(() => {
|
|
798
798
|
if (!IS_WEB3 || !enabled) {
|
|
799
799
|
setRect(null);
|
|
800
800
|
return void 0;
|
|
@@ -843,8 +843,8 @@ function readViewportBottom() {
|
|
|
843
843
|
return viewport === null ? window.innerHeight : viewport.offsetTop + viewport.height;
|
|
844
844
|
}
|
|
845
845
|
function useVisualViewportBottom(enabled) {
|
|
846
|
-
const [bottom, setBottom] =
|
|
847
|
-
|
|
846
|
+
const [bottom, setBottom] = React37.useState(null);
|
|
847
|
+
React37.useLayoutEffect(() => {
|
|
848
848
|
if (!IS_WEB3 || !enabled) {
|
|
849
849
|
setBottom(null);
|
|
850
850
|
return void 0;
|
|
@@ -874,7 +874,7 @@ function scrollAnchorIntoView(ref, marginTop) {
|
|
|
874
874
|
scrollNodeIntoView(node, anchorScrollBlock(node.getBoundingClientRect().bottom, readViewportBottom()));
|
|
875
875
|
}
|
|
876
876
|
function useKeepAnchorInRoom(ref, marginTop, enabled) {
|
|
877
|
-
|
|
877
|
+
React37.useLayoutEffect(() => {
|
|
878
878
|
if (!IS_WEB3 || !enabled) return void 0;
|
|
879
879
|
const place = () => scrollAnchorIntoView(ref, marginTop);
|
|
880
880
|
place();
|
|
@@ -888,7 +888,7 @@ var ESCAPE_KEY = "Escape";
|
|
|
888
888
|
var LISTBOX_ROLE = { role: "listbox" };
|
|
889
889
|
var KEEP_FIELD_FOCUS = { onMouseDown: (event) => event.preventDefault() };
|
|
890
890
|
function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
891
|
-
|
|
891
|
+
React37.useEffect(() => {
|
|
892
892
|
if (!IS_WEB4) return void 0;
|
|
893
893
|
const onMouseDown = (event) => {
|
|
894
894
|
const anchorNode = anchorRef.current;
|
|
@@ -910,7 +910,7 @@ function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
|
910
910
|
}, [anchorRef, menuRef, onDismiss]);
|
|
911
911
|
}
|
|
912
912
|
function useKeepHighlightInView(testID, highlightedValue) {
|
|
913
|
-
|
|
913
|
+
React37.useEffect(() => {
|
|
914
914
|
if (!IS_WEB4 || highlightedValue === void 0 || highlightedValue === "") return;
|
|
915
915
|
scrollNodeIntoView(document.getElementById(optionDomId(testID, highlightedValue)), "nearest");
|
|
916
916
|
}, [testID, highlightedValue]);
|
|
@@ -929,7 +929,7 @@ function AnchoredMenu({
|
|
|
929
929
|
listbox,
|
|
930
930
|
placement
|
|
931
931
|
}) {
|
|
932
|
-
const menuRef =
|
|
932
|
+
const menuRef = React37__default.default.useRef(null);
|
|
933
933
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
934
934
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
935
935
|
const rect2 = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
@@ -1004,27 +1004,27 @@ function useThemedInput(options = {}) {
|
|
|
1004
1004
|
const { hasError = false, onFocus, onBlur, editable = true } = options;
|
|
1005
1005
|
const { theme } = uiFeedback.useUi();
|
|
1006
1006
|
const { colors, palette } = theme;
|
|
1007
|
-
const [isFocused, setIsFocused] =
|
|
1008
|
-
const [isHovered, setIsHovered] =
|
|
1009
|
-
const handleFocus =
|
|
1007
|
+
const [isFocused, setIsFocused] = React37.useState(false);
|
|
1008
|
+
const [isHovered, setIsHovered] = React37.useState(false);
|
|
1009
|
+
const handleFocus = React37.useCallback(
|
|
1010
1010
|
(e) => {
|
|
1011
1011
|
setIsFocused(true);
|
|
1012
1012
|
onFocus?.(e);
|
|
1013
1013
|
},
|
|
1014
1014
|
[onFocus]
|
|
1015
1015
|
);
|
|
1016
|
-
const handleBlur =
|
|
1016
|
+
const handleBlur = React37.useCallback(
|
|
1017
1017
|
(e) => {
|
|
1018
1018
|
setIsFocused(false);
|
|
1019
1019
|
onBlur?.(e);
|
|
1020
1020
|
},
|
|
1021
1021
|
[onBlur]
|
|
1022
1022
|
);
|
|
1023
|
-
const handleHoverIn =
|
|
1024
|
-
const handleHoverOut =
|
|
1023
|
+
const handleHoverIn = React37.useCallback(() => setIsHovered(true), []);
|
|
1024
|
+
const handleHoverOut = React37.useCallback(() => setIsHovered(false), []);
|
|
1025
1025
|
const primary = palette.primary["500"];
|
|
1026
1026
|
const errorColor = fieldErrorInk(theme);
|
|
1027
|
-
const style =
|
|
1027
|
+
const style = React37.useMemo(() => {
|
|
1028
1028
|
const restBorder = hasError ? errorColor : colors.border;
|
|
1029
1029
|
const focusBorder = hasError ? errorColor : primary;
|
|
1030
1030
|
const editableBorder = isFocused ? focusBorder : isHovered ? withAlpha(colors.text, HOVER_BORDER_ALPHA) : restBorder;
|
|
@@ -1057,8 +1057,8 @@ function useThemedInput(options = {}) {
|
|
|
1057
1057
|
errorColor,
|
|
1058
1058
|
theme
|
|
1059
1059
|
]);
|
|
1060
|
-
const focusBind =
|
|
1061
|
-
const hoverBind =
|
|
1060
|
+
const focusBind = React37.useMemo(() => ({ onFocus: handleFocus, onBlur: handleBlur }), [handleFocus, handleBlur]);
|
|
1061
|
+
const hoverBind = React37.useMemo(
|
|
1062
1062
|
() => IS_WEB5 ? { onMouseEnter: handleHoverIn, onMouseLeave: handleHoverOut } : {},
|
|
1063
1063
|
[handleHoverIn, handleHoverOut]
|
|
1064
1064
|
);
|
|
@@ -1089,7 +1089,7 @@ var boxStyles = reactNative.StyleSheet.create({
|
|
|
1089
1089
|
textAlignVertical: "top"
|
|
1090
1090
|
}
|
|
1091
1091
|
});
|
|
1092
|
-
var ThemedTextInput =
|
|
1092
|
+
var ThemedTextInput = React37__default.default.forwardRef(function ThemedTextInput2({
|
|
1093
1093
|
hasError = false,
|
|
1094
1094
|
describedById,
|
|
1095
1095
|
requiredField = false,
|
|
@@ -1184,11 +1184,11 @@ function recentsEqual(a, b) {
|
|
|
1184
1184
|
|
|
1185
1185
|
// src/useRecentValues/useRecentValues.ts
|
|
1186
1186
|
function useRecentValues(key, max = DEFAULT_MAX_RECENTS) {
|
|
1187
|
-
const [recents, setRecents] =
|
|
1188
|
-
|
|
1187
|
+
const [recents, setRecents] = React37.useState(() => readRecents(key).slice(0, max));
|
|
1188
|
+
React37.useEffect(() => {
|
|
1189
1189
|
setRecents(readRecents(key).slice(0, max));
|
|
1190
1190
|
}, [key, max]);
|
|
1191
|
-
const remember =
|
|
1191
|
+
const remember = React37.useCallback(
|
|
1192
1192
|
(value) => {
|
|
1193
1193
|
setRecents((current) => {
|
|
1194
1194
|
const next = computeNextRecents(current, value, max);
|
|
@@ -1199,7 +1199,7 @@ function useRecentValues(key, max = DEFAULT_MAX_RECENTS) {
|
|
|
1199
1199
|
},
|
|
1200
1200
|
[key, max]
|
|
1201
1201
|
);
|
|
1202
|
-
const clear =
|
|
1202
|
+
const clear = React37.useCallback(() => {
|
|
1203
1203
|
clearRecents(key);
|
|
1204
1204
|
setRecents([]);
|
|
1205
1205
|
}, [key]);
|
|
@@ -1221,24 +1221,24 @@ function RecentInputField({
|
|
|
1221
1221
|
const { theme } = uiFeedback.useUi();
|
|
1222
1222
|
const { colors, palette } = theme;
|
|
1223
1223
|
const { recents, remember } = useRecentValues(recentKey, recentMax);
|
|
1224
|
-
const anchorRef =
|
|
1225
|
-
const latestText =
|
|
1226
|
-
const [isOpen, setIsOpen] =
|
|
1227
|
-
const handleChange =
|
|
1224
|
+
const anchorRef = React37.useRef(null);
|
|
1225
|
+
const latestText = React37.useRef(typeof value === "string" ? value : "");
|
|
1226
|
+
const [isOpen, setIsOpen] = React37.useState(false);
|
|
1227
|
+
const handleChange = React37.useCallback(
|
|
1228
1228
|
(text) => {
|
|
1229
1229
|
latestText.current = text;
|
|
1230
1230
|
onChangeText?.(text);
|
|
1231
1231
|
},
|
|
1232
1232
|
[onChangeText]
|
|
1233
1233
|
);
|
|
1234
|
-
const handleFocus =
|
|
1234
|
+
const handleFocus = React37.useCallback(
|
|
1235
1235
|
(event) => {
|
|
1236
1236
|
setIsOpen(true);
|
|
1237
1237
|
onFocus?.(event);
|
|
1238
1238
|
},
|
|
1239
1239
|
[onFocus]
|
|
1240
1240
|
);
|
|
1241
|
-
const handleBlur =
|
|
1241
|
+
const handleBlur = React37.useCallback(
|
|
1242
1242
|
(event) => {
|
|
1243
1243
|
const blurredText = latestText.current;
|
|
1244
1244
|
setTimeout(() => {
|
|
@@ -1249,7 +1249,7 @@ function RecentInputField({
|
|
|
1249
1249
|
},
|
|
1250
1250
|
[remember, onBlur]
|
|
1251
1251
|
);
|
|
1252
|
-
const handleSubmit =
|
|
1252
|
+
const handleSubmit = React37.useCallback(
|
|
1253
1253
|
(event) => {
|
|
1254
1254
|
remember(latestText.current);
|
|
1255
1255
|
setIsOpen(false);
|
|
@@ -1257,7 +1257,7 @@ function RecentInputField({
|
|
|
1257
1257
|
},
|
|
1258
1258
|
[remember, onSubmitEditing]
|
|
1259
1259
|
);
|
|
1260
|
-
const pick =
|
|
1260
|
+
const pick = React37.useCallback(
|
|
1261
1261
|
(picked) => {
|
|
1262
1262
|
latestText.current = picked;
|
|
1263
1263
|
onChangeText?.(picked);
|
|
@@ -1399,7 +1399,7 @@ function ChipContent({ icon, label, textStyle, numberOfLines }) {
|
|
|
1399
1399
|
}
|
|
1400
1400
|
function OutlineChip(props) {
|
|
1401
1401
|
const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
|
|
1402
|
-
const [hovered, setHovered] =
|
|
1402
|
+
const [hovered, setHovered] = React37__default.default.useState(false);
|
|
1403
1403
|
const active = selected || hovered;
|
|
1404
1404
|
const borderColor = active ? colors.primary : colors.border;
|
|
1405
1405
|
const backgroundColor = selected ? colors.tint : colors.muted;
|
|
@@ -1499,8 +1499,8 @@ function radioTabIndex(index, selectedIndex, disabled) {
|
|
|
1499
1499
|
var NO_GROUP_PROPS = {};
|
|
1500
1500
|
function useRadioKeyboard(config) {
|
|
1501
1501
|
const { enabled, disabled, values, selectedIndex, onChange } = config;
|
|
1502
|
-
const nodes =
|
|
1503
|
-
const chipRef =
|
|
1502
|
+
const nodes = React37__default.default.useRef([]);
|
|
1503
|
+
const chipRef = React37__default.default.useCallback((index) => (node) => {
|
|
1504
1504
|
nodes.current[index] = node;
|
|
1505
1505
|
}, []);
|
|
1506
1506
|
const onKeyDown = (event) => {
|
|
@@ -1613,7 +1613,7 @@ var ChipSelector = ({
|
|
|
1613
1613
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1614
1614
|
const { theme } = uiFeedback.useUi();
|
|
1615
1615
|
const { colors, palette } = theme;
|
|
1616
|
-
const chipColors =
|
|
1616
|
+
const chipColors = React37__default.default.useMemo(() => buildChipColors(colors, palette), [colors, palette]);
|
|
1617
1617
|
function isSelected(optionValue) {
|
|
1618
1618
|
if (multiple && Array.isArray(value))
|
|
1619
1619
|
return value.includes(optionValue);
|
|
@@ -1709,12 +1709,12 @@ var FormSwitch = ({
|
|
|
1709
1709
|
accessibilityHint
|
|
1710
1710
|
}) => {
|
|
1711
1711
|
const { theme } = uiFeedback.useUi();
|
|
1712
|
-
const toggle2 =
|
|
1712
|
+
const toggle2 = React37__default.default.useCallback(() => {
|
|
1713
1713
|
if (!disabled) onValueChange(!value);
|
|
1714
1714
|
}, [disabled, onValueChange, value]);
|
|
1715
1715
|
const { colors } = theme;
|
|
1716
1716
|
const hasDescription = typeof description === "string" && description !== "";
|
|
1717
|
-
const themeStyles =
|
|
1717
|
+
const themeStyles = React37__default.default.useMemo(() => {
|
|
1718
1718
|
const labelStyle = { color: colors.text };
|
|
1719
1719
|
const descriptionStyle = { color: colors.textSecondary };
|
|
1720
1720
|
return { label: labelStyle, description: descriptionStyle };
|
|
@@ -1837,8 +1837,8 @@ var FormCheckbox = ({
|
|
|
1837
1837
|
const hintText = typeof hint === "string" && hint !== "" ? hint : description;
|
|
1838
1838
|
const hasHint = typeof hintText === "string" && hintText !== "";
|
|
1839
1839
|
const { hintId } = useFieldIds();
|
|
1840
|
-
const [focused, setFocused] =
|
|
1841
|
-
const themeStyles =
|
|
1840
|
+
const [focused, setFocused] = React37__default.default.useState(false);
|
|
1841
|
+
const themeStyles = React37__default.default.useMemo(() => {
|
|
1842
1842
|
const boxOn = checkboxBoxColors(colors, brand, true);
|
|
1843
1843
|
const boxOff = checkboxBoxColors(colors, brand, false);
|
|
1844
1844
|
const ring = { borderColor: brand };
|
|
@@ -1908,9 +1908,9 @@ function nextHighlight(current, count, delta) {
|
|
|
1908
1908
|
var FORWARD = 1;
|
|
1909
1909
|
var BACKWARD = -1;
|
|
1910
1910
|
function useSelectListbox({ options, isOpen, open, toggle: toggle2, select }) {
|
|
1911
|
-
const [row, setRow] =
|
|
1911
|
+
const [row, setRow] = React37.useState(NO_HIGHLIGHT);
|
|
1912
1912
|
const highlighted = isOpen ? options[row] : void 0;
|
|
1913
|
-
|
|
1913
|
+
React37.useEffect(() => {
|
|
1914
1914
|
if (!isOpen) setRow(NO_HIGHLIGHT);
|
|
1915
1915
|
}, [isOpen]);
|
|
1916
1916
|
const onKeyDown = (event) => {
|
|
@@ -1951,22 +1951,22 @@ function SelectControl({
|
|
|
1951
1951
|
}) {
|
|
1952
1952
|
const { theme } = uiFeedback.useUi();
|
|
1953
1953
|
const { colors, palette } = theme;
|
|
1954
|
-
const anchorRef =
|
|
1955
|
-
const [isOpen, setIsOpen] =
|
|
1956
|
-
const selectedLabel =
|
|
1954
|
+
const anchorRef = React37.useRef(null);
|
|
1955
|
+
const [isOpen, setIsOpen] = React37.useState(false);
|
|
1956
|
+
const selectedLabel = React37.useMemo(() => {
|
|
1957
1957
|
const found = options.find((o) => o.value === value);
|
|
1958
1958
|
return found?.label ?? placeholder;
|
|
1959
1959
|
}, [options, placeholder, value]);
|
|
1960
|
-
const close =
|
|
1960
|
+
const close = React37.useCallback(() => {
|
|
1961
1961
|
setIsOpen(false);
|
|
1962
1962
|
}, []);
|
|
1963
|
-
const open =
|
|
1963
|
+
const open = React37.useCallback(() => {
|
|
1964
1964
|
setIsOpen(true);
|
|
1965
1965
|
}, []);
|
|
1966
|
-
const toggle2 =
|
|
1966
|
+
const toggle2 = React37.useCallback(() => {
|
|
1967
1967
|
setIsOpen((prev) => !prev);
|
|
1968
1968
|
}, []);
|
|
1969
|
-
const select =
|
|
1969
|
+
const select = React37.useCallback(
|
|
1970
1970
|
(next) => {
|
|
1971
1971
|
onChange(next);
|
|
1972
1972
|
setIsOpen(false);
|
|
@@ -2041,17 +2041,17 @@ var SelectField = ({
|
|
|
2041
2041
|
};
|
|
2042
2042
|
var CLOSE_DELAY_MS2 = 140;
|
|
2043
2043
|
function useDelayedBlurClose(open, close) {
|
|
2044
|
-
const timerRef =
|
|
2045
|
-
const cancelClose =
|
|
2044
|
+
const timerRef = React37.useRef(null);
|
|
2045
|
+
const cancelClose = React37.useCallback(() => {
|
|
2046
2046
|
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
2047
2047
|
timerRef.current = null;
|
|
2048
2048
|
}, []);
|
|
2049
|
-
|
|
2050
|
-
const handleFocus =
|
|
2049
|
+
React37.useEffect(() => cancelClose, [cancelClose]);
|
|
2050
|
+
const handleFocus = React37.useCallback(() => {
|
|
2051
2051
|
cancelClose();
|
|
2052
2052
|
open();
|
|
2053
2053
|
}, [cancelClose, open]);
|
|
2054
|
-
const handleBlur =
|
|
2054
|
+
const handleBlur = React37.useCallback(() => {
|
|
2055
2055
|
cancelClose();
|
|
2056
2056
|
timerRef.current = setTimeout(close, CLOSE_DELAY_MS2);
|
|
2057
2057
|
}, [cancelClose, close]);
|
|
@@ -2094,10 +2094,10 @@ function isUnmatched(options, text) {
|
|
|
2094
2094
|
var DEFAULT_TYPEAHEAD_DEBOUNCE_MS = 250;
|
|
2095
2095
|
var IDLE = { results: [], isLoading: false, hasFailed: false, hasSettled: false };
|
|
2096
2096
|
function useTypeaheadSearch(load, query, enabled, debounceMs) {
|
|
2097
|
-
const [state, setState] =
|
|
2098
|
-
const loadRef =
|
|
2097
|
+
const [state, setState] = React37.useState(IDLE);
|
|
2098
|
+
const loadRef = React37.useRef(load);
|
|
2099
2099
|
loadRef.current = load;
|
|
2100
|
-
|
|
2100
|
+
React37.useEffect(() => {
|
|
2101
2101
|
if (!enabled) {
|
|
2102
2102
|
setState(IDLE);
|
|
2103
2103
|
return void 0;
|
|
@@ -2136,30 +2136,30 @@ function useTypeaheadRows(input, isOpen, isPicked) {
|
|
|
2136
2136
|
const query = value.trim();
|
|
2137
2137
|
const isSearching = search !== void 0 && isOpen && !isPicked && query.length >= minChars;
|
|
2138
2138
|
const found = useTypeaheadSearch(search?.load, query, isSearching, search?.debounceMs ?? DEFAULT_TYPEAHEAD_DEBOUNCE_MS);
|
|
2139
|
-
const staticRows =
|
|
2139
|
+
const staticRows = React37.useMemo(() => {
|
|
2140
2140
|
if (options === void 0 || options.some((o) => o.label === value)) return NO_ROWS;
|
|
2141
2141
|
return suggestOptions(options, value, minChars, maxSuggestions);
|
|
2142
2142
|
}, [options, value, minChars, maxSuggestions]);
|
|
2143
|
-
const foundRows =
|
|
2143
|
+
const foundRows = React37.useMemo(() => found.results.slice(0, maxSuggestions), [found.results, maxSuggestions]);
|
|
2144
2144
|
if (search === void 0) return { rows: staticRows, statusText: void 0 };
|
|
2145
2145
|
return { rows: foundRows, statusText: searchStatusText(found, search) };
|
|
2146
2146
|
}
|
|
2147
2147
|
function useTypeaheadState(input) {
|
|
2148
2148
|
const { search, value, onChange, onSubmit } = input;
|
|
2149
|
-
const [isOpen, setIsOpen] =
|
|
2150
|
-
const [picked, setPicked] =
|
|
2151
|
-
const [highlightIndex, setHighlightIndex] =
|
|
2149
|
+
const [isOpen, setIsOpen] = React37.useState(false);
|
|
2150
|
+
const [picked, setPicked] = React37.useState(null);
|
|
2151
|
+
const [highlightIndex, setHighlightIndex] = React37.useState(NO_HIGHLIGHT);
|
|
2152
2152
|
const { rows, statusText } = useTypeaheadRows(input, isOpen, picked !== null && picked.label === value);
|
|
2153
2153
|
const rowKey = rows.map((row) => row.value).join("\n");
|
|
2154
2154
|
const highlighted = isOpen ? rows[highlightIndex] : void 0;
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
const open =
|
|
2158
|
-
const close =
|
|
2155
|
+
React37.useEffect(() => setHighlightIndex(NO_HIGHLIGHT), [rowKey]);
|
|
2156
|
+
React37.useEffect(() => setPicked((current) => current !== null && current.label !== value ? null : current), [value]);
|
|
2157
|
+
const open = React37.useCallback(() => setIsOpen(true), []);
|
|
2158
|
+
const close = React37.useCallback(() => {
|
|
2159
2159
|
setIsOpen(false);
|
|
2160
2160
|
setHighlightIndex(NO_HIGHLIGHT);
|
|
2161
2161
|
}, []);
|
|
2162
|
-
const pick =
|
|
2162
|
+
const pick = React37.useCallback(
|
|
2163
2163
|
(option) => {
|
|
2164
2164
|
setPicked(option);
|
|
2165
2165
|
onChange(option.label);
|
|
@@ -2168,14 +2168,14 @@ function useTypeaheadState(input) {
|
|
|
2168
2168
|
},
|
|
2169
2169
|
[onChange, search, close]
|
|
2170
2170
|
);
|
|
2171
|
-
const selectValue =
|
|
2171
|
+
const selectValue = React37.useCallback(
|
|
2172
2172
|
(optionValue) => {
|
|
2173
2173
|
const option = rows.find((row) => row.value === optionValue);
|
|
2174
2174
|
if (option !== void 0) pick(option);
|
|
2175
2175
|
},
|
|
2176
2176
|
[rows, pick]
|
|
2177
2177
|
);
|
|
2178
|
-
const handleChange =
|
|
2178
|
+
const handleChange = React37.useCallback(
|
|
2179
2179
|
(next) => {
|
|
2180
2180
|
if (picked !== null) {
|
|
2181
2181
|
setPicked(null);
|
|
@@ -2188,7 +2188,7 @@ function useTypeaheadState(input) {
|
|
|
2188
2188
|
[picked, search, onChange]
|
|
2189
2189
|
);
|
|
2190
2190
|
const handleKeyPress = useTypeaheadKeys({ rowCount: rows.length, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick });
|
|
2191
|
-
const handleSubmit =
|
|
2191
|
+
const handleSubmit = React37.useCallback(() => {
|
|
2192
2192
|
if (highlighted !== void 0) {
|
|
2193
2193
|
pick(highlighted);
|
|
2194
2194
|
return;
|
|
@@ -2200,7 +2200,7 @@ function useTypeaheadState(input) {
|
|
|
2200
2200
|
}
|
|
2201
2201
|
function useTypeaheadKeys(input) {
|
|
2202
2202
|
const { rowCount, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick } = input;
|
|
2203
|
-
return
|
|
2203
|
+
return React37.useCallback(
|
|
2204
2204
|
(event) => {
|
|
2205
2205
|
const { key } = event.nativeEvent;
|
|
2206
2206
|
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
@@ -2237,7 +2237,7 @@ function TypeaheadControlImpl(props, ref) {
|
|
|
2237
2237
|
const maxSuggestions = ("search" in props ? props.search.maxResults : props.maxSuggestions) ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
2238
2238
|
const { theme } = uiFeedback.useUi();
|
|
2239
2239
|
const { colors, palette } = theme;
|
|
2240
|
-
const anchorRef =
|
|
2240
|
+
const anchorRef = React37.useRef(null);
|
|
2241
2241
|
const state = useTypeaheadState({ options, search, value, minChars, maxSuggestions, onChange, onSubmit });
|
|
2242
2242
|
const { handleFocus, handleBlur } = useDelayedBlurClose(state.open, state.close);
|
|
2243
2243
|
const showMenu = state.isOpen && (state.rows.length > 0 || state.statusText !== void 0);
|
|
@@ -2290,7 +2290,7 @@ function TypeaheadControlImpl(props, ref) {
|
|
|
2290
2290
|
hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [controlStyles.error, { color: fieldErrorInk(theme) }], testID: `${testID}-error`, children: error }) : null
|
|
2291
2291
|
] });
|
|
2292
2292
|
}
|
|
2293
|
-
var TypeaheadControl =
|
|
2293
|
+
var TypeaheadControl = React37.forwardRef(TypeaheadControlImpl);
|
|
2294
2294
|
var NATIVE_INPUT_BOX = {
|
|
2295
2295
|
borderStyle: "solid",
|
|
2296
2296
|
boxSizing: "border-box",
|
|
@@ -2342,8 +2342,751 @@ function WebDateInput({ fieldProps, context, webInputType }) {
|
|
|
2342
2342
|
}
|
|
2343
2343
|
);
|
|
2344
2344
|
}
|
|
2345
|
+
var PATHS = {
|
|
2346
|
+
["calendar" /* Calendar */]: "M7 3v3M17 3v3M4 9h16M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z",
|
|
2347
|
+
["previous" /* Previous */]: "M15 5l-7 7 7 7",
|
|
2348
|
+
["next" /* Next */]: "M9 5l7 7-7 7"
|
|
2349
|
+
};
|
|
2350
|
+
var SIZE = 18;
|
|
2351
|
+
var STROKE = 2;
|
|
2352
|
+
function Glyph({ name, color }) {
|
|
2353
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { "aria-hidden": "true", fill: "none", height: SIZE, stroke: color, strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: STROKE, viewBox: "0 0 24 24", width: SIZE, children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: PATHS[name] }) });
|
|
2354
|
+
}
|
|
2355
|
+
var TINT_STEP = "100";
|
|
2356
|
+
function usePickerColors() {
|
|
2357
|
+
const { theme } = uiFeedback.useUi();
|
|
2358
|
+
const brand = theme.palette.primary["500"];
|
|
2359
|
+
return {
|
|
2360
|
+
text: theme.colors.text,
|
|
2361
|
+
textSecondary: theme.colors.textSecondary,
|
|
2362
|
+
border: theme.colors.border,
|
|
2363
|
+
surface: theme.colors.surface,
|
|
2364
|
+
brand,
|
|
2365
|
+
onBrand: designTokens.resolveOnBrand(brand),
|
|
2366
|
+
tint: theme.palette.primary[TINT_STEP] ?? theme.colors.background
|
|
2367
|
+
};
|
|
2368
|
+
}
|
|
2369
|
+
var FOCUSABLE = "button, select, input, [tabindex]";
|
|
2370
|
+
var RADIUS = 12;
|
|
2371
|
+
var SHEET_RADIUS = 16;
|
|
2372
|
+
var PAD = 12;
|
|
2373
|
+
var SHEET_MAX_HEIGHT = "90vh";
|
|
2374
|
+
function tabStops(container) {
|
|
2375
|
+
return Array.from(container.querySelectorAll(FOCUSABLE)).filter(
|
|
2376
|
+
(node) => node.tabIndex >= 0 && !node.hasAttribute("disabled") && node.getAttribute("aria-disabled") !== "true"
|
|
2377
|
+
);
|
|
2378
|
+
}
|
|
2379
|
+
function PickerDialog({ testID, sheet, onDismiss, children }) {
|
|
2380
|
+
const colors = usePickerColors();
|
|
2381
|
+
const ref = React37.useRef(null);
|
|
2382
|
+
const onKeyDown = (event) => {
|
|
2383
|
+
if (event.key === "Escape") {
|
|
2384
|
+
event.preventDefault();
|
|
2385
|
+
event.stopPropagation();
|
|
2386
|
+
onDismiss();
|
|
2387
|
+
return;
|
|
2388
|
+
}
|
|
2389
|
+
if (event.key !== "Tab" || ref.current === null) return;
|
|
2390
|
+
const stops = tabStops(ref.current);
|
|
2391
|
+
const first = stops[0];
|
|
2392
|
+
const last = stops[stops.length - 1];
|
|
2393
|
+
if (first === void 0 || last === void 0) return;
|
|
2394
|
+
const atEdge = event.shiftKey ? document.activeElement === first : document.activeElement === last;
|
|
2395
|
+
if (!atEdge) return;
|
|
2396
|
+
event.preventDefault();
|
|
2397
|
+
(event.shiftKey ? last : first).focus();
|
|
2398
|
+
};
|
|
2399
|
+
const shape = sheet ? { borderTopLeftRadius: SHEET_RADIUS, borderTopRightRadius: SHEET_RADIUS, width: "100%", maxHeight: SHEET_MAX_HEIGHT, overflowY: "auto" } : { borderRadius: RADIUS, boxShadow: `0 12px 32px ${colors.border}` };
|
|
2400
|
+
const style = { boxSizing: "border-box", padding: PAD, background: colors.surface, color: colors.text, border: `1px solid ${colors.border}`, fontFamily: "inherit", ...shape };
|
|
2401
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, "data-testid": testID, "data-variant": sheet ? "sheet" : "popover", style, onKeyDown, children });
|
|
2402
|
+
}
|
|
2403
|
+
function useAnchorRect2(anchorRef) {
|
|
2404
|
+
const [rect2, setRect] = React37.useState(null);
|
|
2405
|
+
React37.useEffect(() => {
|
|
2406
|
+
anchorRef.current?.measureInWindow((x, y, width, height) => setRect({ x, y, width, height }));
|
|
2407
|
+
}, [anchorRef]);
|
|
2408
|
+
return rect2;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// src/SearchSelect/DropdownPlacement.ts
|
|
2412
|
+
var DropdownPlacement = /* @__PURE__ */ ((DropdownPlacement2) => {
|
|
2413
|
+
DropdownPlacement2["Below"] = "below";
|
|
2414
|
+
DropdownPlacement2["Above"] = "above";
|
|
2415
|
+
return DropdownPlacement2;
|
|
2416
|
+
})(DropdownPlacement || {});
|
|
2417
|
+
|
|
2418
|
+
// src/SearchSelect/utils/dropdownFrame.ts
|
|
2419
|
+
var MIN_PANEL_WIDTH = 240;
|
|
2420
|
+
var EDGE = 8;
|
|
2421
|
+
function placeDropdown(anchor, panelHeight, viewportHeight) {
|
|
2422
|
+
const roomBelow = viewportHeight - (anchor.y + anchor.height);
|
|
2423
|
+
if (roomBelow >= panelHeight) return "below" /* Below */;
|
|
2424
|
+
return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
|
|
2425
|
+
}
|
|
2426
|
+
function clampTop(top, panelHeight, viewportHeight) {
|
|
2427
|
+
return Math.max(EDGE, Math.min(top, viewportHeight - panelHeight - EDGE));
|
|
2428
|
+
}
|
|
2429
|
+
function dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow = false) {
|
|
2430
|
+
const placement = preferBelow ? "below" /* Below */ : placeDropdown(anchor, panelHeight, viewportHeight);
|
|
2431
|
+
const base = { placement, left: anchor.x, width: anchor.width };
|
|
2432
|
+
if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - clampTop(anchor.y - panelHeight, panelHeight, viewportHeight) - panelHeight };
|
|
2433
|
+
return { ...base, top: clampTop(anchor.y + anchor.height, panelHeight, viewportHeight) };
|
|
2434
|
+
}
|
|
2435
|
+
function fitDropdownWidth(frame, viewportWidth, minWidth = MIN_PANEL_WIDTH) {
|
|
2436
|
+
const width = Math.max(frame.width, Math.min(minWidth, viewportWidth - EDGE - EDGE));
|
|
2437
|
+
const left = Math.max(EDGE, Math.min(frame.left, viewportWidth - width - EDGE));
|
|
2438
|
+
return { ...frame, width, left: frame.width >= width ? frame.left : left };
|
|
2439
|
+
}
|
|
2440
|
+
function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel, preferBelow = false }) {
|
|
2441
|
+
const { height: viewportHeight, width: viewportWidth } = reactNative.useWindowDimensions();
|
|
2442
|
+
const anchor = useAnchorRect2(anchorRef);
|
|
2443
|
+
const [panelHeight, setPanelHeight] = React37.useState(0);
|
|
2444
|
+
const onLayout = React37.useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
|
|
2445
|
+
const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow), viewportWidth, minWidth);
|
|
2446
|
+
const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
|
|
2447
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: [
|
|
2448
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
2449
|
+
frame !== null ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles15.dropdown, place, { opacity: progress, transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, scale === void 0 ? null : styles15.growFromField], testID: `${testID}-dropdown-${frame.placement}`, onLayout, children }) : null
|
|
2450
|
+
] });
|
|
2451
|
+
}
|
|
2452
|
+
var styles15 = reactNative.StyleSheet.create({
|
|
2453
|
+
dropdown: { position: "absolute" },
|
|
2454
|
+
growFromField: { transformOrigin: "top left" }
|
|
2455
|
+
});
|
|
2456
|
+
function SheetSurface({ translateY, onDismiss, closeLabel, closeHint, testID, children, progress, scale, accessibilityLabel }) {
|
|
2457
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles16.backdrop, children: [
|
|
2458
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
2459
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { testID: `${testID}-sheet`, style: [styles16.sheet, { transform: scale === void 0 ? [{ translateY }] : [{ translateY }, { scale }] }, progress === void 0 ? null : { opacity: progress }], children })
|
|
2460
|
+
] }) });
|
|
2461
|
+
}
|
|
2462
|
+
var styles16 = reactNative.StyleSheet.create({
|
|
2463
|
+
backdrop: { flex: 1, justifyContent: "flex-end" },
|
|
2464
|
+
sheet: { width: "100%", alignSelf: "stretch" }
|
|
2465
|
+
});
|
|
2466
|
+
function useReducedMotion() {
|
|
2467
|
+
const [reduced, setReduced] = React37.useState(false);
|
|
2468
|
+
React37.useEffect(() => {
|
|
2469
|
+
let active = true;
|
|
2470
|
+
reactNative.AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
2471
|
+
if (active) setReduced(value);
|
|
2472
|
+
}).catch(() => void 0);
|
|
2473
|
+
const subscription = reactNative.AccessibilityInfo.addEventListener("reduceMotionChanged", setReduced);
|
|
2474
|
+
return () => {
|
|
2475
|
+
active = false;
|
|
2476
|
+
subscription?.remove();
|
|
2477
|
+
};
|
|
2478
|
+
}, []);
|
|
2479
|
+
return reduced;
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// src/DatePicker/data/defaultLabels.ts
|
|
2483
|
+
var DEFAULT_DATE_PICKER_LABELS = {
|
|
2484
|
+
dialog: "Choose a date",
|
|
2485
|
+
rangeDialog: "Choose a date range",
|
|
2486
|
+
openCalendar: "Open calendar",
|
|
2487
|
+
openCalendarHint: "Opens a calendar to pick the date",
|
|
2488
|
+
previousMonth: "Previous month",
|
|
2489
|
+
nextMonth: "Next month",
|
|
2490
|
+
monthHint: "Shows another month",
|
|
2491
|
+
month: "Month",
|
|
2492
|
+
year: "Year",
|
|
2493
|
+
dayHint: "Picks this day",
|
|
2494
|
+
setDate: "Set date",
|
|
2495
|
+
setDateHint: "Saves the picked date",
|
|
2496
|
+
clear: "Clear",
|
|
2497
|
+
clearHint: "Removes the date",
|
|
2498
|
+
cancel: "Cancel",
|
|
2499
|
+
cancelHint: "Closes without changes",
|
|
2500
|
+
apply: "Apply",
|
|
2501
|
+
applyHint: "Saves the picked range",
|
|
2502
|
+
presets: "Quick ranges",
|
|
2503
|
+
presetHint: "Sets the range to this period",
|
|
2504
|
+
today: "Today",
|
|
2505
|
+
last7Days: "Last 7 days",
|
|
2506
|
+
thisMonth: "This month",
|
|
2507
|
+
quarter: "Quarter",
|
|
2508
|
+
dayCount: "{{p1}} days",
|
|
2509
|
+
invalidDate: "Enter a real date",
|
|
2510
|
+
rangeSeparator: " \u2013 ",
|
|
2511
|
+
rangeOrder: "The start must be on or before the end",
|
|
2512
|
+
outOfRange: "This date is outside the allowed range"
|
|
2513
|
+
};
|
|
2514
|
+
|
|
2515
|
+
// src/DatePicker/utils/isoDate.ts
|
|
2516
|
+
var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
2517
|
+
var MONTHS_IN_YEAR = 12;
|
|
2518
|
+
var DAYS_IN_WEEK = 7;
|
|
2519
|
+
var PAD2 = 2;
|
|
2520
|
+
var YEAR_PAD = 4;
|
|
2521
|
+
var SUNDAY = 0;
|
|
2522
|
+
var MONDAY = 1;
|
|
2523
|
+
var MS_PER_DAY = 864e5;
|
|
2524
|
+
var MONTH_PREFIX = "YYYY-MM".length;
|
|
2525
|
+
var EPOCH = { year: 1970, month: 1, day: 1 };
|
|
2526
|
+
function daysInMonth(year, month) {
|
|
2527
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
2528
|
+
}
|
|
2529
|
+
function isValidParts({ year, month, day }) {
|
|
2530
|
+
const inMonth = month >= 1 && month <= MONTHS_IN_YEAR;
|
|
2531
|
+
return Number.isInteger(year) && year > 0 && inMonth && Number.isInteger(day) && day >= 1 && day <= daysInMonth(year, month);
|
|
2532
|
+
}
|
|
2533
|
+
function parseIso(value) {
|
|
2534
|
+
const match = ISO_DATE.exec(value);
|
|
2535
|
+
if (match === null) return null;
|
|
2536
|
+
const parts = { year: Number(match[1]), month: Number(match[2]), day: Number(match[3]) };
|
|
2537
|
+
return isValidParts(parts) ? parts : null;
|
|
2538
|
+
}
|
|
2539
|
+
function toIso({ year, month, day }) {
|
|
2540
|
+
return `${String(year).padStart(YEAR_PAD, "0")}-${String(month).padStart(PAD2, "0")}-${String(day).padStart(PAD2, "0")}`;
|
|
2541
|
+
}
|
|
2542
|
+
function toUtc(iso) {
|
|
2543
|
+
const parts = parseIso(iso) ?? EPOCH;
|
|
2544
|
+
return new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2545
|
+
}
|
|
2546
|
+
function fromUtc(date) {
|
|
2547
|
+
return toIso({ year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() });
|
|
2548
|
+
}
|
|
2549
|
+
function addDays(iso, days) {
|
|
2550
|
+
const date = toUtc(iso);
|
|
2551
|
+
date.setUTCDate(date.getUTCDate() + days);
|
|
2552
|
+
return fromUtc(date);
|
|
2553
|
+
}
|
|
2554
|
+
function addMonths(iso, months) {
|
|
2555
|
+
const parts = parseIso(iso) ?? EPOCH;
|
|
2556
|
+
const index = parts.year * MONTHS_IN_YEAR + (parts.month - 1) + months;
|
|
2557
|
+
const year = Math.floor(index / MONTHS_IN_YEAR);
|
|
2558
|
+
const month = index % MONTHS_IN_YEAR + 1;
|
|
2559
|
+
return toIso({ year, month, day: Math.min(parts.day, daysInMonth(year, month)) });
|
|
2560
|
+
}
|
|
2561
|
+
function weekdayIndex(iso, firstDay = MONDAY) {
|
|
2562
|
+
const day = toUtc(iso).getUTCDay();
|
|
2563
|
+
const isoDay = day === SUNDAY ? DAYS_IN_WEEK : day;
|
|
2564
|
+
return (isoDay - firstDay + DAYS_IN_WEEK) % DAYS_IN_WEEK;
|
|
2565
|
+
}
|
|
2566
|
+
function daysBetweenInclusive(from, to) {
|
|
2567
|
+
return Math.round((toUtc(to).getTime() - toUtc(from).getTime()) / MS_PER_DAY) + 1;
|
|
2568
|
+
}
|
|
2569
|
+
function isWithinBounds(iso, min, max) {
|
|
2570
|
+
const aboveMin = min === void 0 || min === "" || iso >= min.slice(0, iso.length);
|
|
2571
|
+
const belowMax = max === void 0 || max === "" || iso <= max.slice(0, iso.length);
|
|
2572
|
+
return aboveMin && belowMax;
|
|
2573
|
+
}
|
|
2574
|
+
function clampToBounds(iso, min, max) {
|
|
2575
|
+
if (min !== void 0 && min !== "" && iso < min.slice(0, iso.length)) return min.slice(0, iso.length);
|
|
2576
|
+
if (max !== void 0 && max !== "" && iso > max.slice(0, iso.length)) return max.slice(0, iso.length);
|
|
2577
|
+
return iso;
|
|
2578
|
+
}
|
|
2579
|
+
function todayIso(now = /* @__PURE__ */ new Date()) {
|
|
2580
|
+
return toIso({ year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate() });
|
|
2581
|
+
}
|
|
2582
|
+
function monthStart(iso) {
|
|
2583
|
+
return `${iso.slice(0, MONTH_PREFIX)}-01`;
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
// src/DatePicker/utils/weekStart.ts
|
|
2587
|
+
var MONDAY2 = 1;
|
|
2588
|
+
var SUNDAY2 = 7;
|
|
2589
|
+
var SUNDAY_REGIONS = /* @__PURE__ */ new Set(["US", "CA", "MX", "BR", "JP", "KR", "TW", "HK", "IL", "PH", "IN", "ZA", "SA", "PE", "CO", "VE", "GT", "HN", "PA", "PR", "DO", "SV", "TH", "ID"]);
|
|
2590
|
+
function weekFirstDay(locale) {
|
|
2591
|
+
try {
|
|
2592
|
+
const resolved = new Intl.Locale(locale ?? new Intl.DateTimeFormat().resolvedOptions().locale);
|
|
2593
|
+
const info = resolved;
|
|
2594
|
+
const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
|
|
2595
|
+
if (first !== void 0) return first;
|
|
2596
|
+
return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 : MONDAY2;
|
|
2597
|
+
} catch {
|
|
2598
|
+
return MONDAY2;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
var DatePickerContext = React37.createContext({ labels: DEFAULT_DATE_PICKER_LABELS });
|
|
2602
|
+
function DatePickerProvider({ labels, locale, today, children }) {
|
|
2603
|
+
const value = React37.useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today }), [labels, locale, today]);
|
|
2604
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DatePickerContext.Provider, { value, children });
|
|
2605
|
+
}
|
|
2606
|
+
function useDatePickerConfig() {
|
|
2607
|
+
const config = React37.useContext(DatePickerContext);
|
|
2608
|
+
const firstDay = React37.useMemo(() => weekFirstDay(config.locale), [config.locale]);
|
|
2609
|
+
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay };
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// src/DatePicker/utils/motionStyles.ts
|
|
2613
|
+
var OPEN_MS = 180;
|
|
2614
|
+
var MONTH_SLIDE_MS = 200;
|
|
2615
|
+
var MONTH_SLIDE_PX = 16;
|
|
2616
|
+
var OPEN_SCALE = 0.96;
|
|
2617
|
+
var EASE = "cubic-bezier(0.2, 0, 0, 1)";
|
|
2618
|
+
function resolveOpenMotion(reduced) {
|
|
2619
|
+
return reduced ? { durationMs: 0, fromScale: 1 } : { durationMs: OPEN_MS, fromScale: OPEN_SCALE };
|
|
2620
|
+
}
|
|
2621
|
+
function monthSlideStyle(entered, reduced, direction) {
|
|
2622
|
+
if (reduced || direction === 0) return {};
|
|
2623
|
+
return {
|
|
2624
|
+
opacity: entered ? 1 : 0,
|
|
2625
|
+
transform: entered ? "translateX(0px)" : `translateX(${direction * MONTH_SLIDE_PX}px)`,
|
|
2626
|
+
transition: `opacity ${MONTH_SLIDE_MS}ms ${EASE}, transform ${MONTH_SLIDE_MS}ms ${EASE}`
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
function useOpenProgress() {
|
|
2630
|
+
const { durationMs, fromScale } = resolveOpenMotion(useReducedMotion());
|
|
2631
|
+
const progress = React37.useRef(new reactNative.Animated.Value(0)).current;
|
|
2632
|
+
React37.useEffect(() => {
|
|
2633
|
+
reactNative.Animated.timing(progress, { toValue: 1, duration: durationMs, useNativeDriver: false }).start();
|
|
2634
|
+
}, [progress, durationMs]);
|
|
2635
|
+
return {
|
|
2636
|
+
progress,
|
|
2637
|
+
scale: progress.interpolate({ inputRange: [0, 1], outputRange: [fromScale, 1] }),
|
|
2638
|
+
still: progress.interpolate({ inputRange: [0, 1], outputRange: [0, 0] })
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, children }) {
|
|
2642
|
+
const { labels } = useDatePickerConfig();
|
|
2643
|
+
const { progress, scale, still } = useOpenProgress();
|
|
2644
|
+
const body = /* @__PURE__ */ jsxRuntime.jsx(PickerDialog, { sheet: phone, testID, onDismiss, children });
|
|
2645
|
+
if (phone) {
|
|
2646
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SheetSurface, { accessibilityLabel: label, closeHint: labels.cancelHint, closeLabel: labels.cancel, progress, testID, translateY: still, onDismiss, children: body });
|
|
2647
|
+
}
|
|
2648
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DropdownSurface, { accessibilityLabel: label, anchorRef, closeHint: labels.cancelHint, closeLabel: labels.cancel, minWidth, preferBelow: true, progress, scale, testID, translateY: still, onDismiss, children: body });
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
// src/DatePicker/utils/calendarKeys.ts
|
|
2652
|
+
var DAYS_IN_WEEK2 = 7;
|
|
2653
|
+
var MONTHS_IN_YEAR2 = 12;
|
|
2654
|
+
var MONDAY3 = 1;
|
|
2655
|
+
var DAY_STEPS = {
|
|
2656
|
+
ArrowLeft: -1,
|
|
2657
|
+
ArrowRight: 1,
|
|
2658
|
+
ArrowUp: -DAYS_IN_WEEK2,
|
|
2659
|
+
ArrowDown: DAYS_IN_WEEK2
|
|
2660
|
+
};
|
|
2661
|
+
function nextFocusDay(iso, key, shiftKey = false, firstDay = MONDAY3) {
|
|
2662
|
+
const step = DAY_STEPS[key];
|
|
2663
|
+
if (step !== void 0) return addDays(iso, step);
|
|
2664
|
+
const monthStep = shiftKey ? MONTHS_IN_YEAR2 : 1;
|
|
2665
|
+
if (key === "PageUp") return addMonths(iso, -monthStep);
|
|
2666
|
+
if (key === "PageDown") return addMonths(iso, monthStep);
|
|
2667
|
+
if (key === "Home") return addDays(iso, -weekdayIndex(iso, firstDay));
|
|
2668
|
+
if (key === "End") return addDays(iso, DAYS_IN_WEEK2 - 1 - weekdayIndex(iso, firstDay));
|
|
2669
|
+
return null;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
// src/DatePicker/hooks/useGridFocus.ts
|
|
2673
|
+
function dayDomId(testID, iso) {
|
|
2674
|
+
return `${testID}-day-${iso}`;
|
|
2675
|
+
}
|
|
2676
|
+
function useGridFocus(initial, bounds, testID, onPick) {
|
|
2677
|
+
const { firstDay } = useDatePickerConfig();
|
|
2678
|
+
const [focusedDay, setFocusedDay] = React37.useState(initial);
|
|
2679
|
+
const focusPending = React37.useRef(true);
|
|
2680
|
+
const { min, max } = bounds;
|
|
2681
|
+
React37.useEffect(() => {
|
|
2682
|
+
if (!focusPending.current) return;
|
|
2683
|
+
focusPending.current = false;
|
|
2684
|
+
document.getElementById(dayDomId(testID, focusedDay))?.focus();
|
|
2685
|
+
}, [focusedDay, testID]);
|
|
2686
|
+
const moveTo = React37.useCallback((iso) => setFocusedDay(clampToBounds(iso, min, max)), [min, max]);
|
|
2687
|
+
const onDayKey = React37.useCallback(
|
|
2688
|
+
(event, iso) => {
|
|
2689
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
2690
|
+
event.preventDefault();
|
|
2691
|
+
onPick(iso);
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
const next = nextFocusDay(iso, event.key, event.shiftKey, firstDay);
|
|
2695
|
+
if (next === null) return;
|
|
2696
|
+
event.preventDefault();
|
|
2697
|
+
focusPending.current = true;
|
|
2698
|
+
moveTo(next);
|
|
2699
|
+
},
|
|
2700
|
+
[moveTo, onPick, firstDay]
|
|
2701
|
+
);
|
|
2702
|
+
return { focusedDay, moveTo, onDayKey };
|
|
2703
|
+
}
|
|
2704
|
+
var DAY_CELL_PX = 44;
|
|
2705
|
+
var DAY_START = 8;
|
|
2706
|
+
var RING = 2;
|
|
2707
|
+
var FONT = 14;
|
|
2708
|
+
var BOLD = 700;
|
|
2709
|
+
var REGULAR = 400;
|
|
2710
|
+
function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
|
|
2711
|
+
const colors = usePickerColors();
|
|
2712
|
+
const { inRange, isEnd, isToday, enabled, focusable } = state;
|
|
2713
|
+
const cellStyle = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0, background: inRange && !isEnd ? colors.tint : "transparent" };
|
|
2714
|
+
const textColor = isEnd ? colors.onBrand : enabled ? colors.text : colors.textSecondary;
|
|
2715
|
+
const buttonStyle = {
|
|
2716
|
+
width: DAY_CELL_PX,
|
|
2717
|
+
height: DAY_CELL_PX,
|
|
2718
|
+
padding: 0,
|
|
2719
|
+
boxSizing: "border-box",
|
|
2720
|
+
borderRadius: DAY_CELL_PX / 2,
|
|
2721
|
+
border: `${RING}px solid ${isToday ? colors.brand : "transparent"}`,
|
|
2722
|
+
background: isEnd ? colors.brand : "transparent",
|
|
2723
|
+
color: textColor,
|
|
2724
|
+
textDecoration: enabled ? "none" : "line-through",
|
|
2725
|
+
fontFamily: "inherit",
|
|
2726
|
+
fontSize: FONT,
|
|
2727
|
+
fontWeight: isEnd || isToday ? BOLD : REGULAR,
|
|
2728
|
+
cursor: enabled ? "pointer" : "default"
|
|
2729
|
+
};
|
|
2730
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-selected": isEnd, role: "gridcell", style: cellStyle, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2731
|
+
"button",
|
|
2732
|
+
{
|
|
2733
|
+
"aria-current": isToday ? "date" : void 0,
|
|
2734
|
+
"aria-label": label,
|
|
2735
|
+
"data-testid": dayDomId(testID, iso),
|
|
2736
|
+
disabled: !enabled,
|
|
2737
|
+
id: dayDomId(testID, iso),
|
|
2738
|
+
style: buttonStyle,
|
|
2739
|
+
tabIndex: focusable ? 0 : -1,
|
|
2740
|
+
title: hint,
|
|
2741
|
+
type: "button",
|
|
2742
|
+
onClick: () => onPick(iso),
|
|
2743
|
+
onKeyDown: (event) => onKey(event, iso),
|
|
2744
|
+
children: Number(iso.slice(DAY_START))
|
|
2745
|
+
}
|
|
2746
|
+
) });
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
// src/DatePicker/utils/formatDate.ts
|
|
2750
|
+
var SAMPLE_UTC = Date.UTC(2027, 5, 12);
|
|
2751
|
+
var TWO_DIGIT_YEAR = 100;
|
|
2752
|
+
var CENTURY = 2e3;
|
|
2753
|
+
var PART_COUNT = 3;
|
|
2754
|
+
var PAD3 = 2;
|
|
2755
|
+
var MONDAY4 = 1;
|
|
2756
|
+
var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
2757
|
+
var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
|
|
2758
|
+
var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
|
|
2759
|
+
var UTC = "UTC";
|
|
2760
|
+
var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
|
|
2761
|
+
function utcOf(iso) {
|
|
2762
|
+
const parts = parseIso(iso);
|
|
2763
|
+
return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2764
|
+
}
|
|
2765
|
+
function formatWith(iso, locale, options) {
|
|
2766
|
+
const date = utcOf(iso);
|
|
2767
|
+
if (date === null) return iso;
|
|
2768
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
|
|
2769
|
+
}
|
|
2770
|
+
function formatDisplay(iso, locale) {
|
|
2771
|
+
return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
2772
|
+
}
|
|
2773
|
+
function formatShort(iso, locale, withYear = true) {
|
|
2774
|
+
return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
|
|
2775
|
+
}
|
|
2776
|
+
function formatMonthYear(iso, locale) {
|
|
2777
|
+
return formatWith(iso, locale, { month: "long", year: "numeric" });
|
|
2778
|
+
}
|
|
2779
|
+
function monthNames(locale) {
|
|
2780
|
+
const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
|
|
2781
|
+
return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
|
|
2782
|
+
}
|
|
2783
|
+
function weekdayNames(locale, firstDay = MONDAY4) {
|
|
2784
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
|
|
2785
|
+
return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
|
|
2786
|
+
}
|
|
2787
|
+
function typedOrder(locale) {
|
|
2788
|
+
const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
|
|
2789
|
+
return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
|
|
2790
|
+
}
|
|
2791
|
+
function formatTyped(iso, locale) {
|
|
2792
|
+
const parts = parseIso(iso);
|
|
2793
|
+
if (parts === null) return iso;
|
|
2794
|
+
const text = {
|
|
2795
|
+
["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
|
|
2796
|
+
["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
|
|
2797
|
+
["year" /* Year */]: String(parts.year)
|
|
2798
|
+
};
|
|
2799
|
+
return typedOrder(locale).map((part) => text[part]).join("/");
|
|
2800
|
+
}
|
|
2801
|
+
function parseTyped(text, locale) {
|
|
2802
|
+
const trimmed = text.trim();
|
|
2803
|
+
if (ISO_LIKE.test(trimmed)) {
|
|
2804
|
+
const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
|
|
2805
|
+
const parts2 = { year, month, day };
|
|
2806
|
+
return isValidParts(parts2) ? toIso(parts2) : null;
|
|
2807
|
+
}
|
|
2808
|
+
const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
|
|
2809
|
+
if (numbers2.length !== PART_COUNT) return null;
|
|
2810
|
+
const order = typedOrder(locale);
|
|
2811
|
+
const read = (part) => numbers2[order.indexOf(part)] ?? 0;
|
|
2812
|
+
const rawYear = read("year" /* Year */);
|
|
2813
|
+
const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
|
|
2814
|
+
return isValidParts(parts) ? toIso(parts) : null;
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// src/DatePicker/utils/monthGrid.ts
|
|
2818
|
+
var DAYS_IN_WEEK3 = 7;
|
|
2819
|
+
var MONDAY5 = 1;
|
|
2820
|
+
function buildMonthGrid(year, month, firstDay = MONDAY5) {
|
|
2821
|
+
const lead = weekdayIndex(toIso({ year, month, day: 1 }), firstDay);
|
|
2822
|
+
const cells = Array.from({ length: lead }, () => null);
|
|
2823
|
+
for (let day = 1; day <= daysInMonth(year, month); day += 1) cells.push(toIso({ year, month, day }));
|
|
2824
|
+
while (cells.length % DAYS_IN_WEEK3 !== 0) cells.push(null);
|
|
2825
|
+
const weeks = [];
|
|
2826
|
+
for (let start = 0; start < cells.length; start += DAYS_IN_WEEK3) weeks.push(cells.slice(start, start + DAYS_IN_WEEK3));
|
|
2827
|
+
return weeks;
|
|
2828
|
+
}
|
|
2829
|
+
var SHORT_DAY = 2;
|
|
2830
|
+
var DAYS_IN_WEEK4 = 7;
|
|
2831
|
+
var HEADER_LINE = 28;
|
|
2832
|
+
var CAPTION_FONT = 15;
|
|
2833
|
+
var WEEKDAY_FONT = 12;
|
|
2834
|
+
var BOLD2 = 700;
|
|
2835
|
+
var ROW = { display: "flex" };
|
|
2836
|
+
var EMPTY = { width: DAY_CELL_PX, height: DAY_CELL_PX, flexShrink: 0 };
|
|
2837
|
+
var FALLBACK = { year: 1970, month: 1};
|
|
2838
|
+
function MonthGrid({ month, selection, focusedDay, bounds, testID, onPick, onKey, showCaption = false, motion }) {
|
|
2839
|
+
const { labels, locale, today, firstDay } = useDatePickerConfig();
|
|
2840
|
+
const colors = usePickerColors();
|
|
2841
|
+
const parts = parseIso(month) ?? FALLBACK;
|
|
2842
|
+
const weeks = React37.useMemo(() => buildMonthGrid(parts.year, parts.month, firstDay), [parts.year, parts.month, firstDay]);
|
|
2843
|
+
const weekdays = React37.useMemo(() => weekdayNames(locale, firstDay), [locale, firstDay]);
|
|
2844
|
+
const title = formatMonthYear(month, locale);
|
|
2845
|
+
const end = selection.to === "" ? selection.from : selection.to;
|
|
2846
|
+
const stateOf = (iso) => ({
|
|
2847
|
+
inRange: selection.from !== "" && iso >= selection.from && iso <= end,
|
|
2848
|
+
isEnd: iso === selection.from || iso === selection.to,
|
|
2849
|
+
isToday: iso === today,
|
|
2850
|
+
enabled: isWithinBounds(iso, bounds.min, bounds.max),
|
|
2851
|
+
focusable: iso === focusedDay
|
|
2852
|
+
});
|
|
2853
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { width: DAYS_IN_WEEK4 * DAY_CELL_PX, margin: "0 auto", ...motion }, children: [
|
|
2854
|
+
showCaption ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", fontWeight: BOLD2, fontSize: CAPTION_FONT, lineHeight: `${a11y.MIN_TOUCH_TARGET_PX}px` }, children: title }) : null,
|
|
2855
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { "aria-label": title, "data-testid": `${testID}-grid-${month.slice(0, "2026-11".length)}`, role: "grid", children: [
|
|
2856
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { role: "row", style: ROW, children: weekdays.map((name) => /* @__PURE__ */ jsxRuntime.jsx("div", { role: "columnheader", style: { width: DAY_CELL_PX, textAlign: "center", fontSize: WEEKDAY_FONT, lineHeight: `${HEADER_LINE}px`, color: colors.textSecondary }, children: name.slice(0, SHORT_DAY) }, name)) }),
|
|
2857
|
+
weeks.map((week, row) => /* @__PURE__ */ jsxRuntime.jsx("div", { role: "row", style: ROW, children: week.map(
|
|
2858
|
+
(iso, column) => iso === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { role: "gridcell", style: EMPTY }, `empty-${column}`) : /* @__PURE__ */ jsxRuntime.jsx(DayCell, { hint: labels.dayHint, iso, label: formatDisplay(iso, locale), state: stateOf(iso), testID, onKey, onPick }, iso)
|
|
2859
|
+
) }, `${month}-${row}`))
|
|
2860
|
+
] })
|
|
2861
|
+
] });
|
|
2862
|
+
}
|
|
2863
|
+
var YEARS_BACK = 100;
|
|
2864
|
+
var YEARS_AHEAD = 20;
|
|
2865
|
+
var ISO_LENGTH = 10;
|
|
2866
|
+
var FONT2 = 15;
|
|
2867
|
+
var BOLD3 = 700;
|
|
2868
|
+
var GAP = 4;
|
|
2869
|
+
var FALLBACK2 = { year: 1970, month: 1, day: 1 };
|
|
2870
|
+
function boundYear(bound) {
|
|
2871
|
+
return parseIso((bound ?? "").slice(0, ISO_LENGTH))?.year;
|
|
2872
|
+
}
|
|
2873
|
+
function yearOptions(current, bounds) {
|
|
2874
|
+
const first = Math.min(current, boundYear(bounds.min) ?? current - YEARS_BACK);
|
|
2875
|
+
const last = Math.max(current, boundYear(bounds.max) ?? current + YEARS_AHEAD);
|
|
2876
|
+
return Array.from({ length: last - first + 1 }, (_unused, index) => first + index);
|
|
2877
|
+
}
|
|
2878
|
+
function MonthHeader({ focusedDay, bounds, testID, onMove }) {
|
|
2879
|
+
const { labels, locale } = useDatePickerConfig();
|
|
2880
|
+
const colors = usePickerColors();
|
|
2881
|
+
const parts = parseIso(focusedDay) ?? FALLBACK2;
|
|
2882
|
+
const names = React37.useMemo(() => monthNames(locale), [locale]);
|
|
2883
|
+
const setMonthYear = (year, month) => onMove(toIso({ year, month, day: Math.min(parts.day, daysInMonth(year, month)) }));
|
|
2884
|
+
const selectStyle = { minHeight: a11y.MIN_TOUCH_TARGET_PX, border: "none", background: "transparent", color: colors.text, fontWeight: BOLD3, fontSize: FONT2, fontFamily: "inherit", cursor: "pointer" };
|
|
2885
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
2886
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.monthHint, accessibilityLabel: labels.previousMonth, appearance: "ghost", renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "previous" /* Previous */ }), testID: `${testID}-previous`, onPress: () => onMove(addMonths(focusedDay, -1)) }),
|
|
2887
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: GAP }, children: [
|
|
2888
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { "aria-label": labels.month, "data-testid": `${testID}-month`, style: selectStyle, title: labels.monthHint, value: parts.month, onChange: (event) => setMonthYear(parts.year, Number(event.target.value)), children: names.map((name, index) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: index + 1, children: name }, name)) }),
|
|
2889
|
+
/* @__PURE__ */ jsxRuntime.jsx("select", { "aria-label": labels.year, "data-testid": `${testID}-year`, style: selectStyle, title: labels.monthHint, value: parts.year, onChange: (event) => setMonthYear(Number(event.target.value), parts.month), children: yearOptions(parts.year, bounds).map((year) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: year, children: year }, year)) })
|
|
2890
|
+
] }),
|
|
2891
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.monthHint, accessibilityLabel: labels.nextMonth, appearance: "ghost", renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "next" /* Next */ }), testID: `${testID}-next`, onPress: () => onMove(addMonths(focusedDay, 1)) })
|
|
2892
|
+
] });
|
|
2893
|
+
}
|
|
2894
|
+
var GAP2 = 8;
|
|
2895
|
+
function PickerFooter({ summary, children }) {
|
|
2896
|
+
const colors = usePickerColors();
|
|
2897
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: GAP2, borderTop: `1px solid ${colors.border}`, paddingTop: GAP2, marginTop: GAP2 }, children: [
|
|
2898
|
+
summary,
|
|
2899
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: GAP2, marginLeft: "auto" }, children })
|
|
2900
|
+
] });
|
|
2901
|
+
}
|
|
2902
|
+
function useEntered(key, reduced) {
|
|
2903
|
+
const [enteredKey, setEnteredKey] = React37.useState(null);
|
|
2904
|
+
React37.useEffect(() => {
|
|
2905
|
+
if (reduced) return void 0;
|
|
2906
|
+
let inner = 0;
|
|
2907
|
+
const outer = requestAnimationFrame(() => {
|
|
2908
|
+
inner = requestAnimationFrame(() => setEnteredKey(key));
|
|
2909
|
+
});
|
|
2910
|
+
return () => {
|
|
2911
|
+
cancelAnimationFrame(outer);
|
|
2912
|
+
cancelAnimationFrame(inner);
|
|
2913
|
+
};
|
|
2914
|
+
}, [key, reduced]);
|
|
2915
|
+
return reduced || enteredKey === key;
|
|
2916
|
+
}
|
|
2917
|
+
function useMonthSlide(month) {
|
|
2918
|
+
const reduced = useReducedMotion();
|
|
2919
|
+
const previous = React37.useRef(month);
|
|
2920
|
+
const direction = React37.useRef(0);
|
|
2921
|
+
if (previous.current !== month) {
|
|
2922
|
+
direction.current = month > previous.current ? 1 : -1;
|
|
2923
|
+
previous.current = month;
|
|
2924
|
+
}
|
|
2925
|
+
const entered = useEntered(month, reduced);
|
|
2926
|
+
return monthSlideStyle(entered, reduced, direction.current);
|
|
2927
|
+
}
|
|
2928
|
+
function SingleCalendar({ value, bounds, testID, onCommit }) {
|
|
2929
|
+
const { labels, today } = useDatePickerConfig();
|
|
2930
|
+
const [draft, setDraft] = React37.useState(value);
|
|
2931
|
+
const grid = useGridFocus(clampToBounds(value !== "" ? value : today, bounds.min, bounds.max), bounds, testID, setDraft);
|
|
2932
|
+
const month = monthStart(grid.focusedDay);
|
|
2933
|
+
const motion = useMonthSlide(month);
|
|
2934
|
+
const pick = (iso) => {
|
|
2935
|
+
setDraft(iso);
|
|
2936
|
+
grid.moveTo(iso);
|
|
2937
|
+
};
|
|
2938
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2939
|
+
/* @__PURE__ */ jsxRuntime.jsx(MonthHeader, { bounds, focusedDay: grid.focusedDay, testID, onMove: grid.moveTo }),
|
|
2940
|
+
/* @__PURE__ */ jsxRuntime.jsx(MonthGrid, { bounds, focusedDay: grid.focusedDay, month, motion, selection: { from: draft, to: draft }, testID, onKey: grid.onDayKey, onPick: pick }),
|
|
2941
|
+
/* @__PURE__ */ jsxRuntime.jsxs(PickerFooter, { children: [
|
|
2942
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiButtons.Button, { accessibilityHint: labels.clearHint, accessibilityLabel: labels.clear, label: labels.clear, testID: `${testID}-clear`, variant: "ghost", onPress: () => onCommit("") }),
|
|
2943
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiButtons.Button, { accessibilityHint: labels.setDateHint, accessibilityLabel: labels.setDate, disabled: draft === "", label: labels.setDate, testID: `${testID}-set`, onPress: () => onCommit(draft) })
|
|
2944
|
+
] })
|
|
2945
|
+
] });
|
|
2946
|
+
}
|
|
2947
|
+
function useIsPhone() {
|
|
2948
|
+
return !isWideFormLayout(reactNative.useWindowDimensions().width);
|
|
2949
|
+
}
|
|
2950
|
+
function useReturnFocus(open, target) {
|
|
2951
|
+
const wasOpen = React37.useRef(open);
|
|
2952
|
+
React37.useEffect(() => {
|
|
2953
|
+
const closed = wasOpen.current && !open;
|
|
2954
|
+
wasOpen.current = open;
|
|
2955
|
+
if (!closed) return void 0;
|
|
2956
|
+
const timer = setTimeout(() => target.current?.focus(), 0);
|
|
2957
|
+
return () => clearTimeout(timer);
|
|
2958
|
+
}, [open, target]);
|
|
2959
|
+
}
|
|
2960
|
+
function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage }) {
|
|
2961
|
+
const { labels, locale } = useDatePickerConfig();
|
|
2962
|
+
const [focused, setFocused] = React37.useState(false);
|
|
2963
|
+
const [text, setText] = React37.useState("");
|
|
2964
|
+
React37.useEffect(() => {
|
|
2965
|
+
setText((current) => {
|
|
2966
|
+
const parsed = current.trim() === "" ? "" : parseTyped(current, locale);
|
|
2967
|
+
if (parsed === null || parsed === value) return current;
|
|
2968
|
+
return value === "" ? "" : formatTyped(value, locale);
|
|
2969
|
+
});
|
|
2970
|
+
}, [value, locale]);
|
|
2971
|
+
const verdict = (typed) => {
|
|
2972
|
+
if (typed.trim() === "") return void 0;
|
|
2973
|
+
const parsed = parseTyped(typed, locale);
|
|
2974
|
+
if (parsed === null) return labels.invalidDate;
|
|
2975
|
+
return isWithinBounds(parsed, bounds.min, bounds.max) ? void 0 : rangeMessage ?? labels.outOfRange;
|
|
2976
|
+
};
|
|
2977
|
+
const onText = (next) => {
|
|
2978
|
+
setText(next);
|
|
2979
|
+
if (next.trim() === "") {
|
|
2980
|
+
onError?.(void 0);
|
|
2981
|
+
onChange("");
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
const parsed = parseTyped(next, locale);
|
|
2985
|
+
if (parsed === null) return;
|
|
2986
|
+
const message = verdict(next);
|
|
2987
|
+
onError?.(message);
|
|
2988
|
+
if (message === void 0) onChange(parsed);
|
|
2989
|
+
};
|
|
2990
|
+
const isReady = () => {
|
|
2991
|
+
if (!focused) return true;
|
|
2992
|
+
const message = verdict(text);
|
|
2993
|
+
onError?.(message);
|
|
2994
|
+
return message === void 0;
|
|
2995
|
+
};
|
|
2996
|
+
return {
|
|
2997
|
+
display: focused ? text : value === "" ? "" : format(value, locale),
|
|
2998
|
+
onText,
|
|
2999
|
+
onFocus: () => {
|
|
3000
|
+
setFocused(true);
|
|
3001
|
+
setText(value === "" ? "" : formatTyped(value, locale));
|
|
3002
|
+
},
|
|
3003
|
+
onBlur: () => {
|
|
3004
|
+
setFocused(false);
|
|
3005
|
+
if (verdict(text) !== void 0) onError?.(verdict(text));
|
|
3006
|
+
},
|
|
3007
|
+
isReady
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
// src/DatePicker/utils/fieldWidth.ts
|
|
3012
|
+
var FONT_PX = 14;
|
|
3013
|
+
var GLYPH_EM = 0.62;
|
|
3014
|
+
var PAD_INLINE = 12;
|
|
3015
|
+
var BORDER = 1;
|
|
3016
|
+
var PLACEHOLDER_CHARS = 15;
|
|
3017
|
+
function closedFieldMinWidth(text, iconRoom) {
|
|
3018
|
+
const chars = Math.max(text.length, PLACEHOLDER_CHARS);
|
|
3019
|
+
return Math.ceil(chars * FONT_PX * GLYPH_EM) + PAD_INLINE + iconRoom + BORDER + BORDER;
|
|
3020
|
+
}
|
|
3021
|
+
var SINGLE_PICKER_WIDTH = 340;
|
|
3022
|
+
var ICON_ROOM = 48;
|
|
3023
|
+
var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "flex", alignItems: "center" };
|
|
3024
|
+
var anchorStyles = reactNative.StyleSheet.create({ wrap: { position: "relative", width: "100%" } });
|
|
3025
|
+
function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
3026
|
+
const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
|
|
3027
|
+
const { labels } = useDatePickerConfig();
|
|
3028
|
+
const phone = useIsPhone();
|
|
3029
|
+
const [open, setOpen] = React37.useState(false);
|
|
3030
|
+
const anchorRef = React37.useRef(null);
|
|
3031
|
+
const inputRef = React37.useRef(null);
|
|
3032
|
+
const bounds = { min, max };
|
|
3033
|
+
const typed = useTypedDate({ value, onChange, bounds, format: formatDisplay, onError: onTypedError });
|
|
3034
|
+
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3035
|
+
const focus = focusBind;
|
|
3036
|
+
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError, required });
|
|
3037
|
+
const close = React37.useCallback(() => setOpen(false), []);
|
|
3038
|
+
useReturnFocus(open, inputRef);
|
|
3039
|
+
const commit = (iso) => {
|
|
3040
|
+
onTypedError?.(void 0);
|
|
3041
|
+
onChange(iso);
|
|
3042
|
+
close();
|
|
3043
|
+
};
|
|
3044
|
+
const onKeyDown = (event) => {
|
|
3045
|
+
if (event.key === "ArrowDown" && event.altKey) {
|
|
3046
|
+
event.preventDefault();
|
|
3047
|
+
setOpen(true);
|
|
3048
|
+
return;
|
|
3049
|
+
}
|
|
3050
|
+
if (event.key !== "Enter" || onSubmit === void 0) return;
|
|
3051
|
+
event.preventDefault();
|
|
3052
|
+
if (typed.isReady()) onSubmit();
|
|
3053
|
+
};
|
|
3054
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: [anchorStyles.wrap, { minWidth: closedFieldMinWidth(typed.display, ICON_ROOM) }], testID: `${testID}-anchor`, children: [
|
|
3055
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3056
|
+
"input",
|
|
3057
|
+
{
|
|
3058
|
+
...webA11y,
|
|
3059
|
+
...hoverBind,
|
|
3060
|
+
ref: inputRef,
|
|
3061
|
+
"aria-label": label,
|
|
3062
|
+
autoComplete: "off",
|
|
3063
|
+
"data-testid": testID,
|
|
3064
|
+
disabled,
|
|
3065
|
+
id: context.controlId,
|
|
3066
|
+
style: { ...buildNativeInputStyle(style), paddingInlineEnd: ICON_ROOM },
|
|
3067
|
+
title: accessibilityHint,
|
|
3068
|
+
type: "text",
|
|
3069
|
+
value: typed.display,
|
|
3070
|
+
onBlur: (event) => {
|
|
3071
|
+
focus.onBlur?.(event);
|
|
3072
|
+
typed.onBlur();
|
|
3073
|
+
},
|
|
3074
|
+
onChange: (event) => typed.onText(event.target.value),
|
|
3075
|
+
onFocus: (event) => {
|
|
3076
|
+
focus.onFocus?.(event);
|
|
3077
|
+
typed.onFocus();
|
|
3078
|
+
},
|
|
3079
|
+
onKeyDown
|
|
3080
|
+
}
|
|
3081
|
+
),
|
|
3082
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: ICON_SLOT, children: /* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.openCalendarHint, accessibilityLabel: labels.openCalendar, appearance: "ghost", disabled, renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "calendar" /* Calendar */ }), testID: `${testID}-calendar`, onPress: () => setOpen((current) => !current) }) }),
|
|
3083
|
+
open ? /* @__PURE__ */ jsxRuntime.jsx(PickerSurface, { anchorRef, label: labels.dialog, minWidth: SINGLE_PICKER_WIDTH, phone, testID: `${testID}-picker`, onDismiss: close, children: /* @__PURE__ */ jsxRuntime.jsx(SingleCalendar, { bounds, testID: `${testID}-picker`, value, onCommit: commit }) }) : null
|
|
3084
|
+
] });
|
|
3085
|
+
}
|
|
2345
3086
|
var IS_WEB7 = reactNative.Platform.OS === "web";
|
|
2346
|
-
|
|
3087
|
+
var DATE_TYPE = "date";
|
|
3088
|
+
function TemporalInput({ fieldProps, context, webInputType, onTypedError }) {
|
|
3089
|
+
if (IS_WEB7 && webInputType === DATE_TYPE) return /* @__PURE__ */ jsxRuntime.jsx(DatePickerInput, { context, fieldProps, onTypedError });
|
|
2347
3090
|
if (IS_WEB7) return /* @__PURE__ */ jsxRuntime.jsx(WebDateInput, { context, fieldProps, webInputType });
|
|
2348
3091
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2349
3092
|
ThemedTextInput,
|
|
@@ -2364,11 +3107,269 @@ function TemporalInput({ fieldProps, context, webInputType }) {
|
|
|
2364
3107
|
}
|
|
2365
3108
|
function TemporalField({ fieldProps, webInputType }) {
|
|
2366
3109
|
const { label, required, hint, error } = fieldProps;
|
|
2367
|
-
|
|
3110
|
+
const [typedError, setTypedError] = React37.useState(void 0);
|
|
3111
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Field, { error: error ?? typedError, hint, label, required, children: (context) => /* @__PURE__ */ jsxRuntime.jsx(TemporalInput, { context, fieldProps, webInputType, onTypedError: setTypedError }) });
|
|
2368
3112
|
}
|
|
2369
3113
|
function DateField(props) {
|
|
2370
3114
|
return /* @__PURE__ */ jsxRuntime.jsx(TemporalField, { fieldProps: props, webInputType: "date" });
|
|
2371
3115
|
}
|
|
3116
|
+
function NativeDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, style, testID }) {
|
|
3117
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [controlStyles.dateRow, style], testID: `${testID}-range`, children: [
|
|
3118
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: controlStyles.dateCol, children: /* @__PURE__ */ jsxRuntime.jsx(DateField, { accessibilityHint: hint, label: fromLabel, testID: `${testID}-from`, value: value.from, onChange: (from) => onChange({ from, to: value.to }), onSubmit }) }),
|
|
3119
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: controlStyles.dateCol, children: /* @__PURE__ */ jsxRuntime.jsx(DateField, { accessibilityHint: hint, label: toLabel, testID: `${testID}-to`, value: value.to, onChange: (to) => onChange({ from: value.from, to }), onSubmit }) })
|
|
3120
|
+
] });
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
// src/DatePicker/utils/rangePresets.ts
|
|
3124
|
+
var RANGE_PRESETS = ["today" /* Today */, "last7Days" /* Last7Days */, "thisMonth" /* ThisMonth */, "quarter" /* Quarter */];
|
|
3125
|
+
var PRESET_LABEL = {
|
|
3126
|
+
["today" /* Today */]: "today",
|
|
3127
|
+
["last7Days" /* Last7Days */]: "last7Days",
|
|
3128
|
+
["thisMonth" /* ThisMonth */]: "thisMonth",
|
|
3129
|
+
["quarter" /* Quarter */]: "quarter"
|
|
3130
|
+
};
|
|
3131
|
+
var MONTHS_IN_QUARTER = 3;
|
|
3132
|
+
var EPOCH2 = { year: 1970, month: 1};
|
|
3133
|
+
function presetLabel(labels, preset) {
|
|
3134
|
+
return labels[PRESET_LABEL[preset]];
|
|
3135
|
+
}
|
|
3136
|
+
function quarterStart(today) {
|
|
3137
|
+
const parts = parseIso(today) ?? EPOCH2;
|
|
3138
|
+
const month = Math.floor((parts.month - 1) / MONTHS_IN_QUARTER) * MONTHS_IN_QUARTER + 1;
|
|
3139
|
+
return toIso({ year: parts.year, month, day: 1 });
|
|
3140
|
+
}
|
|
3141
|
+
function presetRange(preset, today) {
|
|
3142
|
+
if (preset === "last7Days" /* Last7Days */) return { from: addDays(today, -6), to: today };
|
|
3143
|
+
if (preset === "thisMonth" /* ThisMonth */) return { from: monthStart(today), to: today };
|
|
3144
|
+
if (preset === "quarter" /* Quarter */) return { from: quarterStart(today), to: today };
|
|
3145
|
+
return { from: today, to: today };
|
|
3146
|
+
}
|
|
3147
|
+
function matchingPreset(range, today) {
|
|
3148
|
+
return RANGE_PRESETS.find((preset) => {
|
|
3149
|
+
const span = presetRange(preset, today);
|
|
3150
|
+
return span.from === range.from && span.to === range.to;
|
|
3151
|
+
}) ?? null;
|
|
3152
|
+
}
|
|
3153
|
+
function pickRangeDay(range, day) {
|
|
3154
|
+
const open = range.from !== "" && range.to === "";
|
|
3155
|
+
if (!open) return { from: day, to: "" };
|
|
3156
|
+
return day < range.from ? { from: day, to: range.from } : { from: range.from, to: day };
|
|
3157
|
+
}
|
|
3158
|
+
var GAP3 = 8;
|
|
3159
|
+
var CHIP_PAD = 16;
|
|
3160
|
+
var FONT3 = 14;
|
|
3161
|
+
var BOLD4 = 700;
|
|
3162
|
+
var REGULAR2 = 400;
|
|
3163
|
+
var ACTIVE_BORDER = 2;
|
|
3164
|
+
function PresetChips({ active, testID, onPick }) {
|
|
3165
|
+
const { labels } = useDatePickerConfig();
|
|
3166
|
+
const colors = usePickerColors();
|
|
3167
|
+
const chipStyle = (isActive) => ({
|
|
3168
|
+
minHeight: a11y.MIN_TOUCH_TARGET_PX,
|
|
3169
|
+
padding: `0 ${CHIP_PAD}px`,
|
|
3170
|
+
borderRadius: a11y.MIN_TOUCH_TARGET_PX / 2,
|
|
3171
|
+
border: `${isActive ? ACTIVE_BORDER : 1}px solid ${isActive ? colors.brand : colors.border}`,
|
|
3172
|
+
background: colors.surface,
|
|
3173
|
+
color: colors.text,
|
|
3174
|
+
fontFamily: "inherit",
|
|
3175
|
+
fontSize: FONT3,
|
|
3176
|
+
fontWeight: isActive ? BOLD4 : REGULAR2,
|
|
3177
|
+
cursor: "pointer"
|
|
3178
|
+
});
|
|
3179
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-label": labels.presets, role: "group", style: { display: "flex", flexWrap: "wrap", gap: GAP3, marginBottom: GAP3 }, children: RANGE_PRESETS.map((preset) => /* @__PURE__ */ jsxRuntime.jsxs("button", { "aria-pressed": active === preset, "data-testid": `${testID}-preset-${preset}`, style: chipStyle(active === preset), title: labels.presetHint, type: "button", onClick: () => onPick(preset), children: [
|
|
3180
|
+
active === preset ? "\u2713 " : "",
|
|
3181
|
+
presetLabel(labels, preset)
|
|
3182
|
+
] }, preset)) });
|
|
3183
|
+
}
|
|
3184
|
+
var GAP4 = 8;
|
|
3185
|
+
var FONT4 = 14;
|
|
3186
|
+
function PresetMenu({ active, testID, onPick }) {
|
|
3187
|
+
const { labels } = useDatePickerConfig();
|
|
3188
|
+
const colors = usePickerColors();
|
|
3189
|
+
const onChange = (event) => {
|
|
3190
|
+
const preset = RANGE_PRESETS.find((candidate) => candidate === event.target.value);
|
|
3191
|
+
if (preset !== void 0) onPick(preset);
|
|
3192
|
+
};
|
|
3193
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3194
|
+
"select",
|
|
3195
|
+
{
|
|
3196
|
+
"aria-label": labels.presets,
|
|
3197
|
+
"data-testid": `${testID}-presets`,
|
|
3198
|
+
style: { minHeight: a11y.MIN_TOUCH_TARGET_PX, width: "100%", marginBottom: GAP4, border: `1px solid ${colors.border}`, borderRadius: GAP4, background: colors.surface, color: colors.text, fontFamily: "inherit", fontSize: FONT4 },
|
|
3199
|
+
title: labels.presetHint,
|
|
3200
|
+
value: active ?? "",
|
|
3201
|
+
onChange,
|
|
3202
|
+
children: [
|
|
3203
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: labels.presets }),
|
|
3204
|
+
RANGE_PRESETS.map((preset) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: preset, children: presetLabel(labels, preset) }, preset))
|
|
3205
|
+
]
|
|
3206
|
+
}
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3209
|
+
var PHONE_LIST_HEIGHT = "min(56vh, 440px)";
|
|
3210
|
+
var MONTH_GAP = 32;
|
|
3211
|
+
var NAV_ROW = { position: "absolute", left: 0, right: 0, top: 0, display: "flex", justifyContent: "space-between", pointerEvents: "none" };
|
|
3212
|
+
var NAV_SLOT = { pointerEvents: "auto" };
|
|
3213
|
+
function RangeMonthsList({ months, grid }) {
|
|
3214
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-testid": `${grid.testID}-months`, style: { maxHeight: PHONE_LIST_HEIGHT, overflowY: "auto" }, children: months.map((month) => /* @__PURE__ */ jsxRuntime.jsx(MonthGrid, { showCaption: true, month, ...grid }, month)) });
|
|
3215
|
+
}
|
|
3216
|
+
function RangeMonthsPair({ months, grid, motion, onShift }) {
|
|
3217
|
+
const { labels } = useDatePickerConfig();
|
|
3218
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
|
|
3219
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: NAV_ROW, children: [
|
|
3220
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: NAV_SLOT, children: /* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.monthHint, accessibilityLabel: labels.previousMonth, appearance: "ghost", renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "previous" /* Previous */ }), testID: `${grid.testID}-previous`, onPress: () => onShift(-1) }) }),
|
|
3221
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: NAV_SLOT, children: /* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.monthHint, accessibilityLabel: labels.nextMonth, appearance: "ghost", renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "next" /* Next */ }), testID: `${grid.testID}-next`, onPress: () => onShift(1) }) })
|
|
3222
|
+
] }),
|
|
3223
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: MONTH_GAP }, children: months.map((month) => /* @__PURE__ */ jsxRuntime.jsx(MonthGrid, { showCaption: true, month, motion, ...grid }, month)) })
|
|
3224
|
+
] });
|
|
3225
|
+
}
|
|
3226
|
+
var PHONE_MONTHS = 6;
|
|
3227
|
+
var DESKTOP_MONTHS = 2;
|
|
3228
|
+
var SUMMARY_FONT = 14;
|
|
3229
|
+
var SEMIBOLD = 600;
|
|
3230
|
+
function useRangeSummary(draft) {
|
|
3231
|
+
const { labels, locale } = useDatePickerConfig();
|
|
3232
|
+
if (draft.from === "") return "";
|
|
3233
|
+
if (draft.to === "") return formatShort(draft.from, locale);
|
|
3234
|
+
const days = labels.dayCount.replace("{{p1}}", String(daysBetweenInclusive(draft.from, draft.to)));
|
|
3235
|
+
return `${formatShort(draft.from, locale, false)}${labels.rangeSeparator}${formatShort(draft.to, locale)} \xB7 ${days}`;
|
|
3236
|
+
}
|
|
3237
|
+
function RangeCalendar({ value, bounds, phone, testID, onApply, onCancel }) {
|
|
3238
|
+
const { labels, today } = useDatePickerConfig();
|
|
3239
|
+
const [draft, setDraft] = React37.useState(value);
|
|
3240
|
+
const initialDay = clampToBounds(value.from !== "" ? value.from : today, bounds.min, bounds.max);
|
|
3241
|
+
const pickDraft = React37.useCallback((iso) => setDraft((current) => pickRangeDay(current, iso)), []);
|
|
3242
|
+
const focus = useGridFocus(initialDay, bounds, testID, pickDraft);
|
|
3243
|
+
const visible = phone ? PHONE_MONTHS : DESKTOP_MONTHS;
|
|
3244
|
+
const [first, setFirst] = React37.useState(() => monthStart(phone ? initialDay : addMonths(initialDay, 1 - DESKTOP_MONTHS)));
|
|
3245
|
+
const focusMonth = monthStart(focus.focusedDay);
|
|
3246
|
+
const last = addMonths(first, visible - 1);
|
|
3247
|
+
const motion = useMonthSlide(first);
|
|
3248
|
+
const summary = useRangeSummary(draft);
|
|
3249
|
+
React37.useEffect(() => {
|
|
3250
|
+
if (focusMonth < first) setFirst(focusMonth);
|
|
3251
|
+
else if (focusMonth > last) setFirst(addMonths(focusMonth, 1 - visible));
|
|
3252
|
+
}, [focusMonth, first, last, visible]);
|
|
3253
|
+
const pick = (iso) => {
|
|
3254
|
+
pickDraft(iso);
|
|
3255
|
+
focus.moveTo(iso);
|
|
3256
|
+
};
|
|
3257
|
+
const applyPreset = (preset) => {
|
|
3258
|
+
const range = presetRange(preset, today);
|
|
3259
|
+
setDraft(range);
|
|
3260
|
+
focus.moveTo(range.to);
|
|
3261
|
+
};
|
|
3262
|
+
const shift = (step) => {
|
|
3263
|
+
setFirst(addMonths(first, step));
|
|
3264
|
+
focus.moveTo(addMonths(focus.focusedDay, step));
|
|
3265
|
+
};
|
|
3266
|
+
const months = Array.from({ length: visible }, (_unused, index) => addMonths(first, index));
|
|
3267
|
+
const grid = { selection: draft, focusedDay: focus.focusedDay, bounds, testID, onPick: pick, onKey: focus.onDayKey };
|
|
3268
|
+
const presets = { active: matchingPreset(draft, today), testID, onPick: applyPreset };
|
|
3269
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3270
|
+
phone ? /* @__PURE__ */ jsxRuntime.jsx(PresetMenu, { ...presets }) : /* @__PURE__ */ jsxRuntime.jsx(PresetChips, { ...presets }),
|
|
3271
|
+
phone ? /* @__PURE__ */ jsxRuntime.jsx(RangeMonthsList, { grid, months }) : /* @__PURE__ */ jsxRuntime.jsx(RangeMonthsPair, { grid, months, motion, onShift: shift }),
|
|
3272
|
+
/* @__PURE__ */ jsxRuntime.jsxs(PickerFooter, { summary: /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-live": "polite", "data-testid": `${testID}-summary`, style: { fontSize: SUMMARY_FONT, fontWeight: SEMIBOLD }, children: summary }), children: [
|
|
3273
|
+
/* @__PURE__ */ jsxRuntime.jsx(uiButtons.Button, { accessibilityHint: labels.cancelHint, accessibilityLabel: labels.cancel, label: labels.cancel, testID: `${testID}-cancel`, variant: "ghost", onPress: onCancel }),
|
|
3274
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3275
|
+
uiButtons.Button,
|
|
3276
|
+
{
|
|
3277
|
+
accessibilityHint: labels.applyHint,
|
|
3278
|
+
accessibilityLabel: labels.apply,
|
|
3279
|
+
disabled: draft.from === "",
|
|
3280
|
+
label: labels.apply,
|
|
3281
|
+
testID: `${testID}-apply`,
|
|
3282
|
+
onPress: () => onApply({ from: draft.from, to: draft.to === "" ? draft.from : draft.to })
|
|
3283
|
+
}
|
|
3284
|
+
)
|
|
3285
|
+
] })
|
|
3286
|
+
] });
|
|
3287
|
+
}
|
|
3288
|
+
var RANGE_PICKER_WIDTH = 690;
|
|
3289
|
+
var GAP5 = 8;
|
|
3290
|
+
var NO_BOUNDS = {};
|
|
3291
|
+
var SEGMENT = { flex: 1, minWidth: 0, border: "none", background: "transparent", color: "inherit", font: "inherit", outline: "none", padding: 0 };
|
|
3292
|
+
function orNone(value) {
|
|
3293
|
+
return value !== "" ? value : void 0;
|
|
3294
|
+
}
|
|
3295
|
+
function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, testID, context, onTypedError }) {
|
|
3296
|
+
const { labels } = useDatePickerConfig();
|
|
3297
|
+
const phone = useIsPhone();
|
|
3298
|
+
const [open, setOpen] = React37.useState(false);
|
|
3299
|
+
const [fromError, setFromError] = React37.useState(void 0);
|
|
3300
|
+
const [toError, setToError] = React37.useState(void 0);
|
|
3301
|
+
const anchorRef = React37.useRef(null);
|
|
3302
|
+
const fromRef = React37.useRef(null);
|
|
3303
|
+
const from = useTypedDate({ value: value.from, onChange: (next) => onChange({ from: next, to: value.to }), bounds: { max: orNone(value.to) }, format: formatShort, onError: setFromError, rangeMessage: labels.rangeOrder });
|
|
3304
|
+
const to = useTypedDate({ value: value.to, onChange: (next) => onChange({ from: value.from, to: next }), bounds: { min: orNone(value.from) }, format: formatShort, onError: setToError, rangeMessage: labels.rangeOrder });
|
|
3305
|
+
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: true });
|
|
3306
|
+
const focus = focusBind;
|
|
3307
|
+
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError });
|
|
3308
|
+
React37.useEffect(() => onTypedError(fromError ?? toError), [fromError, toError, onTypedError]);
|
|
3309
|
+
const close = React37.useCallback(() => setOpen(false), []);
|
|
3310
|
+
useReturnFocus(open, fromRef);
|
|
3311
|
+
const onKeyDown = (event) => {
|
|
3312
|
+
if (event.key === "ArrowDown" && event.altKey) {
|
|
3313
|
+
event.preventDefault();
|
|
3314
|
+
setOpen(true);
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
if (event.key !== "Enter" || onSubmit === void 0) return;
|
|
3318
|
+
event.preventDefault();
|
|
3319
|
+
const ready = [from.isReady(), to.isReady()].every(Boolean);
|
|
3320
|
+
if (ready) onSubmit();
|
|
3321
|
+
};
|
|
3322
|
+
const segment = (side, typed) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3323
|
+
"input",
|
|
3324
|
+
{
|
|
3325
|
+
...webA11y,
|
|
3326
|
+
ref: side === "from" /* From */ ? fromRef : void 0,
|
|
3327
|
+
"aria-label": side === "from" /* From */ ? fromLabel : toLabel,
|
|
3328
|
+
autoComplete: "off",
|
|
3329
|
+
"data-testid": `${testID}-${side}`,
|
|
3330
|
+
id: side === "from" /* From */ ? context.controlId : void 0,
|
|
3331
|
+
style: SEGMENT,
|
|
3332
|
+
title: hint,
|
|
3333
|
+
type: "text",
|
|
3334
|
+
value: typed.display,
|
|
3335
|
+
onBlur: (event) => {
|
|
3336
|
+
focus.onBlur?.(event);
|
|
3337
|
+
typed.onBlur();
|
|
3338
|
+
},
|
|
3339
|
+
onChange: (event) => typed.onText(event.target.value),
|
|
3340
|
+
onFocus: (event) => {
|
|
3341
|
+
focus.onFocus?.(event);
|
|
3342
|
+
typed.onFocus();
|
|
3343
|
+
},
|
|
3344
|
+
onKeyDown
|
|
3345
|
+
}
|
|
3346
|
+
);
|
|
3347
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyles.wrap, children: [
|
|
3348
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { ...hoverBind, style: { ...buildNativeInputStyle(style), display: "flex", alignItems: "center", gap: GAP5, paddingInlineEnd: ICON_ROOM }, children: [
|
|
3349
|
+
segment("from" /* From */, from),
|
|
3350
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: "\u2192" }),
|
|
3351
|
+
segment("to" /* To */, to)
|
|
3352
|
+
] }),
|
|
3353
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: ICON_SLOT, children: /* @__PURE__ */ jsxRuntime.jsx(uiButtons.IconButton, { accessibilityHint: labels.openCalendarHint, accessibilityLabel: labels.openCalendar, appearance: "ghost", renderIcon: (color) => /* @__PURE__ */ jsxRuntime.jsx(Glyph, { color, name: "calendar" /* Calendar */ }), testID: `${testID}-calendar`, onPress: () => setOpen((current) => !current) }) }),
|
|
3354
|
+
open ? /* @__PURE__ */ jsxRuntime.jsx(PickerSurface, { anchorRef, label: labels.rangeDialog, minWidth: RANGE_PICKER_WIDTH, phone, testID: `${testID}-picker`, onDismiss: close, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3355
|
+
RangeCalendar,
|
|
3356
|
+
{
|
|
3357
|
+
bounds: NO_BOUNDS,
|
|
3358
|
+
phone,
|
|
3359
|
+
testID: `${testID}-picker`,
|
|
3360
|
+
value,
|
|
3361
|
+
onApply: (range) => {
|
|
3362
|
+
setFromError(void 0);
|
|
3363
|
+
setToError(void 0);
|
|
3364
|
+
onChange(range);
|
|
3365
|
+
close();
|
|
3366
|
+
},
|
|
3367
|
+
onCancel: close
|
|
3368
|
+
}
|
|
3369
|
+
) }) : null
|
|
3370
|
+
] });
|
|
3371
|
+
}
|
|
3372
|
+
var IS_WEB8 = reactNative.Platform.OS === "web";
|
|
2372
3373
|
function DateRangeControl({
|
|
2373
3374
|
value,
|
|
2374
3375
|
onChange,
|
|
@@ -2380,30 +3381,12 @@ function DateRangeControl({
|
|
|
2380
3381
|
testID
|
|
2381
3382
|
}) {
|
|
2382
3383
|
const hint = accessibilityHint ?? `${fromLabel} \u2013 ${toLabel}`;
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
testID: `${testID}-from`,
|
|
2390
|
-
value: value.from,
|
|
2391
|
-
onChange: (from) => onChange({ from, to: value.to }),
|
|
2392
|
-
onSubmit
|
|
2393
|
-
}
|
|
2394
|
-
) }),
|
|
2395
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: controlStyles.dateCol, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2396
|
-
DateField,
|
|
2397
|
-
{
|
|
2398
|
-
accessibilityHint: hint,
|
|
2399
|
-
label: toLabel,
|
|
2400
|
-
testID: `${testID}-to`,
|
|
2401
|
-
value: value.to,
|
|
2402
|
-
onChange: (to) => onChange({ from: value.from, to }),
|
|
2403
|
-
onSubmit
|
|
2404
|
-
}
|
|
2405
|
-
) })
|
|
2406
|
-
] }) });
|
|
3384
|
+
const { labels } = useDatePickerConfig();
|
|
3385
|
+
const [typedError, setTypedError] = React37.useState(void 0);
|
|
3386
|
+
if (!IS_WEB8) {
|
|
3387
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsxRuntime.jsx(NativeDateRange, { fromLabel, hint, style, testID, toLabel, value, onChange, onSubmit }) });
|
|
3388
|
+
}
|
|
3389
|
+
return /* @__PURE__ */ jsxRuntime.jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style, testID: `${testID}-range`, children: /* @__PURE__ */ jsxRuntime.jsx(Field, { error: typedError, label: `${fromLabel}${labels.rangeSeparator}${toLabel}`, children: (context) => /* @__PURE__ */ jsxRuntime.jsx(WebDateRange, { context, fromLabel, hint, testID, toLabel, value, onChange, onSubmit, onTypedError: setTypedError }) }) }) });
|
|
2407
3390
|
}
|
|
2408
3391
|
function DateTimeField(props) {
|
|
2409
3392
|
return /* @__PURE__ */ jsxRuntime.jsx(TemporalField, { fieldProps: props, webInputType: "datetime-local" });
|
|
@@ -2439,7 +3422,7 @@ var ROW_GAP = 4;
|
|
|
2439
3422
|
var TAB_PADDING = 4;
|
|
2440
3423
|
var INDICATOR_WIDTH = 2;
|
|
2441
3424
|
var TAB_FONT_SIZE = 12;
|
|
2442
|
-
var
|
|
3425
|
+
var styles17 = reactNative.StyleSheet.create({
|
|
2443
3426
|
row: { flexDirection: "row", flexWrap: "nowrap", gap: ROW_GAP },
|
|
2444
3427
|
tab: {
|
|
2445
3428
|
borderBottomWidth: INDICATOR_WIDTH,
|
|
@@ -2479,13 +3462,13 @@ var StepperTab = ({
|
|
|
2479
3462
|
accessibilityRole: "tab",
|
|
2480
3463
|
accessibilityState: { selected },
|
|
2481
3464
|
"aria-selected": selected,
|
|
2482
|
-
style: [
|
|
3465
|
+
style: [styles17.tab, { borderBottomColor: indicator }, ring.ringStyle],
|
|
2483
3466
|
testID,
|
|
2484
3467
|
onBlur: ring.onBlur,
|
|
2485
3468
|
onFocus: ring.onFocus,
|
|
2486
3469
|
onPress: () => onStep(step.key),
|
|
2487
3470
|
...webKeyProps,
|
|
2488
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
3471
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles17.text, { color: theme.colors.text }, selected ? styles17.textSelected : void 0], children: step.label })
|
|
2489
3472
|
}
|
|
2490
3473
|
);
|
|
2491
3474
|
};
|
|
@@ -2495,7 +3478,7 @@ var StepperTabs = ({
|
|
|
2495
3478
|
onStep,
|
|
2496
3479
|
stepHint,
|
|
2497
3480
|
testID
|
|
2498
|
-
}) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { accessibilityRole: "tablist", style:
|
|
3481
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { accessibilityRole: "tablist", style: styles17.row, testID, children: steps.map((step) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2499
3482
|
StepperTab,
|
|
2500
3483
|
{
|
|
2501
3484
|
hint: stepHint,
|
|
@@ -2514,7 +3497,7 @@ function resolveStepNeighbours(steps, current) {
|
|
|
2514
3497
|
return { previous: steps[index - 1] ?? null, next: steps[index + 1] ?? null };
|
|
2515
3498
|
}
|
|
2516
3499
|
var ROW_GAP2 = 8;
|
|
2517
|
-
var
|
|
3500
|
+
var styles18 = reactNative.StyleSheet.create({
|
|
2518
3501
|
cell: { flex: 1, minWidth: 0 },
|
|
2519
3502
|
row: { flexDirection: "row", gap: ROW_GAP2 }
|
|
2520
3503
|
});
|
|
@@ -2526,8 +3509,8 @@ var StepperNav = ({
|
|
|
2526
3509
|
testID
|
|
2527
3510
|
}) => {
|
|
2528
3511
|
const { previous, next } = resolveStepNeighbours(steps, current);
|
|
2529
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style:
|
|
2530
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style:
|
|
3512
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles18.row, testID, children: [
|
|
3513
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles18.cell, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2531
3514
|
uiButtons.Button,
|
|
2532
3515
|
{
|
|
2533
3516
|
fullWidth: true,
|
|
@@ -2543,7 +3526,7 @@ var StepperNav = ({
|
|
|
2543
3526
|
}
|
|
2544
3527
|
}
|
|
2545
3528
|
) }),
|
|
2546
|
-
next === null ? null : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style:
|
|
3529
|
+
next === null ? null : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles18.cell, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2547
3530
|
uiButtons.Button,
|
|
2548
3531
|
{
|
|
2549
3532
|
fullWidth: true,
|
|
@@ -2558,18 +3541,18 @@ var StepperNav = ({
|
|
|
2558
3541
|
] });
|
|
2559
3542
|
};
|
|
2560
3543
|
var STATUS_FONT = 16;
|
|
2561
|
-
var
|
|
3544
|
+
var styles19 = reactNative.StyleSheet.create({
|
|
2562
3545
|
line: { fontSize: STATUS_FONT }
|
|
2563
3546
|
});
|
|
2564
3547
|
function FormStatusLine({ message, testID, style }) {
|
|
2565
3548
|
const { theme } = uiFeedback.useUi();
|
|
2566
3549
|
if (message === null || message === void 0 || message === "") return null;
|
|
2567
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [
|
|
3550
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [styles19.line, { color: theme.colors.text }, style], testID, children: message });
|
|
2568
3551
|
}
|
|
2569
3552
|
function useFocusFirstInvalid(refs) {
|
|
2570
|
-
const latest =
|
|
3553
|
+
const latest = React37.useRef(refs);
|
|
2571
3554
|
latest.current = refs;
|
|
2572
|
-
return
|
|
3555
|
+
return React37.useCallback((invalid) => {
|
|
2573
3556
|
const first = invalid.map((field2) => latest.current[field2].current).find((node) => node !== null);
|
|
2574
3557
|
first?.focus();
|
|
2575
3558
|
}, []);
|
|
@@ -2578,8 +3561,8 @@ function isScrollable(node) {
|
|
|
2578
3561
|
return "scrollIntoView" in Object(node);
|
|
2579
3562
|
}
|
|
2580
3563
|
function useKeepInView(trigger) {
|
|
2581
|
-
const ref =
|
|
2582
|
-
|
|
3564
|
+
const ref = React37.useRef(null);
|
|
3565
|
+
React37.useEffect(() => {
|
|
2583
3566
|
const node = ref.current;
|
|
2584
3567
|
const hasTrigger = trigger !== void 0 && trigger !== null;
|
|
2585
3568
|
if (hasTrigger && isScrollable(node)) node.scrollIntoView({ block: "nearest" });
|
|
@@ -2588,13 +3571,13 @@ function useKeepInView(trigger) {
|
|
|
2588
3571
|
}
|
|
2589
3572
|
var DEFAULT_PREVIEW_PX = 48;
|
|
2590
3573
|
var PREVIEW_RADIUS = 8;
|
|
2591
|
-
var
|
|
3574
|
+
var GAP6 = 8;
|
|
2592
3575
|
var TITLE_FONT_SIZE = 14;
|
|
2593
3576
|
var HELP_FONT_SIZE = 13;
|
|
2594
|
-
var
|
|
3577
|
+
var styles20 = reactNative.StyleSheet.create({
|
|
2595
3578
|
help: { flex: 1, fontSize: HELP_FONT_SIZE },
|
|
2596
|
-
root: { gap:
|
|
2597
|
-
tile: { alignItems: "center", flexDirection: "row", gap:
|
|
3579
|
+
root: { gap: GAP6 },
|
|
3580
|
+
tile: { alignItems: "center", flexDirection: "row", gap: GAP6 },
|
|
2598
3581
|
title: { fontSize: TITLE_FONT_SIZE, fontWeight: "700" },
|
|
2599
3582
|
toggle: { alignSelf: "flex-start", justifyContent: "center", minHeight: a11y.MIN_TOUCH_TARGET_PX },
|
|
2600
3583
|
toggleText: { fontSize: TITLE_FONT_SIZE, fontWeight: "700", textDecorationLine: "underline" }
|
|
@@ -2611,13 +3594,13 @@ var UploadWithLinkField = ({
|
|
|
2611
3594
|
const { theme } = uiFeedback.useUi();
|
|
2612
3595
|
const ring = uiButtons.useFocusRing();
|
|
2613
3596
|
const url = value ?? "";
|
|
2614
|
-
const [pasting, setPasting] =
|
|
3597
|
+
const [pasting, setPasting] = React37.useState(url !== "");
|
|
2615
3598
|
const previewBox = { borderRadius: PREVIEW_RADIUS, height: previewSize, width: previewSize };
|
|
2616
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style:
|
|
2617
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
2618
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style:
|
|
3599
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles20.root, children: [
|
|
3600
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles20.title, { color: theme.colors.text }], children: labels.title }),
|
|
3601
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles20.tile, children: [
|
|
2619
3602
|
url === "" ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [previewBox, { backgroundColor: theme.colors.border }] }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Image, { accessible: false, source: { uri: url }, style: previewBox, testID: `${testID}-preview` }),
|
|
2620
|
-
labels.help === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
3603
|
+
labels.help === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles20.help, { color: theme.colors.text }], children: labels.help })
|
|
2621
3604
|
] }),
|
|
2622
3605
|
uploadControl,
|
|
2623
3606
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2628,12 +3611,12 @@ var UploadWithLinkField = ({
|
|
|
2628
3611
|
accessibilityRole: "button",
|
|
2629
3612
|
accessibilityState: { expanded: pasting },
|
|
2630
3613
|
"aria-expanded": pasting,
|
|
2631
|
-
style: [
|
|
3614
|
+
style: [styles20.toggle, ring.ringStyle],
|
|
2632
3615
|
testID: `${testID}-paste`,
|
|
2633
3616
|
onBlur: ring.onBlur,
|
|
2634
3617
|
onFocus: ring.onFocus,
|
|
2635
3618
|
onPress: () => setPasting(!pasting),
|
|
2636
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
3619
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles20.toggleText, { color: theme.colors.text }], children: labels.pasteToggle })
|
|
2637
3620
|
}
|
|
2638
3621
|
),
|
|
2639
3622
|
pasting ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2652,7 +3635,7 @@ var UploadWithLinkField = ({
|
|
|
2652
3635
|
};
|
|
2653
3636
|
var ACTION_GAP = 8;
|
|
2654
3637
|
var GROUP_GAP = 16;
|
|
2655
|
-
var
|
|
3638
|
+
var styles21 = reactNative.StyleSheet.create({
|
|
2656
3639
|
action: { alignItems: "flex-start", marginTop: ACTION_GAP },
|
|
2657
3640
|
group: { marginBottom: GROUP_GAP }
|
|
2658
3641
|
});
|
|
@@ -2669,13 +3652,13 @@ var AddOnRequest = ({
|
|
|
2669
3652
|
disabled = false,
|
|
2670
3653
|
style
|
|
2671
3654
|
}) => {
|
|
2672
|
-
const [requested, setRequested] =
|
|
3655
|
+
const [requested, setRequested] = React37.useState(false);
|
|
2673
3656
|
const remove = () => {
|
|
2674
3657
|
setRequested(false);
|
|
2675
3658
|
onRemove();
|
|
2676
3659
|
};
|
|
2677
3660
|
if (!isAddOnOpen(hasValue, requested))
|
|
2678
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [
|
|
3661
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles21.action, style], children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2679
3662
|
uiButtons.Button,
|
|
2680
3663
|
{
|
|
2681
3664
|
accessibilityHint: addHint,
|
|
@@ -2687,9 +3670,9 @@ var AddOnRequest = ({
|
|
|
2687
3670
|
onPress: () => setRequested(true)
|
|
2688
3671
|
}
|
|
2689
3672
|
) });
|
|
2690
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [
|
|
3673
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles21.group, style], testID, children: [
|
|
2691
3674
|
children,
|
|
2692
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style:
|
|
3675
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles21.action, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2693
3676
|
uiButtons.Button,
|
|
2694
3677
|
{
|
|
2695
3678
|
accessibilityHint: removeHint,
|
|
@@ -2706,7 +3689,7 @@ var AddOnRequest = ({
|
|
|
2706
3689
|
var ROW_GAP3 = 8;
|
|
2707
3690
|
var TEXT_SIZE = 13;
|
|
2708
3691
|
var TEXT_LINE = 18;
|
|
2709
|
-
var
|
|
3692
|
+
var styles22 = reactNative.StyleSheet.create({
|
|
2710
3693
|
row: { alignItems: "center", columnGap: ROW_GAP3, flexDirection: "row", justifyContent: "space-between" },
|
|
2711
3694
|
text: { flexShrink: 1, fontSize: TEXT_SIZE, fontWeight: "700", lineHeight: TEXT_LINE }
|
|
2712
3695
|
});
|
|
@@ -2714,8 +3697,8 @@ var isFixBarVisible = (count) => count > 0;
|
|
|
2714
3697
|
var FixBar = ({ count, message, showLabel, showHint, onShow, testID, style }) => {
|
|
2715
3698
|
const { theme } = uiFeedback.useUi();
|
|
2716
3699
|
if (!isFixBarVisible(count)) return null;
|
|
2717
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [
|
|
2718
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [
|
|
3700
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles22.row, style], testID, children: [
|
|
3701
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [styles22.text, { color: fieldErrorInk(theme) }], testID: `${testID}-count`, children: message }),
|
|
2719
3702
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2720
3703
|
uiButtons.Button,
|
|
2721
3704
|
{
|
|
@@ -2736,55 +3719,6 @@ var SelectSurface = /* @__PURE__ */ ((SelectSurface2) => {
|
|
|
2736
3719
|
SelectSurface2["Dropdown"] = "dropdown";
|
|
2737
3720
|
return SelectSurface2;
|
|
2738
3721
|
})(SelectSurface || {});
|
|
2739
|
-
function useAnchorRect2(anchorRef) {
|
|
2740
|
-
const [rect2, setRect] = React26.useState(null);
|
|
2741
|
-
React26.useEffect(() => {
|
|
2742
|
-
anchorRef.current?.measureInWindow((x, y, width, height) => setRect({ x, y, width, height }));
|
|
2743
|
-
}, [anchorRef]);
|
|
2744
|
-
return rect2;
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
// src/SearchSelect/DropdownPlacement.ts
|
|
2748
|
-
var DropdownPlacement = /* @__PURE__ */ ((DropdownPlacement2) => {
|
|
2749
|
-
DropdownPlacement2["Below"] = "below";
|
|
2750
|
-
DropdownPlacement2["Above"] = "above";
|
|
2751
|
-
return DropdownPlacement2;
|
|
2752
|
-
})(DropdownPlacement || {});
|
|
2753
|
-
|
|
2754
|
-
// src/SearchSelect/utils/dropdownFrame.ts
|
|
2755
|
-
var MIN_PANEL_WIDTH = 240;
|
|
2756
|
-
var EDGE = 8;
|
|
2757
|
-
function placeDropdown(anchor, panelHeight, viewportHeight) {
|
|
2758
|
-
const roomBelow = viewportHeight - (anchor.y + anchor.height);
|
|
2759
|
-
if (roomBelow >= panelHeight) return "below" /* Below */;
|
|
2760
|
-
return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
|
|
2761
|
-
}
|
|
2762
|
-
function dropdownFrame(anchor, panelHeight, viewportHeight) {
|
|
2763
|
-
const placement = placeDropdown(anchor, panelHeight, viewportHeight);
|
|
2764
|
-
const base = { placement, left: anchor.x, width: anchor.width };
|
|
2765
|
-
if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - anchor.y };
|
|
2766
|
-
return { ...base, top: anchor.y + anchor.height };
|
|
2767
|
-
}
|
|
2768
|
-
function fitDropdownWidth(frame, viewportWidth) {
|
|
2769
|
-
const width = Math.max(frame.width, Math.min(MIN_PANEL_WIDTH, viewportWidth - EDGE - EDGE));
|
|
2770
|
-
const left = Math.max(EDGE, Math.min(frame.left, viewportWidth - width - EDGE));
|
|
2771
|
-
return { ...frame, width, left: frame.width >= width ? frame.left : left };
|
|
2772
|
-
}
|
|
2773
|
-
function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children }) {
|
|
2774
|
-
const { height: viewportHeight, width: viewportWidth } = reactNative.useWindowDimensions();
|
|
2775
|
-
const anchor = useAnchorRect2(anchorRef);
|
|
2776
|
-
const [panelHeight, setPanelHeight] = React26.useState(0);
|
|
2777
|
-
const onLayout = React26.useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
|
|
2778
|
-
const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight), viewportWidth);
|
|
2779
|
-
const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
|
|
2780
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Modal, { transparent: true, visible: true, animationType: "none", onRequestClose: onDismiss, children: [
|
|
2781
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
2782
|
-
frame !== null ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles21.dropdown, place, { opacity: progress, transform: [{ translateY }] }], testID: `${testID}-dropdown-${frame.placement}`, onLayout, children }) : null
|
|
2783
|
-
] });
|
|
2784
|
-
}
|
|
2785
|
-
var styles21 = reactNative.StyleSheet.create({
|
|
2786
|
-
dropdown: { position: "absolute" }
|
|
2787
|
-
});
|
|
2788
3722
|
var ROW_PAD_H = 12;
|
|
2789
3723
|
var ROW_GAP4 = 8;
|
|
2790
3724
|
var OPTION_FONT2 = 14;
|
|
@@ -2802,21 +3736,21 @@ function OptionRow2({ option, active, current, renderLeading, renderDetail, onPi
|
|
|
2802
3736
|
accessibilityLabel: option.label,
|
|
2803
3737
|
accessibilityRole: "button",
|
|
2804
3738
|
accessibilityState: { selected: active, checked: current },
|
|
2805
|
-
style: [
|
|
3739
|
+
style: [styles23.row, active ? { backgroundColor: colors.surface } : null],
|
|
2806
3740
|
testID: `${testID}-option-${option.value}`,
|
|
2807
3741
|
onPress: () => onPick(option),
|
|
2808
3742
|
children: [
|
|
2809
3743
|
renderLeading?.(option),
|
|
2810
|
-
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style:
|
|
2811
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
2812
|
-
detailBelow ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [
|
|
3744
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles23.label, children: [
|
|
3745
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles23.primary, { color: colors.text }], children: option.label }),
|
|
3746
|
+
detailBelow ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles23.secondary, { color: colors.textSecondary }], children: option.detail }) : null
|
|
2813
3747
|
] }),
|
|
2814
3748
|
renderDetail?.(option)
|
|
2815
3749
|
]
|
|
2816
3750
|
}
|
|
2817
3751
|
);
|
|
2818
3752
|
}
|
|
2819
|
-
var
|
|
3753
|
+
var styles23 = reactNative.StyleSheet.create({
|
|
2820
3754
|
row: { minHeight: a11y.MIN_TOUCH_TARGET_PX, flexDirection: "row", alignItems: "center", gap: ROW_GAP4, paddingHorizontal: ROW_PAD_H },
|
|
2821
3755
|
label: { flex: 1 },
|
|
2822
3756
|
primary: { fontSize: OPTION_FONT2, flexShrink: 1 },
|
|
@@ -2830,46 +3764,37 @@ function OptionSection({ title, options, offset, highlight, selectedValue, ...ro
|
|
|
2830
3764
|
const { colors } = theme;
|
|
2831
3765
|
if (options.length === 0) return null;
|
|
2832
3766
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { children: [
|
|
2833
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { accessibilityRole: "header", style: [
|
|
3767
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { accessibilityRole: "header", style: [styles24.header, { color: colors.textSecondary }], children: title }),
|
|
2834
3768
|
options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(OptionRow2, { ...row, active: offset + index === highlight, current: option.value === selectedValue, option }, option.value))
|
|
2835
3769
|
] });
|
|
2836
3770
|
}
|
|
2837
|
-
var styles23 = reactNative.StyleSheet.create({
|
|
2838
|
-
header: { fontSize: HEADER_FONT, paddingHorizontal: ROW_PAD_H2, paddingTop: ROW_GAP5, textTransform: "uppercase" }
|
|
2839
|
-
});
|
|
2840
|
-
function SheetSurface({ translateY, onDismiss, closeLabel, closeHint, testID, children }) {
|
|
2841
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, visible: true, animationType: "none", onRequestClose: onDismiss, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles24.backdrop, children: [
|
|
2842
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: reactNative.StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
|
|
2843
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: { transform: [{ translateY }] }, children })
|
|
2844
|
-
] }) });
|
|
2845
|
-
}
|
|
2846
3771
|
var styles24 = reactNative.StyleSheet.create({
|
|
2847
|
-
|
|
3772
|
+
header: { fontSize: HEADER_FONT, paddingHorizontal: ROW_PAD_H2, paddingTop: ROW_GAP5, textTransform: "uppercase" }
|
|
2848
3773
|
});
|
|
2849
3774
|
var KEY_ESCAPE = "Escape";
|
|
2850
3775
|
var PANEL_PAD = 8;
|
|
2851
3776
|
var PANEL_RADIUS = 8;
|
|
2852
|
-
var
|
|
3777
|
+
var SHEET_MAX_HEIGHT2 = 480;
|
|
2853
3778
|
function SearchSelectPanel({ motion, state, labels, anchorRef, renderLeading, renderDetail, selectedValue, testID }) {
|
|
2854
3779
|
const { theme } = uiFeedback.useUi();
|
|
2855
3780
|
const { colors } = theme;
|
|
2856
|
-
const progress =
|
|
3781
|
+
const progress = React37.useRef(new reactNative.Animated.Value(0)).current;
|
|
2857
3782
|
const { durationMs } = motion;
|
|
2858
|
-
|
|
3783
|
+
React37.useEffect(() => {
|
|
2859
3784
|
reactNative.Animated.timing(progress, { toValue: 1, duration: durationMs, useNativeDriver: false }).start();
|
|
2860
3785
|
}, [progress, durationMs]);
|
|
2861
|
-
const leaving =
|
|
2862
|
-
const leave =
|
|
3786
|
+
const leaving = React37.useRef(false);
|
|
3787
|
+
const leave = React37.useCallback((after) => {
|
|
2863
3788
|
if (leaving.current) return;
|
|
2864
3789
|
leaving.current = true;
|
|
2865
3790
|
if (durationMs === 0) return after();
|
|
2866
3791
|
reactNative.Animated.timing(progress, { toValue: 0, duration: durationMs, useNativeDriver: false }).start(() => after());
|
|
2867
3792
|
}, [progress, durationMs]);
|
|
2868
3793
|
const { close, pick: pickNow, submit: submitNow, onKey, sections, highlight } = state;
|
|
2869
|
-
const dismiss =
|
|
2870
|
-
const pick =
|
|
2871
|
-
const submit =
|
|
2872
|
-
const onKeyPress =
|
|
3794
|
+
const dismiss = React37.useCallback(() => leave(close), [leave, close]);
|
|
3795
|
+
const pick = React37.useCallback((option) => leave(() => pickNow(option)), [leave, pickNow]);
|
|
3796
|
+
const submit = React37.useCallback(() => submitNow(pick), [submitNow, pick]);
|
|
3797
|
+
const onKeyPress = React37.useCallback((key) => key === KEY_ESCAPE ? dismiss() : onKey(key), [dismiss, onKey]);
|
|
2873
3798
|
const translateY = progress.interpolate({ inputRange: [0, 1], outputRange: [motion.fromY, 0] });
|
|
2874
3799
|
const isSheet = motion.surface === "sheet" /* Sheet */;
|
|
2875
3800
|
const shared = { selectedValue, renderLeading, renderDetail, onPick: pick, optionHint: labels.optionHint, testID, highlight };
|
|
@@ -2902,27 +3827,12 @@ function SearchSelectPanel({ motion, state, labels, anchorRef, renderLeading, re
|
|
|
2902
3827
|
var styles25 = reactNative.StyleSheet.create({
|
|
2903
3828
|
panel: { borderWidth: 1, borderRadius: PANEL_RADIUS, padding: PANEL_PAD, gap: PANEL_PAD },
|
|
2904
3829
|
dropList: { maxHeight: MENU_MAX_HEIGHT },
|
|
2905
|
-
sheetList: { maxHeight:
|
|
3830
|
+
sheetList: { maxHeight: SHEET_MAX_HEIGHT2 },
|
|
2906
3831
|
empty: { padding: PANEL_PAD }
|
|
2907
3832
|
});
|
|
2908
|
-
function useReducedMotion() {
|
|
2909
|
-
const [reduced, setReduced] = React26.useState(false);
|
|
2910
|
-
React26.useEffect(() => {
|
|
2911
|
-
let active = true;
|
|
2912
|
-
reactNative.AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
2913
|
-
if (active) setReduced(value);
|
|
2914
|
-
}).catch(() => void 0);
|
|
2915
|
-
const subscription = reactNative.AccessibilityInfo.addEventListener("reduceMotionChanged", setReduced);
|
|
2916
|
-
return () => {
|
|
2917
|
-
active = false;
|
|
2918
|
-
subscription.remove();
|
|
2919
|
-
};
|
|
2920
|
-
}, []);
|
|
2921
|
-
return reduced;
|
|
2922
|
-
}
|
|
2923
3833
|
function useRefocusOnClose(open, ref) {
|
|
2924
|
-
const wasOpen =
|
|
2925
|
-
|
|
3834
|
+
const wasOpen = React37.useRef(false);
|
|
3835
|
+
React37.useEffect(() => {
|
|
2926
3836
|
if (wasOpen.current && !open) ref.current?.focus();
|
|
2927
3837
|
wasOpen.current = open;
|
|
2928
3838
|
}, [open, ref]);
|
|
@@ -2955,38 +3865,38 @@ var KEY_DOWN = "ArrowDown";
|
|
|
2955
3865
|
var KEY_UP = "ArrowUp";
|
|
2956
3866
|
var KEY_ESCAPE2 = "Escape";
|
|
2957
3867
|
function useSearchSelectState(options, recents, onChange, onClosed) {
|
|
2958
|
-
const [open, setOpen] =
|
|
2959
|
-
const [query, setQueryState] =
|
|
2960
|
-
const [rawHighlight, setHighlight] =
|
|
2961
|
-
const sections =
|
|
3868
|
+
const [open, setOpen] = React37.useState(false);
|
|
3869
|
+
const [query, setQueryState] = React37.useState("");
|
|
3870
|
+
const [rawHighlight, setHighlight] = React37.useState(-1);
|
|
3871
|
+
const sections = React37.useMemo(() => buildSearchSelectSections(options, query, recents.recents), [options, query, recents.recents]);
|
|
2962
3872
|
const highlight = rawHighlight < sections.flat.length ? rawHighlight : -1;
|
|
2963
3873
|
const active = sections.flat[highlight];
|
|
2964
3874
|
const { remember } = recents;
|
|
2965
|
-
const close =
|
|
3875
|
+
const close = React37.useCallback(() => {
|
|
2966
3876
|
setOpen(false);
|
|
2967
3877
|
setQueryState("");
|
|
2968
3878
|
setHighlight(-1);
|
|
2969
3879
|
onClosed();
|
|
2970
3880
|
}, [onClosed]);
|
|
2971
|
-
const pick =
|
|
3881
|
+
const pick = React37.useCallback((option) => {
|
|
2972
3882
|
remember(option.value);
|
|
2973
3883
|
onChange(option.value);
|
|
2974
3884
|
close();
|
|
2975
3885
|
}, [remember, onChange, close]);
|
|
2976
|
-
const submit =
|
|
3886
|
+
const submit = React37.useCallback((via = pick) => {
|
|
2977
3887
|
if (active !== void 0) via(active);
|
|
2978
3888
|
}, [active, pick]);
|
|
2979
|
-
const setQuery =
|
|
3889
|
+
const setQuery = React37.useCallback((next) => {
|
|
2980
3890
|
setQueryState(next);
|
|
2981
3891
|
setHighlight(highlightAfterQuery(next));
|
|
2982
3892
|
}, []);
|
|
2983
|
-
const onKey =
|
|
3893
|
+
const onKey = React37.useCallback((key) => {
|
|
2984
3894
|
const count = sections.flat.length;
|
|
2985
3895
|
if (key === KEY_DOWN) setHighlight(moveHighlight(highlight, count, 1));
|
|
2986
3896
|
if (key === KEY_UP) setHighlight(moveHighlight(highlight, count, -1));
|
|
2987
3897
|
if (key === KEY_ESCAPE2) close();
|
|
2988
3898
|
}, [sections.flat.length, highlight, close]);
|
|
2989
|
-
const openList =
|
|
3899
|
+
const openList = React37.useCallback(() => setOpen(true), []);
|
|
2990
3900
|
return { open, query, highlight, active, sections, openList, close, setQuery, pick, submit, onKey };
|
|
2991
3901
|
}
|
|
2992
3902
|
|
|
@@ -3010,8 +3920,8 @@ function SearchSelect(props) {
|
|
|
3010
3920
|
const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail, renderTrigger, onBlur } = props;
|
|
3011
3921
|
const { theme } = uiFeedback.useUi();
|
|
3012
3922
|
const { colors } = theme;
|
|
3013
|
-
const triggerRef =
|
|
3014
|
-
const anchorRef =
|
|
3923
|
+
const triggerRef = React37.useRef(null);
|
|
3924
|
+
const anchorRef = React37.useRef(null);
|
|
3015
3925
|
const { width } = reactNative.useWindowDimensions();
|
|
3016
3926
|
const motion = resolveSelectMotion(width, useReducedMotion());
|
|
3017
3927
|
const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
|
|
@@ -3019,9 +3929,9 @@ function SearchSelect(props) {
|
|
|
3019
3929
|
useRefocusOnClose(state.open, triggerRef);
|
|
3020
3930
|
const selected = findOption(options, value);
|
|
3021
3931
|
const onPress = state.open ? state.close : state.openList;
|
|
3022
|
-
const openRef =
|
|
3932
|
+
const openRef = React37.useRef(state.open);
|
|
3023
3933
|
openRef.current = state.open;
|
|
3024
|
-
const onTriggerBlur =
|
|
3934
|
+
const onTriggerBlur = React37.useCallback(() => {
|
|
3025
3935
|
if (!openRef.current) onBlur?.();
|
|
3026
3936
|
}, [onBlur]);
|
|
3027
3937
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: styles26.anchor, children: [
|
|
@@ -3071,7 +3981,7 @@ function isOutside(container, target) {
|
|
|
3071
3981
|
return !(target instanceof Node && container.contains(target));
|
|
3072
3982
|
}
|
|
3073
3983
|
function useOutsidePress(ref, onOutside) {
|
|
3074
|
-
|
|
3984
|
+
React37.useEffect(() => {
|
|
3075
3985
|
if (reactNative.Platform.OS !== "web" || typeof document === "undefined") return void 0;
|
|
3076
3986
|
const onPointerDown = (event) => {
|
|
3077
3987
|
if (isOutside(ref.current, event.target)) onOutside();
|
|
@@ -3082,7 +3992,7 @@ function useOutsidePress(ref, onOutside) {
|
|
|
3082
3992
|
}
|
|
3083
3993
|
var AFTER_SURFACE_UNMOUNT_MS = 0;
|
|
3084
3994
|
function useDeferredFocus(ref) {
|
|
3085
|
-
return
|
|
3995
|
+
return React37.useCallback(() => {
|
|
3086
3996
|
setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
|
|
3087
3997
|
}, [ref]);
|
|
3088
3998
|
}
|
|
@@ -3834,8 +4744,8 @@ var renderFlag = (option) => option.value === NO_COUNTRY2 ? null : /* @__PURE__
|
|
|
3834
4744
|
function CountryField({ value, onChange, accessibilityLabel, accessibilityHint, labels, testID, countries, noneLabel, onBlur }) {
|
|
3835
4745
|
const { theme } = uiFeedback.useUi();
|
|
3836
4746
|
const { textSecondary } = theme.colors;
|
|
3837
|
-
const options =
|
|
3838
|
-
const renderCode =
|
|
4747
|
+
const options = React37.useMemo(() => countryFieldOptions(countries, noneLabel), [countries, noneLabel]);
|
|
4748
|
+
const renderCode = React37.useCallback((option) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles27.code, { color: textSecondary }], children: option.detail }), [textSecondary]);
|
|
3839
4749
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3840
4750
|
SearchSelect,
|
|
3841
4751
|
{
|
|
@@ -3857,9 +4767,9 @@ var styles27 = reactNative.StyleSheet.create({
|
|
|
3857
4767
|
code: { fontSize: CODE_FONT }
|
|
3858
4768
|
});
|
|
3859
4769
|
function useBlurVerdict(validate) {
|
|
3860
|
-
const [verdict, setVerdict] =
|
|
3861
|
-
const onEdit =
|
|
3862
|
-
const onLeave =
|
|
4770
|
+
const [verdict, setVerdict] = React37.useState(null);
|
|
4771
|
+
const onEdit = React37.useCallback(() => setVerdict(null), []);
|
|
4772
|
+
const onLeave = React37.useCallback(() => {
|
|
3863
4773
|
const next = validate();
|
|
3864
4774
|
setVerdict(next);
|
|
3865
4775
|
return next;
|
|
@@ -4013,11 +4923,11 @@ function rawCaretAfterChange(previous, previousCaret, next) {
|
|
|
4013
4923
|
|
|
4014
4924
|
// src/IbanInput/hooks/useIbanCaret.ts
|
|
4015
4925
|
function useIbanCaret(display) {
|
|
4016
|
-
const [selection, setSelection] =
|
|
4017
|
-
const onSelectionChange =
|
|
4926
|
+
const [selection, setSelection] = React37.useState({ start: display.length, end: display.length });
|
|
4927
|
+
const onSelectionChange = React37.useCallback((event) => {
|
|
4018
4928
|
setSelection(event.nativeEvent.selection);
|
|
4019
4929
|
}, []);
|
|
4020
|
-
const placeAfterEdit =
|
|
4930
|
+
const placeAfterEdit = React37.useCallback((text) => {
|
|
4021
4931
|
const caret = caretAfterEdit(text, rawCaretAfterChange(display, selection.end, text));
|
|
4022
4932
|
setSelection({ start: caret, end: caret });
|
|
4023
4933
|
}, [display, selection.end]);
|
|
@@ -4028,7 +4938,7 @@ var FONT_SIZE = 14;
|
|
|
4028
4938
|
var LINE_HEIGHT = 20;
|
|
4029
4939
|
var COUNTER_FONT = 12;
|
|
4030
4940
|
var BRANCH_OPACITY = 0.5;
|
|
4031
|
-
var
|
|
4941
|
+
var GAP7 = 8;
|
|
4032
4942
|
var INPUT_PAD_V2 = 13;
|
|
4033
4943
|
var ghostStyles = reactNative.StyleSheet.create({
|
|
4034
4944
|
field: { flex: 1, justifyContent: "center", minHeight: LINE_HEIGHT },
|
|
@@ -4038,7 +4948,7 @@ var ghostStyles = reactNative.StyleSheet.create({
|
|
|
4038
4948
|
branch: { opacity: BRANCH_OPACITY },
|
|
4039
4949
|
input: { padding: 0, paddingVertical: INPUT_PAD_V2, borderWidth: 0, minHeight: LINE_HEIGHT },
|
|
4040
4950
|
trigger: { paddingVertical: 0 },
|
|
4041
|
-
counter: { fontSize: COUNTER_FONT, marginLeft:
|
|
4951
|
+
counter: { fontSize: COUNTER_FONT, marginLeft: GAP7 }
|
|
4042
4952
|
});
|
|
4043
4953
|
|
|
4044
4954
|
// src/IbanInput/data/IbanRejection.ts
|
|
@@ -4123,19 +5033,19 @@ function rejectionMessage(rejection, none, labels) {
|
|
|
4123
5033
|
function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
|
|
4124
5034
|
const { theme } = uiFeedback.useUi();
|
|
4125
5035
|
const { colors } = theme;
|
|
4126
|
-
const draft =
|
|
4127
|
-
const validate =
|
|
5036
|
+
const draft = React37.useMemo(() => draftIban(value), [value]);
|
|
5037
|
+
const validate = React37.useCallback(() => validateIban(value), [value]);
|
|
4128
5038
|
const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
|
|
4129
5039
|
const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
|
|
4130
5040
|
const counter = ibanCounter(draft);
|
|
4131
5041
|
const { selection, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
|
|
4132
|
-
const onChangeText =
|
|
5042
|
+
const onChangeText = React37.useCallback((text) => {
|
|
4133
5043
|
onEdit();
|
|
4134
5044
|
onVerdict?.(null);
|
|
4135
5045
|
placeAfterEdit(text);
|
|
4136
5046
|
onChange(draftIban(text).electronic);
|
|
4137
5047
|
}, [onEdit, onVerdict, placeAfterEdit, onChange]);
|
|
4138
|
-
const onBlur =
|
|
5048
|
+
const onBlur = React37.useCallback(() => {
|
|
4139
5049
|
const verdict2 = onLeave();
|
|
4140
5050
|
onVerdict?.(value === "" ? null : verdict2);
|
|
4141
5051
|
onLeft?.();
|
|
@@ -4210,16 +5120,16 @@ function validateBic(raw) {
|
|
|
4210
5120
|
function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
|
|
4211
5121
|
const { theme } = uiFeedback.useUi();
|
|
4212
5122
|
const { colors } = theme;
|
|
4213
|
-
const draft =
|
|
4214
|
-
const validate =
|
|
5123
|
+
const draft = React37.useMemo(() => draftBic(value), [value]);
|
|
5124
|
+
const validate = React37.useCallback(() => validateBic(value), [value]);
|
|
4215
5125
|
const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
|
|
4216
5126
|
const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
|
|
4217
|
-
const onChangeText =
|
|
5127
|
+
const onChangeText = React37.useCallback((text) => {
|
|
4218
5128
|
onEdit();
|
|
4219
5129
|
onVerdict?.(null);
|
|
4220
5130
|
onChange(draftBic(text).value);
|
|
4221
5131
|
}, [onEdit, onVerdict, onChange]);
|
|
4222
|
-
const onBlur =
|
|
5132
|
+
const onBlur = React37.useCallback(() => {
|
|
4223
5133
|
const verdict2 = onLeave();
|
|
4224
5134
|
onVerdict?.(value === "" ? null : verdict2);
|
|
4225
5135
|
onLeft?.();
|
|
@@ -4309,14 +5219,14 @@ var DOT_INNER = 8;
|
|
|
4309
5219
|
var ROW_GAP6 = 10;
|
|
4310
5220
|
var PAD_H2 = 12;
|
|
4311
5221
|
var PAD_V2 = 8;
|
|
4312
|
-
var
|
|
5222
|
+
var RADIUS2 = 8;
|
|
4313
5223
|
var LABEL_SIZE = 14;
|
|
4314
5224
|
var DESCRIPTION_SIZE = 12;
|
|
4315
5225
|
var DESCRIPTION_LINE = 16;
|
|
4316
5226
|
var styles31 = reactNative.StyleSheet.create({
|
|
4317
5227
|
row: {
|
|
4318
5228
|
alignItems: "center",
|
|
4319
|
-
borderRadius:
|
|
5229
|
+
borderRadius: RADIUS2,
|
|
4320
5230
|
borderWidth: 1,
|
|
4321
5231
|
columnGap: ROW_GAP6,
|
|
4322
5232
|
flexDirection: "row",
|
|
@@ -4375,7 +5285,7 @@ var styles32 = reactNative.StyleSheet.create({
|
|
|
4375
5285
|
function RadioList(props) {
|
|
4376
5286
|
const { options, value, onChange, optionTestIDPrefix, label, error, required = false, disabled = false, testID } = props;
|
|
4377
5287
|
const { theme } = uiFeedback.useUi();
|
|
4378
|
-
const colors =
|
|
5288
|
+
const colors = React37__default.default.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
|
|
4379
5289
|
const selectedIndex = options.findIndex((option) => option.value === value);
|
|
4380
5290
|
const radio = useRadioKeyboard({ enabled: true, disabled, values: options.map((option) => option.value), selectedIndex, onChange });
|
|
4381
5291
|
return /* @__PURE__ */ jsxRuntime.jsx(Field, { error, label, required, testID, children: ({ describedById, hasError }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4530,12 +5440,12 @@ var SubmitError = ({ message, testID }) => {
|
|
|
4530
5440
|
};
|
|
4531
5441
|
var toggle = (list, id) => list.includes(id) ? list.filter((item) => item !== id) : [...list, id];
|
|
4532
5442
|
function useDecisionPanel(outcomes, onSubmit) {
|
|
4533
|
-
const [outcome, setOutcome] =
|
|
4534
|
-
const [note, setNote] =
|
|
4535
|
-
const [reasons, setReasons] =
|
|
4536
|
-
const [checked, setChecked] =
|
|
4537
|
-
const [error, setError] =
|
|
4538
|
-
const [pending, setPending] =
|
|
5443
|
+
const [outcome, setOutcome] = React37__default.default.useState("");
|
|
5444
|
+
const [note, setNote] = React37__default.default.useState("");
|
|
5445
|
+
const [reasons, setReasons] = React37__default.default.useState([]);
|
|
5446
|
+
const [checked, setChecked] = React37__default.default.useState([]);
|
|
5447
|
+
const [error, setError] = React37__default.default.useState(null);
|
|
5448
|
+
const [pending, setPending] = React37__default.default.useState(null);
|
|
4539
5449
|
const submit = async (override) => {
|
|
4540
5450
|
const target = override ?? outcome;
|
|
4541
5451
|
const problem = validateDecision(outcomes, target, note);
|
|
@@ -4601,12 +5511,14 @@ exports.ChipLabelWrap = ChipLabelWrap;
|
|
|
4601
5511
|
exports.ChipSelector = ChipSelector;
|
|
4602
5512
|
exports.CountryField = CountryField;
|
|
4603
5513
|
exports.CountryFlag = CountryFlag;
|
|
5514
|
+
exports.DEFAULT_DATE_PICKER_LABELS = DEFAULT_DATE_PICKER_LABELS;
|
|
4604
5515
|
exports.DEFAULT_MAX_RECENTS = DEFAULT_MAX_RECENTS;
|
|
4605
5516
|
exports.DEFAULT_OPTIONAL_LABEL = DEFAULT_OPTIONAL_LABEL;
|
|
4606
5517
|
exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
4607
5518
|
exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
4608
5519
|
exports.DateField = DateField;
|
|
4609
5520
|
exports.DateInput = DateInput;
|
|
5521
|
+
exports.DatePickerProvider = DatePickerProvider;
|
|
4610
5522
|
exports.DateRangeControl = DateRangeControl;
|
|
4611
5523
|
exports.DateTimeField = DateTimeField;
|
|
4612
5524
|
exports.DecisionPanel = DecisionPanel;
|