@dloizides/ui-forms 1.53.0 → 1.54.0
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 +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +320 -248
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -59
- 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 React40 = 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');
|
|
@@ -9,17 +9,17 @@ var uiButtons = require('@dloizides/ui-buttons');
|
|
|
9
9
|
var reactDom = require('react-dom');
|
|
10
10
|
var a11y = require('@dloizides/a11y');
|
|
11
11
|
var uiIcons = require('@dloizides/ui-icons');
|
|
12
|
-
var apiClientBase = require('@dloizides/api-client-base');
|
|
13
12
|
var Svg = require('react-native-svg');
|
|
13
|
+
var apiClientBase = require('@dloizides/api-client-base');
|
|
14
14
|
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var React40__default = /*#__PURE__*/_interopDefault(React40);
|
|
18
18
|
var Svg__default = /*#__PURE__*/_interopDefault(Svg);
|
|
19
19
|
|
|
20
20
|
// src/Field/Field.tsx
|
|
21
21
|
function attachControlId(child, candidateId, describedById) {
|
|
22
|
-
if (!
|
|
22
|
+
if (!React40__default.default.isValidElement(child) || child.type === React40__default.default.Fragment) {
|
|
23
23
|
return { node: child };
|
|
24
24
|
}
|
|
25
25
|
const props = child.props;
|
|
@@ -30,15 +30,15 @@ function attachControlId(child, candidateId, describedById) {
|
|
|
30
30
|
if (describedById !== void 0 && props.describedById === void 0) {
|
|
31
31
|
injected.describedById = describedById;
|
|
32
32
|
}
|
|
33
|
-
return { node:
|
|
33
|
+
return { node: React40__default.default.cloneElement(element, injected), controlId };
|
|
34
34
|
}
|
|
35
35
|
var IS_WEB = reactNative.Platform.OS === "web";
|
|
36
36
|
function isAttributeHost(node) {
|
|
37
37
|
return typeof node === "object" && node !== null && typeof node.setAttribute === "function";
|
|
38
38
|
}
|
|
39
39
|
function useHtmlFor(controlId) {
|
|
40
|
-
const ref =
|
|
41
|
-
|
|
40
|
+
const ref = React40.useRef(null);
|
|
41
|
+
React40.useEffect(() => {
|
|
42
42
|
const node = ref.current;
|
|
43
43
|
if (!IS_WEB || !isAttributeHost(node)) return;
|
|
44
44
|
const target = controlId !== void 0 && controlId !== "" ? node.ownerDocument?.getElementById(controlId) : null;
|
|
@@ -148,15 +148,15 @@ var labelVariantStyles = reactNative.StyleSheet.create({
|
|
|
148
148
|
function resolveLabelVariantStyle(variant) {
|
|
149
149
|
return labelVariantStyles[variant ?? "field"] ?? labelVariantStyles.field;
|
|
150
150
|
}
|
|
151
|
-
var FormGridContext =
|
|
152
|
-
var GapOwnedContext =
|
|
151
|
+
var FormGridContext = React40__default.default.createContext(null);
|
|
152
|
+
var GapOwnedContext = React40__default.default.createContext(false);
|
|
153
153
|
var FormGridProvider = FormGridContext.Provider;
|
|
154
154
|
var GapOwnedProvider = GapOwnedContext.Provider;
|
|
155
155
|
function useFormGridMetrics() {
|
|
156
|
-
return
|
|
156
|
+
return React40__default.default.useContext(FormGridContext);
|
|
157
157
|
}
|
|
158
158
|
function useIsGapOwned() {
|
|
159
|
-
return
|
|
159
|
+
return React40__default.default.useContext(GapOwnedContext);
|
|
160
160
|
}
|
|
161
161
|
var ERROR_LIGHT_STEPS = ["500", "600", "700"];
|
|
162
162
|
var ERROR_DARK_STEPS = ["300", "200", "400", "100", "500"];
|
|
@@ -179,7 +179,7 @@ var styles = reactNative.StyleSheet.create({
|
|
|
179
179
|
});
|
|
180
180
|
var fieldSeq = 0;
|
|
181
181
|
function useFieldIds() {
|
|
182
|
-
const [ids] =
|
|
182
|
+
const [ids] = React40__default.default.useState(() => {
|
|
183
183
|
fieldSeq += 1;
|
|
184
184
|
const seq = String(fieldSeq);
|
|
185
185
|
return {
|
|
@@ -226,7 +226,7 @@ var Field = ({
|
|
|
226
226
|
const hasLabel = labelText !== "";
|
|
227
227
|
const marker = resolveFieldMarker(required, optional);
|
|
228
228
|
const { hintId, errorId, controlId, labelId } = useFieldIds();
|
|
229
|
-
const themeStyles =
|
|
229
|
+
const themeStyles = React40__default.default.useMemo(
|
|
230
230
|
() => ({
|
|
231
231
|
label: { color: colors.textSecondary },
|
|
232
232
|
requiredMark: { color: errorColor },
|
|
@@ -278,7 +278,7 @@ var FormGrid = ({
|
|
|
278
278
|
style,
|
|
279
279
|
testID
|
|
280
280
|
}) => {
|
|
281
|
-
const metrics =
|
|
281
|
+
const metrics = React40__default.default.useMemo(() => ({ minWidth, basis }), [minWidth, basis]);
|
|
282
282
|
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 }) }) });
|
|
283
283
|
};
|
|
284
284
|
var LABEL_LINE_PLACEHOLDER = "\xA0";
|
|
@@ -363,8 +363,8 @@ var InlineFieldRow = ({
|
|
|
363
363
|
}) => {
|
|
364
364
|
const { width } = reactNative.useWindowDimensions();
|
|
365
365
|
const layout = inlineFieldRowLayout(width, fieldMaxWidth, inlineMinWidth);
|
|
366
|
-
const rowStyle =
|
|
367
|
-
const fieldStyle =
|
|
366
|
+
const rowStyle = React40.useMemo(() => [styles4.row, { gap }], [gap]);
|
|
367
|
+
const fieldStyle = React40.useMemo(() => [styles4.field, { maxWidth: layout.fieldMaxWidth }], [layout.fieldMaxWidth]);
|
|
368
368
|
if (!layout.inline)
|
|
369
369
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
370
370
|
field2,
|
|
@@ -545,7 +545,7 @@ var styles9 = reactNative.StyleSheet.create({
|
|
|
545
545
|
});
|
|
546
546
|
var sectionSeq = 0;
|
|
547
547
|
function useSectionLegendId() {
|
|
548
|
-
const [id] =
|
|
548
|
+
const [id] = React40__default.default.useState(() => {
|
|
549
549
|
sectionSeq += 1;
|
|
550
550
|
return `form-section-legend-${String(sectionSeq)}`;
|
|
551
551
|
});
|
|
@@ -803,8 +803,8 @@ function horizontalPlacement(rect2, viewportWidth) {
|
|
|
803
803
|
return { left, width };
|
|
804
804
|
}
|
|
805
805
|
function useAnchorRect(ref, enabled) {
|
|
806
|
-
const [rect2, setRect] =
|
|
807
|
-
|
|
806
|
+
const [rect2, setRect] = React40.useState(null);
|
|
807
|
+
React40.useLayoutEffect(() => {
|
|
808
808
|
if (!IS_WEB3 || !enabled) {
|
|
809
809
|
setRect(null);
|
|
810
810
|
return void 0;
|
|
@@ -853,8 +853,8 @@ function readViewportBottom() {
|
|
|
853
853
|
return viewport === null ? window.innerHeight : viewport.offsetTop + viewport.height;
|
|
854
854
|
}
|
|
855
855
|
function useVisualViewportBottom(enabled) {
|
|
856
|
-
const [bottom, setBottom] =
|
|
857
|
-
|
|
856
|
+
const [bottom, setBottom] = React40.useState(null);
|
|
857
|
+
React40.useLayoutEffect(() => {
|
|
858
858
|
if (!IS_WEB3 || !enabled) {
|
|
859
859
|
setBottom(null);
|
|
860
860
|
return void 0;
|
|
@@ -884,7 +884,7 @@ function scrollAnchorIntoView(ref, marginTop) {
|
|
|
884
884
|
scrollNodeIntoView(node, anchorScrollBlock(node.getBoundingClientRect().bottom, readViewportBottom()));
|
|
885
885
|
}
|
|
886
886
|
function useKeepAnchorInRoom(ref, marginTop, enabled) {
|
|
887
|
-
|
|
887
|
+
React40.useLayoutEffect(() => {
|
|
888
888
|
if (!IS_WEB3 || !enabled) return void 0;
|
|
889
889
|
const place = () => scrollAnchorIntoView(ref, marginTop);
|
|
890
890
|
place();
|
|
@@ -898,7 +898,7 @@ var ESCAPE_KEY = "Escape";
|
|
|
898
898
|
var LISTBOX_ROLE = { role: "listbox" };
|
|
899
899
|
var KEEP_FIELD_FOCUS = { onMouseDown: (event) => event.preventDefault() };
|
|
900
900
|
function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
901
|
-
|
|
901
|
+
React40.useEffect(() => {
|
|
902
902
|
if (!IS_WEB4) return void 0;
|
|
903
903
|
const onMouseDown = (event) => {
|
|
904
904
|
const anchorNode = anchorRef.current;
|
|
@@ -920,7 +920,7 @@ function useDismiss(anchorRef, menuRef, onDismiss) {
|
|
|
920
920
|
}, [anchorRef, menuRef, onDismiss]);
|
|
921
921
|
}
|
|
922
922
|
function useKeepHighlightInView(testID, highlightedValue) {
|
|
923
|
-
|
|
923
|
+
React40.useEffect(() => {
|
|
924
924
|
if (!IS_WEB4 || highlightedValue === void 0 || highlightedValue === "") return;
|
|
925
925
|
scrollNodeIntoView(document.getElementById(optionDomId(testID, highlightedValue)), "nearest");
|
|
926
926
|
}, [testID, highlightedValue]);
|
|
@@ -939,7 +939,7 @@ function AnchoredMenu({
|
|
|
939
939
|
listbox,
|
|
940
940
|
placement
|
|
941
941
|
}) {
|
|
942
|
-
const menuRef =
|
|
942
|
+
const menuRef = React40__default.default.useRef(null);
|
|
943
943
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
944
944
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
945
945
|
const rect2 = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
@@ -1014,27 +1014,27 @@ function useThemedInput(options = {}) {
|
|
|
1014
1014
|
const { hasError = false, onFocus, onBlur, editable = true } = options;
|
|
1015
1015
|
const { theme } = uiFeedback.useUi();
|
|
1016
1016
|
const { colors, palette } = theme;
|
|
1017
|
-
const [isFocused, setIsFocused] =
|
|
1018
|
-
const [isHovered, setIsHovered] =
|
|
1019
|
-
const handleFocus =
|
|
1017
|
+
const [isFocused, setIsFocused] = React40.useState(false);
|
|
1018
|
+
const [isHovered, setIsHovered] = React40.useState(false);
|
|
1019
|
+
const handleFocus = React40.useCallback(
|
|
1020
1020
|
(e) => {
|
|
1021
1021
|
setIsFocused(true);
|
|
1022
1022
|
onFocus?.(e);
|
|
1023
1023
|
},
|
|
1024
1024
|
[onFocus]
|
|
1025
1025
|
);
|
|
1026
|
-
const handleBlur =
|
|
1026
|
+
const handleBlur = React40.useCallback(
|
|
1027
1027
|
(e) => {
|
|
1028
1028
|
setIsFocused(false);
|
|
1029
1029
|
onBlur?.(e);
|
|
1030
1030
|
},
|
|
1031
1031
|
[onBlur]
|
|
1032
1032
|
);
|
|
1033
|
-
const handleHoverIn =
|
|
1034
|
-
const handleHoverOut =
|
|
1033
|
+
const handleHoverIn = React40.useCallback(() => setIsHovered(true), []);
|
|
1034
|
+
const handleHoverOut = React40.useCallback(() => setIsHovered(false), []);
|
|
1035
1035
|
const primary = palette.primary["500"];
|
|
1036
1036
|
const errorColor = fieldErrorInk(theme);
|
|
1037
|
-
const style =
|
|
1037
|
+
const style = React40.useMemo(() => {
|
|
1038
1038
|
const restBorder = hasError ? errorColor : colors.border;
|
|
1039
1039
|
const focusBorder = hasError ? errorColor : primary;
|
|
1040
1040
|
const editableBorder = isFocused ? focusBorder : isHovered ? withAlpha(colors.text, HOVER_BORDER_ALPHA) : restBorder;
|
|
@@ -1067,8 +1067,8 @@ function useThemedInput(options = {}) {
|
|
|
1067
1067
|
errorColor,
|
|
1068
1068
|
theme
|
|
1069
1069
|
]);
|
|
1070
|
-
const focusBind =
|
|
1071
|
-
const hoverBind =
|
|
1070
|
+
const focusBind = React40.useMemo(() => ({ onFocus: handleFocus, onBlur: handleBlur }), [handleFocus, handleBlur]);
|
|
1071
|
+
const hoverBind = React40.useMemo(
|
|
1072
1072
|
() => IS_WEB5 ? { onMouseEnter: handleHoverIn, onMouseLeave: handleHoverOut } : {},
|
|
1073
1073
|
[handleHoverIn, handleHoverOut]
|
|
1074
1074
|
);
|
|
@@ -1099,7 +1099,7 @@ var boxStyles = reactNative.StyleSheet.create({
|
|
|
1099
1099
|
textAlignVertical: "top"
|
|
1100
1100
|
}
|
|
1101
1101
|
});
|
|
1102
|
-
var ThemedTextInput =
|
|
1102
|
+
var ThemedTextInput = React40__default.default.forwardRef(function ThemedTextInput2({
|
|
1103
1103
|
hasError = false,
|
|
1104
1104
|
describedById,
|
|
1105
1105
|
requiredField = false,
|
|
@@ -1194,11 +1194,11 @@ function recentsEqual(a, b) {
|
|
|
1194
1194
|
|
|
1195
1195
|
// src/useRecentValues/useRecentValues.ts
|
|
1196
1196
|
function useRecentValues(key, max = DEFAULT_MAX_RECENTS) {
|
|
1197
|
-
const [recents, setRecents] =
|
|
1198
|
-
|
|
1197
|
+
const [recents, setRecents] = React40.useState(() => readRecents(key).slice(0, max));
|
|
1198
|
+
React40.useEffect(() => {
|
|
1199
1199
|
setRecents(readRecents(key).slice(0, max));
|
|
1200
1200
|
}, [key, max]);
|
|
1201
|
-
const remember =
|
|
1201
|
+
const remember = React40.useCallback(
|
|
1202
1202
|
(value) => {
|
|
1203
1203
|
setRecents((current) => {
|
|
1204
1204
|
const next = computeNextRecents(current, value, max);
|
|
@@ -1209,7 +1209,7 @@ function useRecentValues(key, max = DEFAULT_MAX_RECENTS) {
|
|
|
1209
1209
|
},
|
|
1210
1210
|
[key, max]
|
|
1211
1211
|
);
|
|
1212
|
-
const clear =
|
|
1212
|
+
const clear = React40.useCallback(() => {
|
|
1213
1213
|
clearRecents(key);
|
|
1214
1214
|
setRecents([]);
|
|
1215
1215
|
}, [key]);
|
|
@@ -1231,24 +1231,24 @@ function RecentInputField({
|
|
|
1231
1231
|
const { theme } = uiFeedback.useUi();
|
|
1232
1232
|
const { colors, palette } = theme;
|
|
1233
1233
|
const { recents, remember } = useRecentValues(recentKey, recentMax);
|
|
1234
|
-
const anchorRef =
|
|
1235
|
-
const latestText =
|
|
1236
|
-
const [isOpen, setIsOpen] =
|
|
1237
|
-
const handleChange =
|
|
1234
|
+
const anchorRef = React40.useRef(null);
|
|
1235
|
+
const latestText = React40.useRef(typeof value === "string" ? value : "");
|
|
1236
|
+
const [isOpen, setIsOpen] = React40.useState(false);
|
|
1237
|
+
const handleChange = React40.useCallback(
|
|
1238
1238
|
(text) => {
|
|
1239
1239
|
latestText.current = text;
|
|
1240
1240
|
onChangeText?.(text);
|
|
1241
1241
|
},
|
|
1242
1242
|
[onChangeText]
|
|
1243
1243
|
);
|
|
1244
|
-
const handleFocus =
|
|
1244
|
+
const handleFocus = React40.useCallback(
|
|
1245
1245
|
(event) => {
|
|
1246
1246
|
setIsOpen(true);
|
|
1247
1247
|
onFocus?.(event);
|
|
1248
1248
|
},
|
|
1249
1249
|
[onFocus]
|
|
1250
1250
|
);
|
|
1251
|
-
const handleBlur =
|
|
1251
|
+
const handleBlur = React40.useCallback(
|
|
1252
1252
|
(event) => {
|
|
1253
1253
|
const blurredText = latestText.current;
|
|
1254
1254
|
setTimeout(() => {
|
|
@@ -1259,7 +1259,7 @@ function RecentInputField({
|
|
|
1259
1259
|
},
|
|
1260
1260
|
[remember, onBlur]
|
|
1261
1261
|
);
|
|
1262
|
-
const handleSubmit =
|
|
1262
|
+
const handleSubmit = React40.useCallback(
|
|
1263
1263
|
(event) => {
|
|
1264
1264
|
remember(latestText.current);
|
|
1265
1265
|
setIsOpen(false);
|
|
@@ -1267,7 +1267,7 @@ function RecentInputField({
|
|
|
1267
1267
|
},
|
|
1268
1268
|
[remember, onSubmitEditing]
|
|
1269
1269
|
);
|
|
1270
|
-
const pick =
|
|
1270
|
+
const pick = React40.useCallback(
|
|
1271
1271
|
(picked) => {
|
|
1272
1272
|
latestText.current = picked;
|
|
1273
1273
|
onChangeText?.(picked);
|
|
@@ -1323,8 +1323,8 @@ function rowsForText(text, inputWidth, minRows) {
|
|
|
1323
1323
|
|
|
1324
1324
|
// src/FormField/useAutoGrowRows.ts
|
|
1325
1325
|
function useAutoGrowRows(text, minRows) {
|
|
1326
|
-
const [inputWidth, setInputWidth] =
|
|
1327
|
-
const onLayout =
|
|
1326
|
+
const [inputWidth, setInputWidth] = React40.useState(NARROWEST_INPUT_WIDTH);
|
|
1327
|
+
const onLayout = React40.useCallback((event) => {
|
|
1328
1328
|
setInputWidth(event.nativeEvent.layout.width);
|
|
1329
1329
|
}, []);
|
|
1330
1330
|
return { numberOfLines: rowsForText(text, inputWidth, minRows), onLayout };
|
|
@@ -1561,7 +1561,7 @@ function ChipContent(props) {
|
|
|
1561
1561
|
}
|
|
1562
1562
|
function OutlineChip(props) {
|
|
1563
1563
|
const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
|
|
1564
|
-
const [hovered, setHovered] =
|
|
1564
|
+
const [hovered, setHovered] = React40__default.default.useState(false);
|
|
1565
1565
|
const active = selected || hovered;
|
|
1566
1566
|
const borderColor = active ? colors.primary : restBorderColor(colors, props.outlineTone);
|
|
1567
1567
|
const fill = chipFill({
|
|
@@ -1677,8 +1677,8 @@ function radioTabIndex(index, selectedIndex, disabled) {
|
|
|
1677
1677
|
var NO_GROUP_PROPS = {};
|
|
1678
1678
|
function useRadioKeyboard(config) {
|
|
1679
1679
|
const { enabled, disabled, values, selectedIndex, onChange } = config;
|
|
1680
|
-
const nodes =
|
|
1681
|
-
const chipRef =
|
|
1680
|
+
const nodes = React40__default.default.useRef([]);
|
|
1681
|
+
const chipRef = React40__default.default.useCallback((index) => (node) => {
|
|
1682
1682
|
nodes.current[index] = node;
|
|
1683
1683
|
}, []);
|
|
1684
1684
|
const onKeyDown = (event) => {
|
|
@@ -1797,7 +1797,7 @@ var ChipSelector = ({
|
|
|
1797
1797
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1798
1798
|
const { theme } = uiFeedback.useUi();
|
|
1799
1799
|
const { colors, palette } = theme;
|
|
1800
|
-
const chipColors =
|
|
1800
|
+
const chipColors = React40__default.default.useMemo(() => buildChipColors(colors, palette), [colors, palette]);
|
|
1801
1801
|
function isSelected(optionValue) {
|
|
1802
1802
|
if (multiple && Array.isArray(value))
|
|
1803
1803
|
return value.includes(optionValue);
|
|
@@ -1922,10 +1922,10 @@ var FormSwitchBox = ({
|
|
|
1922
1922
|
}) => {
|
|
1923
1923
|
const { colors } = uiFeedback.useUi().theme;
|
|
1924
1924
|
const { disabled, onValueChange, value } = slot;
|
|
1925
|
-
const toggle2 =
|
|
1925
|
+
const toggle2 = React40__default.default.useCallback(() => {
|
|
1926
1926
|
if (!disabled) onValueChange(!value);
|
|
1927
1927
|
}, [disabled, onValueChange, value]);
|
|
1928
|
-
const boxColors =
|
|
1928
|
+
const boxColors = React40__default.default.useMemo(
|
|
1929
1929
|
() => ({ borderColor: colors.border, backgroundColor: colors.surface }),
|
|
1930
1930
|
[colors.border, colors.surface]
|
|
1931
1931
|
);
|
|
@@ -1979,12 +1979,12 @@ var FormSwitchRow = ({
|
|
|
1979
1979
|
activeTrackColor
|
|
1980
1980
|
}) => {
|
|
1981
1981
|
const { theme } = uiFeedback.useUi();
|
|
1982
|
-
const toggle2 =
|
|
1982
|
+
const toggle2 = React40__default.default.useCallback(() => {
|
|
1983
1983
|
if (!disabled) onValueChange(!value);
|
|
1984
1984
|
}, [disabled, onValueChange, value]);
|
|
1985
1985
|
const { colors } = theme;
|
|
1986
1986
|
const hasDescription = typeof description === "string" && description !== "";
|
|
1987
|
-
const themeStyles =
|
|
1987
|
+
const themeStyles = React40__default.default.useMemo(() => {
|
|
1988
1988
|
const labelStyle = { color: colors.text };
|
|
1989
1989
|
const descriptionStyle = { color: colors.textSecondary };
|
|
1990
1990
|
return { label: labelStyle, description: descriptionStyle };
|
|
@@ -2120,8 +2120,8 @@ var FormCheckbox = ({
|
|
|
2120
2120
|
const hintText = typeof hint === "string" && hint !== "" ? hint : description;
|
|
2121
2121
|
const hasHint = typeof hintText === "string" && hintText !== "";
|
|
2122
2122
|
const { hintId } = useFieldIds();
|
|
2123
|
-
const [focused, setFocused] =
|
|
2124
|
-
const themeStyles =
|
|
2123
|
+
const [focused, setFocused] = React40__default.default.useState(false);
|
|
2124
|
+
const themeStyles = React40__default.default.useMemo(() => {
|
|
2125
2125
|
const boxOn = checkboxBoxColors(colors, brand, true);
|
|
2126
2126
|
const boxOff = checkboxBoxColors(colors, brand, false);
|
|
2127
2127
|
const ring = { borderColor: brand };
|
|
@@ -2178,6 +2178,63 @@ var FormCheckbox = ({
|
|
|
2178
2178
|
}
|
|
2179
2179
|
);
|
|
2180
2180
|
};
|
|
2181
|
+
|
|
2182
|
+
// src/SearchSelect/SelectSurface.ts
|
|
2183
|
+
var SelectSurface = /* @__PURE__ */ ((SelectSurface2) => {
|
|
2184
|
+
SelectSurface2["Sheet"] = "sheet";
|
|
2185
|
+
SelectSurface2["Dropdown"] = "dropdown";
|
|
2186
|
+
return SelectSurface2;
|
|
2187
|
+
})(SelectSurface || {});
|
|
2188
|
+
|
|
2189
|
+
// src/SearchSelect/utils/searchSelectMotion.ts
|
|
2190
|
+
var PHONE_MAX_WIDTH = 600;
|
|
2191
|
+
var SHEET_TRAVEL_PX = 320;
|
|
2192
|
+
var DROPDOWN_TRAVEL_PX = -8;
|
|
2193
|
+
var SHEET_MS = 240;
|
|
2194
|
+
var DROPDOWN_MS = 160;
|
|
2195
|
+
function resolveSelectMotion(width, reducedMotion) {
|
|
2196
|
+
const isPhone = width < PHONE_MAX_WIDTH;
|
|
2197
|
+
const surface = isPhone ? "sheet" /* Sheet */ : "dropdown" /* Dropdown */;
|
|
2198
|
+
if (reducedMotion) return { surface, fromY: 0, durationMs: 0 };
|
|
2199
|
+
return isPhone ? { surface, fromY: SHEET_TRAVEL_PX, durationMs: SHEET_MS } : { surface, fromY: DROPDOWN_TRAVEL_PX, durationMs: DROPDOWN_MS };
|
|
2200
|
+
}
|
|
2201
|
+
var FIELD_DESKTOP_HEIGHT = 38;
|
|
2202
|
+
var FIELD_PHONE_HEIGHT = 44;
|
|
2203
|
+
var FIELD_PAD_H = 10;
|
|
2204
|
+
var FIELD_FONT = 13;
|
|
2205
|
+
var FIELD_RADIUS = 8;
|
|
2206
|
+
var FIELD_CHEVRON_ROOM = 30;
|
|
2207
|
+
var CHEVRON_BOX = 16;
|
|
2208
|
+
var DEFAULT_CONFIG = { look: "default" };
|
|
2209
|
+
var SelectLookContext = React40.createContext(DEFAULT_CONFIG);
|
|
2210
|
+
function SelectLookProvider({ look, borderColor, children }) {
|
|
2211
|
+
const value = React40.useMemo(() => ({ look, borderColor }), [look, borderColor]);
|
|
2212
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SelectLookContext.Provider, { value, children });
|
|
2213
|
+
}
|
|
2214
|
+
function selectLookMetrics({ look, borderColor }, windowWidth) {
|
|
2215
|
+
if (look === "default") {
|
|
2216
|
+
return void 0;
|
|
2217
|
+
}
|
|
2218
|
+
const isPhone = windowWidth < PHONE_MAX_WIDTH;
|
|
2219
|
+
return {
|
|
2220
|
+
height: isPhone ? FIELD_PHONE_HEIGHT : FIELD_DESKTOP_HEIGHT,
|
|
2221
|
+
paddingHorizontal: FIELD_PAD_H,
|
|
2222
|
+
paddingVertical: 0,
|
|
2223
|
+
fontSize: FIELD_FONT,
|
|
2224
|
+
borderRadius: FIELD_RADIUS,
|
|
2225
|
+
chevronRoom: FIELD_CHEVRON_ROOM,
|
|
2226
|
+
borderColor
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
function useSelectLookMetrics() {
|
|
2230
|
+
const config = React40.useContext(SelectLookContext);
|
|
2231
|
+
const { width } = reactNative.useWindowDimensions();
|
|
2232
|
+
return selectLookMetrics(config, width);
|
|
2233
|
+
}
|
|
2234
|
+
function chevronDataUri(color) {
|
|
2235
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="${color}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6l4 4 4-4"/></svg>`;
|
|
2236
|
+
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
|
|
2237
|
+
}
|
|
2181
2238
|
var NATIVE_SELECT_BOX = {
|
|
2182
2239
|
borderStyle: "solid",
|
|
2183
2240
|
boxSizing: "border-box",
|
|
@@ -2185,12 +2242,36 @@ var NATIVE_SELECT_BOX = {
|
|
|
2185
2242
|
width: "100%"
|
|
2186
2243
|
};
|
|
2187
2244
|
var FIT_SELECT_BOX = { width: "auto", maxWidth: "none" };
|
|
2245
|
+
var ONE_LINE_BOX = { maxWidth: "100%", minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" };
|
|
2246
|
+
var CHEVRON_INSET = 10;
|
|
2188
2247
|
var fitStyles = reactNative.StyleSheet.create({
|
|
2189
|
-
anchor: { alignSelf: "flex-start", flexShrink: 0 }
|
|
2248
|
+
anchor: { alignSelf: "flex-start", flexShrink: 0 },
|
|
2249
|
+
oneLine: { maxWidth: "100%", minWidth: 0, flexShrink: 1 }
|
|
2190
2250
|
});
|
|
2191
2251
|
function nativeSelectBox(fit) {
|
|
2192
2252
|
return fit ? { ...NATIVE_SELECT_BOX, ...FIT_SELECT_BOX } : NATIVE_SELECT_BOX;
|
|
2193
2253
|
}
|
|
2254
|
+
function lookSelectStyle(fit, m, colors) {
|
|
2255
|
+
return {
|
|
2256
|
+
...nativeSelectBox(fit),
|
|
2257
|
+
...ONE_LINE_BOX,
|
|
2258
|
+
height: m.height,
|
|
2259
|
+
borderWidth: 1,
|
|
2260
|
+
borderRadius: m.borderRadius,
|
|
2261
|
+
fontSize: m.fontSize,
|
|
2262
|
+
paddingBlock: m.paddingVertical,
|
|
2263
|
+
paddingInlineStart: m.paddingHorizontal,
|
|
2264
|
+
paddingInlineEnd: m.chevronRoom,
|
|
2265
|
+
borderColor: m.borderColor ?? colors.border,
|
|
2266
|
+
backgroundColor: colors.background,
|
|
2267
|
+
color: colors.text,
|
|
2268
|
+
appearance: "none",
|
|
2269
|
+
backgroundImage: chevronDataUri(colors.chevron),
|
|
2270
|
+
backgroundRepeat: "no-repeat",
|
|
2271
|
+
backgroundPosition: `right ${String(CHEVRON_INSET)}px center`,
|
|
2272
|
+
backgroundSize: "16px 16px"
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2194
2275
|
function nativeSelectStyle(fit, borderColor, backgroundColor, color) {
|
|
2195
2276
|
const trigger = reactNative.StyleSheet.flatten(controlStyles.selectTrigger);
|
|
2196
2277
|
const text = reactNative.StyleSheet.flatten(controlStyles.selectTriggerText);
|
|
@@ -2224,14 +2305,16 @@ function NativeSelect({
|
|
|
2224
2305
|
const hasMatch = options.some((o) => o.value === value);
|
|
2225
2306
|
const textColor = hasMatch ? colors.text : colors.textSecondary;
|
|
2226
2307
|
const fit = native === "fit";
|
|
2308
|
+
const metrics = useSelectLookMetrics();
|
|
2309
|
+
const selectStyle = metrics === void 0 ? nativeSelectStyle(fit, colors.border, colors.surfaceElevated, textColor) : lookSelectStyle(fit, metrics, { border: colors.border, background: colors.surfaceElevated, text: textColor, chevron: colors.textSecondary });
|
|
2227
2310
|
const handleChange = (event) => onChange(event.target.value);
|
|
2228
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [controlStyles.anchor, fit ? fitStyles.anchor : void 0, style], children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2311
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [controlStyles.anchor, fit ? fitStyles.anchor : void 0, metrics === void 0 ? void 0 : fitStyles.oneLine, style], children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2229
2312
|
"select",
|
|
2230
2313
|
{
|
|
2231
2314
|
"aria-label": accessibilityLabel,
|
|
2232
2315
|
"aria-labelledby": labelledById,
|
|
2233
2316
|
"data-testid": testID,
|
|
2234
|
-
style:
|
|
2317
|
+
style: selectStyle,
|
|
2235
2318
|
title: accessibilityHint,
|
|
2236
2319
|
value,
|
|
2237
2320
|
onChange: handleChange,
|
|
@@ -2242,6 +2325,9 @@ function NativeSelect({
|
|
|
2242
2325
|
}
|
|
2243
2326
|
) });
|
|
2244
2327
|
}
|
|
2328
|
+
function SelectChevron({ color, open }) {
|
|
2329
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Svg__default.default, { "aria-hidden": true, fill: "none", height: CHEVRON_BOX, stroke: color, strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.6, viewBox: "0 0 16 16", width: CHEVRON_BOX, children: /* @__PURE__ */ jsxRuntime.jsx(Svg.Path, { d: open ? "M4 10l4-4 4 4" : "M4 6l4 4 4-4" }) });
|
|
2330
|
+
}
|
|
2245
2331
|
|
|
2246
2332
|
// src/controls/nextHighlight.ts
|
|
2247
2333
|
var NO_HIGHLIGHT = -1;
|
|
@@ -2255,9 +2341,9 @@ function nextHighlight(current, count, delta) {
|
|
|
2255
2341
|
var FORWARD = 1;
|
|
2256
2342
|
var BACKWARD = -1;
|
|
2257
2343
|
function useSelectListbox({ options, isOpen, open, toggle: toggle2, select }) {
|
|
2258
|
-
const [row, setRow] =
|
|
2344
|
+
const [row, setRow] = React40.useState(NO_HIGHLIGHT);
|
|
2259
2345
|
const highlighted = isOpen ? options[row] : void 0;
|
|
2260
|
-
|
|
2346
|
+
React40.useEffect(() => {
|
|
2261
2347
|
if (!isOpen) setRow(NO_HIGHLIGHT);
|
|
2262
2348
|
}, [isOpen]);
|
|
2263
2349
|
const onKeyDown = (event) => {
|
|
@@ -2277,6 +2363,9 @@ function useSelectListbox({ options, isOpen, open, toggle: toggle2, select }) {
|
|
|
2277
2363
|
var IS_WEB7 = reactNative.Platform.OS === "web";
|
|
2278
2364
|
var CHEVRON_DOWN = "\u25BE";
|
|
2279
2365
|
var CHEVRON_UP = "\u25B4";
|
|
2366
|
+
function lookTriggerBox(m) {
|
|
2367
|
+
return m === void 0 ? void 0 : { minHeight: m.height, height: m.height, paddingHorizontal: m.paddingHorizontal, paddingVertical: m.paddingVertical, borderRadius: m.borderRadius };
|
|
2368
|
+
}
|
|
2280
2369
|
function listboxTriggerAria(testID, hasList, highlighted) {
|
|
2281
2370
|
return {
|
|
2282
2371
|
role: "combobox",
|
|
@@ -2302,28 +2391,29 @@ function MenuSelectControl({
|
|
|
2302
2391
|
}) {
|
|
2303
2392
|
const { theme } = uiFeedback.useUi();
|
|
2304
2393
|
const { colors, palette } = theme;
|
|
2305
|
-
const anchorRef =
|
|
2306
|
-
const [isOpen, setIsOpen] =
|
|
2307
|
-
const selectedLabel =
|
|
2394
|
+
const anchorRef = React40.useRef(null);
|
|
2395
|
+
const [isOpen, setIsOpen] = React40.useState(false);
|
|
2396
|
+
const selectedLabel = React40.useMemo(() => {
|
|
2308
2397
|
const found = options.find((o) => o.value === value);
|
|
2309
2398
|
return found?.label ?? placeholder;
|
|
2310
2399
|
}, [options, placeholder, value]);
|
|
2311
|
-
const close =
|
|
2400
|
+
const close = React40.useCallback(() => {
|
|
2312
2401
|
setIsOpen(false);
|
|
2313
2402
|
}, []);
|
|
2314
|
-
const open =
|
|
2403
|
+
const open = React40.useCallback(() => {
|
|
2315
2404
|
setIsOpen(true);
|
|
2316
2405
|
}, []);
|
|
2317
|
-
const toggle2 =
|
|
2406
|
+
const toggle2 = React40.useCallback(() => {
|
|
2318
2407
|
setIsOpen((prev) => !prev);
|
|
2319
2408
|
}, []);
|
|
2320
|
-
const select =
|
|
2409
|
+
const select = React40.useCallback(
|
|
2321
2410
|
(next) => {
|
|
2322
2411
|
onChange(next);
|
|
2323
2412
|
setIsOpen(false);
|
|
2324
2413
|
},
|
|
2325
2414
|
[onChange]
|
|
2326
2415
|
);
|
|
2416
|
+
const metrics = useSelectLookMetrics();
|
|
2327
2417
|
const listbox = useSelectListbox({ options, isOpen, open, toggle: toggle2, select });
|
|
2328
2418
|
const isListbox = menuAnchor !== void 0;
|
|
2329
2419
|
const captureKeys = isListbox ? { onKeyDownCapture: listbox.onKeyDown } : {};
|
|
@@ -2342,11 +2432,11 @@ function MenuSelectControl({
|
|
|
2342
2432
|
"aria-labelledby": labelledById,
|
|
2343
2433
|
onBlur: isListbox ? close : void 0,
|
|
2344
2434
|
onPress: toggle2,
|
|
2345
|
-
style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
|
|
2435
|
+
style: [controlStyles.selectTrigger, lookTriggerBox(metrics), { borderColor: metrics?.borderColor ?? colors.border, backgroundColor: colors.surfaceElevated }],
|
|
2346
2436
|
testID: `${testID}-trigger`,
|
|
2347
2437
|
children: [
|
|
2348
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
|
|
2349
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [controlStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP : CHEVRON_DOWN })
|
|
2438
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, metrics === void 0 ? void 0 : { fontSize: metrics.fontSize }, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
|
|
2439
|
+
metrics === void 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [controlStyles.chevron, { color: colors.textSecondary }], children: isOpen ? CHEVRON_UP : CHEVRON_DOWN }) : /* @__PURE__ */ jsxRuntime.jsx(SelectChevron, { color: colors.textSecondary, open: isOpen })
|
|
2350
2440
|
]
|
|
2351
2441
|
}
|
|
2352
2442
|
),
|
|
@@ -2460,21 +2550,21 @@ var styles19 = reactNative.StyleSheet.create({
|
|
|
2460
2550
|
function MultiSelectBox(props) {
|
|
2461
2551
|
const { label, accessibilityHint, values, options, onChange, placeholder, chipLabels, testID, labelId } = props;
|
|
2462
2552
|
const { colors, palette } = uiFeedback.useUi().theme;
|
|
2463
|
-
const anchorRef =
|
|
2464
|
-
const [isOpen, setIsOpen] =
|
|
2553
|
+
const anchorRef = React40.useRef(null);
|
|
2554
|
+
const [isOpen, setIsOpen] = React40.useState(false);
|
|
2465
2555
|
const chosen = selectedOptions(options, values);
|
|
2466
2556
|
const remaining = remainingOptions(options, values);
|
|
2467
|
-
const close =
|
|
2557
|
+
const close = React40.useCallback(() => {
|
|
2468
2558
|
setIsOpen(false);
|
|
2469
2559
|
}, []);
|
|
2470
|
-
const toggle2 =
|
|
2560
|
+
const toggle2 = React40.useCallback(() => {
|
|
2471
2561
|
setIsOpen((prev) => !prev);
|
|
2472
2562
|
}, []);
|
|
2473
|
-
const add =
|
|
2563
|
+
const add = React40.useCallback((next) => {
|
|
2474
2564
|
onChange(addValue(values, next));
|
|
2475
2565
|
setIsOpen(false);
|
|
2476
2566
|
}, [onChange, values]);
|
|
2477
|
-
const remove =
|
|
2567
|
+
const remove = React40.useCallback((value) => {
|
|
2478
2568
|
onChange(removeValue(values, value));
|
|
2479
2569
|
}, [onChange, values]);
|
|
2480
2570
|
const chipColors = { text: colors.text, border: colors.border, surface: colors.surface };
|
|
@@ -2532,17 +2622,17 @@ function MultiSelectBox(props) {
|
|
|
2532
2622
|
var MultiSelectField = ({ labelVariant, hint, error, ...boxProps }) => /* @__PURE__ */ jsxRuntime.jsx(Field, { error, hint, label: boxProps.label, labelVariant, children: ({ labelId }) => /* @__PURE__ */ jsxRuntime.jsx(MultiSelectBox, { ...boxProps, labelId }) });
|
|
2533
2623
|
var CLOSE_DELAY_MS2 = 140;
|
|
2534
2624
|
function useDelayedBlurClose(open, close) {
|
|
2535
|
-
const timerRef =
|
|
2536
|
-
const cancelClose =
|
|
2625
|
+
const timerRef = React40.useRef(null);
|
|
2626
|
+
const cancelClose = React40.useCallback(() => {
|
|
2537
2627
|
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
2538
2628
|
timerRef.current = null;
|
|
2539
2629
|
}, []);
|
|
2540
|
-
|
|
2541
|
-
const handleFocus =
|
|
2630
|
+
React40.useEffect(() => cancelClose, [cancelClose]);
|
|
2631
|
+
const handleFocus = React40.useCallback(() => {
|
|
2542
2632
|
cancelClose();
|
|
2543
2633
|
open();
|
|
2544
2634
|
}, [cancelClose, open]);
|
|
2545
|
-
const handleBlur =
|
|
2635
|
+
const handleBlur = React40.useCallback(() => {
|
|
2546
2636
|
cancelClose();
|
|
2547
2637
|
timerRef.current = setTimeout(close, CLOSE_DELAY_MS2);
|
|
2548
2638
|
}, [cancelClose, close]);
|
|
@@ -2585,10 +2675,10 @@ function isUnmatched(options, text) {
|
|
|
2585
2675
|
var DEFAULT_TYPEAHEAD_DEBOUNCE_MS = 250;
|
|
2586
2676
|
var IDLE = { results: [], isLoading: false, hasFailed: false, hasSettled: false };
|
|
2587
2677
|
function useTypeaheadSearch(load, query, enabled, debounceMs) {
|
|
2588
|
-
const [state, setState] =
|
|
2589
|
-
const loadRef =
|
|
2678
|
+
const [state, setState] = React40.useState(IDLE);
|
|
2679
|
+
const loadRef = React40.useRef(load);
|
|
2590
2680
|
loadRef.current = load;
|
|
2591
|
-
|
|
2681
|
+
React40.useEffect(() => {
|
|
2592
2682
|
if (!enabled) {
|
|
2593
2683
|
setState(IDLE);
|
|
2594
2684
|
return void 0;
|
|
@@ -2627,30 +2717,30 @@ function useTypeaheadRows(input, isOpen, isPicked) {
|
|
|
2627
2717
|
const query = value.trim();
|
|
2628
2718
|
const isSearching = search !== void 0 && isOpen && !isPicked && query.length >= minChars;
|
|
2629
2719
|
const found = useTypeaheadSearch(search?.load, query, isSearching, search?.debounceMs ?? DEFAULT_TYPEAHEAD_DEBOUNCE_MS);
|
|
2630
|
-
const staticRows =
|
|
2720
|
+
const staticRows = React40.useMemo(() => {
|
|
2631
2721
|
if (options === void 0 || options.some((o) => o.label === value)) return NO_ROWS;
|
|
2632
2722
|
return suggestOptions(options, value, minChars, maxSuggestions);
|
|
2633
2723
|
}, [options, value, minChars, maxSuggestions]);
|
|
2634
|
-
const foundRows =
|
|
2724
|
+
const foundRows = React40.useMemo(() => found.results.slice(0, maxSuggestions), [found.results, maxSuggestions]);
|
|
2635
2725
|
if (search === void 0) return { rows: staticRows, statusText: void 0 };
|
|
2636
2726
|
return { rows: foundRows, statusText: searchStatusText(found, search) };
|
|
2637
2727
|
}
|
|
2638
2728
|
function useTypeaheadState(input) {
|
|
2639
2729
|
const { search, value, onChange, onSubmit } = input;
|
|
2640
|
-
const [isOpen, setIsOpen] =
|
|
2641
|
-
const [picked, setPicked] =
|
|
2642
|
-
const [highlightIndex, setHighlightIndex] =
|
|
2730
|
+
const [isOpen, setIsOpen] = React40.useState(false);
|
|
2731
|
+
const [picked, setPicked] = React40.useState(null);
|
|
2732
|
+
const [highlightIndex, setHighlightIndex] = React40.useState(NO_HIGHLIGHT);
|
|
2643
2733
|
const { rows, statusText } = useTypeaheadRows(input, isOpen, picked !== null && picked.label === value);
|
|
2644
2734
|
const rowKey = rows.map((row) => row.value).join("\n");
|
|
2645
2735
|
const highlighted = isOpen ? rows[highlightIndex] : void 0;
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
const open =
|
|
2649
|
-
const close =
|
|
2736
|
+
React40.useEffect(() => setHighlightIndex(NO_HIGHLIGHT), [rowKey]);
|
|
2737
|
+
React40.useEffect(() => setPicked((current) => current !== null && current.label !== value ? null : current), [value]);
|
|
2738
|
+
const open = React40.useCallback(() => setIsOpen(true), []);
|
|
2739
|
+
const close = React40.useCallback(() => {
|
|
2650
2740
|
setIsOpen(false);
|
|
2651
2741
|
setHighlightIndex(NO_HIGHLIGHT);
|
|
2652
2742
|
}, []);
|
|
2653
|
-
const pick =
|
|
2743
|
+
const pick = React40.useCallback(
|
|
2654
2744
|
(option) => {
|
|
2655
2745
|
setPicked(option);
|
|
2656
2746
|
onChange(option.label);
|
|
@@ -2659,14 +2749,14 @@ function useTypeaheadState(input) {
|
|
|
2659
2749
|
},
|
|
2660
2750
|
[onChange, search, close]
|
|
2661
2751
|
);
|
|
2662
|
-
const selectValue =
|
|
2752
|
+
const selectValue = React40.useCallback(
|
|
2663
2753
|
(optionValue) => {
|
|
2664
2754
|
const option = rows.find((row) => row.value === optionValue);
|
|
2665
2755
|
if (option !== void 0) pick(option);
|
|
2666
2756
|
},
|
|
2667
2757
|
[rows, pick]
|
|
2668
2758
|
);
|
|
2669
|
-
const handleChange =
|
|
2759
|
+
const handleChange = React40.useCallback(
|
|
2670
2760
|
(next) => {
|
|
2671
2761
|
if (picked !== null) {
|
|
2672
2762
|
setPicked(null);
|
|
@@ -2679,7 +2769,7 @@ function useTypeaheadState(input) {
|
|
|
2679
2769
|
[picked, search, onChange]
|
|
2680
2770
|
);
|
|
2681
2771
|
const handleKeyPress = useTypeaheadKeys({ rowCount: rows.length, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick });
|
|
2682
|
-
const handleSubmit =
|
|
2772
|
+
const handleSubmit = React40.useCallback(() => {
|
|
2683
2773
|
if (highlighted !== void 0) {
|
|
2684
2774
|
pick(highlighted);
|
|
2685
2775
|
return;
|
|
@@ -2691,7 +2781,7 @@ function useTypeaheadState(input) {
|
|
|
2691
2781
|
}
|
|
2692
2782
|
function useTypeaheadKeys(input) {
|
|
2693
2783
|
const { rowCount, isOpen, highlighted, setIsOpen, setHighlightIndex, close, pick } = input;
|
|
2694
|
-
return
|
|
2784
|
+
return React40.useCallback(
|
|
2695
2785
|
(event) => {
|
|
2696
2786
|
const { key } = event.nativeEvent;
|
|
2697
2787
|
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
@@ -2728,7 +2818,7 @@ function TypeaheadControlImpl(props, ref) {
|
|
|
2728
2818
|
const maxSuggestions = ("search" in props ? props.search.maxResults : props.maxSuggestions) ?? DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
2729
2819
|
const { theme } = uiFeedback.useUi();
|
|
2730
2820
|
const { colors, palette } = theme;
|
|
2731
|
-
const anchorRef =
|
|
2821
|
+
const anchorRef = React40.useRef(null);
|
|
2732
2822
|
const state = useTypeaheadState({ options, search, value, minChars, maxSuggestions, onChange, onSubmit });
|
|
2733
2823
|
const { handleFocus, handleBlur } = useDelayedBlurClose(state.open, state.close);
|
|
2734
2824
|
const showMenu = state.isOpen && (state.rows.length > 0 || state.statusText !== void 0);
|
|
@@ -2781,7 +2871,7 @@ function TypeaheadControlImpl(props, ref) {
|
|
|
2781
2871
|
hasError ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [controlStyles.error, { color: fieldErrorInk(theme) }], testID: `${testID}-error`, children: error }) : null
|
|
2782
2872
|
] });
|
|
2783
2873
|
}
|
|
2784
|
-
var TypeaheadControl =
|
|
2874
|
+
var TypeaheadControl = React40.forwardRef(TypeaheadControlImpl);
|
|
2785
2875
|
var NATIVE_INPUT_BOX = {
|
|
2786
2876
|
borderStyle: "solid",
|
|
2787
2877
|
boxSizing: "border-box",
|
|
@@ -2869,7 +2959,7 @@ function tabStops(container) {
|
|
|
2869
2959
|
}
|
|
2870
2960
|
function PickerDialog({ testID, sheet, onDismiss, children }) {
|
|
2871
2961
|
const colors = usePickerColors();
|
|
2872
|
-
const ref =
|
|
2962
|
+
const ref = React40.useRef(null);
|
|
2873
2963
|
const onKeyDown = (event) => {
|
|
2874
2964
|
if (event.key === "Escape") {
|
|
2875
2965
|
event.preventDefault();
|
|
@@ -2892,8 +2982,8 @@ function PickerDialog({ testID, sheet, onDismiss, children }) {
|
|
|
2892
2982
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, "data-testid": testID, "data-variant": sheet ? "sheet" : "popover", style, onKeyDown, children });
|
|
2893
2983
|
}
|
|
2894
2984
|
function useAnchorRect2(anchorRef) {
|
|
2895
|
-
const [rect2, setRect] =
|
|
2896
|
-
|
|
2985
|
+
const [rect2, setRect] = React40.useState(null);
|
|
2986
|
+
React40.useEffect(() => {
|
|
2897
2987
|
anchorRef.current?.measureInWindow((x, y, width, height) => setRect({ x, y, width, height }));
|
|
2898
2988
|
}, [anchorRef]);
|
|
2899
2989
|
return rect2;
|
|
@@ -2936,8 +3026,8 @@ function fitDropdownWidth(frame, viewportWidth, minWidth = MIN_PANEL_WIDTH) {
|
|
|
2936
3026
|
function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children, minWidth, scale, accessibilityLabel, preferBelow = false }) {
|
|
2937
3027
|
const { height: viewportHeight, width: viewportWidth } = reactNative.useWindowDimensions();
|
|
2938
3028
|
const anchor = useAnchorRect2(anchorRef);
|
|
2939
|
-
const [panelHeight, setPanelHeight] =
|
|
2940
|
-
const onLayout =
|
|
3029
|
+
const [panelHeight, setPanelHeight] = React40.useState(0);
|
|
3030
|
+
const onLayout = React40.useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
|
|
2941
3031
|
const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight, preferBelow), viewportWidth, minWidth);
|
|
2942
3032
|
const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
|
|
2943
3033
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Modal, { transparent: true, visible: true, animationType: "none", "aria-label": accessibilityLabel, onRequestClose: onDismiss, children: [
|
|
@@ -2960,8 +3050,8 @@ var styles21 = reactNative.StyleSheet.create({
|
|
|
2960
3050
|
sheet: { width: "100%", alignSelf: "stretch" }
|
|
2961
3051
|
});
|
|
2962
3052
|
function useReducedMotion() {
|
|
2963
|
-
const [reduced, setReduced] =
|
|
2964
|
-
|
|
3053
|
+
const [reduced, setReduced] = React40.useState(false);
|
|
3054
|
+
React40.useEffect(() => {
|
|
2965
3055
|
let active = true;
|
|
2966
3056
|
reactNative.AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
2967
3057
|
if (active) setReduced(value);
|
|
@@ -3172,14 +3262,14 @@ function weekFirstDay(locale) {
|
|
|
3172
3262
|
return MONDAY3;
|
|
3173
3263
|
}
|
|
3174
3264
|
}
|
|
3175
|
-
var DatePickerContext =
|
|
3265
|
+
var DatePickerContext = React40.createContext({ labels: DEFAULT_DATE_PICKER_LABELS });
|
|
3176
3266
|
function DatePickerProvider({ labels, locale, today, display, children }) {
|
|
3177
|
-
const value =
|
|
3267
|
+
const value = React40.useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today, display }), [labels, locale, today, display]);
|
|
3178
3268
|
return /* @__PURE__ */ jsxRuntime.jsx(DatePickerContext.Provider, { value, children });
|
|
3179
3269
|
}
|
|
3180
3270
|
function useDatePickerConfig() {
|
|
3181
|
-
const config =
|
|
3182
|
-
const firstDay =
|
|
3271
|
+
const config = React40.useContext(DatePickerContext);
|
|
3272
|
+
const firstDay = React40.useMemo(() => weekFirstDay(config.locale), [config.locale]);
|
|
3183
3273
|
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay, display: config.display ?? "long" /* Long */ };
|
|
3184
3274
|
}
|
|
3185
3275
|
|
|
@@ -3202,8 +3292,8 @@ function monthSlideStyle(entered, reduced, direction) {
|
|
|
3202
3292
|
}
|
|
3203
3293
|
function useOpenProgress() {
|
|
3204
3294
|
const { durationMs, fromScale } = resolveOpenMotion(useReducedMotion());
|
|
3205
|
-
const progress =
|
|
3206
|
-
|
|
3295
|
+
const progress = React40.useRef(new reactNative.Animated.Value(0)).current;
|
|
3296
|
+
React40.useEffect(() => {
|
|
3207
3297
|
reactNative.Animated.timing(progress, { toValue: 1, duration: durationMs, useNativeDriver: false }).start();
|
|
3208
3298
|
}, [progress, durationMs]);
|
|
3209
3299
|
return {
|
|
@@ -3249,16 +3339,16 @@ function dayDomId(testID, iso) {
|
|
|
3249
3339
|
}
|
|
3250
3340
|
function useGridFocus(initial, bounds, testID, onPick) {
|
|
3251
3341
|
const { firstDay } = useDatePickerConfig();
|
|
3252
|
-
const [focusedDay, setFocusedDay] =
|
|
3253
|
-
const focusPending =
|
|
3342
|
+
const [focusedDay, setFocusedDay] = React40.useState(initial);
|
|
3343
|
+
const focusPending = React40.useRef(true);
|
|
3254
3344
|
const { min, max } = bounds;
|
|
3255
|
-
|
|
3345
|
+
React40.useEffect(() => {
|
|
3256
3346
|
if (!focusPending.current) return;
|
|
3257
3347
|
focusPending.current = false;
|
|
3258
3348
|
document.getElementById(dayDomId(testID, focusedDay))?.focus();
|
|
3259
3349
|
}, [focusedDay, testID]);
|
|
3260
|
-
const moveTo =
|
|
3261
|
-
const onDayKey =
|
|
3350
|
+
const moveTo = React40.useCallback((iso) => setFocusedDay(clampToBounds(iso, min, max)), [min, max]);
|
|
3351
|
+
const onDayKey = React40.useCallback(
|
|
3262
3352
|
(event, iso) => {
|
|
3263
3353
|
if (event.key === "Enter" || event.key === " ") {
|
|
3264
3354
|
event.preventDefault();
|
|
@@ -3345,8 +3435,8 @@ function MonthGrid({ month, selection: selection2, focusedDay, bounds, testID, o
|
|
|
3345
3435
|
const { labels, locale, today, firstDay } = useDatePickerConfig();
|
|
3346
3436
|
const colors = usePickerColors();
|
|
3347
3437
|
const parts = parseIso(month) ?? FALLBACK;
|
|
3348
|
-
const weeks =
|
|
3349
|
-
const weekdays =
|
|
3438
|
+
const weeks = React40.useMemo(() => buildMonthGrid(parts.year, parts.month, firstDay), [parts.year, parts.month, firstDay]);
|
|
3439
|
+
const weekdays = React40.useMemo(() => weekdayNames(locale, firstDay), [locale, firstDay]);
|
|
3350
3440
|
const title = formatMonthYear(month, locale);
|
|
3351
3441
|
const end = selection2.to === "" ? selection2.from : selection2.to;
|
|
3352
3442
|
const stateOf = (iso) => ({
|
|
@@ -3385,7 +3475,7 @@ function MonthHeader({ focusedDay, bounds, testID, onMove }) {
|
|
|
3385
3475
|
const { labels, locale } = useDatePickerConfig();
|
|
3386
3476
|
const colors = usePickerColors();
|
|
3387
3477
|
const parts = parseIso(focusedDay) ?? FALLBACK2;
|
|
3388
|
-
const names =
|
|
3478
|
+
const names = React40.useMemo(() => monthNames(locale), [locale]);
|
|
3389
3479
|
const setMonthYear = (year, month) => onMove(toIso({ year, month, day: Math.min(parts.day, daysInMonth(year, month)) }));
|
|
3390
3480
|
const selectStyle = { minHeight: a11y.MIN_TOUCH_TARGET_PX, border: "none", background: "transparent", color: colors.text, fontWeight: BOLD3, fontSize: FONT2, fontFamily: "inherit", cursor: "pointer" };
|
|
3391
3481
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
@@ -3406,8 +3496,8 @@ function PickerFooter({ summary, children }) {
|
|
|
3406
3496
|
] });
|
|
3407
3497
|
}
|
|
3408
3498
|
function useEntered(key, reduced) {
|
|
3409
|
-
const [enteredKey, setEnteredKey] =
|
|
3410
|
-
|
|
3499
|
+
const [enteredKey, setEnteredKey] = React40.useState(null);
|
|
3500
|
+
React40.useEffect(() => {
|
|
3411
3501
|
if (reduced) return void 0;
|
|
3412
3502
|
let inner = 0;
|
|
3413
3503
|
const outer = requestAnimationFrame(() => {
|
|
@@ -3422,8 +3512,8 @@ function useEntered(key, reduced) {
|
|
|
3422
3512
|
}
|
|
3423
3513
|
function useMonthSlide(month) {
|
|
3424
3514
|
const reduced = useReducedMotion();
|
|
3425
|
-
const previous =
|
|
3426
|
-
const direction =
|
|
3515
|
+
const previous = React40.useRef(month);
|
|
3516
|
+
const direction = React40.useRef(0);
|
|
3427
3517
|
if (previous.current !== month) {
|
|
3428
3518
|
direction.current = month > previous.current ? 1 : -1;
|
|
3429
3519
|
previous.current = month;
|
|
@@ -3433,7 +3523,7 @@ function useMonthSlide(month) {
|
|
|
3433
3523
|
}
|
|
3434
3524
|
function SingleCalendar({ value, bounds, testID, onCommit }) {
|
|
3435
3525
|
const { labels, today } = useDatePickerConfig();
|
|
3436
|
-
const [draft, setDraft] =
|
|
3526
|
+
const [draft, setDraft] = React40.useState(value);
|
|
3437
3527
|
const grid = useGridFocus(clampToBounds(value !== "" ? value : today, bounds.min, bounds.max), bounds, testID, setDraft);
|
|
3438
3528
|
const month = monthStart(grid.focusedDay);
|
|
3439
3529
|
const motion = useMonthSlide(month);
|
|
@@ -3454,8 +3544,8 @@ function useIsPhone() {
|
|
|
3454
3544
|
return !isWideFormLayout(reactNative.useWindowDimensions().width);
|
|
3455
3545
|
}
|
|
3456
3546
|
function useReturnFocus(open, target) {
|
|
3457
|
-
const wasOpen =
|
|
3458
|
-
|
|
3547
|
+
const wasOpen = React40.useRef(open);
|
|
3548
|
+
React40.useEffect(() => {
|
|
3459
3549
|
const closed = wasOpen.current && !open;
|
|
3460
3550
|
wasOpen.current = open;
|
|
3461
3551
|
if (!closed) return void 0;
|
|
@@ -3465,9 +3555,9 @@ function useReturnFocus(open, target) {
|
|
|
3465
3555
|
}
|
|
3466
3556
|
function useTypedDate({ value, onChange, bounds, format, onError, rangeMessage, editOnType = false }) {
|
|
3467
3557
|
const { labels, locale } = useDatePickerConfig();
|
|
3468
|
-
const [editing, setEditing] =
|
|
3469
|
-
const [text, setText] =
|
|
3470
|
-
|
|
3558
|
+
const [editing, setEditing] = React40.useState(false);
|
|
3559
|
+
const [text, setText] = React40.useState("");
|
|
3560
|
+
React40.useEffect(() => {
|
|
3471
3561
|
setText((current) => {
|
|
3472
3562
|
const parsed = current.trim() === "" ? "" : parseTyped(current, locale);
|
|
3473
3563
|
if (parsed === null || parsed === value) return current;
|
|
@@ -3587,16 +3677,16 @@ function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
|
3587
3677
|
const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
|
|
3588
3678
|
const { labels, display } = useDatePickerConfig();
|
|
3589
3679
|
const phone = useIsPhone();
|
|
3590
|
-
const [open, setOpen] =
|
|
3591
|
-
const anchorRef =
|
|
3592
|
-
const inputRef =
|
|
3680
|
+
const [open, setOpen] = React40.useState(false);
|
|
3681
|
+
const anchorRef = React40.useRef(null);
|
|
3682
|
+
const inputRef = React40.useRef(null);
|
|
3593
3683
|
const bounds = { min, max };
|
|
3594
3684
|
const typed = useTypedDate({ value, onChange, bounds, format: displayFormatter(display), onError: onTypedError, editOnType: true });
|
|
3595
3685
|
const edit = typedEditBind(typed);
|
|
3596
3686
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3597
3687
|
const focus = focusBind;
|
|
3598
3688
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError, required });
|
|
3599
|
-
const close =
|
|
3689
|
+
const close = React40.useCallback(() => setOpen(false), []);
|
|
3600
3690
|
useReturnFocus(open, inputRef);
|
|
3601
3691
|
const commit = (iso) => {
|
|
3602
3692
|
onTypedError?.(void 0);
|
|
@@ -3672,7 +3762,7 @@ function TemporalInput({ fieldProps, context, webInputType, onTypedError }) {
|
|
|
3672
3762
|
}
|
|
3673
3763
|
function TemporalField({ fieldProps, webInputType }) {
|
|
3674
3764
|
const { label, required, hint, error } = fieldProps;
|
|
3675
|
-
const [typedError, setTypedError] =
|
|
3765
|
+
const [typedError, setTypedError] = React40.useState(void 0);
|
|
3676
3766
|
return /* @__PURE__ */ jsxRuntime.jsx(Field, { error: error ?? typedError, hint, label, required, children: (context) => /* @__PURE__ */ jsxRuntime.jsx(TemporalInput, { context, fieldProps, webInputType, onTypedError: setTypedError }) });
|
|
3677
3767
|
}
|
|
3678
3768
|
function DateField(props) {
|
|
@@ -3801,17 +3891,17 @@ function useRangeSummary(draft) {
|
|
|
3801
3891
|
}
|
|
3802
3892
|
function RangeCalendar({ value, bounds, phone, testID, onApply, onCancel }) {
|
|
3803
3893
|
const { labels, today } = useDatePickerConfig();
|
|
3804
|
-
const [draft, setDraft] =
|
|
3894
|
+
const [draft, setDraft] = React40.useState(value);
|
|
3805
3895
|
const initialDay = clampToBounds(value.from !== "" ? value.from : today, bounds.min, bounds.max);
|
|
3806
|
-
const pickDraft =
|
|
3896
|
+
const pickDraft = React40.useCallback((iso) => setDraft((current) => pickRangeDay(current, iso)), []);
|
|
3807
3897
|
const focus = useGridFocus(initialDay, bounds, testID, pickDraft);
|
|
3808
3898
|
const visible = phone ? PHONE_MONTHS : DESKTOP_MONTHS;
|
|
3809
|
-
const [first, setFirst] =
|
|
3899
|
+
const [first, setFirst] = React40.useState(() => monthStart(phone ? initialDay : addMonths(initialDay, 1 - DESKTOP_MONTHS)));
|
|
3810
3900
|
const focusMonth = monthStart(focus.focusedDay);
|
|
3811
3901
|
const last = addMonths(first, visible - 1);
|
|
3812
3902
|
const motion = useMonthSlide(first);
|
|
3813
3903
|
const summary = useRangeSummary(draft);
|
|
3814
|
-
|
|
3904
|
+
React40.useEffect(() => {
|
|
3815
3905
|
if (focusMonth < first) setFirst(focusMonth);
|
|
3816
3906
|
else if (focusMonth > last) setFirst(addMonths(focusMonth, 1 - visible));
|
|
3817
3907
|
}, [focusMonth, first, last, visible]);
|
|
@@ -3860,18 +3950,18 @@ function orNone(value) {
|
|
|
3860
3950
|
function WebDateRange({ value, onChange, onSubmit, fromLabel, toLabel, hint, testID, context, onTypedError }) {
|
|
3861
3951
|
const { labels } = useDatePickerConfig();
|
|
3862
3952
|
const phone = useIsPhone();
|
|
3863
|
-
const [open, setOpen] =
|
|
3864
|
-
const [fromError, setFromError] =
|
|
3865
|
-
const [toError, setToError] =
|
|
3866
|
-
const anchorRef =
|
|
3867
|
-
const fromRef =
|
|
3953
|
+
const [open, setOpen] = React40.useState(false);
|
|
3954
|
+
const [fromError, setFromError] = React40.useState(void 0);
|
|
3955
|
+
const [toError, setToError] = React40.useState(void 0);
|
|
3956
|
+
const anchorRef = React40.useRef(null);
|
|
3957
|
+
const fromRef = React40.useRef(null);
|
|
3868
3958
|
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, editOnType: true });
|
|
3869
3959
|
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, editOnType: true });
|
|
3870
3960
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: true });
|
|
3871
3961
|
const focus = focusBind;
|
|
3872
3962
|
const webA11y = webFieldA11y({ describedById: context.describedById, hasError: context.hasError });
|
|
3873
|
-
|
|
3874
|
-
const close =
|
|
3963
|
+
React40.useEffect(() => onTypedError(fromError ?? toError), [fromError, toError, onTypedError]);
|
|
3964
|
+
const close = React40.useCallback(() => setOpen(false), []);
|
|
3875
3965
|
useReturnFocus(open, fromRef);
|
|
3876
3966
|
const onKeyDown = (event) => {
|
|
3877
3967
|
if (event.key === "ArrowDown" && event.altKey) {
|
|
@@ -3955,7 +4045,7 @@ function DateRangeControl({
|
|
|
3955
4045
|
}) {
|
|
3956
4046
|
const hint = accessibilityHint ?? `${fromLabel} \u2013 ${toLabel}`;
|
|
3957
4047
|
const { labels } = useDatePickerConfig();
|
|
3958
|
-
const [typedError, setTypedError] =
|
|
4048
|
+
const [typedError, setTypedError] = React40.useState(void 0);
|
|
3959
4049
|
if (!IS_WEB9) {
|
|
3960
4050
|
return /* @__PURE__ */ jsxRuntime.jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsxRuntime.jsx(NativeDateRange, { fromLabel, hint, style, testID, toLabel, value, onChange, onSubmit }) });
|
|
3961
4051
|
}
|
|
@@ -4123,9 +4213,9 @@ function FormStatusLine({ message, testID, style }) {
|
|
|
4123
4213
|
return /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { role: "alert", style: [styles24.line, { color: theme.colors.text }, style], testID, children: message });
|
|
4124
4214
|
}
|
|
4125
4215
|
function useFocusFirstInvalid(refs) {
|
|
4126
|
-
const latest =
|
|
4216
|
+
const latest = React40.useRef(refs);
|
|
4127
4217
|
latest.current = refs;
|
|
4128
|
-
return
|
|
4218
|
+
return React40.useCallback((invalid) => {
|
|
4129
4219
|
const first = invalid.map((field2) => latest.current[field2].current).find((node) => node !== null);
|
|
4130
4220
|
first?.focus();
|
|
4131
4221
|
}, []);
|
|
@@ -4176,10 +4266,10 @@ function withoutField(state, field2) {
|
|
|
4176
4266
|
}
|
|
4177
4267
|
function useServerFieldErrors(options) {
|
|
4178
4268
|
const { fields, refs, formatCode } = options;
|
|
4179
|
-
const [state, setState] =
|
|
4269
|
+
const [state, setState] = React40.useState(EMPTY_STATE);
|
|
4180
4270
|
const focusFirst = useFocusFirstInvalid(refs ?? NO_REFS);
|
|
4181
4271
|
const hasRefs = refs !== void 0;
|
|
4182
|
-
const apply =
|
|
4272
|
+
const apply = React40.useCallback(
|
|
4183
4273
|
(error) => {
|
|
4184
4274
|
const assigned = assignServerErrors(apiClientBase.parseFieldErrors(error), fields, formatCode);
|
|
4185
4275
|
setState({ byField: assigned.byField, formError: assigned.formError });
|
|
@@ -4190,17 +4280,17 @@ function useServerFieldErrors(options) {
|
|
|
4190
4280
|
},
|
|
4191
4281
|
[fields, formatCode, focusFirst, hasRefs]
|
|
4192
4282
|
);
|
|
4193
|
-
const clear =
|
|
4194
|
-
const reset =
|
|
4195
|
-
const errorFor =
|
|
4283
|
+
const clear = React40.useCallback((field2) => setState((current) => withoutField(current, field2)), []);
|
|
4284
|
+
const reset = React40.useCallback(() => setState(EMPTY_STATE), []);
|
|
4285
|
+
const errorFor = React40.useCallback((field2) => state.byField[field2], [state.byField]);
|
|
4196
4286
|
return { errorFor, apply, clear, formError: state.formError, reset };
|
|
4197
4287
|
}
|
|
4198
4288
|
function isScrollable(node) {
|
|
4199
4289
|
return "scrollIntoView" in Object(node);
|
|
4200
4290
|
}
|
|
4201
4291
|
function useKeepInView(trigger) {
|
|
4202
|
-
const ref =
|
|
4203
|
-
|
|
4292
|
+
const ref = React40.useRef(null);
|
|
4293
|
+
React40.useEffect(() => {
|
|
4204
4294
|
const node = ref.current;
|
|
4205
4295
|
const hasTrigger = trigger !== void 0 && trigger !== null;
|
|
4206
4296
|
if (hasTrigger && isScrollable(node)) node.scrollIntoView({ block: "nearest" });
|
|
@@ -4290,7 +4380,7 @@ var UploadWithLinkField = ({
|
|
|
4290
4380
|
const { theme } = uiFeedback.useUi();
|
|
4291
4381
|
const ring = uiButtons.useFocusRing();
|
|
4292
4382
|
const url = value ?? "";
|
|
4293
|
-
const [pasting, setPasting] =
|
|
4383
|
+
const [pasting, setPasting] = React40.useState(url !== "");
|
|
4294
4384
|
const previewBox = { borderRadius: PREVIEW_RADIUS, height: previewSize, width: previewSize };
|
|
4295
4385
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles26.root, children: [
|
|
4296
4386
|
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles26.title, { color: theme.colors.text }], children: labels.title }),
|
|
@@ -4348,7 +4438,7 @@ var AddOnRequest = ({
|
|
|
4348
4438
|
disabled = false,
|
|
4349
4439
|
style
|
|
4350
4440
|
}) => {
|
|
4351
|
-
const [requested, setRequested] =
|
|
4441
|
+
const [requested, setRequested] = React40.useState(false);
|
|
4352
4442
|
const remove = () => {
|
|
4353
4443
|
setRequested(false);
|
|
4354
4444
|
onRemove();
|
|
@@ -4408,13 +4498,6 @@ var FixBar = ({ count, message, showLabel, showHint, onShow, testID, style }) =>
|
|
|
4408
4498
|
)
|
|
4409
4499
|
] });
|
|
4410
4500
|
};
|
|
4411
|
-
|
|
4412
|
-
// src/SearchSelect/SelectSurface.ts
|
|
4413
|
-
var SelectSurface = /* @__PURE__ */ ((SelectSurface2) => {
|
|
4414
|
-
SelectSurface2["Sheet"] = "sheet";
|
|
4415
|
-
SelectSurface2["Dropdown"] = "dropdown";
|
|
4416
|
-
return SelectSurface2;
|
|
4417
|
-
})(SelectSurface || {});
|
|
4418
4501
|
var ROW_PAD_H = 12;
|
|
4419
4502
|
var ROW_GAP4 = 8;
|
|
4420
4503
|
var OPTION_FONT2 = 14;
|
|
@@ -4474,23 +4557,23 @@ var SHEET_MAX_HEIGHT2 = 480;
|
|
|
4474
4557
|
function SearchSelectPanel({ motion, state, labels, anchorRef, renderLeading, renderDetail, selectedValue, testID }) {
|
|
4475
4558
|
const { theme } = uiFeedback.useUi();
|
|
4476
4559
|
const { colors } = theme;
|
|
4477
|
-
const progress =
|
|
4560
|
+
const progress = React40.useRef(new reactNative.Animated.Value(0)).current;
|
|
4478
4561
|
const { durationMs } = motion;
|
|
4479
|
-
|
|
4562
|
+
React40.useEffect(() => {
|
|
4480
4563
|
reactNative.Animated.timing(progress, { toValue: 1, duration: durationMs, useNativeDriver: false }).start();
|
|
4481
4564
|
}, [progress, durationMs]);
|
|
4482
|
-
const leaving =
|
|
4483
|
-
const leave =
|
|
4565
|
+
const leaving = React40.useRef(false);
|
|
4566
|
+
const leave = React40.useCallback((after) => {
|
|
4484
4567
|
if (leaving.current) return;
|
|
4485
4568
|
leaving.current = true;
|
|
4486
4569
|
if (durationMs === 0) return after();
|
|
4487
4570
|
reactNative.Animated.timing(progress, { toValue: 0, duration: durationMs, useNativeDriver: false }).start(() => after());
|
|
4488
4571
|
}, [progress, durationMs]);
|
|
4489
4572
|
const { close, pick: pickNow, submit: submitNow, onKey, sections, highlight } = state;
|
|
4490
|
-
const dismiss =
|
|
4491
|
-
const pick =
|
|
4492
|
-
const submit =
|
|
4493
|
-
const onKeyPress =
|
|
4573
|
+
const dismiss = React40.useCallback(() => leave(close), [leave, close]);
|
|
4574
|
+
const pick = React40.useCallback((option) => leave(() => pickNow(option)), [leave, pickNow]);
|
|
4575
|
+
const submit = React40.useCallback(() => submitNow(pick), [submitNow, pick]);
|
|
4576
|
+
const onKeyPress = React40.useCallback((key) => key === KEY_ESCAPE ? dismiss() : onKey(key), [dismiss, onKey]);
|
|
4494
4577
|
const translateY = progress.interpolate({ inputRange: [0, 1], outputRange: [motion.fromY, 0] });
|
|
4495
4578
|
const isSheet = motion.surface === "sheet" /* Sheet */;
|
|
4496
4579
|
const shared = { selectedValue, renderLeading, renderDetail, onPick: pick, optionHint: labels.optionHint, testID, highlight };
|
|
@@ -4527,8 +4610,8 @@ var styles31 = reactNative.StyleSheet.create({
|
|
|
4527
4610
|
empty: { padding: PANEL_PAD }
|
|
4528
4611
|
});
|
|
4529
4612
|
function useRefocusOnClose(open, ref) {
|
|
4530
|
-
const wasOpen =
|
|
4531
|
-
|
|
4613
|
+
const wasOpen = React40.useRef(false);
|
|
4614
|
+
React40.useEffect(() => {
|
|
4532
4615
|
if (wasOpen.current && !open) ref.current?.focus();
|
|
4533
4616
|
wasOpen.current = open;
|
|
4534
4617
|
}, [open, ref]);
|
|
@@ -4561,53 +4644,40 @@ var KEY_DOWN = "ArrowDown";
|
|
|
4561
4644
|
var KEY_UP = "ArrowUp";
|
|
4562
4645
|
var KEY_ESCAPE2 = "Escape";
|
|
4563
4646
|
function useSearchSelectState(options, recents, onChange, onClosed) {
|
|
4564
|
-
const [open, setOpen] =
|
|
4565
|
-
const [query, setQueryState] =
|
|
4566
|
-
const [rawHighlight, setHighlight] =
|
|
4567
|
-
const sections =
|
|
4647
|
+
const [open, setOpen] = React40.useState(false);
|
|
4648
|
+
const [query, setQueryState] = React40.useState("");
|
|
4649
|
+
const [rawHighlight, setHighlight] = React40.useState(-1);
|
|
4650
|
+
const sections = React40.useMemo(() => buildSearchSelectSections(options, query, recents.recents), [options, query, recents.recents]);
|
|
4568
4651
|
const highlight = rawHighlight < sections.flat.length ? rawHighlight : -1;
|
|
4569
4652
|
const active = sections.flat[highlight];
|
|
4570
4653
|
const { remember } = recents;
|
|
4571
|
-
const close =
|
|
4654
|
+
const close = React40.useCallback(() => {
|
|
4572
4655
|
setOpen(false);
|
|
4573
4656
|
setQueryState("");
|
|
4574
4657
|
setHighlight(-1);
|
|
4575
4658
|
onClosed();
|
|
4576
4659
|
}, [onClosed]);
|
|
4577
|
-
const pick =
|
|
4660
|
+
const pick = React40.useCallback((option) => {
|
|
4578
4661
|
remember(option.value);
|
|
4579
4662
|
onChange(option.value);
|
|
4580
4663
|
close();
|
|
4581
4664
|
}, [remember, onChange, close]);
|
|
4582
|
-
const submit =
|
|
4665
|
+
const submit = React40.useCallback((via = pick) => {
|
|
4583
4666
|
if (active !== void 0) via(active);
|
|
4584
4667
|
}, [active, pick]);
|
|
4585
|
-
const setQuery =
|
|
4668
|
+
const setQuery = React40.useCallback((next) => {
|
|
4586
4669
|
setQueryState(next);
|
|
4587
4670
|
setHighlight(highlightAfterQuery(next));
|
|
4588
4671
|
}, []);
|
|
4589
|
-
const onKey =
|
|
4672
|
+
const onKey = React40.useCallback((key) => {
|
|
4590
4673
|
const count = sections.flat.length;
|
|
4591
4674
|
if (key === KEY_DOWN) setHighlight(moveHighlight(highlight, count, 1));
|
|
4592
4675
|
if (key === KEY_UP) setHighlight(moveHighlight(highlight, count, -1));
|
|
4593
4676
|
if (key === KEY_ESCAPE2) close();
|
|
4594
4677
|
}, [sections.flat.length, highlight, close]);
|
|
4595
|
-
const openList =
|
|
4678
|
+
const openList = React40.useCallback(() => setOpen(true), []);
|
|
4596
4679
|
return { open, query, highlight, active, sections, openList, close, setQuery, pick, submit, onKey };
|
|
4597
4680
|
}
|
|
4598
|
-
|
|
4599
|
-
// src/SearchSelect/utils/searchSelectMotion.ts
|
|
4600
|
-
var PHONE_MAX_WIDTH = 600;
|
|
4601
|
-
var SHEET_TRAVEL_PX = 320;
|
|
4602
|
-
var DROPDOWN_TRAVEL_PX = -8;
|
|
4603
|
-
var SHEET_MS = 240;
|
|
4604
|
-
var DROPDOWN_MS = 160;
|
|
4605
|
-
function resolveSelectMotion(width, reducedMotion) {
|
|
4606
|
-
const isPhone = width < PHONE_MAX_WIDTH;
|
|
4607
|
-
const surface = isPhone ? "sheet" /* Sheet */ : "dropdown" /* Dropdown */;
|
|
4608
|
-
if (reducedMotion) return { surface, fromY: 0, durationMs: 0 };
|
|
4609
|
-
return isPhone ? { surface, fromY: SHEET_TRAVEL_PX, durationMs: SHEET_MS } : { surface, fromY: DROPDOWN_TRAVEL_PX, durationMs: DROPDOWN_MS };
|
|
4610
|
-
}
|
|
4611
4681
|
var CHEVRON = "\u25BE";
|
|
4612
4682
|
var VALUE_GAP = 8;
|
|
4613
4683
|
var MIN_TOUCH = 44;
|
|
@@ -4616,8 +4686,8 @@ function SearchSelect(props) {
|
|
|
4616
4686
|
const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail, renderTrigger, onBlur } = props;
|
|
4617
4687
|
const { theme } = uiFeedback.useUi();
|
|
4618
4688
|
const { colors } = theme;
|
|
4619
|
-
const triggerRef =
|
|
4620
|
-
const anchorRef =
|
|
4689
|
+
const triggerRef = React40.useRef(null);
|
|
4690
|
+
const anchorRef = React40.useRef(null);
|
|
4621
4691
|
const { width } = reactNative.useWindowDimensions();
|
|
4622
4692
|
const motion = resolveSelectMotion(width, useReducedMotion());
|
|
4623
4693
|
const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
|
|
@@ -4625,9 +4695,9 @@ function SearchSelect(props) {
|
|
|
4625
4695
|
useRefocusOnClose(state.open, triggerRef);
|
|
4626
4696
|
const selected = findOption(options, value);
|
|
4627
4697
|
const onPress = state.open ? state.close : state.openList;
|
|
4628
|
-
const openRef =
|
|
4698
|
+
const openRef = React40.useRef(state.open);
|
|
4629
4699
|
openRef.current = state.open;
|
|
4630
|
-
const onTriggerBlur =
|
|
4700
|
+
const onTriggerBlur = React40.useCallback(() => {
|
|
4631
4701
|
if (!openRef.current) onBlur?.();
|
|
4632
4702
|
}, [onBlur]);
|
|
4633
4703
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: styles32.anchor, children: [
|
|
@@ -4677,7 +4747,7 @@ function isOutside(container, target) {
|
|
|
4677
4747
|
return !(target instanceof Node && container.contains(target));
|
|
4678
4748
|
}
|
|
4679
4749
|
function useOutsidePress(ref, onOutside) {
|
|
4680
|
-
|
|
4750
|
+
React40.useEffect(() => {
|
|
4681
4751
|
if (reactNative.Platform.OS !== "web" || typeof document === "undefined") return void 0;
|
|
4682
4752
|
const onPointerDown = (event) => {
|
|
4683
4753
|
if (isOutside(ref.current, event.target)) onOutside();
|
|
@@ -4688,7 +4758,7 @@ function useOutsidePress(ref, onOutside) {
|
|
|
4688
4758
|
}
|
|
4689
4759
|
var AFTER_SURFACE_UNMOUNT_MS = 0;
|
|
4690
4760
|
function useDeferredFocus(ref) {
|
|
4691
|
-
return
|
|
4761
|
+
return React40.useCallback(() => {
|
|
4692
4762
|
setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
|
|
4693
4763
|
}, [ref]);
|
|
4694
4764
|
}
|
|
@@ -5440,8 +5510,8 @@ var renderFlag = (option) => option.value === NO_COUNTRY2 ? null : /* @__PURE__
|
|
|
5440
5510
|
function CountryField({ value, onChange, accessibilityLabel, accessibilityHint, labels, testID, countries, noneLabel, onBlur }) {
|
|
5441
5511
|
const { theme } = uiFeedback.useUi();
|
|
5442
5512
|
const { textSecondary } = theme.colors;
|
|
5443
|
-
const options =
|
|
5444
|
-
const renderCode =
|
|
5513
|
+
const options = React40.useMemo(() => countryFieldOptions(countries, noneLabel), [countries, noneLabel]);
|
|
5514
|
+
const renderCode = React40.useCallback((option) => /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles33.code, { color: textSecondary }], children: option.detail }), [textSecondary]);
|
|
5445
5515
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5446
5516
|
SearchSelect,
|
|
5447
5517
|
{
|
|
@@ -5463,9 +5533,9 @@ var styles33 = reactNative.StyleSheet.create({
|
|
|
5463
5533
|
code: { fontSize: CODE_FONT }
|
|
5464
5534
|
});
|
|
5465
5535
|
function useBlurVerdict(validate) {
|
|
5466
|
-
const [verdict, setVerdict] =
|
|
5467
|
-
const onEdit =
|
|
5468
|
-
const onLeave =
|
|
5536
|
+
const [verdict, setVerdict] = React40.useState(null);
|
|
5537
|
+
const onEdit = React40.useCallback(() => setVerdict(null), []);
|
|
5538
|
+
const onLeave = React40.useCallback(() => {
|
|
5469
5539
|
const next = validate();
|
|
5470
5540
|
setVerdict(next);
|
|
5471
5541
|
return next;
|
|
@@ -5619,11 +5689,11 @@ function rawCaretAfterChange(previous, previousCaret, next) {
|
|
|
5619
5689
|
|
|
5620
5690
|
// src/IbanInput/hooks/useIbanCaret.ts
|
|
5621
5691
|
function useIbanCaret(display) {
|
|
5622
|
-
const [selection2, setSelection] =
|
|
5623
|
-
const onSelectionChange =
|
|
5692
|
+
const [selection2, setSelection] = React40.useState({ start: display.length, end: display.length });
|
|
5693
|
+
const onSelectionChange = React40.useCallback((event) => {
|
|
5624
5694
|
setSelection(event.nativeEvent.selection);
|
|
5625
5695
|
}, []);
|
|
5626
|
-
const placeAfterEdit =
|
|
5696
|
+
const placeAfterEdit = React40.useCallback((text) => {
|
|
5627
5697
|
const caret = caretAfterEdit(text, rawCaretAfterChange(display, selection2.end, text));
|
|
5628
5698
|
setSelection({ start: caret, end: caret });
|
|
5629
5699
|
}, [display, selection2.end]);
|
|
@@ -5729,19 +5799,19 @@ function rejectionMessage(rejection, none, labels) {
|
|
|
5729
5799
|
function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
|
|
5730
5800
|
const { theme } = uiFeedback.useUi();
|
|
5731
5801
|
const { colors } = theme;
|
|
5732
|
-
const draft =
|
|
5733
|
-
const validate =
|
|
5802
|
+
const draft = React40.useMemo(() => draftIban(value), [value]);
|
|
5803
|
+
const validate = React40.useCallback(() => validateIban(value), [value]);
|
|
5734
5804
|
const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
|
|
5735
5805
|
const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
|
|
5736
5806
|
const counter = ibanCounter(draft);
|
|
5737
5807
|
const { selection: selection2, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
|
|
5738
|
-
const onChangeText =
|
|
5808
|
+
const onChangeText = React40.useCallback((text) => {
|
|
5739
5809
|
onEdit();
|
|
5740
5810
|
onVerdict?.(null);
|
|
5741
5811
|
placeAfterEdit(text);
|
|
5742
5812
|
onChange(draftIban(text).electronic);
|
|
5743
5813
|
}, [onEdit, onVerdict, placeAfterEdit, onChange]);
|
|
5744
|
-
const onBlur =
|
|
5814
|
+
const onBlur = React40.useCallback(() => {
|
|
5745
5815
|
const verdict2 = onLeave();
|
|
5746
5816
|
onVerdict?.(value === "" ? null : verdict2);
|
|
5747
5817
|
onLeft?.();
|
|
@@ -5816,16 +5886,16 @@ function validateBic(raw) {
|
|
|
5816
5886
|
function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
|
|
5817
5887
|
const { theme } = uiFeedback.useUi();
|
|
5818
5888
|
const { colors } = theme;
|
|
5819
|
-
const draft =
|
|
5820
|
-
const validate =
|
|
5889
|
+
const draft = React40.useMemo(() => draftBic(value), [value]);
|
|
5890
|
+
const validate = React40.useCallback(() => validateBic(value), [value]);
|
|
5821
5891
|
const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
|
|
5822
5892
|
const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
|
|
5823
|
-
const onChangeText =
|
|
5893
|
+
const onChangeText = React40.useCallback((text) => {
|
|
5824
5894
|
onEdit();
|
|
5825
5895
|
onVerdict?.(null);
|
|
5826
5896
|
onChange(draftBic(text).value);
|
|
5827
5897
|
}, [onEdit, onVerdict, onChange]);
|
|
5828
|
-
const onBlur =
|
|
5898
|
+
const onBlur = React40.useCallback(() => {
|
|
5829
5899
|
const verdict2 = onLeave();
|
|
5830
5900
|
onVerdict?.(value === "" ? null : verdict2);
|
|
5831
5901
|
onLeft?.();
|
|
@@ -5981,7 +6051,7 @@ var styles38 = reactNative.StyleSheet.create({
|
|
|
5981
6051
|
function RadioList(props) {
|
|
5982
6052
|
const { options, value, onChange, optionTestIDPrefix, label, error, required = false, disabled = false, testID } = props;
|
|
5983
6053
|
const { theme } = uiFeedback.useUi();
|
|
5984
|
-
const colors =
|
|
6054
|
+
const colors = React40__default.default.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
|
|
5985
6055
|
const selectedIndex = options.findIndex((option) => option.value === value);
|
|
5986
6056
|
const radio = useRadioKeyboard({ enabled: true, disabled, values: options.map((option) => option.value), selectedIndex, onChange });
|
|
5987
6057
|
return /* @__PURE__ */ jsxRuntime.jsx(Field, { error, label, required, testID, children: ({ describedById, hasError }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -6136,12 +6206,12 @@ var SubmitError = ({ message, testID }) => {
|
|
|
6136
6206
|
};
|
|
6137
6207
|
var toggle = (list, id) => list.includes(id) ? list.filter((item) => item !== id) : [...list, id];
|
|
6138
6208
|
function useDecisionPanel(outcomes, onSubmit) {
|
|
6139
|
-
const [outcome, setOutcome] =
|
|
6140
|
-
const [note, setNote] =
|
|
6141
|
-
const [reasons, setReasons] =
|
|
6142
|
-
const [checked, setChecked] =
|
|
6143
|
-
const [error, setError] =
|
|
6144
|
-
const [pending, setPending] =
|
|
6209
|
+
const [outcome, setOutcome] = React40__default.default.useState("");
|
|
6210
|
+
const [note, setNote] = React40__default.default.useState("");
|
|
6211
|
+
const [reasons, setReasons] = React40__default.default.useState([]);
|
|
6212
|
+
const [checked, setChecked] = React40__default.default.useState([]);
|
|
6213
|
+
const [error, setError] = React40__default.default.useState(null);
|
|
6214
|
+
const [pending, setPending] = React40__default.default.useState(null);
|
|
6145
6215
|
const submit = async (override) => {
|
|
6146
6216
|
const target = override ?? outcome;
|
|
6147
6217
|
const problem = validateDecision(outcomes, target, note);
|
|
@@ -6229,10 +6299,10 @@ var styles42 = reactNative.StyleSheet.create({
|
|
|
6229
6299
|
});
|
|
6230
6300
|
function RuleMark({ tone, colors }) {
|
|
6231
6301
|
const reduced = useReducedMotion();
|
|
6232
|
-
const scale =
|
|
6233
|
-
const wasMet =
|
|
6302
|
+
const scale = React40.useRef(new reactNative.Animated.Value(1)).current;
|
|
6303
|
+
const wasMet = React40.useRef(tone === "met" /* Met */);
|
|
6234
6304
|
const met = tone === "met" /* Met */;
|
|
6235
|
-
|
|
6305
|
+
React40.useEffect(() => {
|
|
6236
6306
|
const turnedMet = met && !wasMet.current;
|
|
6237
6307
|
wasMet.current = met;
|
|
6238
6308
|
if (!turnedMet || reduced) return;
|
|
@@ -6347,9 +6417,9 @@ function ruleAnnouncement(changed, labels) {
|
|
|
6347
6417
|
|
|
6348
6418
|
// src/PasswordField/usePasswordRuleAnnouncement.ts
|
|
6349
6419
|
function usePasswordRuleAnnouncement(rules, labels) {
|
|
6350
|
-
const previous =
|
|
6351
|
-
const [message, setMessage] =
|
|
6352
|
-
|
|
6420
|
+
const previous = React40.useRef(rules);
|
|
6421
|
+
const [message, setMessage] = React40.useState("");
|
|
6422
|
+
React40.useEffect(() => {
|
|
6353
6423
|
const changed = changedRules(previous.current, rules);
|
|
6354
6424
|
previous.current = rules;
|
|
6355
6425
|
if (changed.length > 0) setMessage(ruleAnnouncement(changed, labels));
|
|
@@ -6366,7 +6436,7 @@ function ruleColorsFrom(palette) {
|
|
|
6366
6436
|
}
|
|
6367
6437
|
function useRuleColors(override) {
|
|
6368
6438
|
const { theme } = uiFeedback.useUi();
|
|
6369
|
-
return
|
|
6439
|
+
return React40.useMemo(() => {
|
|
6370
6440
|
if (override !== void 0) return ruleColorsFrom(override);
|
|
6371
6441
|
return ruleColorsFrom({
|
|
6372
6442
|
success: theme.semantic.success?.["500"] ?? theme.colors.text,
|
|
@@ -6393,16 +6463,16 @@ function joinIds(...ids) {
|
|
|
6393
6463
|
return joined === "" ? void 0 : joined;
|
|
6394
6464
|
}
|
|
6395
6465
|
function useCaretKeepingToggle(inputRef, initialLength) {
|
|
6396
|
-
const [revealed, setRevealed] =
|
|
6397
|
-
const selection2 =
|
|
6398
|
-
const hadFocus =
|
|
6399
|
-
const onSelectionChange =
|
|
6466
|
+
const [revealed, setRevealed] = React40.useState(false);
|
|
6467
|
+
const selection2 = React40.useRef({ start: initialLength, end: initialLength });
|
|
6468
|
+
const hadFocus = React40.useRef(false);
|
|
6469
|
+
const onSelectionChange = React40.useCallback((event) => {
|
|
6400
6470
|
selection2.current = event.nativeEvent.selection;
|
|
6401
6471
|
}, []);
|
|
6402
|
-
const onPressIn =
|
|
6472
|
+
const onPressIn = React40.useCallback(() => {
|
|
6403
6473
|
hadFocus.current = inputRef.current?.isFocused?.() ?? false;
|
|
6404
6474
|
}, [inputRef]);
|
|
6405
|
-
const onToggle =
|
|
6475
|
+
const onToggle = React40.useCallback(() => {
|
|
6406
6476
|
setRevealed((current) => !current);
|
|
6407
6477
|
if (!hadFocus.current) return;
|
|
6408
6478
|
const node = inputRef.current;
|
|
@@ -6414,9 +6484,9 @@ function useCaretKeepingToggle(inputRef, initialLength) {
|
|
|
6414
6484
|
}, [inputRef]);
|
|
6415
6485
|
return { revealed, onPressIn, onToggle, onSelectionChange };
|
|
6416
6486
|
}
|
|
6417
|
-
var PasswordField =
|
|
6418
|
-
const inputRef =
|
|
6419
|
-
|
|
6487
|
+
var PasswordField = React40__default.default.forwardRef(function PasswordField2({ label, value, onChangeText, labels, testID, rules = NO_RULES, rulesDisplay = "meterGrid" /* MeterGrid */, flagUnmet = false, error, colors: colorOverride, inputProps }, ref) {
|
|
6488
|
+
const inputRef = React40.useRef(null);
|
|
6489
|
+
React40.useImperativeHandle(ref, () => inputRef.current);
|
|
6420
6490
|
const toggle2 = useCaretKeepingToggle(inputRef, value.length);
|
|
6421
6491
|
const colors = useRuleColors(colorOverride);
|
|
6422
6492
|
const announcement = usePasswordRuleAnnouncement(rules, labels);
|
|
@@ -6514,6 +6584,7 @@ exports.SEGMENT_BESIDE_TEXT_INPUT = SEGMENT_BESIDE_TEXT_INPUT;
|
|
|
6514
6584
|
exports.SearchSelect = SearchSelect;
|
|
6515
6585
|
exports.SelectControl = SelectControl;
|
|
6516
6586
|
exports.SelectField = SelectField;
|
|
6587
|
+
exports.SelectLookProvider = SelectLookProvider;
|
|
6517
6588
|
exports.SelectSurface = SelectSurface;
|
|
6518
6589
|
exports.StepperNav = StepperNav;
|
|
6519
6590
|
exports.StepperTabs = StepperTabs;
|
|
@@ -6565,6 +6636,7 @@ exports.rowsForText = rowsForText;
|
|
|
6565
6636
|
exports.ruleAnnouncement = ruleAnnouncement;
|
|
6566
6637
|
exports.ruleColorsFrom = ruleColorsFrom;
|
|
6567
6638
|
exports.ruleTone = ruleTone;
|
|
6639
|
+
exports.selectLookMetrics = selectLookMetrics;
|
|
6568
6640
|
exports.suggestOptions = suggestOptions;
|
|
6569
6641
|
exports.toCountryValue = toCountryValue;
|
|
6570
6642
|
exports.toggleGroupSelection = toggleGroupSelection;
|