@dloizides/ui-forms 1.34.0 → 1.35.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
@@ -1195,6 +1195,18 @@ var TRANSPARENT_COLOR = "transparent";
1195
1195
  var CHIP_HIT_SLOP = { top: 10, bottom: 10, left: 4, right: 4 };
1196
1196
  var CHIP_GUTTER = 8;
1197
1197
  var DEFAULT_CHIP_TESTID_PREFIX = "chip-selector-chip";
1198
+
1199
+ // src/ChipSelector/utils/chipLabelLayout.ts
1200
+ var CAPPED_BOX = { maxWidth: "100%", flexShrink: 1 };
1201
+ var SHRINKING_TEXT = { flexShrink: 1 };
1202
+ var SINGLE_LINE = 1;
1203
+ function chipLabelLayout(labelWrap) {
1204
+ if (labelWrap === "wrap")
1205
+ return { boxStyle: CAPPED_BOX, textStyle: SHRINKING_TEXT, numberOfLines: void 0 };
1206
+ if (labelWrap === "truncate")
1207
+ return { boxStyle: CAPPED_BOX, textStyle: SHRINKING_TEXT, numberOfLines: SINGLE_LINE };
1208
+ return { boxStyle: void 0, textStyle: void 0, numberOfLines: void 0 };
1209
+ }
1198
1210
  var SOLID_RADIUS = 20;
1199
1211
  var OUTLINE_RADIUS = 999;
1200
1212
  var OUTLINE_PAD_H = 12;
@@ -1226,8 +1238,8 @@ var chipStyles = StyleSheet.create({
1226
1238
  chipText: {},
1227
1239
  chipTextOutline: { fontSize: OUTLINE_FONT_SIZE }
1228
1240
  });
1229
- function ChipContent({ icon, label, textStyle }) {
1230
- const text = /* @__PURE__ */ jsx(Text, { style: textStyle, children: label });
1241
+ function ChipContent({ icon, label, textStyle, numberOfLines }) {
1242
+ const text = /* @__PURE__ */ jsx(Text, { numberOfLines, style: textStyle, children: label });
1231
1243
  if (icon === void 0 || icon === null)
1232
1244
  return text;
1233
1245
  return /* @__PURE__ */ jsxs(View, { style: chipStyles.chipContent, children: [
@@ -1242,6 +1254,7 @@ function OutlineChip(props) {
1242
1254
  const borderColor = active ? colors.primary : colors.border;
1243
1255
  const backgroundColor = selected ? colors.tint : colors.muted;
1244
1256
  const textColor = active ? colors.primary : colors.textMuted;
1257
+ const layout = chipLabelLayout(option.labelWrap);
1245
1258
  return /* @__PURE__ */ jsx(
1246
1259
  Pressable,
1247
1260
  {
@@ -1254,17 +1267,19 @@ function OutlineChip(props) {
1254
1267
  "aria-pressed": props.ariaPressed,
1255
1268
  disabled,
1256
1269
  hitSlop: CHIP_HIT_SLOP,
1270
+ style: layout.boxStyle,
1257
1271
  tabIndex: props.tabIndex,
1258
1272
  testID,
1259
1273
  onHoverIn: () => setHovered(true),
1260
1274
  onHoverOut: () => setHovered(false),
1261
1275
  onPress,
1262
- children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chipOutline, { borderColor, backgroundColor }], children: /* @__PURE__ */ jsx(
1276
+ children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chipOutline, { borderColor, backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1263
1277
  ChipContent,
1264
1278
  {
1265
1279
  icon: option.icon,
1266
1280
  label: option.label,
1267
- textStyle: [chipStyles.chipText, chipStyles.chipTextOutline, { color: textColor }]
1281
+ numberOfLines: layout.numberOfLines,
1282
+ textStyle: [chipStyles.chipText, chipStyles.chipTextOutline, { color: textColor }, layout.textStyle]
1268
1283
  }
1269
1284
  ) })
1270
1285
  }
@@ -1274,6 +1289,7 @@ function SolidChip(props) {
1274
1289
  const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
1275
1290
  const backgroundColor = selected ? colors.primary : TRANSPARENT_COLOR;
1276
1291
  const textColor = selected ? colors.onPrimary : colors.textStrong;
1292
+ const layout = chipLabelLayout(option.labelWrap);
1277
1293
  const rovingTabStop = { tabIndex: props.tabIndex };
1278
1294
  return /* @__PURE__ */ jsx(
1279
1295
  TouchableOpacity,
@@ -1287,10 +1303,19 @@ function SolidChip(props) {
1287
1303
  "aria-pressed": props.ariaPressed,
1288
1304
  disabled,
1289
1305
  hitSlop: CHIP_HIT_SLOP,
1306
+ style: layout.boxStyle,
1290
1307
  testID,
1291
1308
  onPress,
1292
1309
  ...rovingTabStop,
1293
- children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chip, { borderColor: colors.border, backgroundColor }], children: /* @__PURE__ */ jsx(ChipContent, { icon: option.icon, label: option.label, textStyle: [chipStyles.chipText, { color: textColor }] }) })
1310
+ children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chip, { borderColor: colors.border, backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1311
+ ChipContent,
1312
+ {
1313
+ icon: option.icon,
1314
+ label: option.label,
1315
+ numberOfLines: layout.numberOfLines,
1316
+ textStyle: [chipStyles.chipText, { color: textColor }, layout.textStyle]
1317
+ }
1318
+ ) })
1294
1319
  }
1295
1320
  );
1296
1321
  }
@@ -2723,12 +2748,6 @@ var styles22 = StyleSheet.create({
2723
2748
  sheetList: { maxHeight: SHEET_MAX_HEIGHT },
2724
2749
  empty: { padding: PANEL_PAD }
2725
2750
  });
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
- }
2732
2751
  function useReducedMotion() {
2733
2752
  const [reduced, setReduced] = useState(false);
2734
2753
  useEffect(() => {
@@ -2744,6 +2763,13 @@ function useReducedMotion() {
2744
2763
  }, []);
2745
2764
  return reduced;
2746
2765
  }
2766
+ function useRefocusOnClose(open, ref) {
2767
+ const wasOpen = useRef(false);
2768
+ useEffect(() => {
2769
+ if (wasOpen.current && !open) ref.current?.focus();
2770
+ wasOpen.current = open;
2771
+ }, [open, ref]);
2772
+ }
2747
2773
 
2748
2774
  // src/SearchSelect/utils/searchSelectModel.ts
2749
2775
  var MIN_QUERY = 1;
@@ -2821,6 +2847,7 @@ function resolveSelectMotion(width, reducedMotion) {
2821
2847
  }
2822
2848
  var CHEVRON = "\u25BE";
2823
2849
  var VALUE_GAP = 8;
2850
+ var NOTHING_ON_CLOSE = () => void 0;
2824
2851
  function SearchSelect(props) {
2825
2852
  const { options, value, onChange, accessibilityLabel, accessibilityHint, labels, testID, recentKey, renderLeading, renderDetail } = props;
2826
2853
  const { theme } = useUi();
@@ -2830,8 +2857,8 @@ function SearchSelect(props) {
2830
2857
  const { width } = useWindowDimensions();
2831
2858
  const motion = resolveSelectMotion(width, useReducedMotion());
2832
2859
  const recents = useRecentValues(recentKey ?? `search-select:${testID}`);
2833
- const refocus = useDeferredFocus(triggerRef);
2834
- const state = useSearchSelectState(options, recents, onChange, refocus);
2860
+ const state = useSearchSelectState(options, recents, onChange, NOTHING_ON_CLOSE);
2861
+ useRefocusOnClose(state.open, triggerRef);
2835
2862
  const selected = findOption(options, value);
2836
2863
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles23.anchor, children: [
2837
2864
  /* @__PURE__ */ jsxs(
@@ -2884,6 +2911,12 @@ function useOutsidePress(ref, onOutside) {
2884
2911
  return () => document.removeEventListener("pointerdown", onPointerDown, true);
2885
2912
  }, [ref, onOutside]);
2886
2913
  }
2914
+ var AFTER_SURFACE_UNMOUNT_MS = 0;
2915
+ function useDeferredFocus(ref) {
2916
+ return useCallback(() => {
2917
+ setTimeout(() => ref.current?.focus(), AFTER_SURFACE_UNMOUNT_MS);
2918
+ }, [ref]);
2919
+ }
2887
2920
 
2888
2921
  // src/CountryFlag/data/flagPalette.ts
2889
2922
  var FLAG_PALETTE = {
@@ -4039,6 +4072,6 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
4039
4072
  ] });
4040
4073
  }
4041
4074
 
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 };
4075
+ 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, chipLabelLayout, 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 };
4043
4076
  //# sourceMappingURL=index.mjs.map
4044
4077
  //# sourceMappingURL=index.mjs.map