@dloizides/ui-forms 1.36.0 → 1.37.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 } = props;
2861
2869
  const { theme } = useUi();
2862
2870
  const { colors } = theme;
2863
2871
  const triggerRef = useRef(null);
@@ -2868,8 +2876,9 @@ 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;
2871
2880
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
2872
- /* @__PURE__ */ jsxs(
2881
+ /* @__PURE__ */ jsx(
2873
2882
  Pressable,
2874
2883
  {
2875
2884
  ref: triggerRef,
@@ -2877,22 +2886,25 @@ function SearchSelect(props) {
2877
2886
  accessibilityLabel,
2878
2887
  accessibilityRole: "button",
2879
2888
  accessibilityState: { expanded: state.open },
2880
- style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
2889
+ style: renderTrigger === void 0 ? [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }] : styles23.customTrigger,
2881
2890
  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
- ]
2891
+ onPress,
2892
+ children: renderTrigger !== void 0 ? renderTrigger({ open: state.open, selected, onPress, ref: triggerRef }) : /* @__PURE__ */ jsx(FieldBoxContent, { colors, placeholder: labels.placeholder, renderDetail, renderLeading, selected })
2891
2893
  }
2892
2894
  ),
2893
2895
  state.open ? /* @__PURE__ */ jsx(SearchSelectPanel, { anchorRef, labels, motion, renderDetail, renderLeading, selectedValue: value, state, testID }) : null
2894
2896
  ] });
2895
2897
  }
2898
+ function FieldBoxContent({ selected, placeholder, colors, renderLeading, renderDetail }) {
2899
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2900
+ /* @__PURE__ */ jsxs(View, { style: styles23.value, children: [
2901
+ selected !== null && renderLeading !== void 0 ? renderLeading(selected) : null,
2902
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, { color: selected === null ? colors.textSecondary : colors.text }], children: selected?.label ?? placeholder }),
2903
+ selected !== null ? /* @__PURE__ */ jsx(SelectedDetail, { colors, option: selected, renderDetail }) : null
2904
+ ] }),
2905
+ /* @__PURE__ */ jsx(Text, { "aria-hidden": true, style: [controlStyles.chevron, { color: colors.textSecondary }], children: CHEVRON })
2906
+ ] });
2907
+ }
2896
2908
  function SelectedDetail({ option, colors, renderDetail }) {
2897
2909
  if (renderDetail !== void 0) return /* @__PURE__ */ jsx(Fragment, { children: renderDetail(option) });
2898
2910
  if (option.detail === void 0) return null;
@@ -2900,6 +2912,7 @@ function SelectedDetail({ option, colors, renderDetail }) {
2900
2912
  }
2901
2913
  var styles23 = StyleSheet.create({
2902
2914
  anchor: { position: "relative" },
2915
+ customTrigger: { minHeight: MIN_TOUCH, minWidth: MIN_TOUCH, alignSelf: "flex-start", justifyContent: "center" },
2903
2916
  value: { flex: 1, flexDirection: "row", alignItems: "center", gap: VALUE_GAP }
2904
2917
  });
2905
2918
  function isContainer(node) {
@@ -3652,6 +3665,12 @@ var KNOWN_CODES = new Set(COUNTRIES.map((country) => country.code));
3652
3665
  function countryOptions(list = COUNTRIES) {
3653
3666
  return list.map((country) => ({ label: country.name, value: country.code, detail: country.code }));
3654
3667
  }
3668
+ var DEFAULT_OPTIONS = countryOptions();
3669
+ var NO_COUNTRY = "";
3670
+ function countryFieldOptions(countries, noneLabel) {
3671
+ const list = countries === void 0 ? DEFAULT_OPTIONS : countryOptions(countries);
3672
+ return noneLabel === void 0 ? list : [{ label: noneLabel, value: NO_COUNTRY }, ...list];
3673
+ }
3655
3674
  function countryFlag(code) {
3656
3675
  const upper = code.toUpperCase();
3657
3676
  if (!TWO_LETTERS.test(upper)) return "";
@@ -3662,12 +3681,12 @@ function toCountryValue(input) {
3662
3681
  return KNOWN_CODES.has(upper) ? upper : "";
3663
3682
  }
3664
3683
  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 }) {
3684
+ var NO_COUNTRY2 = "";
3685
+ var renderFlag = (option) => option.value === NO_COUNTRY2 ? null : /* @__PURE__ */ jsx(CountryFlag, { code: option.value });
3686
+ function CountryField({ value, onChange, accessibilityLabel, accessibilityHint, labels, testID, countries, noneLabel }) {
3668
3687
  const { theme } = useUi();
3669
3688
  const { textSecondary } = theme.colors;
3670
- const options = useMemo(() => countries === void 0 ? DEFAULT_OPTIONS : countryOptions(countries), [countries]);
3689
+ const options = useMemo(() => countryFieldOptions(countries, noneLabel), [countries, noneLabel]);
3671
3690
  const renderCode = useCallback((option) => /* @__PURE__ */ jsx(Text, { style: [styles24.code, { color: textSecondary }], children: option.detail }), [textSecondary]);
3672
3691
  return /* @__PURE__ */ jsx(
3673
3692
  SearchSelect,
@@ -3950,7 +3969,7 @@ function rejectionMessage(rejection, none, labels) {
3950
3969
  if (labels === void 0 || rejection === null || rejection === none) return null;
3951
3970
  return labels[rejection];
3952
3971
  }
3953
- function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder }) {
3972
+ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
3954
3973
  const { theme } = useUi();
3955
3974
  const { colors } = theme;
3956
3975
  const draft = useMemo(() => draftIban(value), [value]);
@@ -3968,7 +3987,8 @@ function IbanInput({ value, onChange, onVerdict, accessibilityLabel, accessibili
3968
3987
  const onBlur = useCallback(() => {
3969
3988
  const verdict2 = onLeave();
3970
3989
  onVerdict?.(value === "" ? null : verdict2);
3971
- }, [onLeave, onVerdict, value]);
3990
+ onLeft?.();
3991
+ }, [onLeave, onVerdict, value, onLeft]);
3972
3992
  return /* @__PURE__ */ jsxs(View, { children: [
3973
3993
  /* @__PURE__ */ jsxs(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: [
3974
3994
  /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
@@ -4036,7 +4056,7 @@ function validateBic(raw) {
4036
4056
  if (RESERVED_LOCATION.includes(bic.charAt(LOCATION_INDEX))) return refused2("MalformedLocation" /* MalformedLocation */);
4037
4057
  return { rejection: "None" /* None */, electronic: bic };
4038
4058
  }
4039
- function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels }) {
4059
+ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilityHint, testID, rejectionLabels, placeholder, onBlur: onLeft }) {
4040
4060
  const { theme } = useUi();
4041
4061
  const { colors } = theme;
4042
4062
  const draft = useMemo(() => draftBic(value), [value]);
@@ -4051,7 +4071,8 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4051
4071
  const onBlur = useCallback(() => {
4052
4072
  const verdict2 = onLeave();
4053
4073
  onVerdict?.(value === "" ? null : verdict2);
4054
- }, [onLeave, onVerdict, value]);
4074
+ onLeft?.();
4075
+ }, [onLeave, onVerdict, value, onLeft]);
4055
4076
  return /* @__PURE__ */ jsxs(View, { children: [
4056
4077
  /* @__PURE__ */ jsx(View, { style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }], children: /* @__PURE__ */ jsxs(View, { style: ghostStyles.field, children: [
4057
4078
  /* @__PURE__ */ jsxs(Text, { "aria-hidden": true, style: [ghostStyles.mono, ghostStyles.layer], children: [
@@ -4067,6 +4088,8 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4067
4088
  autoCapitalize: "characters",
4068
4089
  autoComplete: "off",
4069
4090
  autoCorrect: false,
4091
+ placeholder: draft.value === "" ? placeholder : void 0,
4092
+ placeholderTextColor: colors.textSecondary,
4070
4093
  spellCheck: false,
4071
4094
  style: [ghostStyles.mono, ghostStyles.input, { color: colors.text }],
4072
4095
  testID,
@@ -4080,6 +4103,6 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4080
4103
  ] });
4081
4104
  }
4082
4105
 
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 };
4106
+ 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
4107
  //# sourceMappingURL=index.mjs.map
4085
4108
  //# sourceMappingURL=index.mjs.map