@tmlmobilidade/ui 20250129.1606.25 → 20250129.1656.11

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/cjs/index.js CHANGED
@@ -860,6 +860,15 @@ function Component({ classNames, ...props }) {
860
860
 
861
861
  var styles$i = {"wrapper":"styles-module_wrapper__7zsRX","input":"styles-module_input__kZP4l","placeholder":"styles-module_placeholder__uazW4","pillInputWrapper":"styles-module_pillInputWrapper__rtJzo","pillInputField":"styles-module_pillInputField__LYXhi","icon":"styles-module_icon__jXQ8R","pillClearButton":"styles-module_pillClearButton__RYrwJ","pill":"styles-module_pill__eWbVa","label":"styles-module_label__tB0Ce","description":"styles-module_description__KHjxV","error":"styles-module_error__fOsRf","dropdownWrapper":"styles-module_dropdownWrapper__guQYa"};
862
862
 
863
+ function parseComboboxItem(item) {
864
+ if (typeof item === 'string') {
865
+ return {
866
+ value: item,
867
+ label: item,
868
+ };
869
+ }
870
+ return item;
871
+ }
863
872
  function ComboboxComponent(props) {
864
873
  const { multiple = false, searchable = false, autoComplete = false, onChange, data = [], clearable = false, label, description, fullWidth = false, maxHeight = 200, className, error, ...rest } = props;
865
874
  // Setup Combobox store
@@ -892,7 +901,7 @@ function ComboboxComponent(props) {
892
901
  function updateValue(val) {
893
902
  if (multiple && Array.isArray(value)) {
894
903
  let updatedValue;
895
- if (value.some((v) => getValue(v) === getValue(val))) {
904
+ if (value.some((v) => v === val)) {
896
905
  updatedValue = value.filter((v) => v !== getValue(val));
897
906
  }
898
907
  else {
@@ -903,7 +912,10 @@ function ComboboxComponent(props) {
903
912
  }
904
913
  else {
905
914
  const newValue = val;
906
- setSearch(searchable ? getLabel(val) : '');
915
+ const itemData = data.find(dataItem => getValue(dataItem) === val);
916
+ if (!itemData)
917
+ return;
918
+ setSearch(searchable ? parseComboboxItem(itemData)?.label : '');
907
919
  setValue(newValue);
908
920
  onChange?.(newValue); // Type assertion handled via discriminated union
909
921
  }
@@ -957,7 +969,12 @@ function ComboboxComponent(props) {
957
969
  // Render Selected Values as Pills
958
970
  function renderValues() {
959
971
  if (multiple && Array.isArray(value)) {
960
- return value.map((item) => (jsxRuntimeExports.jsx(core.Pill, { className: styles$i.pill, withRemoveButton: true, onRemove: () => removeValue(item), children: jsxRuntimeExports.jsx("span", { children: getLabel(item) }) }, item)));
972
+ return value.map((item) => {
973
+ const itemData = data.find(dataItem => getValue(dataItem) === item);
974
+ if (!itemData)
975
+ return null;
976
+ return (jsxRuntimeExports.jsx(core.Pill, { className: styles$i.pill, withRemoveButton: true, onRemove: () => removeValue(item), children: jsxRuntimeExports.jsx("span", { children: parseComboboxItem(itemData)?.label }) }, item));
977
+ });
961
978
  }
962
979
  return null;
963
980
  }
@@ -984,17 +1001,17 @@ function ComboboxComponent(props) {
984
1001
  }
985
1002
  } }) }), jsxRuntimeExports.jsx("div", { className: styles$i.pillClearButton, children: renderClearButton() })] }) }) }));
986
1003
  }
1004
+ const itemData = data.find(dataItem => getValue(dataItem) === value);
987
1005
  return (jsxRuntimeExports.jsx(core.Combobox.Target, { children: searchable ? (jsxRuntimeExports.jsx(core.InputBase, { className: styles$i.input, type: "text", value: search, rightSection: renderClearButton(), rightSectionPointerEvents: value === null ? 'none' : 'all', onClick: () => combobox.openDropdown(), onFocus: () => combobox.openDropdown(), onBlur: () => {
988
1006
  combobox.closeDropdown();
989
- setSearch(value?.toString() || '');
1007
+ setSearch(itemData ? parseComboboxItem(itemData)?.label : '');
990
1008
  }, onChange: handleSearchChange, placeholder: "Search value" })) : (jsxRuntimeExports.jsx(core.InputBase, { className: styles$i.input, component: "button", type: "button", pointer: true, onClick: () => combobox.openDropdown(), onFocus: () => combobox.openDropdown(), onBlur: () => {
991
1009
  combobox.closeDropdown();
992
1010
  setSearch(value?.toString() || '');
993
- }, rightSection: renderClearButton(), rightSectionPointerEvents: value === null ? 'none' : 'all', children: Array.isArray(value) ? (value.map((item) => getLabel(item)).join(', ')) : typeof value === 'string' ? (getLabel(value)) : (jsxRuntimeExports.jsx(core.Input.Placeholder, { className: styles$i.placeholder, children: "Pick value" })) })) }));
1011
+ }, rightSection: renderClearButton(), rightSectionPointerEvents: value === null ? 'none' : 'all', children: itemData ? parseComboboxItem(itemData)?.label : jsxRuntimeExports.jsx(core.Input.Placeholder, { className: styles$i.placeholder, children: "Pick value" }) })) }));
994
1012
  }
995
1013
  return (jsxRuntimeExports.jsxs("div", { className: cn(styles$i.wrapper, className), style: { width: fullWidth ? '100%' : undefined }, children: [label && jsxRuntimeExports.jsx("label", { className: styles$i.label, children: label }), description && jsxRuntimeExports.jsx("p", { className: styles$i.description, children: description }), error && jsxRuntimeExports.jsx("p", { className: styles$i.error, children: error }), jsxRuntimeExports.jsxs(core.Combobox, { store: combobox, onOptionSubmit: (val) => {
996
- const selectedItem = data.find((item) => getValue(item) === val) || val;
997
- updateValue(selectedItem);
1014
+ updateValue(val);
998
1015
  }, withinPortal: false, ...rest, children: [renderInput(), jsxRuntimeExports.jsx(core.Combobox.Dropdown, { className: styles$i.dropdownWrapper, children: jsxRuntimeExports.jsx(core.Combobox.Options, { style: { overflowY: 'scroll', maxHeight }, children: filterData().length > 0 ? (renderOptions()) : (jsxRuntimeExports.jsx(core.Combobox.Empty, { children: "Nothing found..." })) }) })] })] }));
999
1016
  }
1000
1017