@dloizides/ui-forms 1.33.0 → 1.34.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.mjs CHANGED
@@ -2561,30 +2561,47 @@ var SelectSurface = /* @__PURE__ */ ((SelectSurface2) => {
2561
2561
  SelectSurface2["Dropdown"] = "dropdown";
2562
2562
  return SelectSurface2;
2563
2563
  })(SelectSurface || {});
2564
- function isContainer(node) {
2565
- return "contains" in Object(node);
2566
- }
2567
- function isOutside(container, target) {
2568
- if (!isContainer(container)) return false;
2569
- return !(target instanceof Node && container.contains(target));
2570
- }
2571
- function useOutsidePress(ref, onOutside) {
2564
+ function useAnchorRect2(anchorRef) {
2565
+ const [rect2, setRect] = useState(null);
2572
2566
  useEffect(() => {
2573
- if (Platform.OS !== "web" || typeof document === "undefined") return void 0;
2574
- const onPointerDown = (event) => {
2575
- if (isOutside(ref.current, event.target)) onOutside();
2576
- };
2577
- document.addEventListener("pointerdown", onPointerDown, true);
2578
- return () => document.removeEventListener("pointerdown", onPointerDown, true);
2579
- }, [ref, onOutside]);
2567
+ anchorRef.current?.measureInWindow((x, y, width, height) => setRect({ x, y, width, height }));
2568
+ }, [anchorRef]);
2569
+ return rect2;
2580
2570
  }
2581
- var PANEL_Z = 10;
2582
- function DropdownSurface({ progress, translateY, anchorRef, onDismiss, children }) {
2583
- useOutsidePress(anchorRef, onDismiss);
2584
- return /* @__PURE__ */ jsx(Animated.View, { style: [styles18.dropdown, { opacity: progress, transform: [{ translateY }] }], children });
2571
+
2572
+ // src/SearchSelect/DropdownPlacement.ts
2573
+ var DropdownPlacement = /* @__PURE__ */ ((DropdownPlacement2) => {
2574
+ DropdownPlacement2["Below"] = "below";
2575
+ DropdownPlacement2["Above"] = "above";
2576
+ return DropdownPlacement2;
2577
+ })(DropdownPlacement || {});
2578
+
2579
+ // src/SearchSelect/utils/dropdownFrame.ts
2580
+ function placeDropdown(anchor, panelHeight, viewportHeight) {
2581
+ const roomBelow = viewportHeight - (anchor.y + anchor.height);
2582
+ if (roomBelow >= panelHeight) return "below" /* Below */;
2583
+ return anchor.y > roomBelow ? "above" /* Above */ : "below" /* Below */;
2584
+ }
2585
+ function dropdownFrame(anchor, panelHeight, viewportHeight) {
2586
+ const placement = placeDropdown(anchor, panelHeight, viewportHeight);
2587
+ const base = { placement, left: anchor.x, width: anchor.width };
2588
+ if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - anchor.y };
2589
+ return { ...base, top: anchor.y + anchor.height };
2590
+ }
2591
+ function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children }) {
2592
+ const { height: viewportHeight } = useWindowDimensions();
2593
+ const anchor = useAnchorRect2(anchorRef);
2594
+ const [panelHeight, setPanelHeight] = useState(0);
2595
+ const onLayout = useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
2596
+ const frame = anchor === null ? null : dropdownFrame(anchor, panelHeight, viewportHeight);
2597
+ const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
2598
+ return /* @__PURE__ */ jsxs(Modal, { transparent: true, visible: true, animationType: "none", onRequestClose: onDismiss, children: [
2599
+ /* @__PURE__ */ jsx(Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
2600
+ frame !== null ? /* @__PURE__ */ jsx(Animated.View, { style: [styles18.dropdown, place, { opacity: progress, transform: [{ translateY }] }], testID: `${testID}-dropdown-${frame.placement}`, onLayout, children }) : null
2601
+ ] });
2585
2602
  }
2586
2603
  var styles18 = StyleSheet.create({
2587
- dropdown: { position: "absolute", top: "100%", left: 0, right: 0, zIndex: PANEL_Z }
2604
+ dropdown: { position: "absolute" }
2588
2605
  });
2589
2606
  var ROW_PAD_H = 12;
2590
2607
  var ROW_GAP4 = 8;
@@ -2697,7 +2714,7 @@ function SearchSelectPanel({ motion, state, labels, anchorRef, renderLeading, re
2697
2714
  sections.flat.length === 0 ? /* @__PURE__ */ jsx(Text, { style: [styles22.empty, { color: colors.textSecondary }], children: labels.empty }) : null
2698
2715
  ] })
2699
2716
  ] });
2700
- if (!isSheet) return /* @__PURE__ */ jsx(DropdownSurface, { anchorRef, progress, translateY, onDismiss: dismiss, children: list });
2717
+ if (!isSheet) return /* @__PURE__ */ jsx(DropdownSurface, { anchorRef, closeHint: labels.closeHint, closeLabel: labels.close, progress, testID, translateY, onDismiss: dismiss, children: list });
2701
2718
  return /* @__PURE__ */ jsx(SheetSurface, { closeHint: labels.closeHint, closeLabel: labels.close, testID, translateY, onDismiss: dismiss, children: list });
2702
2719
  }
2703
2720
  var styles22 = StyleSheet.create({
@@ -2706,6 +2723,12 @@ var styles22 = StyleSheet.create({
2706
2723
  sheetList: { maxHeight: SHEET_MAX_HEIGHT },
2707
2724
  empty: { padding: PANEL_PAD }
2708
2725
  });
2726
+ var AFTER_SURFACE_UNMOUNT_MS = 0;
2727
+ function useDeferredFocus(ref) {
2728
+ return useCallback(() => {
2729
+ setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
2730
+ }, [ref]);
2731
+ }
2709
2732
  function useReducedMotion() {
2710
2733
  const [reduced, setReduced] = useState(false);
2711
2734
  useEffect(() => {
@@ -2807,7 +2830,7 @@ function SearchSelect(props) {
2807
2830
  const { width } = useWindowDimensions();
2808
2831
  const motion = resolveSelectMotion(width, useReducedMotion());
2809
2832
  const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
2810
- const refocus = useCallback(() => triggerRef.current?.focus(), []);
2833
+ const refocus = useDeferredFocus(triggerRef);
2811
2834
  const state = useSearchSelectState(options, recents, onChange, refocus);
2812
2835
  const selected = findOption(options, value);
2813
2836
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
@@ -2844,6 +2867,23 @@ var styles23 = StyleSheet.create({
2844
2867
  anchor: { position: "relative" },
2845
2868
  value: { flex: 1, flexDirection: "row", alignItems: "center", gap: VALUE_GAP }
2846
2869
  });
2870
+ function isContainer(node) {
2871
+ return "contains" in Object(node);
2872
+ }
2873
+ function isOutside(container, target) {
2874
+ if (!isContainer(container)) return false;
2875
+ return !(target instanceof Node && container.contains(target));
2876
+ }
2877
+ function useOutsidePress(ref, onOutside) {
2878
+ useEffect(() => {
2879
+ if (Platform.OS !== "web" || typeof document === "undefined") return void 0;
2880
+ const onPointerDown = (event) => {
2881
+ if (isOutside(ref.current, event.target)) onOutside();
2882
+ };
2883
+ document.addEventListener("pointerdown", onPointerDown, true);
2884
+ return () => document.removeEventListener("pointerdown", onPointerDown, true);
2885
+ }, [ref, onOutside]);
2886
+ }
2847
2887
 
2848
2888
  // src/CountryFlag/data/flagPalette.ts
2849
2889
  var FLAG_PALETTE = {
@@ -3854,12 +3894,28 @@ function validateIban(raw) {
3854
3894
  if (mod97(normalised) !== VALID_REMAINDER) return refused("ChecksumFailed" /* ChecksumFailed */);
3855
3895
  return { rejection: "None" /* None */, electronic: normalised, expectedLength: null };
3856
3896
  }
3857
- function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, placeholder }) {
3897
+ var LINE_GAP = 4;
3898
+ function RejectionLine({ message, testID }) {
3899
+ const { theme } = useUi();
3900
+ if (message === null) return null;
3901
+ return /* @__PURE__ */ jsx(Text, { accessibilityLiveRegion: "polite", style: [styles25.line, { color: fieldErrorInk(theme) }], testID: `${testID}-rejection`, children: message });
3902
+ }
3903
+ var styles25 = StyleSheet.create({
3904
+ line: { marginTop: LINE_GAP }
3905
+ });
3906
+
3907
+ // src/IbanInput/utils/rejectionMessage.ts
3908
+ function rejectionMessage(rejection, none, labels) {
3909
+ if (labels === void 0 || rejection === null || rejection === none) return null;
3910
+ return labels[rejection];
3911
+ }
3912
+ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder }) {
3858
3913
  const { theme } = useUi();
3859
3914
  const { colors } = theme;
3860
3915
  const draft = useMemo(() => draftIban(value), [value]);
3861
3916
  const validate = useCallback(() => validateIban(value), [value]);
3862
- const { onEdit, onLeave } = useBlurVerdict(validate);
3917
+ const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
3918
+ const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
3863
3919
  const counter = ibanCounter(draft);
3864
3920
  const { selection, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
3865
3921
  const onChangeText = useCallback((text) => {
@@ -3869,37 +3925,40 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
3869
3925
  onChange(draftIban(text).electronic);
3870
3926
  }, [onEdit, onVerdict, placeAfterEdit, onChange]);
3871
3927
  const onBlur = useCallback(() => {
3872
- const verdict = onLeave();
3873
- onVerdict?.(value === "" ? null : verdict);
3928
+ const verdict2 = onLeave();
3929
+ onVerdict?.(value === "" ? null : verdict2);
3874
3930
  }, [onLeave, onVerdict, value]);
3875
- return /* @__PURE__ */ jsxs(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: [
3876
- /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
3877
- /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
3878
- /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.display }),
3879
- /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost })
3931
+ return /* @__PURE__ */ jsxs(View, { children: [
3932
+ /* @__PURE__ */ jsxs(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: [
3933
+ /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
3934
+ /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
3935
+ /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.display }),
3936
+ /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost })
3937
+ ] }),
3938
+ /* @__PURE__ */ jsx(
3939
+ TextInput,
3940
+ {
3941
+ accessibilityHint,
3942
+ accessibilityLabel,
3943
+ autoCapitalize: "characters",
3944
+ autoComplete: "off",
3945
+ autoCorrect: false,
3946
+ placeholder: draft.display === "" ? placeholder : void 0,
3947
+ placeholderTextColor: colors.textSecondary,
3948
+ selection,
3949
+ spellCheck: false,
3950
+ style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
3951
+ testID,
3952
+ value: draft.display,
3953
+ onBlur,
3954
+ onChangeText,
3955
+ onSelectionChange
3956
+ }
3957
+ )
3880
3958
  ] }),
3881
- /* @__PURE__ */ jsx(
3882
- TextInput,
3883
- {
3884
- accessibilityHint,
3885
- accessibilityLabel,
3886
- autoCapitalize: "characters",
3887
- autoComplete: "off",
3888
- autoCorrect: false,
3889
- placeholder: draft.display === "" ? placeholder : void 0,
3890
- placeholderTextColor: colors.textSecondary,
3891
- selection,
3892
- spellCheck: false,
3893
- style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
3894
- testID,
3895
- value: draft.display,
3896
- onBlur,
3897
- onChangeText,
3898
- onSelectionChange
3899
- }
3900
- )
3959
+ counter !== null ? /* @__PURE__ */ jsx(Text, { testID: `${testID}-counter`, style: [ghostStyles.counter, { color: colors.textSecondary }], children: counter }) : null
3901
3960
  ] }),
3902
- counter !== null ? /* @__PURE__ */ jsx(Text, { testID: `${testID}-counter`, style: [ghostStyles.counter, { color: colors.textSecondary }], children: counter }) : null
3961
+ /* @__PURE__ */ jsx(RejectionLine, { message, testID })
3903
3962
  ] });
3904
3963
  }
3905
3964
 
@@ -3936,46 +3995,50 @@ function validateBic(raw) {
3936
3995
  if (RESERVED_LOCATION.includes(bic.charAt(LOCATION_INDEX))) return refused2("MalformedLocation" /* MalformedLocation */);
3937
3996
  return { rejection: "None" /* None */, electronic: bic };
3938
3997
  }
3939
- function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID }) {
3998
+ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels }) {
3940
3999
  const { theme } = useUi();
3941
4000
  const { colors } = theme;
3942
4001
  const draft = useMemo(() => draftBic(value), [value]);
3943
4002
  const validate = useCallback(() => validateBic(value), [value]);
3944
- const { onEdit, onLeave } = useBlurVerdict(validate);
4003
+ const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
4004
+ const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
3945
4005
  const onChangeText = useCallback((text) => {
3946
4006
  onEdit();
3947
4007
  onVerdict?.(null);
3948
4008
  onChange(draftBic(text).value);
3949
4009
  }, [onEdit, onVerdict, onChange]);
3950
4010
  const onBlur = useCallback(() => {
3951
- const verdict = onLeave();
3952
- onVerdict?.(value === "" ? null : verdict);
4011
+ const verdict2 = onLeave();
4012
+ onVerdict?.(value === "" ? null : verdict2);
3953
4013
  }, [onLeave, onVerdict, value]);
3954
- return /* @__PURE__ */ jsx(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
3955
- /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
3956
- /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.value }),
3957
- /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost }),
3958
- /* @__PURE__ */ jsx(Text, { style: [ghostStyles.branch, { color: colors.textSecondary }], children: draft.branchGhost })
3959
- ] }),
3960
- /* @__PURE__ */ jsx(
3961
- TextInput,
3962
- {
3963
- accessibilityHint,
3964
- accessibilityLabel,
3965
- autoCapitalize: "characters",
3966
- autoComplete: "off",
3967
- autoCorrect: false,
3968
- spellCheck: false,
3969
- style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
3970
- testID,
3971
- value: draft.value,
3972
- onBlur,
3973
- onChangeText
3974
- }
3975
- )
3976
- ] }) });
4014
+ return /* @__PURE__ */ jsxs(View, { children: [
4015
+ /* @__PURE__ */ jsx(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
4016
+ /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
4017
+ /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.value }),
4018
+ /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost }),
4019
+ /* @__PURE__ */ jsx(Text, { style: [ghostStyles.branch, { color: colors.textSecondary }], children: draft.branchGhost })
4020
+ ] }),
4021
+ /* @__PURE__ */ jsx(
4022
+ TextInput,
4023
+ {
4024
+ accessibilityHint,
4025
+ accessibilityLabel,
4026
+ autoCapitalize: "characters",
4027
+ autoComplete: "off",
4028
+ autoCorrect: false,
4029
+ spellCheck: false,
4030
+ style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
4031
+ testID,
4032
+ value: draft.value,
4033
+ onBlur,
4034
+ onChangeText
4035
+ }
4036
+ )
4037
+ ] }) }),
4038
+ /* @__PURE__ */ jsx(RejectionLine, { message, testID })
4039
+ ] });
3977
4040
  }
3978
4041
 
3979
- export { AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipSelector, CountryField, CountryFlag, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateInput, DateRangeControl, DateTimeField, FLAG_HEIGHT, FLAG_WIDTH, Field, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, ResponsiveFormLayout, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, buildSearchSelectSections, controlStyles, countryFlag, countryOptions, draftBic, draftIban, findOption, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isFallbackFlag, isFixBarVisible, isOutside, isUnmatched, isWideFormLayout, moveHighlight, nextHighlight, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, suggestOptions, toCountryValue, toggleGroupSelection, useBlurVerdict, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateIban };
4042
+ export { AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipSelector, CountryField, CountryFlag, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateInput, DateRangeControl, DateTimeField, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, ResponsiveFormLayout, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, buildSearchSelectSections, controlStyles, countryFlag, countryOptions, draftBic, draftIban, dropdownFrame, findOption, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isFallbackFlag, isFixBarVisible, isOutside, isUnmatched, isWideFormLayout, moveHighlight, nextHighlight, placeDropdown, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, suggestOptions, toCountryValue, toggleGroupSelection, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateIban };
3980
4043
  //# sourceMappingURL=index.mjs.map
3981
4044
  //# sourceMappingURL=index.mjs.map