@dloizides/ui-forms 1.36.0 → 1.38.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
@@ -2610,6 +2610,8 @@ var DropdownPlacement = /* @__PURE__ */ ((DropdownPlacement2) => {
2610
2610
  })(DropdownPlacement || {});
2611
2611
 
2612
2612
  // src/SearchSelect/utils/dropdownFrame.ts
2613
+ var MIN_PANEL_WIDTH = 240;
2614
+ var EDGE = 8;
2613
2615
  function placeDropdown(anchor, panelHeight, viewportHeight) {
2614
2616
  const roomBelow = viewportHeight - (anchor.y + anchor.height);
2615
2617
  if (roomBelow >= panelHeight) return "below" /* Below */;
@@ -2621,12 +2623,17 @@ function dropdownFrame(anchor, panelHeight, viewportHeight) {
2621
2623
  if (placement === "above" /* Above */) return { ...base, bottom: viewportHeight - anchor.y };
2622
2624
  return { ...base, top: anchor.y + anchor.height };
2623
2625
  }
2626
+ function fitDropdownWidth(frame, viewportWidth) {
2627
+ const width = Math.max(frame.width, Math.min(MIN_PANEL_WIDTH, viewportWidth - EDGE - EDGE));
2628
+ const left = Math.max(EDGE, Math.min(frame.left, viewportWidth - width - EDGE));
2629
+ return { ...frame, width, left: frame.width >= width ? frame.left : left };
2630
+ }
2624
2631
  function DropdownSurface({ progress, translateY, anchorRef, onDismiss, closeLabel, closeHint, testID, children }) {
2625
- const { height: viewportHeight } = useWindowDimensions();
2632
+ const { height: viewportHeight, width: viewportWidth } = useWindowDimensions();
2626
2633
  const anchor = useAnchorRect2(anchorRef);
2627
2634
  const [panelHeight, setPanelHeight] = useState(0);
2628
2635
  const onLayout = useCallback((event) => setPanelHeight(event.nativeEvent.layout.height), []);
2629
- const frame = anchor === null ? null : dropdownFrame(anchor, panelHeight, viewportHeight);
2636
+ const frame = anchor === null ? null : fitDropdownWidth(dropdownFrame(anchor, panelHeight, viewportHeight), viewportWidth);
2630
2637
  const place = frame === null ? null : { left: frame.left, width: frame.width, top: frame.top, bottom: frame.bottom };
2631
2638
  return /* @__PURE__ */ jsxs(Modal, { transparent: true, visible: true, animationType: "none", onRequestClose: onDismiss, children: [
2632
2639
  /* @__PURE__ */ jsx(Pressable, { accessibilityHint: closeHint, accessibilityLabel: closeLabel, accessibilityRole: "button", style: StyleSheet.absoluteFill, testID: `${testID}-backdrop`, onPress: onDismiss }),
@@ -2855,9 +2862,10 @@ function resolveSelectMotion(width, reducedMotion) {
2855
2862
  }
2856
2863
  var CHEVRON = "\u25BE";
2857
2864
  var VALUE_GAP = 8;
2865
+ var MIN_TOUCH = 44;
2858
2866
  var NOTHING_ON_CLOSE = () => void 0;
2859
2867
  function SearchSelect(props) {
2860
- const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail } = props;
2868
+ const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail, renderTrigger, onBlur } = props;
2861
2869
  const { theme } = useUi();
2862
2870
  const { colors } = theme;
2863
2871
  const triggerRef = useRef(null);
@@ -2868,8 +2876,14 @@ function SearchSelect(props) {
2868
2876
  const state = useSearchSelectState(options, recents, onChange, NOTHING_ON_CLOSE);
2869
2877
  useRefocusOnClose(state.open, triggerRef);
2870
2878
  const selected = findOption(options, value);
2879
+ const onPress = state.open ? state.close : state.openList;
2880
+ const openRef = useRef(state.open);
2881
+ openRef.current = state.open;
2882
+ const onTriggerBlur = useCallback(() => {
2883
+ if (!openRef.current) onBlur?.();
2884
+ }, [onBlur]);
2871
2885
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
2872
- /* @__PURE__ */ jsxs(
2886
+ /* @__PURE__ */ jsx(
2873
2887
  Pressable,
2874
2888
  {
2875
2889
  ref: triggerRef,
@@ -2877,22 +2891,26 @@ function SearchSelect(props) {
2877
2891
  accessibilityLabel,
2878
2892
  accessibilityRole: "button",
2879
2893
  accessibilityState: { expanded: state.open },
2880
- style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
2894
+ style: renderTrigger === void 0 ? [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }] : styles23.customTrigger,
2881
2895
  testID,
2882
- onPress: state.open ? state.close : state.openList,
2883
- children: [
2884
- /* @__PURE__ */ jsxs(View, { style: styles23.value, children: [
2885
- selected !== null && renderLeading !== void 0 ? renderLeading(selected) : null,
2886
- /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, { color: selected === null ? colors.textSecondary : colors.text }], children: selected?.label ?? labels.placeholder }),
2887
- selected !== null ? /* @__PURE__ */ jsx(SelectedDetail, { colors, option: selected, renderDetail }) : null
2888
- ] }),
2889
- /* @__PURE__ */ jsx(Text, { "aria-hidden": true, style: [controlStyles.chevron, { color: colors.textSecondary }], children: CHEVRON })
2890
- ]
2896
+ onBlur: onTriggerBlur,
2897
+ onPress,
2898
+ children: renderTrigger !== void 0 ? renderTrigger({ open: state.open, selected, onPress, ref: triggerRef }) : /* @__PURE__ */ jsx(FieldBoxContent, { colors, placeholder: labels.placeholder, renderDetail, renderLeading, selected })
2891
2899
  }
2892
2900
  ),
2893
2901
  state.open ? /* @__PURE__ */ jsx(SearchSelectPanel, { anchorRef, labels, motion, renderDetail, renderLeading, selectedValue: value, state, testID }) : null
2894
2902
  ] });
2895
2903
  }
2904
+ function FieldBoxContent({ selected, placeholder, colors, renderLeading, renderDetail }) {
2905
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2906
+ /* @__PURE__ */ jsxs(View, { style: styles23.value, children: [
2907
+ selected !== null && renderLeading !== void 0 ? renderLeading(selected) : null,
2908
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, { color: selected === null ? colors.textSecondary : colors.text }], children: selected?.label ?? placeholder }),
2909
+ selected !== null ? /* @__PURE__ */ jsx(SelectedDetail, { colors, option: selected, renderDetail }) : null
2910
+ ] }),
2911
+ /* @__PURE__ */ jsx(Text, { "aria-hidden": true, style: [controlStyles.chevron, { color: colors.textSecondary }], children: CHEVRON })
2912
+ ] });
2913
+ }
2896
2914
  function SelectedDetail({ option, colors, renderDetail }) {
2897
2915
  if (renderDetail !== void 0) return /* @__PURE__ */ jsx(Fragment, { children: renderDetail(option) });
2898
2916
  if (option.detail === void 0) return null;
@@ -2900,6 +2918,7 @@ function SelectedDetail({ option, colors, renderDetail }) {
2900
2918
  }
2901
2919
  var styles23 = StyleSheet.create({
2902
2920
  anchor: { position: "relative" },
2921
+ customTrigger: { minHeight: MIN_TOUCH, minWidth: MIN_TOUCH, alignSelf: "flex-start", justifyContent: "center" },
2903
2922
  value: { flex: 1, flexDirection: "row", alignItems: "center", gap: VALUE_GAP }
2904
2923
  });
2905
2924
  function isContainer(node) {
@@ -3652,6 +3671,12 @@ var KNOWN_CODES = new Set(COUNTRIES.map((country) => country.code));
3652
3671
  function countryOptions(list = COUNTRIES) {
3653
3672
  return list.map((country) => ({ label: country.name, value: country.code, detail: country.code }));
3654
3673
  }
3674
+ var DEFAULT_OPTIONS = countryOptions();
3675
+ var NO_COUNTRY = "";
3676
+ function countryFieldOptions(countries, noneLabel) {
3677
+ const list = countries === void 0 ? DEFAULT_OPTIONS : countryOptions(countries);
3678
+ return noneLabel === void 0 ? list : [{ label: noneLabel, value: NO_COUNTRY }, ...list];
3679
+ }
3655
3680
  function countryFlag(code) {
3656
3681
  const upper = code.toUpperCase();
3657
3682
  if (!TWO_LETTERS.test(upper)) return "";
@@ -3662,12 +3687,12 @@ function toCountryValue(input) {
3662
3687
  return KNOWN_CODES.has(upper) ? upper : "";
3663
3688
  }
3664
3689
  var CODE_FONT = 12;
3665
- var DEFAULT_OPTIONS = countryOptions();
3666
- var renderFlag = (option) => /* @__PURE__ */ jsx(CountryFlag, { code: option.value });
3667
- function CountryField({ value, onChange, accessibilityLabel, accessibilityHint, labels, testID, countries }) {
3690
+ var NO_COUNTRY2 = "";
3691
+ var renderFlag = (option) => option.value === NO_COUNTRY2 ? null : /* @__PURE__ */ jsx(CountryFlag, { code: option.value });
3692
+ function CountryField({ value, onChange, accessibilityLabel, accessibilityHint, labels, testID, countries, noneLabel, onBlur }) {
3668
3693
  const { theme } = useUi();
3669
3694
  const { textSecondary } = theme.colors;
3670
- const options = useMemo(() => countries === void 0 ? DEFAULT_OPTIONS : countryOptions(countries), [countries]);
3695
+ const options = useMemo(() => countryFieldOptions(countries, noneLabel), [countries, noneLabel]);
3671
3696
  const renderCode = useCallback((option) => /* @__PURE__ */ jsx(Text, { style: [styles24.code, { color: textSecondary }], children: option.detail }), [textSecondary]);
3672
3697
  return /* @__PURE__ */ jsx(
3673
3698
  SearchSelect,
@@ -3681,6 +3706,7 @@ function CountryField({ value, onChange, accessibilityLabel, accessibilityHint,
3681
3706
  renderLeading: renderFlag,
3682
3707
  testID,
3683
3708
  value: toCountryValue(value),
3709
+ onBlur,
3684
3710
  onChange
3685
3711
  }
3686
3712
  );
@@ -3950,7 +3976,7 @@ function rejectionMessage(rejection, none, labels) {
3950
3976
  if (labels === void 0 || rejection === null || rejection === none) return null;
3951
3977
  return labels[rejection];
3952
3978
  }
3953
- function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder }) {
3979
+ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
3954
3980
  const { theme } = useUi();
3955
3981
  const { colors } = theme;
3956
3982
  const draft = useMemo(() => draftIban(value), [value]);
@@ -3968,7 +3994,8 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
3968
3994
  const onBlur = useCallback(() => {
3969
3995
  const verdict2 = onLeave();
3970
3996
  onVerdict?.(value === "" ? null : verdict2);
3971
- }, [onLeave, onVerdict, value]);
3997
+ onLeft?.();
3998
+ }, [onLeave, onVerdict, value, onLeft]);
3972
3999
  return /* @__PURE__ */ jsxs(View, { children: [
3973
4000
  /* @__PURE__ */ jsxs(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: [
3974
4001
  /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
@@ -4036,7 +4063,7 @@ function validateBic(raw) {
4036
4063
  if (RESERVED_LOCATION.includes(bic.charAt(LOCATION_INDEX))) return refused2("MalformedLocation" /* MalformedLocation */);
4037
4064
  return { rejection: "None" /* None */, electronic: bic };
4038
4065
  }
4039
- function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels }) {
4066
+ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
4040
4067
  const { theme } = useUi();
4041
4068
  const { colors } = theme;
4042
4069
  const draft = useMemo(() => draftBic(value), [value]);
@@ -4051,7 +4078,8 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4051
4078
  const onBlur = useCallback(() => {
4052
4079
  const verdict2 = onLeave();
4053
4080
  onVerdict?.(value === "" ? null : verdict2);
4054
- }, [onLeave, onVerdict, value]);
4081
+ onLeft?.();
4082
+ }, [onLeave, onVerdict, value, onLeft]);
4055
4083
  return /* @__PURE__ */ jsxs(View, { children: [
4056
4084
  /* @__PURE__ */ jsx(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
4057
4085
  /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
@@ -4067,6 +4095,8 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4067
4095
  autoCapitalize: "characters",
4068
4096
  autoComplete: "off",
4069
4097
  autoCorrect: false,
4098
+ placeholder: draft.value === "" ? placeholder : void 0,
4099
+ placeholderTextColor: colors.textSecondary,
4070
4100
  spellCheck: false,
4071
4101
  style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
4072
4102
  testID,
@@ -4080,6 +4110,6 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4080
4110
  ] });
4081
4111
  }
4082
4112
 
4083
- export { AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, 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 };
4113
+ export { AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, 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, countryFieldOptions, countryFlag, countryOptions, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, 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 };
4084
4114
  //# sourceMappingURL=index.mjs.map
4085
4115
  //# sourceMappingURL=index.mjs.map