@megha-ui/react 1.3.92 → 1.3.93

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,14 +1,37 @@
1
1
  import React from "react";
2
+ interface DropdownOption {
3
+ label: string;
4
+ value: string;
5
+ action: (columnKey: string, optionValue: string) => void;
6
+ }
2
7
  interface MenuPosition {
3
8
  top: number;
4
9
  left: number;
5
10
  }
6
11
  interface GridFilterDropdownProps {
12
+ searchOptions: DropdownOption[];
7
13
  position: MenuPosition;
14
+ columnKey: string;
15
+ activeSearchType: string;
16
+ searchElement: any;
8
17
  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;
9
25
  sortingOps: any;
10
- searchOps: any | null;
26
+ uniqueSearch: {
27
+ [key: string]: (string | number)[];
28
+ };
29
+ searchInput: any;
30
+ searchable: boolean;
11
31
  columnIndex: number;
32
+ columnType: string;
33
+ locale?: string;
34
+ formatOptions?: any;
12
35
  portalTarget?: HTMLElement | null;
13
36
  }
14
37
  declare const GridFilterDropdown: React.FC<GridFilterDropdownProps>;
@@ -1,24 +1,100 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
2
3
  import ReactDOM from "react-dom";
3
- const GridFilterDropdown = ({ headerDropdownIndex, position, sortingOps, searchOps, columnIndex, portalTarget, }) => {
4
- const dropdownContent = (_jsx("div", { style: Object.assign(Object.assign({ position: position ? "absolute" : "absolute" }, (position
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
+ };
56
+ const dropdownContent = (_jsxs("div", { style: Object.assign(Object.assign({ position: position ? "absolute" : "absolute" }, (position
5
57
  ? {
6
58
  top: position.top,
7
59
  left: position.left,
8
60
  }
9
- : Object.assign({ top: "calc(100% + 5px)" }, (columnIndex > 1 ? { right: 0 } : { left: 0 })))), { zIndex: headerDropdownIndex ? headerDropdownIndex : 1000, backgroundColor: "var(--card-bg, var(--background))", color: "var(--foreground)", boxShadow: "0px 0.5rem 1rem 0px rgba(0,0,0,0.2)", border: "1px solid var(--divider, #eceff4)", listStyleType: "none", padding: "0.35rem 0.35rem", width: "max-content", maxWidth: "500px", borderRadius: "0.5rem", margin: 0 }), onClick: (e) => e.stopPropagation(), children: _jsxs("div", { style: {
10
- display: "flex",
11
- flexDirection: "column",
12
- gap: "0.25rem",
13
- minWidth: "12rem",
14
- }, children: [sortingOps && (_jsx("div", { style: {
15
- padding: "0.35rem 0.5rem 0.25rem",
16
- borderBottom: searchOps
17
- ? "1px solid var(--divider, #eceff4)"
18
- : "none",
19
- }, children: sortingOps })), searchOps && (_jsx("div", { style: {
20
- padding: "0.25rem 0.5rem 0.35rem",
21
- }, children: searchOps }))] }) }));
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 }))] }));
22
98
  // Render in a portal so the dropdown is not occluded
23
99
  // by sticky header cells or other stacking contexts.
24
100
  return ReactDOM.createPortal(dropdownContent, portalTarget || document.body);