@charlesgomes/leafcode-shared-lib-react 1.0.76 → 1.0.77
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.mts +32 -16
- package/dist/index.d.ts +32 -16
- package/dist/index.js +63 -50
- package/dist/index.mjs +63 -50
- package/dist/styles/input.css +2 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import react__default, { ReactNode as ReactNode$1, InputHTMLAttributes } from 'react';
|
|
3
|
+
import react__default, { ReactNode as ReactNode$1, InputHTMLAttributes, JSX } from 'react';
|
|
4
4
|
import { FieldError } from 'react-hook-form';
|
|
5
5
|
import { FilterMatchMode } from 'primereact/api';
|
|
6
6
|
export { FilterMatchMode, FilterOperator } from 'primereact/api';
|
|
@@ -18,7 +18,7 @@ interface ButtonProps {
|
|
|
18
18
|
}
|
|
19
19
|
declare function Button({ disabled, loading, color, type, onClick, title, ...rest }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
20
20
|
|
|
21
|
-
interface InputProps
|
|
21
|
+
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
22
22
|
name: string;
|
|
23
23
|
label?: string | ReactNode$1;
|
|
24
24
|
error?: FieldError;
|
|
@@ -29,7 +29,7 @@ interface InputProps$1 extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
|
29
29
|
validationMode?: "default" | "restricted";
|
|
30
30
|
showPasswordToggle?: boolean;
|
|
31
31
|
}
|
|
32
|
-
declare const Input: react.ForwardRefExoticComponent<InputProps
|
|
32
|
+
declare const Input: react.ForwardRefExoticComponent<InputProps & react.RefAttributes<HTMLInputElement>>;
|
|
33
33
|
|
|
34
34
|
interface TextAreaProps {
|
|
35
35
|
name: string;
|
|
@@ -94,26 +94,42 @@ interface Props {
|
|
|
94
94
|
}
|
|
95
95
|
declare function ModalBase({ show, onHide, onAction, title, children, loading, btnCancel, btnSuccess, type, disabledBtnSuccess, colors, fonts, modalMaxWidth, }: Props): react_jsx_runtime.JSX.Element;
|
|
96
96
|
|
|
97
|
-
interface PaginatedResponse$1 {
|
|
98
|
-
items:
|
|
97
|
+
interface PaginatedResponse$1<T> {
|
|
98
|
+
items: T[];
|
|
99
99
|
totalPages: number;
|
|
100
100
|
totalCount: number;
|
|
101
101
|
}
|
|
102
|
-
interface
|
|
102
|
+
interface ServiceParams {
|
|
103
|
+
page: number;
|
|
104
|
+
size: number;
|
|
105
|
+
search: string;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
}
|
|
108
|
+
type QueryMode<T> = {
|
|
109
|
+
queryKey: string;
|
|
110
|
+
mutationFn: (page: number, size: number, search: string) => Promise<PaginatedResponse$1<T>>;
|
|
111
|
+
service?: never;
|
|
112
|
+
};
|
|
113
|
+
type ServiceMode<T> = {
|
|
114
|
+
service: (params: ServiceParams) => Promise<PaginatedResponse$1<T>>;
|
|
115
|
+
queryKey?: never;
|
|
116
|
+
mutationFn?: never;
|
|
117
|
+
};
|
|
118
|
+
type InputAutoCompleteProps<T> = (QueryMode<T> | ServiceMode<T>) & Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> & {
|
|
103
119
|
name: string;
|
|
104
120
|
label?: string;
|
|
105
121
|
value?: string;
|
|
106
|
-
onChange?: (value: any) => void;
|
|
107
|
-
onSelect: (item: any) => void;
|
|
108
122
|
error?: FieldError;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
getLabel?: (item: T) => string;
|
|
124
|
+
renderOption: (item: T) => ReactNode$1;
|
|
125
|
+
onSelect: (item: T | null) => void;
|
|
126
|
+
onChange?: (value: string) => void;
|
|
112
127
|
isUppercaseLabel?: boolean;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
declare const InputAutoComplete: <T>(props: InputAutoCompleteProps<T> & {
|
|
131
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
132
|
+
}) => JSX.Element;
|
|
117
133
|
|
|
118
134
|
type IDataTableProps<T extends object> = {
|
|
119
135
|
queryKey: string;
|
|
@@ -343,4 +359,4 @@ declare const LeafcodeThemeProvider: ({ children, theme, }: LeafcodeThemeProvide
|
|
|
343
359
|
|
|
344
360
|
declare const defaultTheme: LeafcodeTheme;
|
|
345
361
|
|
|
346
|
-
export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, FilterMatchModeSelect, type IDataTableProps, type IItemProps, Input, InputAutoComplete, InputSelect, LeafcodeThemeProvider, ModalBase, SelectFilterTemplate, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
|
|
362
|
+
export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, FilterMatchModeSelect, type IDataTableProps, type IItemProps, Input, InputAutoComplete, type InputAutoCompleteProps, InputSelect, LeafcodeThemeProvider, ModalBase, type PaginatedResponse$1 as PaginatedResponse, SelectFilterTemplate, type ServiceParams, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import react__default, { ReactNode as ReactNode$1, InputHTMLAttributes } from 'react';
|
|
3
|
+
import react__default, { ReactNode as ReactNode$1, InputHTMLAttributes, JSX } from 'react';
|
|
4
4
|
import { FieldError } from 'react-hook-form';
|
|
5
5
|
import { FilterMatchMode } from 'primereact/api';
|
|
6
6
|
export { FilterMatchMode, FilterOperator } from 'primereact/api';
|
|
@@ -18,7 +18,7 @@ interface ButtonProps {
|
|
|
18
18
|
}
|
|
19
19
|
declare function Button({ disabled, loading, color, type, onClick, title, ...rest }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
20
20
|
|
|
21
|
-
interface InputProps
|
|
21
|
+
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
22
22
|
name: string;
|
|
23
23
|
label?: string | ReactNode$1;
|
|
24
24
|
error?: FieldError;
|
|
@@ -29,7 +29,7 @@ interface InputProps$1 extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
|
29
29
|
validationMode?: "default" | "restricted";
|
|
30
30
|
showPasswordToggle?: boolean;
|
|
31
31
|
}
|
|
32
|
-
declare const Input: react.ForwardRefExoticComponent<InputProps
|
|
32
|
+
declare const Input: react.ForwardRefExoticComponent<InputProps & react.RefAttributes<HTMLInputElement>>;
|
|
33
33
|
|
|
34
34
|
interface TextAreaProps {
|
|
35
35
|
name: string;
|
|
@@ -94,26 +94,42 @@ interface Props {
|
|
|
94
94
|
}
|
|
95
95
|
declare function ModalBase({ show, onHide, onAction, title, children, loading, btnCancel, btnSuccess, type, disabledBtnSuccess, colors, fonts, modalMaxWidth, }: Props): react_jsx_runtime.JSX.Element;
|
|
96
96
|
|
|
97
|
-
interface PaginatedResponse$1 {
|
|
98
|
-
items:
|
|
97
|
+
interface PaginatedResponse$1<T> {
|
|
98
|
+
items: T[];
|
|
99
99
|
totalPages: number;
|
|
100
100
|
totalCount: number;
|
|
101
101
|
}
|
|
102
|
-
interface
|
|
102
|
+
interface ServiceParams {
|
|
103
|
+
page: number;
|
|
104
|
+
size: number;
|
|
105
|
+
search: string;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
}
|
|
108
|
+
type QueryMode<T> = {
|
|
109
|
+
queryKey: string;
|
|
110
|
+
mutationFn: (page: number, size: number, search: string) => Promise<PaginatedResponse$1<T>>;
|
|
111
|
+
service?: never;
|
|
112
|
+
};
|
|
113
|
+
type ServiceMode<T> = {
|
|
114
|
+
service: (params: ServiceParams) => Promise<PaginatedResponse$1<T>>;
|
|
115
|
+
queryKey?: never;
|
|
116
|
+
mutationFn?: never;
|
|
117
|
+
};
|
|
118
|
+
type InputAutoCompleteProps<T> = (QueryMode<T> | ServiceMode<T>) & Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> & {
|
|
103
119
|
name: string;
|
|
104
120
|
label?: string;
|
|
105
121
|
value?: string;
|
|
106
|
-
onChange?: (value: any) => void;
|
|
107
|
-
onSelect: (item: any) => void;
|
|
108
122
|
error?: FieldError;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
getLabel?: (item: T) => string;
|
|
124
|
+
renderOption: (item: T) => ReactNode$1;
|
|
125
|
+
onSelect: (item: T | null) => void;
|
|
126
|
+
onChange?: (value: string) => void;
|
|
112
127
|
isUppercaseLabel?: boolean;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
};
|
|
130
|
+
declare const InputAutoComplete: <T>(props: InputAutoCompleteProps<T> & {
|
|
131
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
132
|
+
}) => JSX.Element;
|
|
117
133
|
|
|
118
134
|
type IDataTableProps<T extends object> = {
|
|
119
135
|
queryKey: string;
|
|
@@ -343,4 +359,4 @@ declare const LeafcodeThemeProvider: ({ children, theme, }: LeafcodeThemeProvide
|
|
|
343
359
|
|
|
344
360
|
declare const defaultTheme: LeafcodeTheme;
|
|
345
361
|
|
|
346
|
-
export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, FilterMatchModeSelect, type IDataTableProps, type IItemProps, Input, InputAutoComplete, InputSelect, LeafcodeThemeProvider, ModalBase, SelectFilterTemplate, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
|
|
362
|
+
export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, FilterMatchModeSelect, type IDataTableProps, type IItemProps, Input, InputAutoComplete, type InputAutoCompleteProps, InputSelect, LeafcodeThemeProvider, ModalBase, type PaginatedResponse$1 as PaginatedResponse, SelectFilterTemplate, type ServiceParams, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
|
package/dist/index.js
CHANGED
|
@@ -723,23 +723,24 @@ LoadingSpinner.displayName = "LoadingSpinner";
|
|
|
723
723
|
// src/components/Input/InputAutocomplete.tsx
|
|
724
724
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
725
725
|
var PAGE_SIZE = 10;
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
726
|
+
function AutoCompleteInner(props, ref) {
|
|
727
|
+
const {
|
|
728
|
+
name,
|
|
729
|
+
label,
|
|
730
|
+
error,
|
|
731
|
+
value,
|
|
732
|
+
onChange,
|
|
733
|
+
onSelect,
|
|
734
|
+
renderOption,
|
|
735
|
+
getLabel = (item) => item?.label ?? item?.nome ?? String(item),
|
|
736
|
+
disabled,
|
|
737
|
+
placeholder,
|
|
738
|
+
isUppercaseLabel = true,
|
|
739
|
+
queryKey,
|
|
740
|
+
mutationFn,
|
|
741
|
+
service,
|
|
742
|
+
...inputProps
|
|
743
|
+
} = props;
|
|
743
744
|
const theme = useLeafcodeTheme();
|
|
744
745
|
const styleVars = {
|
|
745
746
|
"--label-line": theme.colors.light,
|
|
@@ -762,13 +763,31 @@ var InputBase3 = ({
|
|
|
762
763
|
const [search, setSearch] = (0, import_react12.useState)("");
|
|
763
764
|
const [isOpen, setIsOpen] = (0, import_react12.useState)(false);
|
|
764
765
|
const listRef = (0, import_react12.useRef)(null);
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
|
|
766
|
+
const fetcher = () => {
|
|
767
|
+
if (service) {
|
|
768
|
+
return service({
|
|
769
|
+
page: pageNumber,
|
|
770
|
+
size: PAGE_SIZE,
|
|
771
|
+
search,
|
|
772
|
+
...props
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
return mutationFn(pageNumber, PAGE_SIZE, search);
|
|
776
|
+
};
|
|
777
|
+
const queryKeyInternal = [
|
|
778
|
+
"autocomplete",
|
|
779
|
+
queryKey ?? "service",
|
|
780
|
+
pageNumber,
|
|
781
|
+
search
|
|
782
|
+
];
|
|
783
|
+
const query = (0, import_react_query.useQuery)({
|
|
784
|
+
queryKey: queryKeyInternal,
|
|
785
|
+
queryFn: fetcher,
|
|
768
786
|
enabled: isOpen
|
|
769
787
|
});
|
|
788
|
+
const { data, isLoading } = query;
|
|
770
789
|
(0, import_react12.useEffect)(() => {
|
|
771
|
-
if (!data
|
|
790
|
+
if (!data) return;
|
|
772
791
|
setItems(
|
|
773
792
|
(prev) => pageNumber === 1 ? data.items : [...prev, ...data.items]
|
|
774
793
|
);
|
|
@@ -777,7 +796,7 @@ var InputBase3 = ({
|
|
|
777
796
|
const debounced = import_lodash2.default.debounce(() => {
|
|
778
797
|
setPageNumber(1);
|
|
779
798
|
setSearch(value ?? "");
|
|
780
|
-
},
|
|
799
|
+
}, 500);
|
|
781
800
|
debounced();
|
|
782
801
|
return () => debounced.cancel();
|
|
783
802
|
}, [value]);
|
|
@@ -789,35 +808,18 @@ var InputBase3 = ({
|
|
|
789
808
|
}
|
|
790
809
|
};
|
|
791
810
|
const handleSelect = (item) => {
|
|
792
|
-
|
|
811
|
+
const label2 = getLabel(item);
|
|
812
|
+
onChange?.(label2);
|
|
793
813
|
setIsOpen(false);
|
|
794
814
|
onSelect(item);
|
|
795
815
|
};
|
|
796
|
-
const renderDropdown = () => {
|
|
797
|
-
if (!isOpen) return null;
|
|
798
|
-
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "dropdown-container", style: styleVars, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
799
|
-
items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
800
|
-
"li",
|
|
801
|
-
{
|
|
802
|
-
onClick: () => handleSelect(item),
|
|
803
|
-
className: "dropdown-item",
|
|
804
|
-
children: renderOption(item)
|
|
805
|
-
},
|
|
806
|
-
item.id
|
|
807
|
-
)),
|
|
808
|
-
isLoading && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("li", { className: "dropdown-loading", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LoadingSpinner, { size: 20 }) }),
|
|
809
|
-
!isLoading && items.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("li", { className: "dropdown-empty", children: "N\xE3o encontrado" })
|
|
810
|
-
] }) });
|
|
811
|
-
};
|
|
812
816
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
813
817
|
"div",
|
|
814
818
|
{
|
|
815
819
|
className: "input-wrapper",
|
|
816
820
|
style: styleVars,
|
|
817
821
|
tabIndex: -1,
|
|
818
|
-
onBlur: (e) =>
|
|
819
|
-
e.relatedTarget === null && setIsOpen(false);
|
|
820
|
-
},
|
|
822
|
+
onBlur: (e) => e.relatedTarget === null && setIsOpen(false),
|
|
821
823
|
children: [
|
|
822
824
|
label && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
823
825
|
"label",
|
|
@@ -840,35 +842,46 @@ var InputBase3 = ({
|
|
|
840
842
|
className: "input",
|
|
841
843
|
value: value ?? "",
|
|
842
844
|
onChange: (e) => {
|
|
843
|
-
|
|
844
|
-
onChange?.(val);
|
|
845
|
+
onChange?.(e.target.value);
|
|
845
846
|
setIsOpen(true);
|
|
846
847
|
},
|
|
847
848
|
onFocus: () => setIsOpen(true),
|
|
848
|
-
...
|
|
849
|
+
...inputProps
|
|
849
850
|
}
|
|
850
851
|
),
|
|
851
852
|
value && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
852
853
|
"button",
|
|
853
854
|
{
|
|
854
855
|
type: "button",
|
|
856
|
+
className: "dropdown-clear",
|
|
855
857
|
onClick: () => {
|
|
856
858
|
setPageNumber(1);
|
|
857
859
|
onChange?.("");
|
|
858
860
|
onSelect(null);
|
|
859
861
|
},
|
|
860
|
-
|
|
861
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react11.X, { size: 16, className: "icone-clear" })
|
|
862
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react11.X, { size: 16, color: "#bf1717" })
|
|
862
863
|
}
|
|
863
864
|
),
|
|
864
|
-
|
|
865
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "dropdown-container", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
866
|
+
items.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
867
|
+
"li",
|
|
868
|
+
{
|
|
869
|
+
onClick: () => handleSelect(item),
|
|
870
|
+
className: "dropdown-item",
|
|
871
|
+
children: renderOption(item)
|
|
872
|
+
},
|
|
873
|
+
i
|
|
874
|
+
)),
|
|
875
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("li", { className: "dropdown-loading", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LoadingSpinner, { size: 20 }) }),
|
|
876
|
+
!isLoading && items.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("li", { className: "dropdown-empty", children: "N\xE3o encontrado" })
|
|
877
|
+
] }) })
|
|
865
878
|
] }),
|
|
866
879
|
!value && !isOpen && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TooltipErrorInput, { error, name })
|
|
867
880
|
]
|
|
868
881
|
}
|
|
869
882
|
);
|
|
870
|
-
}
|
|
871
|
-
var InputAutoComplete = (0, import_react12.forwardRef)(
|
|
883
|
+
}
|
|
884
|
+
var InputAutoComplete = (0, import_react12.forwardRef)(AutoCompleteInner);
|
|
872
885
|
|
|
873
886
|
// src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
|
|
874
887
|
var import_react19 = require("react");
|
package/dist/index.mjs
CHANGED
|
@@ -673,23 +673,24 @@ LoadingSpinner.displayName = "LoadingSpinner";
|
|
|
673
673
|
// src/components/Input/InputAutocomplete.tsx
|
|
674
674
|
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
675
675
|
var PAGE_SIZE = 10;
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
676
|
+
function AutoCompleteInner(props, ref) {
|
|
677
|
+
const {
|
|
678
|
+
name,
|
|
679
|
+
label,
|
|
680
|
+
error,
|
|
681
|
+
value,
|
|
682
|
+
onChange,
|
|
683
|
+
onSelect,
|
|
684
|
+
renderOption,
|
|
685
|
+
getLabel = (item) => item?.label ?? item?.nome ?? String(item),
|
|
686
|
+
disabled,
|
|
687
|
+
placeholder,
|
|
688
|
+
isUppercaseLabel = true,
|
|
689
|
+
queryKey,
|
|
690
|
+
mutationFn,
|
|
691
|
+
service,
|
|
692
|
+
...inputProps
|
|
693
|
+
} = props;
|
|
693
694
|
const theme = useLeafcodeTheme();
|
|
694
695
|
const styleVars = {
|
|
695
696
|
"--label-line": theme.colors.light,
|
|
@@ -712,13 +713,31 @@ var InputBase3 = ({
|
|
|
712
713
|
const [search, setSearch] = useState4("");
|
|
713
714
|
const [isOpen, setIsOpen] = useState4(false);
|
|
714
715
|
const listRef = useRef(null);
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
716
|
+
const fetcher = () => {
|
|
717
|
+
if (service) {
|
|
718
|
+
return service({
|
|
719
|
+
page: pageNumber,
|
|
720
|
+
size: PAGE_SIZE,
|
|
721
|
+
search,
|
|
722
|
+
...props
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
return mutationFn(pageNumber, PAGE_SIZE, search);
|
|
726
|
+
};
|
|
727
|
+
const queryKeyInternal = [
|
|
728
|
+
"autocomplete",
|
|
729
|
+
queryKey ?? "service",
|
|
730
|
+
pageNumber,
|
|
731
|
+
search
|
|
732
|
+
];
|
|
733
|
+
const query = useQuery({
|
|
734
|
+
queryKey: queryKeyInternal,
|
|
735
|
+
queryFn: fetcher,
|
|
718
736
|
enabled: isOpen
|
|
719
737
|
});
|
|
738
|
+
const { data, isLoading } = query;
|
|
720
739
|
useEffect4(() => {
|
|
721
|
-
if (!data
|
|
740
|
+
if (!data) return;
|
|
722
741
|
setItems(
|
|
723
742
|
(prev) => pageNumber === 1 ? data.items : [...prev, ...data.items]
|
|
724
743
|
);
|
|
@@ -727,7 +746,7 @@ var InputBase3 = ({
|
|
|
727
746
|
const debounced = _.debounce(() => {
|
|
728
747
|
setPageNumber(1);
|
|
729
748
|
setSearch(value ?? "");
|
|
730
|
-
},
|
|
749
|
+
}, 500);
|
|
731
750
|
debounced();
|
|
732
751
|
return () => debounced.cancel();
|
|
733
752
|
}, [value]);
|
|
@@ -739,35 +758,18 @@ var InputBase3 = ({
|
|
|
739
758
|
}
|
|
740
759
|
};
|
|
741
760
|
const handleSelect = (item) => {
|
|
742
|
-
|
|
761
|
+
const label2 = getLabel(item);
|
|
762
|
+
onChange?.(label2);
|
|
743
763
|
setIsOpen(false);
|
|
744
764
|
onSelect(item);
|
|
745
765
|
};
|
|
746
|
-
const renderDropdown = () => {
|
|
747
|
-
if (!isOpen) return null;
|
|
748
|
-
return /* @__PURE__ */ jsx10("div", { className: "dropdown-container", style: styleVars, children: /* @__PURE__ */ jsxs7("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
749
|
-
items.map((item) => /* @__PURE__ */ jsx10(
|
|
750
|
-
"li",
|
|
751
|
-
{
|
|
752
|
-
onClick: () => handleSelect(item),
|
|
753
|
-
className: "dropdown-item",
|
|
754
|
-
children: renderOption(item)
|
|
755
|
-
},
|
|
756
|
-
item.id
|
|
757
|
-
)),
|
|
758
|
-
isLoading && /* @__PURE__ */ jsx10("li", { className: "dropdown-loading", children: /* @__PURE__ */ jsx10(LoadingSpinner, { size: 20 }) }),
|
|
759
|
-
!isLoading && items.length === 0 && /* @__PURE__ */ jsx10("li", { className: "dropdown-empty", children: "N\xE3o encontrado" })
|
|
760
|
-
] }) });
|
|
761
|
-
};
|
|
762
766
|
return /* @__PURE__ */ jsxs7(
|
|
763
767
|
"div",
|
|
764
768
|
{
|
|
765
769
|
className: "input-wrapper",
|
|
766
770
|
style: styleVars,
|
|
767
771
|
tabIndex: -1,
|
|
768
|
-
onBlur: (e) =>
|
|
769
|
-
e.relatedTarget === null && setIsOpen(false);
|
|
770
|
-
},
|
|
772
|
+
onBlur: (e) => e.relatedTarget === null && setIsOpen(false),
|
|
771
773
|
children: [
|
|
772
774
|
label && /* @__PURE__ */ jsx10(
|
|
773
775
|
"label",
|
|
@@ -790,35 +792,46 @@ var InputBase3 = ({
|
|
|
790
792
|
className: "input",
|
|
791
793
|
value: value ?? "",
|
|
792
794
|
onChange: (e) => {
|
|
793
|
-
|
|
794
|
-
onChange?.(val);
|
|
795
|
+
onChange?.(e.target.value);
|
|
795
796
|
setIsOpen(true);
|
|
796
797
|
},
|
|
797
798
|
onFocus: () => setIsOpen(true),
|
|
798
|
-
...
|
|
799
|
+
...inputProps
|
|
799
800
|
}
|
|
800
801
|
),
|
|
801
802
|
value && /* @__PURE__ */ jsx10(
|
|
802
803
|
"button",
|
|
803
804
|
{
|
|
804
805
|
type: "button",
|
|
806
|
+
className: "dropdown-clear",
|
|
805
807
|
onClick: () => {
|
|
806
808
|
setPageNumber(1);
|
|
807
809
|
onChange?.("");
|
|
808
810
|
onSelect(null);
|
|
809
811
|
},
|
|
810
|
-
|
|
811
|
-
children: /* @__PURE__ */ jsx10(X3, { size: 16, className: "icone-clear" })
|
|
812
|
+
children: /* @__PURE__ */ jsx10(X3, { size: 16, color: "#bf1717" })
|
|
812
813
|
}
|
|
813
814
|
),
|
|
814
|
-
|
|
815
|
+
isOpen && /* @__PURE__ */ jsx10("div", { className: "dropdown-container", children: /* @__PURE__ */ jsxs7("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
816
|
+
items.map((item, i) => /* @__PURE__ */ jsx10(
|
|
817
|
+
"li",
|
|
818
|
+
{
|
|
819
|
+
onClick: () => handleSelect(item),
|
|
820
|
+
className: "dropdown-item",
|
|
821
|
+
children: renderOption(item)
|
|
822
|
+
},
|
|
823
|
+
i
|
|
824
|
+
)),
|
|
825
|
+
isLoading && /* @__PURE__ */ jsx10("li", { className: "dropdown-loading", children: /* @__PURE__ */ jsx10(LoadingSpinner, { size: 20 }) }),
|
|
826
|
+
!isLoading && items.length === 0 && /* @__PURE__ */ jsx10("li", { className: "dropdown-empty", children: "N\xE3o encontrado" })
|
|
827
|
+
] }) })
|
|
815
828
|
] }),
|
|
816
829
|
!value && !isOpen && /* @__PURE__ */ jsx10(TooltipErrorInput, { error, name })
|
|
817
830
|
]
|
|
818
831
|
}
|
|
819
832
|
);
|
|
820
|
-
}
|
|
821
|
-
var InputAutoComplete = forwardRef4(
|
|
833
|
+
}
|
|
834
|
+
var InputAutoComplete = forwardRef4(AutoCompleteInner);
|
|
822
835
|
|
|
823
836
|
// src/components/DataTableAdvancedFilter/DataTableAdvancedFilter.tsx
|
|
824
837
|
import { useEffect as useEffect7, useState as useState7 } from "react";
|
package/dist/styles/input.css
CHANGED
|
@@ -156,6 +156,7 @@ input:-webkit-autofill:focus {
|
|
|
156
156
|
font-size: var(--input-font-size, 13px);
|
|
157
157
|
box-shadow: none !important;
|
|
158
158
|
background-color: var(--input-bg, #ffffff) !important;
|
|
159
|
+
text-align: left;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
.react-select__control--is-focused {
|
|
@@ -178,6 +179,7 @@ input:-webkit-autofill:focus {
|
|
|
178
179
|
font-family: var(--input-font-family, "Roboto", sans-serif);
|
|
179
180
|
font-weight: var(--input-font-weight, 400);
|
|
180
181
|
font-size: var(--input-font-size, 13px) !important;
|
|
182
|
+
text-align: left;
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
.react-select__option--is-focused {
|