@tmlmobilidade/ui 20250128.1225.12 → 20250128.1609.43
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 +99 -52
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/common/Combobox/index.d.ts +20 -7
- package/dist/cjs/types/src/components/common/index.d.ts +1 -1
- package/dist/esm/index.js +95 -48
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/common/Combobox/index.d.ts +20 -7
- package/dist/esm/types/src/components/common/index.d.ts +1 -1
- package/dist/index.d.ts +23 -11
- package/dist/styles.css +9 -7
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -778,7 +778,7 @@ function getValueAtPath(obj, path) {
|
|
|
778
778
|
}
|
|
779
779
|
|
|
780
780
|
/* * */
|
|
781
|
-
function Component$
|
|
781
|
+
function Component$3({ className, icon, children, onClick, target, type = 'button', variant = 'primary', disabled, textTransform = 'none', ...props }) {
|
|
782
782
|
//
|
|
783
783
|
const btnClass = cn(className, styles$l.button, !disabled && {
|
|
784
784
|
[styles$l.danger]: variant === 'danger',
|
|
@@ -806,7 +806,7 @@ function SegmentedControl({ ...props }) {
|
|
|
806
806
|
return jsxRuntimeExports.jsx(core.SegmentedControl, { ...props, className: cn(props.className), classNames: { ...styles$j, ...props.classNames }, style: { width: props.fullWidth ? '100%' : undefined } });
|
|
807
807
|
}
|
|
808
808
|
|
|
809
|
-
function Component$
|
|
809
|
+
function Component$2({ error, validation, value, classNames, ...props }) {
|
|
810
810
|
//
|
|
811
811
|
//
|
|
812
812
|
// A. Setup variables
|
|
@@ -828,7 +828,7 @@ function Component$3({ error, validation, value, classNames, ...props }) {
|
|
|
828
828
|
return (jsxRuntimeExports.jsx(core.TextInput, { classNames: classNames, error: error ? error : isValid ? '' : error, rightSection: props.tooltip && renderTooltip(props.tooltip), value: value, ...props }));
|
|
829
829
|
}
|
|
830
830
|
|
|
831
|
-
function Component$
|
|
831
|
+
function Component$1({ error, validation, value, classNames, ...props }) {
|
|
832
832
|
//
|
|
833
833
|
//
|
|
834
834
|
// A. Setup variables
|
|
@@ -850,7 +850,7 @@ function Component$2({ error, validation, value, classNames, ...props }) {
|
|
|
850
850
|
return (jsxRuntimeExports.jsx(core.PasswordInput, { classNames: classNames, error: error ? error : isValid ? '' : error, rightSection: props.tooltip && renderTooltip(props.tooltip), value: value, ...props }));
|
|
851
851
|
}
|
|
852
852
|
|
|
853
|
-
function Component
|
|
853
|
+
function Component({ classNames, ...props }) {
|
|
854
854
|
//
|
|
855
855
|
//
|
|
856
856
|
// A. Render components
|
|
@@ -859,76 +859,116 @@ function Component$1({ classNames, ...props }) {
|
|
|
859
859
|
|
|
860
860
|
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","dropdownWrapper":"styles-module_dropdownWrapper__guQYa"};
|
|
861
861
|
|
|
862
|
-
function
|
|
863
|
-
|
|
862
|
+
function ComboboxComponent(props) {
|
|
863
|
+
const { multiple = false, searchable = false, autoComplete = false, onChange, data = [], clearable = false, label, description, fullWidth = false, className, ...rest } = props;
|
|
864
|
+
// Setup Combobox store
|
|
864
865
|
const combobox = core.useCombobox({
|
|
865
866
|
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
866
867
|
onDropdownOpen: () => combobox.updateSelectedOptionIndex('active'),
|
|
867
868
|
});
|
|
868
|
-
|
|
869
|
+
// Define state with conditional types
|
|
870
|
+
const [value, setValue] = React.useState(props.value || (clearable ? undefined : multiple ? [] : undefined));
|
|
869
871
|
const [search, setSearch] = React.useState('');
|
|
870
|
-
//
|
|
872
|
+
// Reset value when props.value changes
|
|
871
873
|
React.useEffect(() => {
|
|
872
874
|
resetValue(props.value);
|
|
873
|
-
}, [multiple]);
|
|
874
|
-
//
|
|
875
|
+
}, [multiple, props.value]);
|
|
876
|
+
// Helper functions
|
|
877
|
+
const getValue = (val) => typeof val === 'string' ? val : val.value;
|
|
878
|
+
const getLabel = (val) => typeof val === 'string' ? val : val.label;
|
|
879
|
+
/**
|
|
880
|
+
* Resets the value based on initialValue or default state.
|
|
881
|
+
*/
|
|
875
882
|
const resetValue = (initialValue) => {
|
|
876
|
-
|
|
883
|
+
const newValue = initialValue || (multiple ? [] : undefined);
|
|
884
|
+
setValue(newValue);
|
|
877
885
|
setSearch('');
|
|
886
|
+
onChange?.(newValue); // Type assertion handled via discriminated union
|
|
878
887
|
};
|
|
879
|
-
|
|
888
|
+
/**
|
|
889
|
+
* Updates the current value based on selection.
|
|
890
|
+
*/
|
|
891
|
+
function updateValue(val) {
|
|
880
892
|
if (multiple && Array.isArray(value)) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
893
|
+
let updatedValue;
|
|
894
|
+
if (value.some(v => getValue(v) === getValue(val))) {
|
|
895
|
+
updatedValue = value.filter((v) => getValue(v) !== getValue(val));
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
updatedValue = [...value, val];
|
|
899
|
+
}
|
|
900
|
+
setValue(updatedValue);
|
|
901
|
+
onChange?.(updatedValue); // Type assertion handled via discriminated union
|
|
888
902
|
}
|
|
889
903
|
else {
|
|
890
|
-
|
|
891
|
-
|
|
904
|
+
const newValue = val;
|
|
905
|
+
setSearch(searchable ? getLabel(val) : '');
|
|
906
|
+
setValue(newValue);
|
|
907
|
+
onChange?.(newValue); // Type assertion handled via discriminated union
|
|
892
908
|
}
|
|
893
|
-
}
|
|
894
|
-
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Removes a specified value from the selection.
|
|
912
|
+
*/
|
|
913
|
+
function removeValue(val) {
|
|
895
914
|
if (multiple && Array.isArray(value)) {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
return prev.filter((v) => v !== val);
|
|
900
|
-
});
|
|
915
|
+
const updatedValue = value.filter((v) => getValue(v) !== getValue(val));
|
|
916
|
+
setValue(updatedValue);
|
|
917
|
+
onChange?.(updatedValue); // Type assertion handled via discriminated union
|
|
901
918
|
}
|
|
902
919
|
else {
|
|
903
|
-
setValue(
|
|
920
|
+
setValue(undefined);
|
|
921
|
+
onChange?.(undefined);
|
|
904
922
|
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Filters data based on search input.
|
|
926
|
+
*/
|
|
927
|
+
function filterData() {
|
|
928
|
+
return searchable ? data.filter((item) => typeof item === 'string' ?
|
|
929
|
+
item.toLowerCase().includes(search.trim().toLowerCase()) :
|
|
930
|
+
item.label.toLowerCase().includes(search.trim().toLowerCase())) : data;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Handles changes in the search input field.
|
|
934
|
+
*/
|
|
935
|
+
function handleSearchChange(event) {
|
|
908
936
|
const inputValue = event.currentTarget.value;
|
|
909
937
|
setSearch(inputValue);
|
|
910
938
|
combobox.openDropdown();
|
|
911
939
|
combobox.updateSelectedOptionIndex();
|
|
912
|
-
}
|
|
913
|
-
//
|
|
914
|
-
|
|
915
|
-
if (clearable && value && value.length > 0) {
|
|
940
|
+
}
|
|
941
|
+
// Render Clear Button
|
|
942
|
+
function renderClearButton() {
|
|
943
|
+
if (clearable && value && (Array.isArray(value) ? value.length > 0 : true)) {
|
|
916
944
|
return (jsxRuntimeExports.jsx(core.ActionIcon, { variant: "transparent", onClick: () => resetValue(), "aria-label": "Clear value", style: { cursor: 'pointer' }, className: styles$i.icon, children: jsxRuntimeExports.jsx(iconsReact.IconX, { size: 24 }) }));
|
|
917
945
|
}
|
|
918
946
|
return jsxRuntimeExports.jsx(iconsReact.IconCaretDownFilled, { size: 24, className: styles$i.icon });
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
947
|
+
}
|
|
948
|
+
// Render Selected Values as Pills
|
|
949
|
+
function renderValues() {
|
|
950
|
+
if (multiple && Array.isArray(value)) {
|
|
951
|
+
return value.map((item) => (jsxRuntimeExports.jsx(core.Pill, { className: styles$i.pill, withRemoveButton: true, onRemove: () => removeValue(item), children: jsxRuntimeExports.jsx("span", { children: getLabel(item) }) }, getValue(item))));
|
|
952
|
+
}
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
// Render Combobox Options
|
|
956
|
+
function renderOptions() {
|
|
957
|
+
const filtered = filterData();
|
|
958
|
+
return filtered.map((item) => (jsxRuntimeExports.jsx(core.Combobox.Option, { value: getValue(item), active: Array.isArray(value) && value.some(v => getValue(v) === getValue(item)), children: jsxRuntimeExports.jsxs(core.Group, { gap: "sm", children: [multiple && Array.isArray(value) && value.some(v => getValue(v) === getValue(item)) && jsxRuntimeExports.jsx(core.CheckIcon, { size: 12 }), jsxRuntimeExports.jsx("span", { children: getLabel(item) })] }) }, getValue(item))));
|
|
959
|
+
}
|
|
960
|
+
// Render Input Field
|
|
961
|
+
function renderInput() {
|
|
925
962
|
if (multiple) {
|
|
926
963
|
return (jsxRuntimeExports.jsx(core.Combobox.DropdownTarget, { children: jsxRuntimeExports.jsx(core.PillsInput, { onClick: () => combobox.openDropdown(), className: cn(styles$i.input, styles$i.pillInputWrapper), children: jsxRuntimeExports.jsxs(core.Pill.Group, { style: { marginRight: '25px' }, children: [renderValues(), jsxRuntimeExports.jsx(core.Combobox.EventsTarget, { children: jsxRuntimeExports.jsx(core.PillsInput.Field, { style: { backgroundColor: 'transparent' }, type: searchable ? 'visible' : 'hidden', value: search, placeholder: "Search values", onFocus: () => combobox.openDropdown(), onBlur: () => combobox.closeDropdown(), onChange: handleSearchChange, onKeyDown: (event) => {
|
|
927
964
|
if (event.key === 'Backspace' &&
|
|
928
965
|
!search &&
|
|
929
966
|
Array.isArray(value) &&
|
|
930
967
|
value.length > 0) {
|
|
931
|
-
|
|
968
|
+
const lastValue = value[value.length - 1];
|
|
969
|
+
if (lastValue) {
|
|
970
|
+
removeValue(lastValue);
|
|
971
|
+
}
|
|
932
972
|
}
|
|
933
973
|
} }) }), jsxRuntimeExports.jsx("div", { className: styles$i.pillClearButton, children: renderClearButton() })] }) }) }));
|
|
934
974
|
}
|
|
@@ -938,9 +978,16 @@ function Component({ multiple = false, searchable = false, autoComplete = false,
|
|
|
938
978
|
}, 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: () => {
|
|
939
979
|
combobox.closeDropdown();
|
|
940
980
|
setSearch(value?.toString() || '');
|
|
941
|
-
}, rightSection: renderClearButton(), rightSectionPointerEvents: value === null ? 'none' : 'all', children:
|
|
942
|
-
|
|
943
|
-
|
|
981
|
+
}, rightSection: renderClearButton(), rightSectionPointerEvents: value === null ? 'none' : 'all', children: Array.isArray(value)
|
|
982
|
+
? value.map((item) => getLabel(item)).join(', ')
|
|
983
|
+
: typeof value === 'string'
|
|
984
|
+
? getLabel(value)
|
|
985
|
+
: (jsxRuntimeExports.jsx(core.Input.Placeholder, { className: styles$i.placeholder, children: "Pick value" })) })) }));
|
|
986
|
+
}
|
|
987
|
+
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 }), jsxRuntimeExports.jsxs(core.Combobox, { store: combobox, onOptionSubmit: (val) => {
|
|
988
|
+
const selectedItem = data.find(item => getValue(item) === val) || val;
|
|
989
|
+
updateValue(selectedItem);
|
|
990
|
+
}, withinPortal: false, ...rest, children: [renderInput(), jsxRuntimeExports.jsx(core.Combobox.Dropdown, { className: styles$i.dropdownWrapper, children: jsxRuntimeExports.jsx(core.Combobox.Options, { children: renderOptions().length > 0 ? (renderOptions()) : (jsxRuntimeExports.jsx(core.Combobox.Empty, { children: "Nothing found..." })) }) })] })] }));
|
|
944
991
|
}
|
|
945
992
|
|
|
946
993
|
var styles$h = {"button":"styles-module_button__fQIgs","fontxs":"styles-module_fontxs__c61kh","fontsm":"styles-module_fontsm__zi0bq","fontbase":"styles-module_fontbase__Uzeoy","fontlg":"styles-module_fontlg__TfMwu","fontxl":"styles-module_fontxl__4IxFS","tag":"styles-module_tag__HOLQE","pill":"styles-module_pill__VAXc-","fullWidth":"styles-module_fullWidth__zWbR4","primary":"styles-module_primary__HWgQU","secondary":"styles-module_secondary__UOKnw","muted":"styles-module_muted__fA0Fl","disabled":"styles-module_disabled__EKMKd","danger":"styles-module_danger__gZERs","info":"styles-module_info__b-gyN","success":"styles-module_success__mRhfk","warning":"styles-module_warning__G977Z","active":"styles-module_active__5pkXl"};
|
|
@@ -1447,7 +1494,7 @@ function DataTableTitle({ search, title }) {
|
|
|
1447
1494
|
};
|
|
1448
1495
|
//
|
|
1449
1496
|
// C. Render Components
|
|
1450
|
-
return (jsxRuntimeExports.jsxs("div", { className: styles$1.root, children: [jsxRuntimeExports.jsx("div", { className: styles$1.title, children: title && title }), search && !search.hidden && (jsxRuntimeExports.jsx("div", { className: styles$1.filters, children: jsxRuntimeExports.jsx(Component$
|
|
1497
|
+
return (jsxRuntimeExports.jsxs("div", { className: styles$1.root, children: [jsxRuntimeExports.jsx("div", { className: styles$1.title, children: title && title }), search && !search.hidden && (jsxRuntimeExports.jsx("div", { className: styles$1.filters, children: jsxRuntimeExports.jsx(Component$2, { onChange: handleSearchChange, placeholder: search.placeholder, value: searchQuery }) }))] }));
|
|
1451
1498
|
}
|
|
1452
1499
|
|
|
1453
1500
|
var styles = {"root":"styles-module_root__AStX6","tableWrapper":"styles-module_tableWrapper__ByR84","table":"styles-module_table__IKm6A","body":"styles-module_body__Ou1Rp"};
|
|
@@ -1618,16 +1665,16 @@ const useToast = new Toast();
|
|
|
1618
1665
|
|
|
1619
1666
|
exports.ActionIcon = ActionIcon;
|
|
1620
1667
|
exports.Badge = Badge;
|
|
1621
|
-
exports.Button = Component$
|
|
1668
|
+
exports.Button = Component$3;
|
|
1622
1669
|
exports.CMIcon = CMIcon;
|
|
1623
1670
|
exports.CMLogo = CMLogo;
|
|
1624
1671
|
exports.Checkbox = Checkbox;
|
|
1625
|
-
exports.Combobox =
|
|
1672
|
+
exports.Combobox = ComboboxComponent;
|
|
1626
1673
|
exports.DataTable = DataTable;
|
|
1627
1674
|
exports.DateTimePicker = DateTimePicker;
|
|
1628
1675
|
exports.Grid = Grid;
|
|
1629
1676
|
exports.Menu = Menu;
|
|
1630
|
-
exports.PasswordInput = Component$
|
|
1677
|
+
exports.PasswordInput = Component$1;
|
|
1631
1678
|
exports.Section = Section;
|
|
1632
1679
|
exports.SegmentedControl = SegmentedControl;
|
|
1633
1680
|
exports.Sidebar = Sidebar;
|
|
@@ -1639,8 +1686,8 @@ exports.TMLogo = TMLogo;
|
|
|
1639
1686
|
exports.TMLogoDark = TMLogoDark;
|
|
1640
1687
|
exports.TMLogoLight = TMLogoLight;
|
|
1641
1688
|
exports.Text = Text;
|
|
1642
|
-
exports.TextArea = Component
|
|
1643
|
-
exports.TextInput = Component$
|
|
1689
|
+
exports.TextArea = Component;
|
|
1690
|
+
exports.TextInput = Component$2;
|
|
1644
1691
|
exports.ThemeDark = ThemeDark;
|
|
1645
1692
|
exports.ThemeLight = ThemeLight;
|
|
1646
1693
|
exports.ThemeProvider = ThemeProvider;
|