@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 +21 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6493,6 +6493,7 @@ interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProps, Pres
|
|
|
6493
6493
|
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. `isUnsetOpt` is only defined for single SelectField */
|
|
6494
6494
|
getOptionMenuLabel?: (opt: O, isUnsetOpt?: boolean, isAddNewOption?: boolean) => string | ReactNode;
|
|
6495
6495
|
getOptionValue: (opt: O) => V;
|
|
6496
|
+
/** Returns the display label for an option. Used for rendering and for sorting when `autoSort` is enabled. */
|
|
6496
6497
|
getOptionLabel: (opt: O) => string;
|
|
6497
6498
|
/** The current value; it can be `undefined`, even if `V` cannot be. */
|
|
6498
6499
|
values: V[] | undefined;
|
|
@@ -6540,6 +6541,11 @@ interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProps, Pres
|
|
|
6540
6541
|
multiline?: boolean;
|
|
6541
6542
|
onSearch?: (search: string) => void;
|
|
6542
6543
|
onAddNew?: (v: string) => void;
|
|
6544
|
+
/**
|
|
6545
|
+
* When true (default), options are sorted alphabetically by their label.
|
|
6546
|
+
* Set to false to maintain the original order of options.
|
|
6547
|
+
*/
|
|
6548
|
+
autoSort?: boolean;
|
|
6543
6549
|
}
|
|
6544
6550
|
/** Allows lazy-loading select fields, which is useful for pages w/lots of fields the user may not actually use. */
|
|
6545
6551
|
type OptionsOrLoad<O> = O[] | {
|
package/dist/index.d.ts
CHANGED
|
@@ -6493,6 +6493,7 @@ interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProps, Pres
|
|
|
6493
6493
|
/** Renders `opt` in the dropdown menu, defaults to the `getOptionLabel` prop. `isUnsetOpt` is only defined for single SelectField */
|
|
6494
6494
|
getOptionMenuLabel?: (opt: O, isUnsetOpt?: boolean, isAddNewOption?: boolean) => string | ReactNode;
|
|
6495
6495
|
getOptionValue: (opt: O) => V;
|
|
6496
|
+
/** Returns the display label for an option. Used for rendering and for sorting when `autoSort` is enabled. */
|
|
6496
6497
|
getOptionLabel: (opt: O) => string;
|
|
6497
6498
|
/** The current value; it can be `undefined`, even if `V` cannot be. */
|
|
6498
6499
|
values: V[] | undefined;
|
|
@@ -6540,6 +6541,11 @@ interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProps, Pres
|
|
|
6540
6541
|
multiline?: boolean;
|
|
6541
6542
|
onSearch?: (search: string) => void;
|
|
6542
6543
|
onAddNew?: (v: string) => void;
|
|
6544
|
+
/**
|
|
6545
|
+
* When true (default), options are sorted alphabetically by their label.
|
|
6546
|
+
* Set to false to maintain the original order of options.
|
|
6547
|
+
*/
|
|
6548
|
+
autoSort?: boolean;
|
|
6543
6549
|
}
|
|
6544
6550
|
/** Allows lazy-loading select fields, which is useful for pages w/lots of fields the user may not actually use. */
|
|
6545
6551
|
type OptionsOrLoad<O> = O[] | {
|
package/dist/index.js
CHANGED
|
@@ -10230,6 +10230,7 @@ function ComboBoxBase(props) {
|
|
|
10230
10230
|
fullWidth = fieldProps?.fullWidth ?? false,
|
|
10231
10231
|
onSearch,
|
|
10232
10232
|
onAddNew,
|
|
10233
|
+
autoSort = true,
|
|
10233
10234
|
...otherProps
|
|
10234
10235
|
} = props;
|
|
10235
10236
|
const labelStyle = otherProps.labelStyle ?? fieldProps?.labelStyle ?? "above";
|
|
@@ -10252,11 +10253,11 @@ function ComboBoxBase(props) {
|
|
|
10252
10253
|
[unsetLabel, getOptionLabel]
|
|
10253
10254
|
);
|
|
10254
10255
|
const options = useMemo15(
|
|
10255
|
-
() => initializeOptions(propOptions, getOptionValue, unsetLabel, !!onAddNew),
|
|
10256
|
+
() => initializeOptions(propOptions, getOptionValue, getOptionLabel, unsetLabel, !!onAddNew, autoSort),
|
|
10256
10257
|
// If the caller is using { current, load, options }, memoize on only `current` and `options` values.
|
|
10257
10258
|
// ...and don't bother on memoizing on getOptionValue b/c it's basically always a lambda
|
|
10258
10259
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10259
|
-
Array.isArray(propOptions) ? [propOptions, unsetLabel, onAddNew] : [propOptions.current, propOptions.options, unsetLabel, onAddNew]
|
|
10260
|
+
Array.isArray(propOptions) ? [propOptions, unsetLabel, onAddNew, autoSort] : [propOptions.current, propOptions.options, unsetLabel, onAddNew, autoSort]
|
|
10260
10261
|
);
|
|
10261
10262
|
const values = useMemo15(() => propValues ?? [], [propValues]);
|
|
10262
10263
|
const inputStylePalette = useMemo15(() => propsInputStylePalette, [propsInputStylePalette]);
|
|
@@ -10476,17 +10477,18 @@ function ComboBoxBase(props) {
|
|
|
10476
10477
|
function getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, readOnly) {
|
|
10477
10478
|
return selectedOptions.length === 1 ? getOptionLabel(selectedOptions[0]) : readOnly && selectedOptions.length > 0 ? selectedOptions.map(getOptionLabel).join(", ") : multiselect && selectedOptions.length === 0 ? nothingSelectedText : "";
|
|
10478
10479
|
}
|
|
10479
|
-
function initializeOptions(optionsOrLoad, getOptionValue, unsetLabel, addNew) {
|
|
10480
|
-
const
|
|
10480
|
+
function initializeOptions(optionsOrLoad, getOptionValue, getOptionLabel, unsetLabel, addNew, autoSort) {
|
|
10481
|
+
const result = [];
|
|
10481
10482
|
if (unsetLabel) {
|
|
10482
|
-
|
|
10483
|
+
result.push(unsetOption);
|
|
10483
10484
|
}
|
|
10485
|
+
const userOptions = [];
|
|
10484
10486
|
if (Array.isArray(optionsOrLoad)) {
|
|
10485
|
-
|
|
10487
|
+
userOptions.push(...optionsOrLoad);
|
|
10486
10488
|
} else {
|
|
10487
10489
|
const { options, current } = optionsOrLoad;
|
|
10488
10490
|
if (options) {
|
|
10489
|
-
|
|
10491
|
+
userOptions.push(...options);
|
|
10490
10492
|
}
|
|
10491
10493
|
if (current) {
|
|
10492
10494
|
const toCheck = Array.isArray(current) ? current : [current];
|
|
@@ -10494,15 +10496,23 @@ function initializeOptions(optionsOrLoad, getOptionValue, unsetLabel, addNew) {
|
|
|
10494
10496
|
const value = getOptionValue(current2);
|
|
10495
10497
|
const found = options && options.find((o) => getOptionValue(o) === value);
|
|
10496
10498
|
if (!found) {
|
|
10497
|
-
|
|
10499
|
+
userOptions.push(current2);
|
|
10498
10500
|
}
|
|
10499
10501
|
});
|
|
10500
10502
|
}
|
|
10501
10503
|
}
|
|
10504
|
+
result.push(...autoSort ? sortOptions(userOptions, getOptionLabel) : userOptions);
|
|
10502
10505
|
if (addNew) {
|
|
10503
|
-
|
|
10506
|
+
result.push(addNewOption);
|
|
10504
10507
|
}
|
|
10505
|
-
return
|
|
10508
|
+
return result;
|
|
10509
|
+
}
|
|
10510
|
+
function sortOptions(options, getOptionLabel) {
|
|
10511
|
+
return [...options].sort((a, b) => {
|
|
10512
|
+
const labelA = getOptionLabel(a).toLowerCase();
|
|
10513
|
+
const labelB = getOptionLabel(b).toLowerCase();
|
|
10514
|
+
return labelA.localeCompare(labelB);
|
|
10515
|
+
});
|
|
10506
10516
|
}
|
|
10507
10517
|
var unsetOption = {};
|
|
10508
10518
|
var addNewOption = { id: "new", name: "Add New" };
|
|
@@ -17255,6 +17265,7 @@ function Pagination(props) {
|
|
|
17255
17265
|
options: pageOptions,
|
|
17256
17266
|
value: pageSize,
|
|
17257
17267
|
onSelect: (val) => set({ pageNumber: 1, pageSize: val }),
|
|
17268
|
+
autoSort: false,
|
|
17258
17269
|
...tid.pageSize
|
|
17259
17270
|
}
|
|
17260
17271
|
) }),
|