@homebound/beam 2.405.0 → 2.406.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.cjs CHANGED
@@ -10593,6 +10593,7 @@ function ComboBoxBase(props) {
10593
10593
  fullWidth = fieldProps?.fullWidth ?? false,
10594
10594
  onSearch,
10595
10595
  onAddNew,
10596
+ autoSort = true,
10596
10597
  ...otherProps
10597
10598
  } = props;
10598
10599
  const labelStyle = otherProps.labelStyle ?? fieldProps?.labelStyle ?? "above";
@@ -10615,11 +10616,11 @@ function ComboBoxBase(props) {
10615
10616
  [unsetLabel, getOptionLabel]
10616
10617
  );
10617
10618
  const options = (0, import_react46.useMemo)(
10618
- () => initializeOptions(propOptions, getOptionValue, unsetLabel, !!onAddNew),
10619
+ () => initializeOptions(propOptions, getOptionValue, getOptionLabel, unsetLabel, !!onAddNew, autoSort),
10619
10620
  // If the caller is using { current, load, options }, memoize on only `current` and `options` values.
10620
10621
  // ...and don't bother on memoizing on getOptionValue b/c it's basically always a lambda
10621
10622
  // eslint-disable-next-line react-hooks/exhaustive-deps
10622
- Array.isArray(propOptions) ? [propOptions, unsetLabel, onAddNew] : [propOptions.current, propOptions.options, unsetLabel, onAddNew]
10623
+ Array.isArray(propOptions) ? [propOptions, unsetLabel, onAddNew, autoSort] : [propOptions.current, propOptions.options, unsetLabel, onAddNew, autoSort]
10623
10624
  );
10624
10625
  const values = (0, import_react46.useMemo)(() => propValues ?? [], [propValues]);
10625
10626
  const inputStylePalette = (0, import_react46.useMemo)(() => propsInputStylePalette, [propsInputStylePalette]);
@@ -10839,17 +10840,18 @@ function ComboBoxBase(props) {
10839
10840
  function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, readOnly) {
10840
10841
  return selectedOptions.length === 1 ? getOptionLabel(selectedOptions[0]) : readOnly && selectedOptions.length > 0 ? selectedOptions.map(getOptionLabel).join(", ") : multiselect && selectedOptions.length === 0 ? nothingSelectedText : "";
10841
10842
  }
10842
- function initializeOptions(optionsOrLoad, getOptionValue, unsetLabel, addNew) {
10843
- const opts = [];
10843
+ function initializeOptions(optionsOrLoad, getOptionValue, getOptionLabel, unsetLabel, addNew, autoSort) {
10844
+ const result = [];
10844
10845
  if (unsetLabel) {
10845
- opts.push(unsetOption);
10846
+ result.push(unsetOption);
10846
10847
  }
10848
+ const userOptions = [];
10847
10849
  if (Array.isArray(optionsOrLoad)) {
10848
- opts.push(...optionsOrLoad);
10850
+ userOptions.push(...optionsOrLoad);
10849
10851
  } else {
10850
10852
  const { options, current } = optionsOrLoad;
10851
10853
  if (options) {
10852
- opts.push(...options);
10854
+ userOptions.push(...options);
10853
10855
  }
10854
10856
  if (current) {
10855
10857
  const toCheck = Array.isArray(current) ? current : [current];
@@ -10857,15 +10859,23 @@ function initializeOptions(optionsOrLoad, getOptionValue, unsetLabel, addNew) {
10857
10859
  const value = getOptionValue(current2);
10858
10860
  const found = options && options.find((o) => getOptionValue(o) === value);
10859
10861
  if (!found) {
10860
- opts.push(current2);
10862
+ userOptions.push(current2);
10861
10863
  }
10862
10864
  });
10863
10865
  }
10864
10866
  }
10867
+ result.push(...autoSort ? sortOptions(userOptions, getOptionLabel) : userOptions);
10865
10868
  if (addNew) {
10866
- opts.push(addNewOption);
10869
+ result.push(addNewOption);
10867
10870
  }
10868
- return opts;
10871
+ return result;
10872
+ }
10873
+ function sortOptions(options, getOptionLabel) {
10874
+ return [...options].sort((a, b) => {
10875
+ const labelA = getOptionLabel(a).toLowerCase();
10876
+ const labelB = getOptionLabel(b).toLowerCase();
10877
+ return labelA.localeCompare(labelB);
10878
+ });
10869
10879
  }
10870
10880
  var unsetOption = {};
10871
10881
  var addNewOption = { id: "new", name: "Add New" };
@@ -17611,6 +17621,7 @@ function Pagination(props) {
17611
17621
  options: pageOptions,
17612
17622
  value: pageSize,
17613
17623
  onSelect: (val) => set({ pageNumber: 1, pageSize: val }),
17624
+ autoSort: false,
17614
17625
  ...tid.pageSize
17615
17626
  }
17616
17627
  ) }),