@onesaz/ui 0.3.4 → 0.3.5

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.d.ts CHANGED
@@ -678,8 +678,10 @@ interface ComboboxOption {
678
678
  label: string;
679
679
  disabled?: boolean;
680
680
  }
681
+ type ComboboxPrimitiveOption = string;
682
+ type ComboboxObjectOption = Record<string, unknown>;
681
683
  interface ComboboxSingleProps {
682
- options: ComboboxOption[];
684
+ options: ComboboxOption[] | ComboboxPrimitiveOption[] | ComboboxObjectOption[];
683
685
  value?: ComboboxOption | null;
684
686
  defaultValue?: ComboboxOption | null;
685
687
  onChange?: (value: ComboboxOption | null) => void;
@@ -693,9 +695,12 @@ interface ComboboxSingleProps {
693
695
  openOnFocus?: boolean;
694
696
  inputValue?: string;
695
697
  onInputChange?: (value: string) => void;
698
+ simpleOptions?: boolean;
699
+ labelKey?: string;
700
+ valueKey?: string;
696
701
  }
697
702
  interface ComboboxMultipleProps {
698
- options: ComboboxOption[];
703
+ options: ComboboxOption[] | ComboboxPrimitiveOption[] | ComboboxObjectOption[];
699
704
  value?: ComboboxOption[];
700
705
  defaultValue?: ComboboxOption[];
701
706
  onChange?: (value: ComboboxOption[]) => void;
@@ -713,6 +718,9 @@ interface ComboboxMultipleProps {
713
718
  selectAll?: boolean;
714
719
  /** Label for select-all option */
715
720
  selectAllLabel?: string;
721
+ simpleOptions?: boolean;
722
+ labelKey?: string;
723
+ valueKey?: string;
716
724
  /** Maximum number of items to display as chips before showing "+N more" */
717
725
  maxDisplayItems?: number;
718
726
  }
package/dist/index.js CHANGED
@@ -2975,6 +2975,23 @@ var Combobox = React30.forwardRef(
2975
2975
  openOnFocus = true,
2976
2976
  className
2977
2977
  } = props;
2978
+ const labelKey = props.labelKey ?? "label";
2979
+ const valueKey = props.valueKey ?? "value";
2980
+ const normalizedOptions = React30.useMemo(() => {
2981
+ return (options ?? []).map((option) => {
2982
+ if (typeof option === "string") {
2983
+ return { label: option, value: option };
2984
+ }
2985
+ const record = option;
2986
+ const maybeLabel = record[labelKey];
2987
+ const maybeValue = record[valueKey];
2988
+ return {
2989
+ label: typeof maybeLabel === "string" ? maybeLabel : String(maybeLabel ?? ""),
2990
+ value: typeof maybeValue === "string" ? maybeValue : String(maybeValue ?? ""),
2991
+ disabled: Boolean(option.disabled)
2992
+ };
2993
+ });
2994
+ }, [options, labelKey, valueKey]);
2978
2995
  const [open, setOpen] = React30.useState(false);
2979
2996
  const [internalSearch, setInternalSearch] = React30.useState("");
2980
2997
  const containerRef = React30.useRef(null);
@@ -2988,15 +3005,15 @@ var Combobox = React30.forwardRef(
2988
3005
  const multiValue = isMultiple ? props.value !== void 0 ? props.value : internalMultiValue : [];
2989
3006
  const search = props.inputValue !== void 0 ? props.inputValue : internalSearch;
2990
3007
  const filteredOptions = React30.useMemo(() => {
2991
- if (!search) return options;
2992
- return options.filter(
3008
+ if (!search) return normalizedOptions;
3009
+ return normalizedOptions.filter(
2993
3010
  (option) => option.label.toLowerCase().includes(search.toLowerCase())
2994
3011
  );
2995
- }, [options, search]);
3012
+ }, [normalizedOptions, search]);
2996
3013
  const selectedOptions = isMultiple ? multiValue : [];
2997
3014
  const selectableOptions = React30.useMemo(
2998
- () => options.filter((option) => !option.disabled),
2999
- [options]
3015
+ () => normalizedOptions.filter((option) => !option.disabled),
3016
+ [normalizedOptions]
3000
3017
  );
3001
3018
  const allSelected = isMultiple && selectableOptions.length > 0 && selectableOptions.every(
3002
3019
  (option) => multiValue.some((item) => item.value === option.value)