@megha-ui/react 1.3.84 → 1.3.87

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.
@@ -1,37 +1,14 @@
1
1
  import React from "react";
2
- interface DropdownOption {
3
- label: string;
4
- value: string;
5
- action: (columnKey: string, optionValue: string) => void;
6
- }
7
2
  interface MenuPosition {
8
3
  top: number;
9
4
  left: number;
10
5
  }
11
6
  interface GridFilterDropdownProps {
12
- searchOptions: DropdownOption[];
13
7
  position: MenuPosition;
14
- columnKey: string;
15
- activeSearchType: string;
16
- searchElement: any;
17
8
  headerDropdownIndex?: number;
18
- textFilterLabel: string;
19
- columnData: any[];
20
- checkboxWrapper?: string;
21
- onFilter: (data: {
22
- [key: string]: string[];
23
- }, key: string) => void;
24
- setUniqueSearch: any;
25
9
  sortingOps: any;
26
- uniqueSearch: {
27
- [key: string]: (string | number)[];
28
- };
29
- searchInput: any;
30
- searchable: boolean;
10
+ searchOps: any | null;
31
11
  columnIndex: number;
32
- columnType: string;
33
- locale?: string;
34
- formatOptions?: any;
35
12
  portalTarget?: HTMLElement | null;
36
13
  }
37
14
  declare const GridFilterDropdown: React.FC<GridFilterDropdownProps>;
@@ -1,100 +1,12 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from "react";
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
3
2
  import ReactDOM from "react-dom";
4
- import { FiChevronRight } from "react-icons/fi";
5
- import TextFilterDropdown from "./textFilterDropdown";
6
- import TextInput from "../../text-input";
7
- import Checkbox from "../../checkbox";
8
- import { formatValue } from "../../../services/commonService";
9
- const GridFilterDropdown = ({ headerDropdownIndex, searchOptions, position, columnKey, searchElement, activeSearchType, textFilterLabel, columnData, checkboxWrapper, onFilter, setUniqueSearch, uniqueSearch, sortingOps, searchable, searchInput, columnIndex, columnType, locale, formatOptions, portalTarget, }) => {
10
- var _a, _b, _c, _d;
11
- const [isOpen, setIsOpen] = useState(false);
12
- const [filterColumnData, setFilterColumnData] = useState([]);
13
- const [filterSearch, setFilterSearch] = useState("");
14
- const headerDropdown = useRef(null);
15
- useEffect(() => {
16
- var _a;
17
- if (searchElement) {
18
- const _searchElement = document.getElementById("search-input");
19
- if (_searchElement) {
20
- const ele = _searchElement.getElementsByTagName("input");
21
- (_a = ele.item(0)) === null || _a === void 0 ? void 0 : _a.focus();
22
- }
23
- }
24
- }, []);
25
- useEffect(() => {
26
- if (columnData.length > 0) {
27
- setFilterColumnData(columnData.filter((item) => typeof item !== "undefined" &&
28
- item !== "" &&
29
- `${item}`.toLowerCase().includes(filterSearch.toLowerCase())));
30
- }
31
- }, [columnData, filterSearch]);
32
- const handleSelect = (value, columnKey) => {
33
- var _a;
34
- let _uniqueSeach = {};
35
- if (value === "all") {
36
- if (((_a = uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
37
- uniqueSearch[columnKey].every((item) => columnData.includes(item))) {
38
- _uniqueSeach = Object.assign(Object.assign({}, uniqueSearch), { [columnKey]: [] });
39
- }
40
- else {
41
- _uniqueSeach = Object.assign(Object.assign({}, uniqueSearch), { [columnKey]: columnData });
42
- }
43
- setUniqueSearch(_uniqueSeach);
44
- }
45
- else {
46
- const newValueArray = uniqueSearch[columnKey] && uniqueSearch[columnKey].includes(value)
47
- ? uniqueSearch[columnKey].filter((item) => item !== value)
48
- : uniqueSearch[columnKey]
49
- ? [...uniqueSearch[columnKey], value]
50
- : columnData.filter((item) => item !== value);
51
- _uniqueSeach = Object.assign(Object.assign({}, uniqueSearch), { [columnKey]: newValueArray });
52
- setUniqueSearch(_uniqueSeach);
53
- }
54
- onFilter(_uniqueSeach, columnKey);
55
- };
3
+ const GridFilterDropdown = ({ headerDropdownIndex, position, sortingOps, searchOps, columnIndex, portalTarget, }) => {
56
4
  const dropdownContent = (_jsxs("div", { style: Object.assign(Object.assign({ position: position ? "absolute" : "absolute" }, (position
57
5
  ? {
58
6
  top: position.top,
59
7
  left: position.left,
60
8
  }
61
- : Object.assign({ top: "calc(100% + 5px)" }, (columnIndex > 1 ? { right: 0 } : { left: 0 })))), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "var(--background)", color: "var(--foreground)", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.35rem 0", width: "max-content", maxWidth: "500px", borderRadius: "0.5rem", margin: 0 }), ref: headerDropdown, onClick: (e) => e.stopPropagation(), children: [searchInput && searchInput, sortingOps, _jsxs("div", { style: {
62
- padding: "0.5rem 0.75rem",
63
- cursor: "pointer",
64
- display: "flex",
65
- alignItems: "center",
66
- justifyContent: "space-between",
67
- }, onClick: () => setIsOpen((prev) => !prev), children: [_jsx("span", { children: textFilterLabel }), _jsx(FiChevronRight, {})] }), columnData.length > 0 && (_jsxs("div", { style: {
68
- width: "100%",
69
- maxHeight: 300,
70
- overflow: "auto",
71
- padding: "0.5rem 0.75rem",
72
- }, children: [_jsx("div", { className: "mb-2", children: _jsx(TextInput, { placeholder: `filter`, onChange: (e) => setFilterSearch(e.target.value), value: filterSearch, height: 32, width: "100%", className: "w-full", backgroundColor: "var(--background)" }) }), filterColumnData.length > 0 && (_jsxs(_Fragment, { children: [_jsxs("div", { style: {
73
- cursor: "pointer",
74
- display: "flex",
75
- alignItems: "center",
76
- }, onClick: () => handleSelect("all", columnKey), children: [_jsx(Checkbox, { id: CSS.escape(columnKey), selected: typeof (uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) !== "undefined"
77
- ? ((_a = uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
78
- filterColumnData.every((item) => uniqueSearch[columnKey].includes(item))
79
- : true, indeterminate: ((_b = uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
80
- filterColumnData.some((item) => uniqueSearch[columnKey].includes(item)), onChange: () => { }, style: { pointerEvents: "none" }, noLabel: true, wrapperClass: checkboxWrapper }), _jsx("span", { style: { marginLeft: "0.5rem" }, children: "All" })] }), filterColumnData.map((item) => {
81
- var _a;
82
- return (_jsxs("div", { style: {
83
- cursor: "pointer",
84
- display: "flex",
85
- alignItems: "center",
86
- }, onClick: () => handleSelect(item, columnKey), children: [_jsx(Checkbox, { id: CSS.escape(`${columnKey}-${item}`), selected: typeof (uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) !== "undefined"
87
- ? (uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey].length) > 0 &&
88
- ((_a = uniqueSearch === null || uniqueSearch === void 0 ? void 0 : uniqueSearch[columnKey]) === null || _a === void 0 ? void 0 : _a.includes(item))
89
- : true, onChange: () => { }, style: { pointerEvents: "none" }, noLabel: true, wrapperClass: checkboxWrapper }), _jsx("span", { style: { marginLeft: "0.5rem" }, children: formatValue(item, columnType, locale, formatOptions) })] }, item));
90
- })] }))] })), isOpen && (_jsx(TextFilterDropdown, { combined: true, columnIndex: columnIndex, headerDropdownIndex: headerDropdownIndex || 1001, searchOptions: searchOptions, position: position
91
- ? {
92
- top: position.top,
93
- left: ((_c = headerDropdown === null || headerDropdown === void 0 ? void 0 : headerDropdown.current) === null || _c === void 0 ? void 0 : _c.clientWidth)
94
- ? ((_d = headerDropdown === null || headerDropdown === void 0 ? void 0 : headerDropdown.current) === null || _d === void 0 ? void 0 : _d.clientWidth) + 2 + position.left
95
- : position.left,
96
- }
97
- : { top: 0, left: 0 }, columnKey: columnKey, searchElement: searchElement, activeSearchType: activeSearchType, searchable: searchable }))] }));
9
+ : Object.assign({ top: "calc(100% + 5px)" }, (columnIndex > 1 ? { right: 0 } : { left: 0 })))), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "var(--background)", color: "var(--foreground)", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", listStyleType: "none", padding: "0.35rem 0", width: "max-content", maxWidth: "500px", borderRadius: "0.5rem", margin: 0 }), onClick: (e) => e.stopPropagation(), children: [sortingOps, searchOps] }));
98
10
  // Render in a portal so the dropdown is not occluded
99
11
  // by sticky header cells or other stacking contexts.
100
12
  return ReactDOM.createPortal(dropdownContent, portalTarget || document.body);