@dloizides/ui-forms 1.33.0 → 1.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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({
@@ -2721,6 +2738,13 @@ function useReducedMotion() {
2721
2738
  }, []);
2722
2739
  return reduced;
2723
2740
  }
2741
+ function useRefocusOnClose(open, ref) {
2742
+ const wasOpen = useRef(false);
2743
+ useEffect(() => {
2744
+ if (wasOpen.current && !open) ref.current?.focus();
2745
+ wasOpen.current = open;
2746
+ }, [open, ref]);
2747
+ }
2724
2748
 
2725
2749
  // src/SearchSelect/utils/searchSelectModel.ts
2726
2750
  var MIN_QUERY = 1;
@@ -2798,6 +2822,7 @@ function resolveSelectMotion(width, reducedMotion) {
2798
2822
  }
2799
2823
  var CHEVRON = "\u25BE";
2800
2824
  var VALUE_GAP = 8;
2825
+ var NOTHING_ON_CLOSE = () => void 0;
2801
2826
  function SearchSelect(props) {
2802
2827
  const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail } = props;
2803
2828
  const { theme } = useUi();
@@ -2807,8 +2832,8 @@ function SearchSelect(props) {
2807
2832
  const { width } = useWindowDimensions();
2808
2833
  const motion = resolveSelectMotion(width, useReducedMotion());
2809
2834
  const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
2810
- const refocus = useCallback(() => triggerRef.current?.focus(), []);
2811
- const state = useSearchSelectState(options, recents, onChange, refocus);
2835
+ const state = useSearchSelectState(options, recents, onChange, NOTHING_ON_CLOSE);
2836
+ useRefocusOnClose(state.open, triggerRef);
2812
2837
  const selected = findOption(options, value);
2813
2838
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
2814
2839
  /* @__PURE__ */ jsxs(
@@ -2844,6 +2869,29 @@ var styles23 = StyleSheet.create({
2844
2869
  anchor: { position: "relative" },
2845
2870
  value: { flex: 1, flexDirection: "row", alignItems: "center", gap: VALUE_GAP }
2846
2871
  });
2872
+ function isContainer(node) {
2873
+ return "contains" in Object(node);
2874
+ }
2875
+ function isOutside(container, target) {
2876
+ if (!isContainer(container)) return false;
2877
+ return !(target instanceof Node && container.contains(target));
2878
+ }
2879
+ function useOutsidePress(ref, onOutside) {
2880
+ useEffect(() => {
2881
+ if (Platform.OS !== "web" || typeof document === "undefined") return void 0;
2882
+ const onPointerDown = (event) => {
2883
+ if (isOutside(ref.current, event.target)) onOutside();
2884
+ };
2885
+ document.addEventListener("pointerdown", onPointerDown, true);
2886
+ return () => document.removeEventListener("pointerdown", onPointerDown, true);
2887
+ }, [ref, onOutside]);
2888
+ }
2889
+ var AFTER_SURFACE_UNMOUNT_MS = 0;
2890
+ function useDeferredFocus(ref) {
2891
+ return useCallback(() => {
2892
+ setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
2893
+ }, [ref]);
2894
+ }
2847
2895
 
2848
2896
  // src/CountryFlag/data/flagPalette.ts
2849
2897
  var FLAG_PALETTE = {
@@ -3854,12 +3902,28 @@ function validateIban(raw) {
3854
3902
  if (mod97(normalised) !== VALID_REMAINDER) return refused("ChecksumFailed" /* ChecksumFailed */);
3855
3903
  return { rejection: "None" /* None */, electronic: normalised, expectedLength: null };
3856
3904
  }
3857
- function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, placeholder }) {
3905
+ var LINE_GAP = 4;
3906
+ function RejectionLine({ message, testID }) {
3907
+ const { theme } = useUi();
3908
+ if (message === null) return null;
3909
+ return /* @__PURE__ */ jsx(Text, { accessibilityLiveRegion: "polite", style: [styles25.line, { color: fieldErrorInk(theme) }], testID: `${testID}-rejection`, children: message });
3910
+ }
3911
+ var styles25 = StyleSheet.create({
3912
+ line: { marginTop: LINE_GAP }
3913
+ });
3914
+
3915
+ // src/IbanInput/utils/rejectionMessage.ts
3916
+ function rejectionMessage(rejection, none, labels) {
3917
+ if (labels === void 0 || rejection === null || rejection === none) return null;
3918
+ return labels[rejection];
3919
+ }
3920
+ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder }) {
3858
3921
  const { theme } = useUi();
3859
3922
  const { colors } = theme;
3860
3923
  const draft = useMemo(() => draftIban(value), [value]);
3861
3924
  const validate = useCallback(() => validateIban(value), [value]);
3862
- const { onEdit, onLeave } = useBlurVerdict(validate);
3925
+ const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
3926
+ const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
3863
3927
  const counter = ibanCounter(draft);
3864
3928
  const { selection, onSelectionChange, placeAfterEdit } = useIbanCaret(draft.display);
3865
3929
  const onChangeText = useCallback((text) => {
@@ -3869,37 +3933,40 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
3869
3933
  onChange(draftIban(text).electronic);
3870
3934
  }, [onEdit, onVerdict, placeAfterEdit, onChange]);
3871
3935
  const onBlur = useCallback(() => {
3872
- const verdict = onLeave();
3873
- onVerdict?.(value === "" ? null : verdict);
3936
+ const verdict2 = onLeave();
3937
+ onVerdict?.(value === "" ? null : verdict2);
3874
3938
  }, [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 })
3939
+ return /* @__PURE__ */ jsxs(View, { children: [
3940
+ /* @__PURE__ */ jsxs(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: [
3941
+ /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
3942
+ /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
3943
+ /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.display }),
3944
+ /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost })
3945
+ ] }),
3946
+ /* @__PURE__ */ jsx(
3947
+ TextInput,
3948
+ {
3949
+ accessibilityHint,
3950
+ accessibilityLabel,
3951
+ autoCapitalize: "characters",
3952
+ autoComplete: "off",
3953
+ autoCorrect: false,
3954
+ placeholder: draft.display === "" ? placeholder : void 0,
3955
+ placeholderTextColor: colors.textSecondary,
3956
+ selection,
3957
+ spellCheck: false,
3958
+ style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
3959
+ testID,
3960
+ value: draft.display,
3961
+ onBlur,
3962
+ onChangeText,
3963
+ onSelectionChange
3964
+ }
3965
+ )
3880
3966
  ] }),
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
- )
3967
+ counter !== null ? /* @__PURE__ */ jsx(Text, { testID: `${testID}-counter`, style: [ghostStyles.counter, { color: colors.textSecondary }], children: counter }) : null
3901
3968
  ] }),
3902
- counter !== null ? /* @__PURE__ */ jsx(Text, { testID: `${testID}-counter`, style: [ghostStyles.counter, { color: colors.textSecondary }], children: counter }) : null
3969
+ /* @__PURE__ */ jsx(RejectionLine, { message, testID })
3903
3970
  ] });
3904
3971
  }
3905
3972
 
@@ -3936,46 +4003,50 @@ function validateBic(raw) {
3936
4003
  if (RESERVED_LOCATION.includes(bic.charAt(LOCATION_INDEX))) return refused2("MalformedLocation" /* MalformedLocation */);
3937
4004
  return { rejection: "None" /* None */, electronic: bic };
3938
4005
  }
3939
- function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID }) {
4006
+ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels }) {
3940
4007
  const { theme } = useUi();
3941
4008
  const { colors } = theme;
3942
4009
  const draft = useMemo(() => draftBic(value), [value]);
3943
4010
  const validate = useCallback(() => validateBic(value), [value]);
3944
- const { onEdit, onLeave } = useBlurVerdict(validate);
4011
+ const { verdict, onEdit, onLeave } = useBlurVerdict(validate);
4012
+ const message = value === "" ? null : rejectionMessage(verdict?.rejection ?? null, "None" /* None */, rejectionLabels);
3945
4013
  const onChangeText = useCallback((text) => {
3946
4014
  onEdit();
3947
4015
  onVerdict?.(null);
3948
4016
  onChange(draftBic(text).value);
3949
4017
  }, [onEdit, onVerdict, onChange]);
3950
4018
  const onBlur = useCallback(() => {
3951
- const verdict = onLeave();
3952
- onVerdict?.(value === "" ? null : verdict);
4019
+ const verdict2 = onLeave();
4020
+ onVerdict?.(value === "" ? null : verdict2);
3953
4021
  }, [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
- ] }) });
4022
+ return /* @__PURE__ */ jsxs(View, { children: [
4023
+ /* @__PURE__ */ jsx(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
4024
+ /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
4025
+ /* @__PURE__ */ jsx(Text, { style: ghostStyles.hidden, children: draft.value }),
4026
+ /* @__PURE__ */ jsx(Text, { style: { color: colors.textSecondary }, children: draft.ghost }),
4027
+ /* @__PURE__ */ jsx(Text, { style: [ghostStyles.branch, { color: colors.textSecondary }], children: draft.branchGhost })
4028
+ ] }),
4029
+ /* @__PURE__ */ jsx(
4030
+ TextInput,
4031
+ {
4032
+ accessibilityHint,
4033
+ accessibilityLabel,
4034
+ autoCapitalize: "characters",
4035
+ autoComplete: "off",
4036
+ autoCorrect: false,
4037
+ spellCheck: false,
4038
+ style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
4039
+ testID,
4040
+ value: draft.value,
4041
+ onBlur,
4042
+ onChangeText
4043
+ }
4044
+ )
4045
+ ] }) }),
4046
+ /* @__PURE__ */ jsx(RejectionLine, { message, testID })
4047
+ ] });
3977
4048
  }
3978
4049
 
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 };
4050
+ 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
4051
  //# sourceMappingURL=index.mjs.map
3981
4052
  //# sourceMappingURL=index.mjs.map