pixelize-design-library 1.1.47 → 1.1.50

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,9 +1,8 @@
1
- /// <reference types="react" />
2
1
  import { AlertDialogProps, AlertProps } from "@chakra-ui/react";
3
- import { ButtonProps } from "../Button/ButtonProps";
2
+ import { ReactElement } from "react";
4
3
  export type AlertDialogsProps = Pick<AlertDialogProps, "isOpen" | "onClose" | "leastDestructiveRef"> & Pick<AlertProps, "addRole" | "colorScheme" | "size" | "status" | "variant"> & {
5
4
  title: string;
6
- content: string;
5
+ content: ReactElement;
7
6
  isCentered?: boolean;
8
7
  confirmButtonText?: string;
9
8
  cancelButtonText?: string;
@@ -16,5 +15,5 @@ export type AlertDialogsProps = Pick<AlertDialogProps, "isOpen" | "onClose" | "l
16
15
  button1Style?: React.CSSProperties;
17
16
  button2Style?: React.CSSProperties;
18
17
  key?: string | number;
19
- confirmButtonColor?: ButtonProps["color"];
18
+ confirmButtonColor?: string;
20
19
  };
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- // import React, {
3
- // useCallback,
4
- // useEffect,
5
- // useMemo,
6
- // useRef,
7
- // useState,
8
- // } from "react";
9
- // import {
10
- // Box,
11
- // Input,
12
- // Spinner,
13
- // VStack,
14
- // Text,
15
- // InputGroup,
16
- // InputRightElement,
17
- // HStack,
18
- // Tag,
19
- // TagLabel,
20
- // TagCloseButton,
21
- // } from "@chakra-ui/react";
22
- // import { selectOptions, SelectSearchProps } from "./SelectSearchProps";
23
- // import { TextLabel } from "../Common/FormLabel";
24
- // import { useCustomTheme } from "../../Theme/useCustomTheme";
25
2
  var __assign = (this && this.__assign) || function () {
26
3
  __assign = Object.assign || function(t) {
27
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -66,236 +43,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
43
  return to.concat(ar || Array.prototype.slice.call(from));
67
44
  };
68
45
  Object.defineProperty(exports, "__esModule", { value: true });
69
- // export default function SelectSearch({
70
- // options,
71
- // initialSelectedOption,
72
- // onOptionSelect,
73
- // inputOnchange,
74
- // id,
75
- // name,
76
- // label,
77
- // inputStyle,
78
- // dropdownStyle,
79
- // isOptionLoading,
80
- // loadingText = "loading",
81
- // boxStyle,
82
- // placeholder = "Select Option",
83
- // searchQuery = "",
84
- // isInformation = false,
85
- // informationMessage,
86
- // rightIcon,
87
- // rightElementStyle,
88
- // isMultipleSelect,
89
- // isRequired=false,
90
- // onOptionMultiSelect,
91
- // }: Readonly<SelectSearchProps>) {
92
- // const theme = useCustomTheme();
93
- // const [selectedOptions, setSelectedOptions] = useState<selectOptions[]>(
94
- // initialSelectedOption ? [initialSelectedOption] : []
95
- // );
96
- // const [inputValue, setInputValue] = useState(searchQuery);
97
- // const [isOpen, setIsOpen] = useState(false);
98
- // const [position, setPosition] = useState<"above" | "below">("below");
99
- // const inputRef = useRef<HTMLInputElement>(null);
100
- // const dropdownRef = useRef<HTMLDivElement>(null);
101
- // const filteredOptions = useMemo(() => {
102
- // return options.filter((option) =>
103
- // option.label.toLowerCase().includes(inputValue.toLowerCase())
104
- // );
105
- // }, [options, inputValue]);
106
- // const handleOptionClick = useCallback(
107
- // (option: selectOptions) => {
108
- // if (isMultipleSelect) {
109
- // setSelectedOptions((prev) => {
110
- // const isSelected = prev.some((selected) => selected.id === option.id);
111
- // const newSelected = isSelected
112
- // ? prev.filter((selected) => selected.id !== option.id)
113
- // : [...prev, option];
114
- // setInputValue("");
115
- // if (onOptionMultiSelect) {
116
- // onOptionMultiSelect(newSelected);
117
- // }
118
- // return newSelected;
119
- // });
120
- // } else {
121
- // setInputValue(option.label);
122
- // setIsOpen(false);
123
- // if (onOptionSelect) {
124
- // onOptionSelect(option);
125
- // }
126
- // }
127
- // },
128
- // [isMultipleSelect, onOptionSelect]
129
- // );
130
- // const handleRemoveOption = (option: selectOptions) => {
131
- // setSelectedOptions((prev) =>
132
- // prev.filter((selected) => selected.id !== option.id)
133
- // );
134
- // if (onOptionMultiSelect) {
135
- // onOptionMultiSelect(selectedOptions.filter((selected) => selected.id !== option.id));
136
- // }
137
- // };
138
- // const handleInputChange = (value: any) => {
139
- // setInputValue(value);
140
- // inputOnchange(value);
141
- // };
142
- // const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
143
- // if (e.key === "Enter") {
144
- // const matchingOption = options.find(
145
- // (option) => option.label.toLowerCase() === inputValue.toLowerCase()
146
- // );
147
- // if (matchingOption) {
148
- // handleOptionClick(matchingOption);
149
- // }
150
- // }
151
- // };
152
- // const updateDropdownPosition = () => {
153
- // if (inputRef.current && dropdownRef.current) {
154
- // const inputRect = inputRef.current.getBoundingClientRect();
155
- // const dropdownRect = dropdownRef.current.getBoundingClientRect();
156
- // const viewportHeight = window.innerHeight;
157
- // const spaceBelow = viewportHeight - inputRect.bottom + window.scrollY;
158
- // const spaceAbove = inputRect.top + window.scrollY;
159
- // if (spaceBelow >= dropdownRect.height) {
160
- // setPosition("below");
161
- // } else if (spaceAbove >= dropdownRect.height) {
162
- // setPosition("above");
163
- // } else {
164
- // setPosition("below");
165
- // }
166
- // }
167
- // };
168
- // useEffect(() => {
169
- // if (isOpen) {
170
- // updateDropdownPosition();
171
- // }
172
- // const handleClickOutside = (event: MouseEvent) => {
173
- // if (
174
- // inputRef.current &&
175
- // dropdownRef.current &&
176
- // !inputRef.current.contains(event.target as Node) &&
177
- // !dropdownRef.current.contains(event.target as Node)
178
- // ) {
179
- // setIsOpen(false);
180
- // }
181
- // };
182
- // document.addEventListener("mousedown", handleClickOutside);
183
- // return () => {
184
- // document.removeEventListener("mousedown", handleClickOutside);
185
- // };
186
- // }, [isOpen]);
187
- // const RenderOptions = useCallback(() => {
188
- // if (isOptionLoading) {
189
- // return (
190
- // <VStack py={2}>
191
- // <Spinner size="sm" color="blue.500" />
192
- // <Text color="blue.500">{loadingText}</Text>
193
- // </VStack>
194
- // );
195
- // }
196
- // if (filteredOptions?.length) {
197
- // return filteredOptions.map((option) => (
198
- // <Box
199
- // key={option.id}
200
- // px={4}
201
- // py={2}
202
- // cursor="pointer"
203
- // _hover={{ backgroundColor: "blue.50" }}
204
- // onClick={() => handleOptionClick(option)}
205
- // >
206
- // {option.label}
207
- // </Box>
208
- // ));
209
- // }
210
- // return (
211
- // <Text px={4} py={2} color="gray.500">
212
- // No options found
213
- // </Text>
214
- // );
215
- // }, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
216
- // return (
217
- // <Box display="flex" flexDirection="column" position="relative" sx={boxStyle}>
218
- // {label && (
219
- // <TextLabel
220
- // label={label}
221
- // id={id}
222
- // isRequired={isRequired}
223
- // isInformation={isInformation}
224
- // informationMessage={informationMessage}
225
- // />
226
- // )}
227
- // {/* Display selected options as chips */}
228
- // {isMultipleSelect && selectedOptions.length > 0 && (
229
- // <HStack spacing={2} mb={2}>
230
- // {selectedOptions.map((option) => (
231
- // <Tag
232
- // size="md"
233
- // key={option.id}
234
- // borderRadius="full"
235
- // variant="solid"
236
- // sx={{ backgroundColor: theme.colors.primary[500] }}
237
- // >
238
- // <TagLabel width={"50px"}>{option.label}</TagLabel>
239
- // <TagCloseButton onClick={() => handleRemoveOption(option)} />
240
- // </Tag>
241
- // ))}
242
- // </HStack>
243
- // )}
244
- // <InputGroup>
245
- // <Input
246
- // ref={inputRef}
247
- // variant="flushed"
248
- // value={inputValue}
249
- // onClick={() => setIsOpen(true)}
250
- // onChange={(e) => handleInputChange(e.target.value)}
251
- // placeholder={placeholder}
252
- // onKeyDown={handleKeyDown}
253
- // id={id}
254
- // name={name}
255
- // cursor="pointer"
256
- // borderColor="gray.300"
257
- // _hover={{ borderColor: "blue.500" }}
258
- // _focus={{ borderColor: "blue.500" }}
259
- // style={{
260
- // ...inputStyle,
261
- // backgroundColor: theme.colors.backgroundColor.main,
262
- // fontWeight: 800,
263
- // color: theme.colors.gray[700],
264
- // padding: "0 0.5rem",
265
- // fontSize: 15,
266
- // letterSpacing: 0.7,
267
- // }}
268
- // />
269
- // {rightIcon && (
270
- // <InputRightElement
271
- // pointerEvents="none"
272
- // children={rightIcon}
273
- // style={{ ...rightElementStyle }}
274
- // />
275
- // )}
276
- // </InputGroup>
277
- // {isOpen && (
278
- // <Box
279
- // ref={dropdownRef}
280
- // position="absolute"
281
- // top={position === "below" ? "100%" : "auto"}
282
- // bottom={position === "above" ? "100%" : "auto"}
283
- // left={0}
284
- // right={0}
285
- // border="1px solid"
286
- // borderColor="gray.300"
287
- // borderRadius="md"
288
- // bg="white"
289
- // maxHeight="150px"
290
- // overflowY="auto"
291
- // zIndex={10}
292
- // >
293
- // {RenderOptions()}
294
- // </Box>
295
- // )}
296
- // </Box>
297
- // );
298
- // }
299
46
  var react_1 = __importStar(require("react"));
300
47
  var react_2 = require("@chakra-ui/react");
301
48
  var FormLabel_1 = require("../Common/FormLabel");
@@ -321,9 +68,34 @@ function SelectSearch(_a) {
321
68
  var _m = (0, react_1.useState)("below"), position = _m[0], setPosition = _m[1];
322
69
  var inputRef = (0, react_1.useRef)(null);
323
70
  var dropdownRef = (0, react_1.useRef)(null);
71
+ // const filteredOptions = useMemo(() => {
72
+ // return options.filter((option) => {
73
+ // const optionLabel = option.label || '';
74
+ // const searchValue = inputValue || '';
75
+ // return optionLabel.toLowerCase().includes(searchValue.toLowerCase());
76
+ // });
77
+ // }, [options, inputValue]);
324
78
  var filteredOptions = (0, react_1.useMemo)(function () {
325
- return options.filter(function (option) { var _a, _b; return (_a = option.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes((_b = (inputValue !== null && inputValue !== void 0 ? inputValue : "")) === null || _b === void 0 ? void 0 : _b.toLowerCase()); });
326
- }, [options, inputValue]);
79
+ return options
80
+ .filter(function (option) {
81
+ // First filter out already selected options
82
+ // const isNotSelected = !selectedOptions.some(
83
+ // (selected) => selected.id === option.id
84
+ // );
85
+ var isNotSelected = isMultipleSelect ?
86
+ !selectedOptions.some(function (selected) { return selected.id === option.id; }) :
87
+ true;
88
+ // Then apply the search filter
89
+ var optionLabel = option.label || '';
90
+ var searchValue = inputValue || '';
91
+ return isNotSelected && optionLabel.toLowerCase().includes(searchValue.toLowerCase());
92
+ });
93
+ }, [options, inputValue, selectedOptions]);
94
+ // const filteredOptions = useMemo(() => {
95
+ // return options.filter((option) =>
96
+ // option.label?.toLowerCase().includes((inputValue ?? "")?.toLowerCase())
97
+ // );
98
+ // }, [options, inputValue]);
327
99
  // const handleOptionClick = useCallback(
328
100
  // (option: selectOptions) => {
329
101
  // if (isMultipleSelect) {
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const TableActions: ({ row }: any) => React.JSX.Element;
3
+ export default TableActions;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var react_1 = __importDefault(require("react"));
7
+ var react_2 = require("@chakra-ui/react");
8
+ var fa_1 = require("react-icons/fa");
9
+ var md_1 = require("react-icons/md");
10
+ var icons_1 = require("@chakra-ui/icons");
11
+ var TableActions = function (_a) {
12
+ var row = _a.row;
13
+ return (react_1.default.createElement(react_2.Popover, { placement: "bottom-start" },
14
+ react_1.default.createElement(react_2.PopoverTrigger, null,
15
+ react_1.default.createElement(react_2.IconButton, { "aria-label": "Link", color: "black", icon: react_1.default.createElement(fa_1.FaEllipsisV, { fontSize: 12 }), size: "sm", p: 0, variant: "ghost", _hover: { transform: "scale(1.2)" } })),
16
+ react_1.default.createElement(react_2.Portal, null,
17
+ react_1.default.createElement(react_2.PopoverContent, { w: "auto", minW: "150px", boxShadow: "lg", p: 0, zIndex: 999 },
18
+ react_1.default.createElement(react_2.PopoverBody, null,
19
+ react_1.default.createElement(react_2.VStack, { align: "stretch", spacing: 1 },
20
+ row.onLink && (react_1.default.createElement(react_2.Button, { size: "sm", variant: "ghost", justifyContent: "flex-start", gap: 2, onClick: function () { return row === null || row === void 0 ? void 0 : row.onLink(row); } },
21
+ react_1.default.createElement(icons_1.ExternalLinkIcon, null),
22
+ " View")),
23
+ row.onEdit && (react_1.default.createElement(react_2.Button, { size: "sm", variant: "ghost", justifyContent: "flex-start", gap: 2, onClick: function () { var _a; return (_a = row === null || row === void 0 ? void 0 : row.onEdit) === null || _a === void 0 ? void 0 : _a.call(row, row); } },
24
+ react_1.default.createElement(icons_1.EditIcon, null),
25
+ " Edit")),
26
+ row.onDelete && (react_1.default.createElement(react_2.Button, { size: "sm", variant: "ghost", justifyContent: "flex-start", colorScheme: "red", gap: 2, onClick: function () { var _a; return (_a = row === null || row === void 0 ? void 0 : row.onDelete) === null || _a === void 0 ? void 0 : _a.call(row, row); } },
27
+ react_1.default.createElement(md_1.MdDelete, null),
28
+ "Delete"))))))));
29
+ };
30
+ exports.default = TableActions;
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { TableBodyPageProps } from "../TableProps";
3
- declare const TableBody: ({ data, isCheckbox, columns, visibleColumns, startRow, endRow, columnWidths, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, selections, isLoading, onRowClick, isContent, isLink, }: TableBodyPageProps) => React.JSX.Element;
3
+ declare const TableBody: ({ data, isCheckbox, columns, visibleColumns, startRow, endRow, columnWidths, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, selections, isLoading, onRowClick, isContent, isLink, isActionFreeze, }: TableBodyPageProps) => React.JSX.Element;
4
4
  export default TableBody;
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  var react_1 = require("@chakra-ui/react");
27
30
  var react_2 = __importStar(require("react"));
@@ -29,10 +32,10 @@ var table_1 = require("../../../Utils/table");
29
32
  var useCustomTheme_1 = require("../../../Theme/useCustomTheme");
30
33
  var TableLoading_1 = require("./TableLoading");
31
34
  var fa_1 = require("react-icons/fa");
32
- var icons_1 = require("@chakra-ui/icons");
35
+ var TableActions_1 = __importDefault(require("./TableActions"));
33
36
  var TableBody = function (_a) {
34
37
  var _b;
35
- var data = _a.data, isCheckbox = _a.isCheckbox, columns = _a.columns, visibleColumns = _a.visibleColumns, startRow = _a.startRow, endRow = _a.endRow, columnWidths = _a.columnWidths, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, selections = _a.selections, isLoading = _a.isLoading, onRowClick = _a.onRowClick, isContent = _a.isContent, isLink = _a.isLink;
38
+ var data = _a.data, isCheckbox = _a.isCheckbox, columns = _a.columns, visibleColumns = _a.visibleColumns, startRow = _a.startRow, endRow = _a.endRow, columnWidths = _a.columnWidths, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, selections = _a.selections, isLoading = _a.isLoading, onRowClick = _a.onRowClick, isContent = _a.isContent, isLink = _a.isLink, isActionFreeze = _a.isActionFreeze;
36
39
  var theme = (0, useCustomTheme_1.useCustomTheme)();
37
40
  var _c = (0, react_2.useState)(new Set()), expandedRows = _c[0], setExpandedRows = _c[1];
38
41
  var toggleRowExpansion = function (rowIndex) {
@@ -52,27 +55,26 @@ var TableBody = function (_a) {
52
55
  };
53
56
  var RenderCheckbox = (0, react_2.useCallback)(function (_a) {
54
57
  var _b;
55
- var row = _a.row;
58
+ var row = _a.row, isChecked = _a.isChecked;
56
59
  return (react_2.default.createElement(react_1.Td, { w: "6", fontSize: 14, fontWeight: 600, color: freezedTextColor, textTransform: "capitalize", backgroundColor: freezedBgColor, position: "sticky", border: noBorders ? "none" : "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" },
57
- react_2.default.createElement(react_1.Checkbox, { "aria-label": "Select all rows", colorScheme: "gray", backgroundColor: theme.colors.gray[50], borderColor: theme.colors.gray[500], variant: "subtle", onChange: function () { return handleCheckbox(row.id); }, isChecked: selections.includes(row.id) })));
60
+ react_2.default.createElement(react_1.Checkbox, { "aria-label": "Select all rows", colorScheme: "gray", backgroundColor: theme.colors.gray[50], borderColor: theme.colors.gray[500], variant: "subtle", onChange: function () { return handleCheckbox(row.id); }, isChecked: isChecked, _hover: { transform: "scale(1.1)" } })));
58
61
  }, [
59
62
  freezedBgColor,
60
63
  freezedTextColor,
61
64
  handleCheckbox,
62
65
  noBorders,
63
- selections,
64
66
  (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray,
65
67
  ]);
66
68
  var RenderContent = (0, react_2.useCallback)(function (_a) {
67
69
  var _b, _c;
68
70
  var isExpanded = _a.isExpanded, rowIndex = _a.rowIndex, isContent = _a.isContent;
69
- return (react_2.default.createElement(react_1.Td, { w: "6", p: 0, fontSize: 14, backgroundColor: freezedBgColor, color: freezedTextColor, position: "sticky", border: noBorders ? "none" : "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" }, isContent && (react_2.default.createElement(react_1.IconButton, { "aria-label": isExpanded ? "Collapse row" : "Expand row", color: (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], icon: isExpanded ? (react_2.default.createElement(fa_1.FaAngleDown, { fontSize: 16 })) : (react_2.default.createElement(fa_1.FaAngleRight, { fontSize: 16 })), size: "sm", onClick: function () { return toggleRowExpansion(rowIndex); }, variant: "ghost" }))));
71
+ return (react_2.default.createElement(react_1.Td, { w: "6", p: 0, fontSize: 14, backgroundColor: freezedBgColor, color: freezedTextColor, position: "sticky", border: noBorders ? "none" : "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" }, isContent && (react_2.default.createElement(react_1.IconButton, { "aria-label": isExpanded ? "Collapse row" : "Expand row", color: (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], icon: isExpanded ? (react_2.default.createElement(fa_1.FaAngleDown, { fontSize: 16 })) : (react_2.default.createElement(fa_1.FaAngleRight, { fontSize: 16 })), _hover: { transform: "scale(1.1)" }, size: "sm", onClick: function () { return toggleRowExpansion(rowIndex); }, variant: "ghost" }))));
70
72
  }, [freezedBgColor, freezedTextColor, noBorders, theme.colors.gray]);
71
73
  var RenderView = (0, react_2.useCallback)(function (_a) {
72
- var _b, _c;
73
- var row = _a.row;
74
- return (react_2.default.createElement(react_1.Td, { w: 2, p: 0, fontSize: 14, backgroundColor: freezedBgColor, color: freezedTextColor, position: "sticky", border: noBorders ? "none" : "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), boxSizing: "border-box", right: 0, zIndex: 1, className: "columns sticky-columns" }, !!row.onLink && (react_2.default.createElement(react_1.IconButton, { "aria-label": "Link", color: (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], icon: react_2.default.createElement(icons_1.ExternalLinkIcon, { fontSize: 16 }), size: "sm", onClick: function () { return row === null || row === void 0 ? void 0 : row.onLink(row); }, variant: "ghost" }))));
75
- }, [freezedBgColor, freezedTextColor, noBorders, theme.colors.gray]);
74
+ var _b;
75
+ var row = _a.row, bgcolor = _a.bgcolor;
76
+ return (react_2.default.createElement(react_1.Td, { w: 2, p: 0, fontSize: 14, backgroundColor: isActionFreeze ? freezedBgColor : bgcolor, color: freezedTextColor, position: isActionFreeze ? "sticky" : "relative", border: noBorders ? "none" : "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), boxSizing: "border-box", right: 0, zIndex: 1, className: "columns sticky-columns".concat(isActionFreeze ? "-right" : "") }, (row.onLink || row.onEdit || row.onDelete) && (react_2.default.createElement(TableActions_1.default, { row: row }))));
77
+ }, [freezedBgColor, freezedTextColor, noBorders, theme.colors, isActionFreeze]);
76
78
  if (isLoading) {
77
79
  var totalVisibleColumns = Object.values(visibleColumns).filter(Boolean).length +
78
80
  (isCheckbox ? 1 : 0);
@@ -80,7 +82,9 @@ var TableBody = function (_a) {
80
82
  }
81
83
  if (data.length === 0) {
82
84
  var totalVisibleColumns = Object.values(visibleColumns).filter(Boolean).length +
83
- (isCheckbox ? 1 : 0);
85
+ (isCheckbox ? 1 : 0) +
86
+ (isContent ? 1 : 0) +
87
+ (isLink ? 1 : 0);
84
88
  return (react_2.default.createElement(react_1.Tr, { backgroundColor: theme.colors.white },
85
89
  react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, textAlign: "center", py: 4 },
86
90
  react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14 },
@@ -89,14 +93,22 @@ var TableBody = function (_a) {
89
93
  return (react_2.default.createElement(react_2.default.Fragment, null, data.slice(startRow, endRow).map(function (row, index) {
90
94
  var rowIndex = startRow + index;
91
95
  var isExpanded = expandedRows.has(rowIndex);
96
+ var isChecked = selections.includes(row.id);
97
+ var freezeViewColor = index % 2 === 1 ? theme.colors.backgroundColor.light : "white";
92
98
  return (react_2.default.createElement(react_2.default.Fragment, { key: rowIndex },
93
- react_2.default.createElement(react_1.Tr, { key: index + 1, _hover: {
99
+ react_2.default.createElement(react_1.Tr, { key: index + 1, sx: isChecked
100
+ ? {
101
+ "& td": {
102
+ backgroundColor: theme.colors.gray[100],
103
+ },
104
+ }
105
+ : {}, _hover: {
94
106
  "& > td": {
95
107
  backgroundColor: theme.colors.gray[100],
96
108
  },
97
109
  } },
98
110
  isContent && (react_2.default.createElement(RenderContent, { rowIndex: rowIndex, isExpanded: isExpanded, isContent: !!row.content })),
99
- isCheckbox && react_2.default.createElement(RenderCheckbox, { row: row }),
111
+ isCheckbox && react_2.default.createElement(RenderCheckbox, { row: row, isChecked: isChecked }),
100
112
  columns.map(function (header, headerIndex) {
101
113
  var _a;
102
114
  var isFrozen = header.isFreeze;
@@ -117,12 +129,15 @@ var TableBody = function (_a) {
117
129
  ? theme.colors.backgroundColor.light
118
130
  : "white", textOverflow: "ellipsis", border: noBorders
119
131
  ? "none"
120
- : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[isFrozen ? 300 : 200]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns"), boxSizing: "border-box", color: isFrozen ? freezedTextColor : undefined },
132
+ : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[isFrozen || isChecked ? 300 : 200]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns"), boxSizing: "border-box", color: isFrozen ? freezedTextColor : undefined },
121
133
  react_2.default.createElement(react_1.Box, { textOverflow: "ellipsis", whiteSpace: "nowrap", display: "block", overflow: "hidden" }, header.node ? header.node(row) : row[header.id]))));
122
134
  }),
123
- isLink && react_2.default.createElement(RenderView, { row: row })),
135
+ isLink && react_2.default.createElement(RenderView, { row: row, bgcolor: freezeViewColor })),
124
136
  row.content && isExpanded && (react_2.default.createElement(react_1.Tr, null,
125
- react_2.default.createElement(react_1.Td, { colSpan: columns.length + (isCheckbox ? 1 : 0) + (isContent ? 1 : 0), p: 2 },
137
+ react_2.default.createElement(react_1.Td, { colSpan: columns.length +
138
+ (isCheckbox ? 1 : 0) +
139
+ (isContent ? 1 : 0) +
140
+ (isLink ? 1 : 0), p: 2 },
126
141
  react_2.default.createElement(react_1.Box, { p: 2, bg: theme.colors.white, borderRadius: "md" }, row === null || row === void 0 ? void 0 : row.content(row)))))));
127
142
  })));
128
143
  };
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { TableHeaderPageProps } from "../TableProps";
3
- declare const TableHeader: ({ columns, isCheckbox, visibleColumns, handleSort, headerRefs, columnWidths, columnsSort, headerBgColor, headerTextColor, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, checked, isLoading, isContent, isLink, }: TableHeaderPageProps) => React.JSX.Element;
3
+ declare const TableHeader: ({ columns, isCheckbox, visibleColumns, handleSort, headerRefs, columnWidths, columnsSort, headerBgColor, headerTextColor, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, checked, isLoading, isContent, isLink, onColumnSearch, columnFilters, isActionFreeze, }: TableHeaderPageProps) => React.JSX.Element;
4
4
  export default TableHeader;
@@ -27,15 +27,42 @@ var react_1 = require("@chakra-ui/react");
27
27
  var react_2 = __importStar(require("react"));
28
28
  var table_1 = require("../../../Utils/table");
29
29
  var useCustomTheme_1 = require("../../../Theme/useCustomTheme");
30
+ var icons_1 = require("@chakra-ui/icons");
30
31
  var fa_1 = require("react-icons/fa");
32
+ var pi_1 = require("react-icons/pi");
33
+ var lu_1 = require("react-icons/lu");
31
34
  var TableHeader = function (_a) {
32
35
  var _b;
33
- var columns = _a.columns, isCheckbox = _a.isCheckbox, visibleColumns = _a.visibleColumns, handleSort = _a.handleSort, headerRefs = _a.headerRefs, columnWidths = _a.columnWidths, columnsSort = _a.columnsSort, headerBgColor = _a.headerBgColor, headerTextColor = _a.headerTextColor, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, checked = _a.checked, isLoading = _a.isLoading, isContent = _a.isContent, isLink = _a.isLink;
36
+ var columns = _a.columns, isCheckbox = _a.isCheckbox, visibleColumns = _a.visibleColumns, handleSort = _a.handleSort, headerRefs = _a.headerRefs, columnWidths = _a.columnWidths, columnsSort = _a.columnsSort, headerBgColor = _a.headerBgColor, headerTextColor = _a.headerTextColor, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, checked = _a.checked, isLoading = _a.isLoading, isContent = _a.isContent, isLink = _a.isLink, onColumnSearch = _a.onColumnSearch, _c = _a.columnFilters, columnFilters = _c === void 0 ? {} : _c, isActionFreeze = _a.isActionFreeze;
34
37
  var theme = (0, useCustomTheme_1.useCustomTheme)();
38
+ var _d = (0, react_2.useState)(null), openPopoverId = _d[0], setOpenPopoverId = _d[1];
39
+ var handleSearchChange = (0, react_2.useCallback)(function (columnId, value) {
40
+ onColumnSearch === null || onColumnSearch === void 0 ? void 0 : onColumnSearch(columnId, value);
41
+ }, [onColumnSearch]);
42
+ (0, react_2.useEffect)(function () {
43
+ if (!columnFilters)
44
+ return;
45
+ var lastKey = Object.keys(columnFilters).pop() || null;
46
+ if (!lastKey)
47
+ return;
48
+ setOpenPopoverId(lastKey);
49
+ }, [columnFilters]);
50
+ (0, react_2.useEffect)(function () {
51
+ var handleClickOutside = function (event) {
52
+ var target = event.target;
53
+ if (!(target === null || target === void 0 ? void 0 : target.closest(".search-popover"))) {
54
+ setOpenPopoverId(null);
55
+ }
56
+ };
57
+ document.addEventListener("mousedown", handleClickOutside);
58
+ return function () {
59
+ document.removeEventListener("mousedown", handleClickOutside);
60
+ };
61
+ }, [openPopoverId]);
35
62
  var RenderCheckbox = (0, react_2.useCallback)(function () {
36
63
  var _a;
37
- return (react_2.default.createElement(react_1.Th, { w: "6", fontSize: 14, fontWeight: 600, color: freezedTextColor, textTransform: "capitalize", backgroundColor: freezedBgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
38
- react_2.default.createElement(react_1.Checkbox, { "aria-label": "Select all rows", colorScheme: "gray", backgroundColor: theme.colors.gray[50], borderColor: theme.colors.gray[500], variant: "subtle", onChange: function () { return handleCheckbox(0); }, isChecked: isLoading ? false : checked === true, isIndeterminate: checked === "indeterminate" })));
64
+ return (react_2.default.createElement(react_1.Th, { w: 6, fontSize: 14, fontWeight: 600, color: freezedTextColor, textTransform: "capitalize", backgroundColor: freezedBgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 9, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)", top: 0 },
65
+ react_2.default.createElement(react_1.Checkbox, { "aria-label": "Select all rows", colorScheme: "gray", backgroundColor: theme.colors.gray[50], borderColor: theme.colors.gray[500], variant: "outline", onChange: function () { return handleCheckbox(0); }, isChecked: isLoading ? false : checked === true, isIndeterminate: checked === "indeterminate", _hover: { transform: "scale(1.1)" } })));
39
66
  }, [
40
67
  checked,
41
68
  freezedBgColor,
@@ -47,42 +74,77 @@ var TableHeader = function (_a) {
47
74
  ]);
48
75
  var RenderConent = (0, react_2.useCallback)(function () {
49
76
  var _a;
50
- return (react_2.default.createElement(react_1.Th, { w: "6", p: 0, backgroundColor: freezedBgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
77
+ return (react_2.default.createElement(react_1.Th, { w: 6, minW: "35px", p: 0, backgroundColor: freezedBgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
51
78
  react_2.default.createElement(react_1.Box, { display: "flex", justifyContent: "center" },
52
- react_2.default.createElement(fa_1.FaExpandArrowsAlt, { fontSize: 14 }))));
79
+ react_2.default.createElement(pi_1.PiTreeViewFill, { fontSize: 18 }))));
53
80
  }, [freezedBgColor, noBorders, theme.colors.gray]);
54
81
  var RenderView = (0, react_2.useCallback)(function () {
55
82
  var _a;
56
- return (react_2.default.createElement(react_1.Th, { w: "6", p: 0, backgroundColor: freezedBgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: "sticky", className: "columns sticky-columns", right: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" }));
57
- }, [freezedBgColor, noBorders, theme.colors.gray]);
58
- return (react_2.default.createElement(react_1.Tr, null,
83
+ var BgColor = isActionFreeze ? freezedBgColor : headerBgColor;
84
+ return (react_2.default.createElement(react_1.Th, { w: 2, p: 0, backgroundColor: BgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: isActionFreeze ? "sticky" : "relative", className: "columns sticky-columns", right: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
85
+ react_2.default.createElement(react_1.Box, { display: "flex", justifyContent: "center" },
86
+ react_2.default.createElement(lu_1.LuFileSymlink, { fontSize: 16 }))));
87
+ }, [
88
+ freezedBgColor,
89
+ noBorders,
90
+ theme.colors.gray,
91
+ headerBgColor,
92
+ isActionFreeze,
93
+ ]);
94
+ var Sorting = (0, react_2.useCallback)(function (_a) {
95
+ var _b;
96
+ var isSorting = _a.isSorting, header = _a.header;
97
+ return (react_2.default.createElement(SortingIcon, { sortState: (_b = isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) !== null && _b !== void 0 ? _b : "none", handleSortClick: function () {
98
+ var direction = "asc";
99
+ if ((isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) === "asc") {
100
+ direction = "desc";
101
+ }
102
+ else if ((isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) === "desc") {
103
+ direction = "none";
104
+ }
105
+ handleSort(header.id, direction);
106
+ } }));
107
+ }, [handleSort]);
108
+ var Popvers = (0, react_2.useCallback)(function (_a) {
109
+ var header = _a.header;
110
+ return (react_2.default.createElement("div", { className: "search-popover" },
111
+ react_2.default.createElement(react_1.Popover, { isOpen: openPopoverId === header.id, onClose: function () { return setOpenPopoverId(null); }, placement: "bottom-start", closeOnBlur: false, closeOnEsc: false },
112
+ react_2.default.createElement(react_1.PopoverTrigger, null,
113
+ react_2.default.createElement(react_1.IconButton, { "aria-label": "Search", icon: react_2.default.createElement(fa_1.FaEllipsisV, null), size: "xs", variant: "ghost", onClick: function () {
114
+ return setOpenPopoverId(openPopoverId === header.id ? null : header.id);
115
+ }, _hover: { bg: "none" } })),
116
+ react_2.default.createElement(react_1.PopoverContent, { width: "200px" },
117
+ react_2.default.createElement(react_1.PopoverBody, { p: 2 },
118
+ react_2.default.createElement(react_1.InputGroup, { flex: "1", size: "xs" },
119
+ react_2.default.createElement(react_1.InputLeftElement, { pointerEvents: "none" },
120
+ react_2.default.createElement(icons_1.SearchIcon, { color: "gray.300" })),
121
+ react_2.default.createElement(react_1.Input, { autoFocus: true, placeholder: "Search ".concat(header.label, "..."), size: "xs", value: columnFilters[header.id] || "", onChange: function (e) {
122
+ e.stopPropagation();
123
+ handleSearchChange(header.id, e.target.value);
124
+ } })))))));
125
+ }, [columnFilters, openPopoverId, handleSearchChange]);
126
+ var renderColumnHeader = function (header, index) {
127
+ var _a;
128
+ var isFrozen = header.isFreeze;
129
+ var leftOffset = isFrozen
130
+ ? (0, table_1.calculateLeftOffset)(columnWidths, index) + (isCheckbox ? 50 : 0)
131
+ : undefined;
132
+ var isSorting = header.isSort
133
+ ? columnsSort.find(function (o) { return o.column === header.id; })
134
+ : undefined;
135
+ var BgColor = isFrozen ? freezedBgColor : headerBgColor;
136
+ var TextColor = isFrozen ? freezedTextColor : headerTextColor;
137
+ return (visibleColumns[header.label] && (react_2.default.createElement(react_1.Th, { key: index + 1, ref: function (el) { return (headerRefs.current[index] = el); }, textTransform: "capitalize", color: TextColor, fontSize: 14, fontWeight: 600, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffset : undefined, minWidth: 120, backgroundColor: BgColor, maxWidth: 500, zIndex: isFrozen ? 2 : 1, py: 2, pr: 0, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns") },
138
+ react_2.default.createElement(react_1.Box, { display: "flex", color: TextColor, justifyContent: "space-between", alignItems: "center" },
139
+ react_2.default.createElement(react_1.Box, { textOverflow: "ellipsis", whiteSpace: "nowrap", display: "block", overflow: "hidden" }, header.label),
140
+ react_2.default.createElement(react_1.Box, { display: "flex", alignItems: "center" },
141
+ header.isSort ? (react_2.default.createElement(Sorting, { isSorting: isSorting, header: header })) : null,
142
+ react_2.default.createElement(Popvers, { header: header }))))));
143
+ };
144
+ return (react_2.default.createElement(react_1.Tr, { pr: 0 },
59
145
  isContent && react_2.default.createElement(RenderConent, null),
60
146
  isCheckbox && react_2.default.createElement(RenderCheckbox, null),
61
- columns.map(function (header, index) {
62
- var _a, _b;
63
- var isFrozen = header.isFreeze;
64
- var leftOffset = isFrozen
65
- ? (0, table_1.calculateLeftOffset)(columnWidths, index) + (isCheckbox ? 50 : 0)
66
- : undefined;
67
- var isSorting = header.isSort
68
- ? columnsSort.find(function (o) { return o.column === header.id; })
69
- : undefined;
70
- var BgColor = isFrozen ? freezedBgColor : headerBgColor;
71
- var TextColor = isFrozen ? freezedTextColor : headerTextColor;
72
- return (visibleColumns[header.label] && (react_2.default.createElement(react_1.Th, { key: index + 1, ref: function (el) { return (headerRefs.current[index] = el); }, textTransform: "capitalize", color: TextColor, fontSize: 14, fontWeight: 600, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffset : undefined, minWidth: 120, backgroundColor: BgColor, maxWidth: 500, zIndex: isFrozen ? 2 : 1, py: 2, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns") },
73
- react_2.default.createElement(react_1.Box, { display: "flex", color: TextColor, justifyContent: "space-between", alignItems: "center" },
74
- react_2.default.createElement(react_1.Box, { textOverflow: "ellipsis", whiteSpace: "nowrap", display: "block", overflow: "hidden" }, header.label),
75
- react_2.default.createElement("span", null, header.isSort && (react_2.default.createElement(SortingIcon, { sortState: (_b = isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) !== null && _b !== void 0 ? _b : "none", handleSortClick: function () {
76
- var direction = "asc";
77
- if ((isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) === "asc") {
78
- direction = "desc";
79
- }
80
- else if ((isSorting === null || isSorting === void 0 ? void 0 : isSorting.direction) === "desc") {
81
- direction = "none";
82
- }
83
- handleSort(header.id, direction);
84
- } })))))));
85
- }),
147
+ columns.map(function (header, index) { return renderColumnHeader(header, index); }),
86
148
  isLink && react_2.default.createElement(RenderView, null)));
87
149
  };
88
150
  exports.default = TableHeader;
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { TableProps } from "./TableProps";
3
- export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagintaion, onRowClick, }: TableProps): React.JSX.Element;
3
+ export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagintaion, onRowClick, selections, isActionFreeze, }: TableProps): React.JSX.Element;
@@ -58,18 +58,23 @@ var useCustomTheme_1 = require("../../Theme/useCustomTheme");
58
58
  var defaultPageSize = 5;
59
59
  function Table(_a) {
60
60
  var _b;
61
- var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _c = _a.isCheckbox, isCheckbox = _c === void 0 ? false : _c, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _d = _a.noBorders, noBorders = _d === void 0 ? false : _d, _e = _a.isPagintaion, isPagintaion = _e === void 0 ? true : _e, onRowClick = _a.onRowClick;
61
+ var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _c = _a.isCheckbox, isCheckbox = _c === void 0 ? false : _c, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _d = _a.noBorders, noBorders = _d === void 0 ? false : _d, _e = _a.isPagintaion, isPagintaion = _e === void 0 ? true : _e, onRowClick = _a.onRowClick, selections = _a.selections, _f = _a.isActionFreeze, isActionFreeze = _f === void 0 ? true : _f;
62
62
  var theme = (0, useCustomTheme_1.useCustomTheme)();
63
- var _f = (0, react_4.useState)([]), selection = _f[0], setSelection = _f[1];
64
- var _g = (0, react_4.useState)(0), currentPage = _g[0], setCurrentPage = _g[1];
65
- var _h = (0, react_4.useState)(defaultPageSize), rowsPerPage = _h[0], setRowsPerPage = _h[1];
66
- var _j = (0, react_4.useState)(columns.reduce(function (acc, curr) {
63
+ var _g = (0, react_4.useState)(selections !== null && selections !== void 0 ? selections : []), selection = _g[0], setSelection = _g[1];
64
+ var _h = (0, react_4.useState)(0), currentPage = _h[0], setCurrentPage = _h[1];
65
+ var _j = (0, react_4.useState)(defaultPageSize), rowsPerPage = _j[0], setRowsPerPage = _j[1];
66
+ var _k = (0, react_4.useState)({}), columnFilters = _k[0], setColumnFilters = _k[1];
67
+ var _l = (0, react_4.useState)(data), filteredData = _l[0], setFilteredData = _l[1];
68
+ (0, react_1.useEffect)(function () {
69
+ setSelection(selections !== null && selections !== void 0 ? selections : []);
70
+ }, [selections]);
71
+ var _m = (0, react_4.useState)(columns.reduce(function (acc, curr) {
67
72
  var _a;
68
73
  return (__assign(__assign({}, acc), (_a = {}, _a[curr.label] = true, _a)));
69
- }, {})), visibleColumns = _j[0], setVisibleColumns = _j[1];
70
- var _k = (0, react_4.useState)([]), columnWidths = _k[0], setColumnWidths = _k[1];
74
+ }, {})), visibleColumns = _m[0], setVisibleColumns = _m[1];
75
+ var _o = (0, react_4.useState)([]), columnWidths = _o[0], setColumnWidths = _o[1];
71
76
  var headerRefs = (0, react_1.useRef)([]);
72
- var _l = (0, react_4.useState)([]), columnsSort = _l[0], setColumnsSort = _l[1];
77
+ var _p = (0, react_4.useState)([]), columnsSort = _p[0], setColumnsSort = _p[1];
73
78
  (0, react_1.useEffect)(function () {
74
79
  // Measure widths after the component mounts
75
80
  var widths = headerRefs.current.map(function (ref) { return (ref === null || ref === void 0 ? void 0 : ref.offsetWidth) || 0; });
@@ -98,50 +103,69 @@ function Table(_a) {
98
103
  setColumnsSort(newSortState);
99
104
  }, [columnsSort]);
100
105
  var handleCheckbox = function (id) {
106
+ var selectedItems = [];
101
107
  if (id === 0) {
102
108
  if (selection.length === data.length) {
103
- setSelection([]);
109
+ selectedItems = [];
104
110
  }
105
111
  else {
106
- setSelection(data.map(function (item) { return item.id; }));
112
+ selectedItems = data.map(function (item) { return item.id; });
107
113
  }
108
114
  }
109
115
  else if (selection.includes(id)) {
110
- setSelection(selection.filter(function (item) { return item !== id; }));
116
+ selectedItems = selection.filter(function (item) { return item !== id; });
111
117
  }
112
118
  else {
113
- setSelection(__spreadArray(__spreadArray([], selection, true), [id], false));
119
+ selectedItems = __spreadArray(__spreadArray([], selection, true), [id], false);
114
120
  }
121
+ setSelection(selectedItems);
122
+ onSelection && onSelection(selectedItems);
115
123
  };
124
+ var pages = isPagintaion ? Math.ceil(data.length / rowsPerPage) : 0;
125
+ var startRow = !isPagintaion ? 0 : currentPage * rowsPerPage;
126
+ var endRow = !isPagintaion ? data.length : startRow + rowsPerPage;
116
127
  (0, react_1.useEffect)(function () {
117
- onSelection && onSelection(selection);
118
- }, [selection, onSelection]);
119
- var pages = Math.ceil(data.length / rowsPerPage);
120
- var startRow = currentPage * rowsPerPage;
121
- var endRow = startRow + rowsPerPage;
122
- var tableData = (0, react_1.useMemo)(function () {
123
- return (0, table_1.SortMultiColumnData)(data, columnsSort);
124
- }, [data, columnsSort]);
128
+ var sortedData = (0, table_1.SortMultiColumnData)(filteredData, columnsSort);
129
+ var data = sortedData.slice(startRow, endRow);
130
+ setFilteredData(data);
131
+ }, [columnsSort, startRow, endRow]);
125
132
  var handleColumnVisibilityChange = function (header) {
126
133
  setVisibleColumns(function (prev) {
127
134
  var _a;
128
135
  return (__assign(__assign({}, prev), (_a = {}, _a[header] = !prev[header], _a)));
129
136
  });
130
137
  };
138
+ var handleColumnSearch = function (columnId, searchValue) {
139
+ var _a;
140
+ var newFilters = __assign(__assign({}, columnFilters), (_a = {}, _a[columnId] = searchValue, _a));
141
+ if (!searchValue) {
142
+ delete newFilters[columnId];
143
+ }
144
+ setColumnFilters(newFilters);
145
+ // Apply all active filters
146
+ var filtered = data.filter(function (row) {
147
+ return Object.entries(newFilters).every(function (_a) {
148
+ var colId = _a[0], filterValue = _a[1];
149
+ var cellValue = String(row[colId]).toLowerCase();
150
+ return cellValue.includes(filterValue.toLowerCase());
151
+ });
152
+ });
153
+ setFilteredData(filtered);
154
+ };
131
155
  var isContent = (0, react_1.useMemo)(function () { return data.some(function (o) { return o.content; }); }, [data]);
132
- var isLink = (0, react_1.useMemo)(function () { return data.some(function (o) { return o.onLink; }); }, [data]);
156
+ var isLink = (0, react_1.useMemo)(function () { return data.some(function (o) { return o.onLink || o.onDelete || o.onEdit; }); }, [data]);
133
157
  var RenderTable = function (_a) {
134
158
  var _b, _c, _d;
135
159
  var columns = _a.columns;
136
160
  return (react_1.default.createElement(react_3.Table, { variant: "simple", size: "sm", overflowX: "scroll", minW: "100%", className: "sticky-columns" },
137
- react_1.default.createElement(react_3.Thead, null,
161
+ react_1.default.createElement(react_3.Thead, { position: "sticky", top: 0, zIndex: 2 },
138
162
  react_1.default.createElement(TableHeader_1.default, { columns: columns, isCheckbox: isCheckbox, headerBgColor: headerBgColor !== null && headerBgColor !== void 0 ? headerBgColor : theme.colors.backgroundColor.muted, headerTextColor: headerTextColor !== null && headerTextColor !== void 0 ? headerTextColor : (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[600], freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], visibleColumns: visibleColumns, handleSort: handleSort, headerRefs: headerRefs, columnWidths: columnWidths, columnsSort: columnsSort, noBorders: noBorders, handleCheckbox: handleCheckbox, isLoading: isLoading, checked: data.length !== 0 && selection.length === data.length
139
163
  ? true
140
164
  : selection.length === 0
141
165
  ? false
142
- : "indeterminate", isContent: isContent, isLink: isLink })),
166
+ : "indeterminate", isContent: isContent, isLink: isLink, onColumnSearch: handleColumnSearch, columnFilters: columnFilters, isActionFreeze: isActionFreeze })),
143
167
  react_1.default.createElement(react_3.Tbody, null,
144
- react_1.default.createElement(TableBody_1.default, { data: tableData, columns: columns, startRow: startRow, endRow: endRow, visibleColumns: visibleColumns, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isLoading, onRowClick: onRowClick, isContent: isContent, isLink: isLink }))));
168
+ react_1.default.createElement(TableBody_1.default, { data: filteredData, columns: columns, startRow: startRow, endRow: endRow, visibleColumns: visibleColumns, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isLoading, onRowClick: onRowClick, isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze }))));
145
169
  };
146
170
  return (react_1.default.createElement(react_1.default.Fragment, null,
147
171
  react_1.default.createElement(react_2.TableContainer, { sx: {
@@ -149,8 +173,10 @@ function Table(_a) {
149
173
  borderWidth: "0px 0px 0px 5px",
150
174
  borderColor: tableBorderColor !== null && tableBorderColor !== void 0 ? tableBorderColor : (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[500],
151
175
  boxShadow: theme.shadows.lg,
176
+ maxHeight: "50vh",
177
+ overflowY: "auto",
152
178
  } },
153
179
  react_1.default.createElement(RenderTable, { columns: columns })),
154
- isPagintaion && !!tableData.length && (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(data.length), handlePageSizeChange: handlePageSizeChange, dataLength: data.length, visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }))));
180
+ isPagintaion && !!filteredData.length && (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(data.length), handlePageSizeChange: handlePageSizeChange, dataLength: data.length, visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }))));
155
181
  }
156
182
  exports.default = Table;
@@ -16,7 +16,9 @@ export type TableProps = {
16
16
  noBorders?: boolean;
17
17
  onSelection?: (selected: (string | number)[]) => void;
18
18
  isPagintaion?: boolean;
19
+ selections?: (string | number)[];
19
20
  onRowClick?: (row: DataObject, header: Record<string | number, string | number>) => void;
21
+ isActionFreeze?: boolean;
20
22
  };
21
23
  export type DataObject = {
22
24
  [key: string]: string | number | any;
@@ -37,7 +39,7 @@ export type ColumnSortingProps = {
37
39
  column: string | number;
38
40
  direction: "asc" | "desc" | "none";
39
41
  };
40
- export type TableHeaderPageProps = Pick<TableProps, "columns" | "isCheckbox" | "headerBgColor" | "headerTextColor" | "freezedBgColor" | "freezedTextColor" | "noBorders" | "isLoading"> & {
42
+ export type TableHeaderPageProps = Pick<TableProps, "columns" | "isCheckbox" | "headerBgColor" | "headerTextColor" | "freezedBgColor" | "freezedTextColor" | "noBorders" | "isLoading" | "isActionFreeze"> & {
41
43
  visibleColumns: Record<string, boolean>;
42
44
  handleSort: (label: string | number, type: "asc" | "desc" | "none") => void;
43
45
  activeHeader?: string | null;
@@ -52,8 +54,10 @@ export type TableHeaderPageProps = Pick<TableProps, "columns" | "isCheckbox" | "
52
54
  checked: boolean | "indeterminate";
53
55
  isContent: boolean;
54
56
  isLink: boolean;
57
+ onColumnSearch?: (columnId: string, searchValue: string) => void;
58
+ columnFilters?: Record<string, string>;
55
59
  };
56
- export type TableBodyPageProps = Pick<TableProps, "columns" | "isCheckbox" | "data" | "freezedBgColor" | "freezedTextColor" | "noBorders" | "isLoading" | "onRowClick"> & {
60
+ export type TableBodyPageProps = Pick<TableProps, "columns" | "isCheckbox" | "data" | "freezedBgColor" | "freezedTextColor" | "noBorders" | "isLoading" | "onRowClick" | "isActionFreeze"> & {
57
61
  visibleColumns: Record<string, boolean>;
58
62
  startRow: number;
59
63
  endRow: number;
@@ -39,6 +39,6 @@ var AlertdialogBox = function () {
39
39
  react_1.default.createElement(react_2.Button, { onClick: function () {
40
40
  setAlertActive(true);
41
41
  } }, "AlertDialog"),
42
- react_1.default.createElement(AlertDialog_1.default, { isOpen: alertActive, onClose: handleAlert, leastDestructiveRef: leastDestructiveRef, title: "hello", content: "hellobody", onConfirm: function () { return handleAlert(); }, size: "500" })));
42
+ react_1.default.createElement(AlertDialog_1.default, { isOpen: alertActive, onClose: handleAlert, leastDestructiveRef: leastDestructiveRef, title: "hello", content: react_1.default.createElement("div", { style: { color: "red", height: "200px" } }, "hellobody"), onConfirm: function () { return handleAlert(); }, size: "500" })));
43
43
  };
44
44
  exports.default = AlertdialogBox;
@@ -30,23 +30,43 @@ var react_1 = __importStar(require("react"));
30
30
  var SelectSearch_1 = __importDefault(require("../Components/SelectSearch/SelectSearch"));
31
31
  var fi_1 = require("react-icons/fi");
32
32
  var SelectSearchs = function () {
33
- var _a = (0, react_1.useState)(""), selectSearchText = _a[0], setSelectSearchText = _a[1];
34
- var _b = (0, react_1.useState)(), selectedOption = _b[0], setSelectedOption = _b[1];
33
+ var _a = (0, react_1.useState)("Option 1"), selectSearchText = _a[0], setSelectSearchText = _a[1];
34
+ var _b = (0, react_1.useState)({ id: "1", label: "Option 1" }), selectedOption = _b[0], setSelectedOption = _b[1];
35
+ var _c = (0, react_1.useState)("Option 1"), multiSelectSearchText = _c[0], setMultiSelectSearchText = _c[1];
36
+ var _d = (0, react_1.useState)({ id: "1", label: "Option 1" }), multiselectedOption = _d[0], setMultiSelectedOption = _d[1];
35
37
  return (react_1.default.createElement("div", null,
36
- react_1.default.createElement(SelectSearch_1.default, { options: [
37
- { id: "1", label: "Option 1" },
38
- { id: "2", label: "select 2" },
39
- {
40
- id: "3",
41
- label: "clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3clone 3",
42
- },
43
- ], inputOnchange: function (value) {
44
- setSelectSearchText(value.toString());
45
- console.log(value);
46
- }, initialSelectedOption: { id: "1", label: "Option 1" }, onOptionSelect: function (data) {
47
- setSelectSearchText(data.label);
48
- }, name: "hai", label: "SelectSearch", searchQuery: selectSearchText, rightIcon: react_1.default.createElement(fi_1.FiUser, { color: "gray.300" }), isMultipleSelect: false, onOptionMultiSelect: function (data) {
49
- setSelectedOption(data);
50
- } })));
38
+ react_1.default.createElement("div", null,
39
+ react_1.default.createElement(SelectSearch_1.default, { options: [
40
+ { id: "1", label: "Option 1" },
41
+ { id: "2", label: "select 2" },
42
+ { id: "3", label: "clone 3", },
43
+ ], inputOnchange: function (value) {
44
+ setSelectSearchText(value.toString());
45
+ console.log(value);
46
+ }, initialSelectedOption: selectedOption, onOptionSelect: function (data) {
47
+ setSelectSearchText(data.label);
48
+ }, name: "hai", label: "SelectSearch", searchQuery: selectSearchText, rightIcon: react_1.default.createElement(fi_1.FiUser, { color: "gray.300" }), isMultipleSelect: false, onOptionMultiSelect: function (data) {
49
+ setSelectedOption(data);
50
+ } })),
51
+ react_1.default.createElement("br", null),
52
+ react_1.default.createElement("br", null),
53
+ react_1.default.createElement("br", null),
54
+ react_1.default.createElement("br", null),
55
+ react_1.default.createElement("br", null),
56
+ react_1.default.createElement("div", null,
57
+ react_1.default.createElement(SelectSearch_1.default, { options: [
58
+ { id: "1", label: "Option 1" },
59
+ { id: "2", label: "select 2" },
60
+ { id: "3", label: "clone 3", },
61
+ ], inputOnchange: function (value) {
62
+ setMultiSelectSearchText(value.toString());
63
+ // console.log(value);
64
+ }, initialSelectedOption: multiselectedOption,
65
+ // onOptionSelect={(data) => {
66
+ // setMultiSelectSearchText(data.label);
67
+ // }}
68
+ name: "hai", label: "MultiSelectSearch", searchQuery: multiSelectSearchText, rightIcon: react_1.default.createElement(fi_1.FiUser, { color: "gray.300" }), isMultipleSelect: true, onOptionMultiSelect: function (data) {
69
+ setMultiSelectedOption(data);
70
+ } }))));
51
71
  };
52
72
  exports.default = SelectSearchs;
@@ -21,11 +21,9 @@ var tableData = [
21
21
  name: "Jane Doe",
22
22
  age: 25,
23
23
  gender: "Female",
24
- content: function (data) {
24
+ content: function () {
25
25
  return (react_1.default.createElement("div", null,
26
- data.name,
27
- " - ",
28
- data.age));
26
+ react_1.default.createElement(Table_1.default, { columns: column, data: [] })));
29
27
  },
30
28
  },
31
29
  {
@@ -34,6 +32,78 @@ var tableData = [
34
32
  age: 40,
35
33
  gender: "Male",
36
34
  },
35
+ {
36
+ id: 3,
37
+ name: "Bob Smith",
38
+ age: 40,
39
+ gender: "Male",
40
+ },
41
+ {
42
+ id: 3,
43
+ name: "Bob Smith",
44
+ age: 40,
45
+ gender: "Male",
46
+ },
47
+ {
48
+ id: 3,
49
+ name: "Bob Smith",
50
+ age: 40,
51
+ gender: "Male",
52
+ },
53
+ {
54
+ id: 3,
55
+ name: "Bob Smith",
56
+ age: 40,
57
+ gender: "Male",
58
+ },
59
+ {
60
+ id: 3,
61
+ name: "Bob Smith",
62
+ age: 40,
63
+ gender: "Male",
64
+ },
65
+ {
66
+ id: 3,
67
+ name: "Bob Smith",
68
+ age: 40,
69
+ gender: "Male",
70
+ },
71
+ {
72
+ id: 33,
73
+ name: "Bob Smith333",
74
+ age: 40,
75
+ gender: "Male",
76
+ },
77
+ {
78
+ id: 3,
79
+ name: "Bob Smith",
80
+ age: 40,
81
+ gender: "Male",
82
+ },
83
+ {
84
+ id: 3,
85
+ name: "Bob Smith",
86
+ age: 40,
87
+ gender: "Male",
88
+ },
89
+ {
90
+ id: 3,
91
+ name: "Bob Smith",
92
+ age: 40,
93
+ gender: "Male",
94
+ },
95
+ {
96
+ id: 3,
97
+ name: "Bob Smith",
98
+ age: 40,
99
+ gender: "Male",
100
+ },
101
+ {
102
+ id: 3,
103
+ name: "Bob Smith",
104
+ age: 40,
105
+ gender: "Male",
106
+ },
37
107
  ];
38
108
  var column = [
39
109
  {
@@ -63,6 +133,6 @@ var column = [
63
133
  ];
64
134
  var TableExample = function () {
65
135
  return (react_1.default.createElement("div", null,
66
- react_1.default.createElement(Table_1.default, { columns: column, data: tableData, isCheckbox: true, isVisiblity: false, isLoading: false, noBorders: false, onSelection: function (checked) { return console.log(checked); }, onRowClick: function (row, header) { return console.log(row, header); } })));
136
+ react_1.default.createElement(Table_1.default, { columns: column, data: tableData, isCheckbox: true, isVisiblity: false, isLoading: false, noBorders: false, onSelection: function (checked) { return console.log(checked); }, onRowClick: function (row, header) { return console.log(row, header); }, isPagintaion: false })));
67
137
  };
68
138
  exports.TableExample = TableExample;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "1.1.47",
3
+ "version": "1.1.50",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",