@charlesgomes/leafcode-shared-lib-react 1.0.66 → 1.0.69

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 CHANGED
@@ -186,12 +186,21 @@ type TableState = {
186
186
  declare function DataTableAdvancedFilter<T extends object>({ queryKey, mutationFn, columns, initFilters, onNew, onEdit, onDelete, customActions, customActionsColums, disablePagination, sortFieldInitial, sortOrderInitial, isMultiSelectionMode, isLanguagePtBr, rowsPerPageOptions, state, onStateChange, }: IDataTableProps<T>): react_jsx_runtime.JSX.Element;
187
187
 
188
188
  interface IItemProps {
189
- value: string;
189
+ value: string | boolean;
190
190
  label: string;
191
191
  }
192
192
 
193
- declare const DateFilterTemplate: (options: any, mask?: (value: any) => string | number) => react_jsx_runtime.JSX.Element;
194
- declare const DateTimeFilterTemplate: (options: any, mask?: (date: Date) => string) => react_jsx_runtime.JSX.Element;
193
+ type FilterMatchModeSelectProps = {
194
+ options: any;
195
+ items: {
196
+ label: string;
197
+ value: string;
198
+ }[];
199
+ placeholder?: string;
200
+ };
201
+ declare const FilterMatchModeSelect: ({ options, items, placeholder, }: FilterMatchModeSelectProps) => react_jsx_runtime.JSX.Element;
202
+ declare const DateFilterTemplate: (options: any, isLanguagePtBr?: boolean, isNullable?: boolean, items?: any[], mask?: (value: Date) => string) => react_jsx_runtime.JSX.Element;
203
+ declare const DateTimeFilterTemplate: (options: any, isLanguagePtBr?: boolean, isNullable?: boolean, mask?: (date: Date) => string) => react_jsx_runtime.JSX.Element;
195
204
  declare const ValueFilterTemplate: (options: any, mask?: (value: any) => string | number) => react_jsx_runtime.JSX.Element;
196
205
  declare const SelectFilterTemplate: (options: any, isLanguagePtBr?: boolean, items?: IItemProps[]) => react_jsx_runtime.JSX.Element;
197
206
  declare const CustomFilterElement: (options: any, isLanguagePtBr?: boolean, items?: any[]) => react_jsx_runtime.JSX.Element;
@@ -331,4 +340,4 @@ declare const LeafcodeThemeProvider: ({ children, theme, }: LeafcodeThemeProvide
331
340
 
332
341
  declare const defaultTheme: LeafcodeTheme;
333
342
 
334
- export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, Input, InputAutoComplete, InputSelect, LeafcodeThemeProvider, ModalBase, SelectFilterTemplate, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
343
+ 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 };
package/dist/index.d.ts CHANGED
@@ -186,12 +186,21 @@ type TableState = {
186
186
  declare function DataTableAdvancedFilter<T extends object>({ queryKey, mutationFn, columns, initFilters, onNew, onEdit, onDelete, customActions, customActionsColums, disablePagination, sortFieldInitial, sortOrderInitial, isMultiSelectionMode, isLanguagePtBr, rowsPerPageOptions, state, onStateChange, }: IDataTableProps<T>): react_jsx_runtime.JSX.Element;
187
187
 
188
188
  interface IItemProps {
189
- value: string;
189
+ value: string | boolean;
190
190
  label: string;
191
191
  }
192
192
 
193
- declare const DateFilterTemplate: (options: any, mask?: (value: any) => string | number) => react_jsx_runtime.JSX.Element;
194
- declare const DateTimeFilterTemplate: (options: any, mask?: (date: Date) => string) => react_jsx_runtime.JSX.Element;
193
+ type FilterMatchModeSelectProps = {
194
+ options: any;
195
+ items: {
196
+ label: string;
197
+ value: string;
198
+ }[];
199
+ placeholder?: string;
200
+ };
201
+ declare const FilterMatchModeSelect: ({ options, items, placeholder, }: FilterMatchModeSelectProps) => react_jsx_runtime.JSX.Element;
202
+ declare const DateFilterTemplate: (options: any, isLanguagePtBr?: boolean, isNullable?: boolean, items?: any[], mask?: (value: Date) => string) => react_jsx_runtime.JSX.Element;
203
+ declare const DateTimeFilterTemplate: (options: any, isLanguagePtBr?: boolean, isNullable?: boolean, mask?: (date: Date) => string) => react_jsx_runtime.JSX.Element;
195
204
  declare const ValueFilterTemplate: (options: any, mask?: (value: any) => string | number) => react_jsx_runtime.JSX.Element;
196
205
  declare const SelectFilterTemplate: (options: any, isLanguagePtBr?: boolean, items?: IItemProps[]) => react_jsx_runtime.JSX.Element;
197
206
  declare const CustomFilterElement: (options: any, isLanguagePtBr?: boolean, items?: any[]) => react_jsx_runtime.JSX.Element;
@@ -331,4 +340,4 @@ declare const LeafcodeThemeProvider: ({ children, theme, }: LeafcodeThemeProvide
331
340
 
332
341
  declare const defaultTheme: LeafcodeTheme;
333
342
 
334
- export { Button, type ColumnCustom, CustomFilterElement, DataTableAdvancedFilter, DateFilterTemplate, DateTimeFilterTemplate, type IDataTableProps, type IItemProps, Input, InputAutoComplete, InputSelect, LeafcodeThemeProvider, ModalBase, SelectFilterTemplate, TextArea, ValueFilterTemplate, buildDynamicCampoFilters, buildSortingWithFilters, customMatchModes, defaultTheme, getDefaultFilterMatchOptionsDate, getDefaultFilterMatchOptionsEnum, getDefaultFilterMatchOptionsString, getDefaultFilterMatchOptionsStringArray, getNullable, getUrlParams, mapPrimeToBackendFilters };
343
+ 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 };
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  DateFilterTemplate: () => DateFilterTemplate,
37
37
  DateTimeFilterTemplate: () => DateTimeFilterTemplate,
38
38
  FilterMatchMode: () => import_api5.FilterMatchMode,
39
+ FilterMatchModeSelect: () => FilterMatchModeSelect,
39
40
  FilterOperator: () => import_api5.FilterOperator,
40
41
  Input: () => Input,
41
42
  InputAutoComplete: () => InputAutoComplete,
@@ -1730,55 +1731,126 @@ var import_react_select2 = __toESM(require("react-select"));
1730
1731
  var import_dropdown = require("primereact/dropdown");
1731
1732
  var import_moment2 = __toESM(require("moment"));
1732
1733
  var import_jsx_runtime18 = require("react/jsx-runtime");
1733
- var DateFilterTemplate = (options, mask) => {
1734
- const parsedValue = options.value && typeof options.value === "string" ? /* @__PURE__ */ new Date(options.value + "T00:00:00") : options.value;
1734
+ var FilterMatchModeSelect = ({
1735
+ options,
1736
+ items,
1737
+ placeholder = "Tipo de filtro"
1738
+ }) => {
1739
+ const rawFilter = options.value ?? {};
1740
+ const currentMatchMode = rawFilter.matchMode ?? items[0]?.value;
1741
+ const isSpecial = (mode) => mode === customMatchModes.empty || mode === customMatchModes.notEmpty;
1735
1742
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1736
- import_calendar.Calendar,
1743
+ import_dropdown.Dropdown,
1737
1744
  {
1738
- value: parsedValue,
1745
+ value: currentMatchMode,
1746
+ options: items,
1747
+ optionLabel: "label",
1748
+ optionValue: "value",
1749
+ placeholder,
1750
+ style: { width: "100%" },
1739
1751
  onChange: (e) => {
1740
- if (!e.value) {
1741
- options.filterCallback(null, options.index);
1752
+ const newMatchMode = e.value;
1753
+ if (isSpecial(newMatchMode)) {
1754
+ options.filterCallback({
1755
+ text: null,
1756
+ matchMode: newMatchMode
1757
+ });
1742
1758
  return;
1743
1759
  }
1744
- const date = e.value;
1745
- const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1746
- 2,
1747
- "0"
1748
- )}-${String(date.getDate()).padStart(2, "0")}`;
1749
- options.filterCallback(valueToFilter, options.index);
1750
- },
1751
- dateFormat: "dd/mm/yy",
1752
- placeholder: "dd/mm/yyyy",
1753
- mask: "99/99/9999",
1754
- inputClassName: "p-column-filter"
1760
+ options.filterCallback({
1761
+ text: null,
1762
+ matchMode: newMatchMode
1763
+ });
1764
+ }
1755
1765
  }
1756
1766
  );
1757
1767
  };
1758
- var DateTimeFilterTemplate = (options, mask) => {
1759
- const value = typeof options.value === "string" ? (0, import_moment2.default)(options.value).toDate() : options.value ?? null;
1760
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1761
- import_calendar.Calendar,
1762
- {
1763
- value,
1764
- showTime: true,
1765
- showSeconds: true,
1766
- hourFormat: "24",
1767
- dateFormat: "dd/mm/yy",
1768
- placeholder: "dd/mm/yyyy 00:00:00",
1769
- readOnlyInput: true,
1770
- inputClassName: "p-column-filter",
1771
- onChange: (e) => {
1772
- const selectedDate = e.value;
1773
- if (!selectedDate) {
1774
- options.filterCallback(null, options.index);
1775
- return;
1768
+ var DateFilterTemplate = (options, isLanguagePtBr = true, isNullable = true, items, mask) => {
1769
+ const resolvedItems = items ?? getDefaultFilterMatchOptionsDate(isLanguagePtBr, isNullable);
1770
+ const rawFilter = options.value ?? {};
1771
+ const currentMatchMode = rawFilter.matchMode;
1772
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1773
+ const parsedValue = options.value?.text && typeof options.value.text === "string" ? /* @__PURE__ */ new Date(options.value.text + "T00:00:00") : null;
1774
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1775
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1776
+ FilterMatchModeSelect,
1777
+ {
1778
+ options,
1779
+ items: resolvedItems
1780
+ }
1781
+ ),
1782
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1783
+ import_calendar.Calendar,
1784
+ {
1785
+ value: parsedValue,
1786
+ onChange: (e) => {
1787
+ if (!e.value) {
1788
+ options.filterCallback({
1789
+ text: null,
1790
+ matchMode: currentMatchMode
1791
+ });
1792
+ return;
1793
+ }
1794
+ const date = e.value;
1795
+ const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(
1796
+ date.getMonth() + 1
1797
+ ).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
1798
+ options.filterCallback({
1799
+ text: valueToFilter,
1800
+ matchMode: currentMatchMode
1801
+ });
1802
+ },
1803
+ dateFormat: "dd/mm/yy",
1804
+ placeholder: "dd/mm/yyyy",
1805
+ mask: "99/99/9999",
1806
+ inputClassName: "p-column-filter"
1807
+ }
1808
+ )
1809
+ ] });
1810
+ };
1811
+ var DateTimeFilterTemplate = (options, isLanguagePtBr = true, isNullable = true, mask) => {
1812
+ const items = getDefaultFilterMatchOptionsDate(isLanguagePtBr, isNullable);
1813
+ const rawFilter = options.value ?? {};
1814
+ const currentMatchMode = rawFilter.matchMode;
1815
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1816
+ const value = typeof rawFilter.text === "string" ? (0, import_moment2.default)(rawFilter.text).toDate() : null;
1817
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1818
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1819
+ FilterMatchModeSelect,
1820
+ {
1821
+ options,
1822
+ items
1823
+ }
1824
+ ),
1825
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1826
+ import_calendar.Calendar,
1827
+ {
1828
+ value,
1829
+ showTime: true,
1830
+ showSeconds: true,
1831
+ hourFormat: "24",
1832
+ dateFormat: "dd/mm/yy",
1833
+ placeholder: "dd/mm/yyyy 00:00:00",
1834
+ readOnlyInput: true,
1835
+ inputClassName: "p-column-filter",
1836
+ onChange: (e) => {
1837
+ const selectedDate = e.value;
1838
+ if (!selectedDate) {
1839
+ options.filterCallback({
1840
+ text: null,
1841
+ matchMode: currentMatchMode
1842
+ });
1843
+ return;
1844
+ }
1845
+ const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1846
+ options.filterCallback({
1847
+ text: formatted,
1848
+ matchMode: currentMatchMode
1849
+ });
1776
1850
  }
1777
- const formatted = mask ? mask(selectedDate) : (0, import_moment2.default)(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1778
- options.filterCallback(formatted, options.index);
1779
1851
  }
1780
- }
1781
- );
1852
+ )
1853
+ ] });
1782
1854
  };
1783
1855
  var ValueFilterTemplate = (options, mask) => {
1784
1856
  const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
@@ -1804,63 +1876,83 @@ var ValueFilterTemplate = (options, mask) => {
1804
1876
  );
1805
1877
  };
1806
1878
  var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1879
+ const matchModeItems = getDefaultFilterMatchOptionsEnum(isLanguagePtBr);
1807
1880
  const selectOptions = items.length > 0 ? items : [
1808
1881
  { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1809
1882
  { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1810
1883
  ];
1811
- const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1812
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1813
- import_react_select2.default,
1814
- {
1815
- options: selectOptions,
1816
- value: currentValue,
1817
- onChange: (selected) => options.filterCallback(selected?.value),
1818
- placeholder: "Todos",
1819
- isClearable: false,
1820
- isSearchable: false,
1821
- className: "custom-select-filtro",
1822
- classNamePrefix: "custom-select-filtro",
1823
- styles: {
1824
- control: (baseStyles, state) => ({
1825
- ...baseStyles,
1826
- "&:hover": {
1827
- borderColor: state.isFocused ? "#094394" : ""
1828
- },
1829
- borderRadius: "6px"
1830
- }),
1831
- menuList: (base) => ({
1832
- ...base,
1833
- "::-webkit-scrollbar": {
1834
- width: "6px",
1835
- height: "auto",
1836
- overflowX: "hidden",
1837
- overflowY: "hidden"
1838
- },
1839
- "::-webkit-scrollbar-track": {
1840
- background: "#fff"
1841
- },
1842
- "::-webkit-scrollbar-thumb": {
1843
- background: "#888",
1844
- borderRadius: "2rem"
1845
- },
1846
- "::-webkit-scrollbar-thumb:hover": {
1847
- background: "#555"
1848
- }
1849
- }),
1850
- option: (provided, state) => ({
1851
- ...provided,
1852
- backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1853
- color: state.isFocused ? "#ffffff" : "black",
1854
- "&:hover": {
1855
- backgroundColor: "#094394",
1856
- // Cor de fundo quando em hover
1857
- color: "#ffffff"
1858
- // Cor da palavra quando em hover
1884
+ const rawFilter = options.value ?? {};
1885
+ const currentMatchMode = rawFilter.matchMode;
1886
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1887
+ const currentValue = selectOptions.find((opt) => opt.value === rawFilter.text) || null;
1888
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1889
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1890
+ FilterMatchModeSelect,
1891
+ {
1892
+ options,
1893
+ items: matchModeItems
1894
+ }
1895
+ ),
1896
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1897
+ import_react_select2.default,
1898
+ {
1899
+ options: selectOptions,
1900
+ value: currentValue,
1901
+ onChange: (selected) => {
1902
+ if (!selected) {
1903
+ options.filterCallback({
1904
+ text: null,
1905
+ matchMode: currentMatchMode
1906
+ });
1907
+ return;
1859
1908
  }
1860
- })
1909
+ options.filterCallback({
1910
+ text: selected.value,
1911
+ matchMode: currentMatchMode
1912
+ });
1913
+ },
1914
+ placeholder: isLanguagePtBr ? "Selecione..." : "Select...",
1915
+ isClearable: false,
1916
+ isSearchable: false,
1917
+ className: "custom-select-filtro",
1918
+ classNamePrefix: "custom-select-filtro",
1919
+ styles: {
1920
+ control: (baseStyles, state) => ({
1921
+ ...baseStyles,
1922
+ "&:hover": {
1923
+ borderColor: state.isFocused ? "#094394" : ""
1924
+ },
1925
+ borderRadius: "6px"
1926
+ }),
1927
+ menuList: (base) => ({
1928
+ ...base,
1929
+ "::-webkit-scrollbar": {
1930
+ width: "6px"
1931
+ },
1932
+ "::-webkit-scrollbar-track": {
1933
+ background: "#fff"
1934
+ },
1935
+ "::-webkit-scrollbar-thumb": {
1936
+ background: "#888",
1937
+ borderRadius: "2rem"
1938
+ },
1939
+ "::-webkit-scrollbar-thumb:hover": {
1940
+ background: "#555"
1941
+ }
1942
+ }),
1943
+ option: (provided, state) => ({
1944
+ ...provided,
1945
+ backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1946
+ color: state.isFocused ? "#ffffff" : "black",
1947
+ "&:hover": {
1948
+ backgroundColor: "#094394",
1949
+ color: "#ffffff"
1950
+ }
1951
+ })
1952
+ }
1861
1953
  }
1862
- }
1863
- );
1954
+ )
1955
+ ] });
1864
1956
  };
1865
1957
  var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1866
1958
  const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
@@ -1868,69 +1960,30 @@ var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1868
1960
  const currentMatchMode = rawFilter.matchMode ?? "contains";
1869
1961
  const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1870
1962
  const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1871
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
1872
- "div",
1873
- {
1874
- className: "filter-wrapper",
1875
- style: {
1876
- display: "flex",
1877
- flexDirection: "column",
1878
- gap: "8px",
1879
- minWidth: "200px"
1880
- },
1881
- children: [
1882
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1883
- import_dropdown.Dropdown,
1884
- {
1885
- value: currentMatchMode,
1886
- options: resolvedItems,
1887
- optionLabel: "label",
1888
- optionValue: "value",
1889
- placeholder: "Tipo de filtro",
1890
- style: { width: "100%" },
1891
- onChange: (e) => {
1892
- const newMatchMode = e.value;
1893
- const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1894
- if (isNewSpecial) {
1895
- options.filterCallback({
1896
- text: null,
1897
- matchMode: newMatchMode
1898
- });
1899
- return;
1900
- }
1901
- options.filterCallback({
1902
- text: null,
1903
- matchMode: newMatchMode
1904
- });
1905
- }
1906
- }
1907
- ),
1908
- !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1909
- import_inputtext.InputText,
1910
- {
1911
- value: currentValue,
1912
- placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1913
- style: { width: "100%" },
1914
- className: "p-column-filter",
1915
- onChange: (e) => {
1916
- const value = e.target.value;
1917
- if (value.trim()) {
1918
- options.filterCallback({
1919
- text: value,
1920
- matchMode: currentMatchMode
1921
- });
1922
- } else {
1923
- options.filterCallback({
1924
- text: null,
1925
- matchMode: currentMatchMode
1926
- });
1927
- }
1928
- }
1929
- }
1930
- )
1931
- ]
1932
- }
1933
- );
1963
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "filter-wrapper", style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1964
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1965
+ FilterMatchModeSelect,
1966
+ {
1967
+ options,
1968
+ items: resolvedItems
1969
+ }
1970
+ ),
1971
+ !isSpecial && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1972
+ import_inputtext.InputText,
1973
+ {
1974
+ value: currentValue,
1975
+ placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1976
+ className: "p-column-filter",
1977
+ onChange: (e) => {
1978
+ const value = e.target.value;
1979
+ options.filterCallback({
1980
+ text: value.trim() ? value : null,
1981
+ matchMode: currentMatchMode
1982
+ });
1983
+ }
1984
+ }
1985
+ )
1986
+ ] });
1934
1987
  };
1935
1988
 
1936
1989
  // src/components/DataTableAdvancedFilter/filterModes.ts
@@ -2359,6 +2412,7 @@ var import_api5 = require("primereact/api");
2359
2412
  DateFilterTemplate,
2360
2413
  DateTimeFilterTemplate,
2361
2414
  FilterMatchMode,
2415
+ FilterMatchModeSelect,
2362
2416
  FilterOperator,
2363
2417
  Input,
2364
2418
  InputAutoComplete,
package/dist/index.mjs CHANGED
@@ -1681,55 +1681,126 @@ import Select2 from "react-select";
1681
1681
  import { Dropdown } from "primereact/dropdown";
1682
1682
  import moment2 from "moment";
1683
1683
  import { jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
1684
- var DateFilterTemplate = (options, mask) => {
1685
- const parsedValue = options.value && typeof options.value === "string" ? /* @__PURE__ */ new Date(options.value + "T00:00:00") : options.value;
1684
+ var FilterMatchModeSelect = ({
1685
+ options,
1686
+ items,
1687
+ placeholder = "Tipo de filtro"
1688
+ }) => {
1689
+ const rawFilter = options.value ?? {};
1690
+ const currentMatchMode = rawFilter.matchMode ?? items[0]?.value;
1691
+ const isSpecial = (mode) => mode === customMatchModes.empty || mode === customMatchModes.notEmpty;
1686
1692
  return /* @__PURE__ */ jsx18(
1687
- Calendar,
1693
+ Dropdown,
1688
1694
  {
1689
- value: parsedValue,
1695
+ value: currentMatchMode,
1696
+ options: items,
1697
+ optionLabel: "label",
1698
+ optionValue: "value",
1699
+ placeholder,
1700
+ style: { width: "100%" },
1690
1701
  onChange: (e) => {
1691
- if (!e.value) {
1692
- options.filterCallback(null, options.index);
1702
+ const newMatchMode = e.value;
1703
+ if (isSpecial(newMatchMode)) {
1704
+ options.filterCallback({
1705
+ text: null,
1706
+ matchMode: newMatchMode
1707
+ });
1693
1708
  return;
1694
1709
  }
1695
- const date = e.value;
1696
- const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
1697
- 2,
1698
- "0"
1699
- )}-${String(date.getDate()).padStart(2, "0")}`;
1700
- options.filterCallback(valueToFilter, options.index);
1701
- },
1702
- dateFormat: "dd/mm/yy",
1703
- placeholder: "dd/mm/yyyy",
1704
- mask: "99/99/9999",
1705
- inputClassName: "p-column-filter"
1710
+ options.filterCallback({
1711
+ text: null,
1712
+ matchMode: newMatchMode
1713
+ });
1714
+ }
1706
1715
  }
1707
1716
  );
1708
1717
  };
1709
- var DateTimeFilterTemplate = (options, mask) => {
1710
- const value = typeof options.value === "string" ? moment2(options.value).toDate() : options.value ?? null;
1711
- return /* @__PURE__ */ jsx18(
1712
- Calendar,
1713
- {
1714
- value,
1715
- showTime: true,
1716
- showSeconds: true,
1717
- hourFormat: "24",
1718
- dateFormat: "dd/mm/yy",
1719
- placeholder: "dd/mm/yyyy 00:00:00",
1720
- readOnlyInput: true,
1721
- inputClassName: "p-column-filter",
1722
- onChange: (e) => {
1723
- const selectedDate = e.value;
1724
- if (!selectedDate) {
1725
- options.filterCallback(null, options.index);
1726
- return;
1718
+ var DateFilterTemplate = (options, isLanguagePtBr = true, isNullable = true, items, mask) => {
1719
+ const resolvedItems = items ?? getDefaultFilterMatchOptionsDate(isLanguagePtBr, isNullable);
1720
+ const rawFilter = options.value ?? {};
1721
+ const currentMatchMode = rawFilter.matchMode;
1722
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1723
+ const parsedValue = options.value?.text && typeof options.value.text === "string" ? /* @__PURE__ */ new Date(options.value.text + "T00:00:00") : null;
1724
+ return /* @__PURE__ */ jsxs12("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1725
+ /* @__PURE__ */ jsx18(
1726
+ FilterMatchModeSelect,
1727
+ {
1728
+ options,
1729
+ items: resolvedItems
1730
+ }
1731
+ ),
1732
+ !isSpecial && /* @__PURE__ */ jsx18(
1733
+ Calendar,
1734
+ {
1735
+ value: parsedValue,
1736
+ onChange: (e) => {
1737
+ if (!e.value) {
1738
+ options.filterCallback({
1739
+ text: null,
1740
+ matchMode: currentMatchMode
1741
+ });
1742
+ return;
1743
+ }
1744
+ const date = e.value;
1745
+ const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(
1746
+ date.getMonth() + 1
1747
+ ).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
1748
+ options.filterCallback({
1749
+ text: valueToFilter,
1750
+ matchMode: currentMatchMode
1751
+ });
1752
+ },
1753
+ dateFormat: "dd/mm/yy",
1754
+ placeholder: "dd/mm/yyyy",
1755
+ mask: "99/99/9999",
1756
+ inputClassName: "p-column-filter"
1757
+ }
1758
+ )
1759
+ ] });
1760
+ };
1761
+ var DateTimeFilterTemplate = (options, isLanguagePtBr = true, isNullable = true, mask) => {
1762
+ const items = getDefaultFilterMatchOptionsDate(isLanguagePtBr, isNullable);
1763
+ const rawFilter = options.value ?? {};
1764
+ const currentMatchMode = rawFilter.matchMode;
1765
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1766
+ const value = typeof rawFilter.text === "string" ? moment2(rawFilter.text).toDate() : null;
1767
+ return /* @__PURE__ */ jsxs12("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1768
+ /* @__PURE__ */ jsx18(
1769
+ FilterMatchModeSelect,
1770
+ {
1771
+ options,
1772
+ items
1773
+ }
1774
+ ),
1775
+ !isSpecial && /* @__PURE__ */ jsx18(
1776
+ Calendar,
1777
+ {
1778
+ value,
1779
+ showTime: true,
1780
+ showSeconds: true,
1781
+ hourFormat: "24",
1782
+ dateFormat: "dd/mm/yy",
1783
+ placeholder: "dd/mm/yyyy 00:00:00",
1784
+ readOnlyInput: true,
1785
+ inputClassName: "p-column-filter",
1786
+ onChange: (e) => {
1787
+ const selectedDate = e.value;
1788
+ if (!selectedDate) {
1789
+ options.filterCallback({
1790
+ text: null,
1791
+ matchMode: currentMatchMode
1792
+ });
1793
+ return;
1794
+ }
1795
+ const formatted = mask ? mask(selectedDate) : moment2(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1796
+ options.filterCallback({
1797
+ text: formatted,
1798
+ matchMode: currentMatchMode
1799
+ });
1727
1800
  }
1728
- const formatted = mask ? mask(selectedDate) : moment2(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
1729
- options.filterCallback(formatted, options.index);
1730
1801
  }
1731
- }
1732
- );
1802
+ )
1803
+ ] });
1733
1804
  };
1734
1805
  var ValueFilterTemplate = (options, mask) => {
1735
1806
  const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
@@ -1755,63 +1826,83 @@ var ValueFilterTemplate = (options, mask) => {
1755
1826
  );
1756
1827
  };
1757
1828
  var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
1829
+ const matchModeItems = getDefaultFilterMatchOptionsEnum(isLanguagePtBr);
1758
1830
  const selectOptions = items.length > 0 ? items : [
1759
1831
  { label: isLanguagePtBr ? "Sim" : "Yes", value: true },
1760
1832
  { label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
1761
1833
  ];
1762
- const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
1763
- return /* @__PURE__ */ jsx18(
1764
- Select2,
1765
- {
1766
- options: selectOptions,
1767
- value: currentValue,
1768
- onChange: (selected) => options.filterCallback(selected?.value),
1769
- placeholder: "Todos",
1770
- isClearable: false,
1771
- isSearchable: false,
1772
- className: "custom-select-filtro",
1773
- classNamePrefix: "custom-select-filtro",
1774
- styles: {
1775
- control: (baseStyles, state) => ({
1776
- ...baseStyles,
1777
- "&:hover": {
1778
- borderColor: state.isFocused ? "#094394" : ""
1779
- },
1780
- borderRadius: "6px"
1781
- }),
1782
- menuList: (base) => ({
1783
- ...base,
1784
- "::-webkit-scrollbar": {
1785
- width: "6px",
1786
- height: "auto",
1787
- overflowX: "hidden",
1788
- overflowY: "hidden"
1789
- },
1790
- "::-webkit-scrollbar-track": {
1791
- background: "#fff"
1792
- },
1793
- "::-webkit-scrollbar-thumb": {
1794
- background: "#888",
1795
- borderRadius: "2rem"
1796
- },
1797
- "::-webkit-scrollbar-thumb:hover": {
1798
- background: "#555"
1799
- }
1800
- }),
1801
- option: (provided, state) => ({
1802
- ...provided,
1803
- backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1804
- color: state.isFocused ? "#ffffff" : "black",
1805
- "&:hover": {
1806
- backgroundColor: "#094394",
1807
- // Cor de fundo quando em hover
1808
- color: "#ffffff"
1809
- // Cor da palavra quando em hover
1834
+ const rawFilter = options.value ?? {};
1835
+ const currentMatchMode = rawFilter.matchMode;
1836
+ const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1837
+ const currentValue = selectOptions.find((opt) => opt.value === rawFilter.text) || null;
1838
+ return /* @__PURE__ */ jsxs12("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1839
+ /* @__PURE__ */ jsx18(
1840
+ FilterMatchModeSelect,
1841
+ {
1842
+ options,
1843
+ items: matchModeItems
1844
+ }
1845
+ ),
1846
+ !isSpecial && /* @__PURE__ */ jsx18(
1847
+ Select2,
1848
+ {
1849
+ options: selectOptions,
1850
+ value: currentValue,
1851
+ onChange: (selected) => {
1852
+ if (!selected) {
1853
+ options.filterCallback({
1854
+ text: null,
1855
+ matchMode: currentMatchMode
1856
+ });
1857
+ return;
1810
1858
  }
1811
- })
1859
+ options.filterCallback({
1860
+ text: selected.value,
1861
+ matchMode: currentMatchMode
1862
+ });
1863
+ },
1864
+ placeholder: isLanguagePtBr ? "Selecione..." : "Select...",
1865
+ isClearable: false,
1866
+ isSearchable: false,
1867
+ className: "custom-select-filtro",
1868
+ classNamePrefix: "custom-select-filtro",
1869
+ styles: {
1870
+ control: (baseStyles, state) => ({
1871
+ ...baseStyles,
1872
+ "&:hover": {
1873
+ borderColor: state.isFocused ? "#094394" : ""
1874
+ },
1875
+ borderRadius: "6px"
1876
+ }),
1877
+ menuList: (base) => ({
1878
+ ...base,
1879
+ "::-webkit-scrollbar": {
1880
+ width: "6px"
1881
+ },
1882
+ "::-webkit-scrollbar-track": {
1883
+ background: "#fff"
1884
+ },
1885
+ "::-webkit-scrollbar-thumb": {
1886
+ background: "#888",
1887
+ borderRadius: "2rem"
1888
+ },
1889
+ "::-webkit-scrollbar-thumb:hover": {
1890
+ background: "#555"
1891
+ }
1892
+ }),
1893
+ option: (provided, state) => ({
1894
+ ...provided,
1895
+ backgroundColor: state.isFocused ? "#094394" : "#ffffff",
1896
+ color: state.isFocused ? "#ffffff" : "black",
1897
+ "&:hover": {
1898
+ backgroundColor: "#094394",
1899
+ color: "#ffffff"
1900
+ }
1901
+ })
1902
+ }
1812
1903
  }
1813
- }
1814
- );
1904
+ )
1905
+ ] });
1815
1906
  };
1816
1907
  var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1817
1908
  const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
@@ -1819,69 +1910,30 @@ var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
1819
1910
  const currentMatchMode = rawFilter.matchMode ?? "contains";
1820
1911
  const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
1821
1912
  const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
1822
- return /* @__PURE__ */ jsxs12(
1823
- "div",
1824
- {
1825
- className: "filter-wrapper",
1826
- style: {
1827
- display: "flex",
1828
- flexDirection: "column",
1829
- gap: "8px",
1830
- minWidth: "200px"
1831
- },
1832
- children: [
1833
- /* @__PURE__ */ jsx18(
1834
- Dropdown,
1835
- {
1836
- value: currentMatchMode,
1837
- options: resolvedItems,
1838
- optionLabel: "label",
1839
- optionValue: "value",
1840
- placeholder: "Tipo de filtro",
1841
- style: { width: "100%" },
1842
- onChange: (e) => {
1843
- const newMatchMode = e.value;
1844
- const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
1845
- if (isNewSpecial) {
1846
- options.filterCallback({
1847
- text: null,
1848
- matchMode: newMatchMode
1849
- });
1850
- return;
1851
- }
1852
- options.filterCallback({
1853
- text: null,
1854
- matchMode: newMatchMode
1855
- });
1856
- }
1857
- }
1858
- ),
1859
- !isSpecial && /* @__PURE__ */ jsx18(
1860
- InputText,
1861
- {
1862
- value: currentValue,
1863
- placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1864
- style: { width: "100%" },
1865
- className: "p-column-filter",
1866
- onChange: (e) => {
1867
- const value = e.target.value;
1868
- if (value.trim()) {
1869
- options.filterCallback({
1870
- text: value,
1871
- matchMode: currentMatchMode
1872
- });
1873
- } else {
1874
- options.filterCallback({
1875
- text: null,
1876
- matchMode: currentMatchMode
1877
- });
1878
- }
1879
- }
1880
- }
1881
- )
1882
- ]
1883
- }
1884
- );
1913
+ return /* @__PURE__ */ jsxs12("div", { className: "filter-wrapper", style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
1914
+ /* @__PURE__ */ jsx18(
1915
+ FilterMatchModeSelect,
1916
+ {
1917
+ options,
1918
+ items: resolvedItems
1919
+ }
1920
+ ),
1921
+ !isSpecial && /* @__PURE__ */ jsx18(
1922
+ InputText,
1923
+ {
1924
+ value: currentValue,
1925
+ placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
1926
+ className: "p-column-filter",
1927
+ onChange: (e) => {
1928
+ const value = e.target.value;
1929
+ options.filterCallback({
1930
+ text: value.trim() ? value : null,
1931
+ matchMode: currentMatchMode
1932
+ });
1933
+ }
1934
+ }
1935
+ )
1936
+ ] });
1885
1937
  };
1886
1938
 
1887
1939
  // src/components/DataTableAdvancedFilter/filterModes.ts
@@ -2309,6 +2361,7 @@ export {
2309
2361
  DateFilterTemplate,
2310
2362
  DateTimeFilterTemplate,
2311
2363
  FilterMatchMode5 as FilterMatchMode,
2364
+ FilterMatchModeSelect,
2312
2365
  FilterOperator2 as FilterOperator,
2313
2366
  Input,
2314
2367
  InputAutoComplete,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charlesgomes/leafcode-shared-lib-react",
3
- "version": "1.0.66",
3
+ "version": "1.0.69",
4
4
  "description": "Lib de componentes react",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",