gbs-add-block 0.0.93 → 0.0.97

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GBS Building Blocks 2.0 (v0.0.93)
1
+ # GBS Building Blocks 2.0 (v0.0.97)
2
2
 
3
3
  Latest and upgraded version of GBS building blocks with headless UI and removed dependencies.
4
4
 
@@ -6,7 +6,7 @@ Latest and upgraded version of GBS building blocks with headless UI and removed
6
6
 
7
7
  For detailed documentation on usage and props, Please visit: [Building Block Documentation v2.0](https://blackmax-designs.gitbook.io/building-block-v2.0)
8
8
 
9
- ## What's New 🎉 (Ver 0.0.93)
9
+ ## What's New 🎉 (Ver 0.0.97)
10
10
 
11
11
  - Updated for bug fixes.
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.93",
3
+ "version": "0.0.97",
4
4
  "description": "React Component Library",
5
5
  "type": "module",
6
6
  "files": [
@@ -64,6 +64,9 @@ interface GridContextType {
64
64
  gridColumnStyleSelectAll: string;
65
65
  gridColumnStyle: string;
66
66
  rowChange: (rowData: any) => void;
67
+ showTotalPages?: boolean;
68
+ onSearch?: (searchParam: string) => void;
69
+ onToolbarButtonClick?: (action: string) => void;
67
70
  }
68
71
 
69
72
  const GridContext = createContext<GridContextType | undefined>(undefined);
@@ -83,7 +86,7 @@ export const GridProvider: React.FC<{
83
86
  enablePdfExport = false,
84
87
  pdfName = "data",
85
88
  pdfOptions = {},
86
- gridButtonClass = "px-1 py-2 text-xs rounded bg-zinc-200 dark:bg-zinc-700",
89
+ gridButtonClass = "px-1 py-2 text-xs rounded bg-zinc-200 dark:bg-zinc-700 cursor-pointer",
87
90
  selectAll = false,
88
91
  onSelectRow,
89
92
  isFetching,
@@ -95,6 +98,9 @@ export const GridProvider: React.FC<{
95
98
  pageStatus = () => {},
96
99
  activeFilterArrayValue = [],
97
100
  searchParamValue = () => {},
101
+ showTotalPages = false,
102
+ onSearch = () => {},
103
+ onToolbarButtonClick = () => {},
98
104
  } = props;
99
105
 
100
106
  // States Handling Grid
@@ -134,7 +140,7 @@ export const GridProvider: React.FC<{
134
140
  // Calculates total pages and determine dataSource type
135
141
  useEffect(() => {
136
142
  const handleDataSource = async () => {
137
- if (Array.isArray(dataSource) && dataSource.length > 0) {
143
+ if (Array.isArray(dataSource)) {
138
144
  setWorkingDataSource(dataSource);
139
145
 
140
146
  // if lazy is true, then totalPages will be taken from pageSettings
@@ -238,11 +244,10 @@ export const GridProvider: React.FC<{
238
244
  const handleSearchInput = (e: any) => {
239
245
  const searchValue = e.target.value;
240
246
  if (searchParamValue) searchParamValue(searchValue);
247
+ setSearchParam(searchValue);
241
248
 
242
- if (!lazy) {
243
- setSearchParam(searchValue);
244
-
245
- if (searchValue === "") {
249
+ if (searchValue === "") {
250
+ if (!lazy) {
246
251
  setWorkingDataSource(
247
252
  fallbackSourceData.length > 0 ? fallbackSourceData : dataSource
248
253
  );
@@ -256,15 +261,17 @@ export const GridProvider: React.FC<{
256
261
  };
257
262
 
258
263
  const handleSearch = (searchParam: string) => {
259
- const filteredData = workingDataSource.filter((item: any) =>
260
- Object.values(item).some((val: any) => {
261
- const trimmedVal = val.toString().toLowerCase().trim();
262
- const trimmedSearchParam = searchParam.toLowerCase().trim();
263
- return trimmedVal.includes(trimmedSearchParam);
264
- })
265
- );
266
- setWorkingDataSource(filteredData);
267
- resetPage(filteredData);
264
+ if (!lazy) {
265
+ const filteredData = workingDataSource.filter((item: any) =>
266
+ Object.values(item).some((val: any) => {
267
+ const trimmedVal = val.toString().toLowerCase().trim();
268
+ const trimmedSearchParam = searchParam.toLowerCase().trim();
269
+ return trimmedVal.includes(trimmedSearchParam);
270
+ })
271
+ );
272
+ setWorkingDataSource(filteredData);
273
+ resetPage(filteredData);
274
+ }
268
275
  };
269
276
 
270
277
  // *** Filter Functions
@@ -418,6 +425,9 @@ export const GridProvider: React.FC<{
418
425
  gridColumnStyleSelectAll,
419
426
  gridColumnStyle,
420
427
  rowChange,
428
+ showTotalPages,
429
+ onSearch,
430
+ onToolbarButtonClick,
421
431
  };
422
432
 
423
433
  return (
@@ -15,6 +15,7 @@ export const useGridPagination = () => {
15
15
  workingDataSource,
16
16
  lazy,
17
17
  pageSettings,
18
+ showTotalPages,
18
19
  } = useGridContext();
19
20
 
20
21
  return {
@@ -30,19 +31,26 @@ export const useGridPagination = () => {
30
31
  workingDataSource,
31
32
  lazy,
32
33
  pageSettings,
34
+ showTotalPages,
33
35
  };
34
36
  };
35
37
 
36
38
  // Hook for grid search functionality
37
39
  export const useGridSearch = () => {
38
- const { searchParam, handleSearchInput, handleSearch, enableSearch } =
39
- useGridContext();
40
+ const {
41
+ searchParam,
42
+ handleSearchInput,
43
+ handleSearch,
44
+ enableSearch,
45
+ onSearch,
46
+ } = useGridContext();
40
47
 
41
48
  return {
42
49
  searchParam,
43
50
  handleSearchInput,
44
51
  handleSearch,
45
52
  enableSearch,
53
+ onSearch,
46
54
  };
47
55
  };
48
56
 
@@ -87,6 +95,8 @@ export const useGridExport = () => {
87
95
  pdfName,
88
96
  pdfOptions,
89
97
  gridButtonClass,
98
+ onToolbarButtonClick,
99
+ lazy,
90
100
  } = useGridContext();
91
101
 
92
102
  return {
@@ -98,5 +108,7 @@ export const useGridExport = () => {
98
108
  pdfName,
99
109
  pdfOptions,
100
110
  gridButtonClass,
111
+ onToolbarButtonClick,
112
+ lazy,
101
113
  };
102
114
  };
@@ -123,7 +123,10 @@ const GridBody = () => {
123
123
  </tr>
124
124
  ) : displayData.length === 0 ? (
125
125
  <tr>
126
- <td colSpan={workingColumns.length + (selectAll ? 1 : 0)}>
126
+ <td
127
+ colSpan={workingColumns.length + (selectAll ? 1 : 0)}
128
+ className="text-center py-3"
129
+ >
127
130
  No data found
128
131
  </td>
129
132
  </tr>
@@ -22,11 +22,21 @@ const Pagination = () => {
22
22
  workingDataSource,
23
23
  lazy,
24
24
  pageSettings,
25
+ showTotalPages,
25
26
  } = useGridPagination();
26
27
 
27
28
  return (
28
- <div className="flex flex-wrap justify-between items-center text-xs px-2 py-4 bg-zinc-100 dark:bg-zinc-900 gap-2 md:gap-4">
29
- <div className="flex flex-1 space-x-1">
29
+ <div className="w-full flex flex-wrap justify-between items-center text-xs px-2 py-4 bg-zinc-100 dark:bg-zinc-900 gap-2 md:gap-4">
30
+ <div className="flex text-xs">
31
+ Showing {currentPage + 1} of {totalPages} pages
32
+ {showTotalPages && (
33
+ <span className="pl-1">
34
+ ({lazy ? pageSettings?.totalCount : workingDataSource.length} items)
35
+ </span>
36
+ )}
37
+ </div>
38
+
39
+ <div className="flex space-x-1">
30
40
  <button onClick={goToFirstPage} disabled={currentPage === 0}>
31
41
  <Icon
32
42
  elements={leftArrows}
@@ -35,6 +45,7 @@ const Pagination = () => {
35
45
  ? "stroke-gray-200 fill-none dark:stroke-gray-700 cursor-not-allowed"
36
46
  : "stroke-black fill-none dark:stroke-white cursor-pointer"
37
47
  }`}
48
+ dimensions={{ width: 18, height: 18 }}
38
49
  />
39
50
  </button>
40
51
  <button onClick={prevPage} disabled={currentPage === 0}>
@@ -45,6 +56,7 @@ const Pagination = () => {
45
56
  ? "stroke-gray-200 fill-none dark:stroke-gray-700 cursor-not-allowed"
46
57
  : "stroke-black fill-none dark:stroke-white cursor-pointer"
47
58
  }`}
59
+ dimensions={{ width: 18, height: 18 }}
48
60
  />
49
61
  </button>
50
62
  {pageStart > 0 && (
@@ -56,19 +68,20 @@ const Pagination = () => {
56
68
  </button>
57
69
  )}
58
70
  <div className="flex md:space-x-1">
59
- {Array.from({ length: pageEnd - pageStart }, (_, i) => (
60
- <button
61
- key={pageStart + i}
62
- onClick={() => goToPage(pageStart + i)}
63
- className={`hidden md:block px-2 py-1 text-sm rounded-md transition-colors duration-200 ease-in-out ${
64
- currentPage === pageStart + i
65
- ? "bg-black text-white dark:bg-white dark:text-black"
66
- : "bg-gray-200 dark:bg-zinc-700 hover:bg-gray-300 dark:hover:bg-zinc-600"
67
- }`}
68
- >
69
- {pageStart + i + 1}
70
- </button>
71
- ))}
71
+ {totalPages > 0 &&
72
+ Array.from({ length: pageEnd - pageStart }, (_, i) => (
73
+ <button
74
+ key={pageStart + i}
75
+ onClick={() => goToPage(pageStart + i)}
76
+ className={`hidden md:block px-2 py-1 text-sm rounded-md transition-colors duration-200 ease-in-out ${
77
+ currentPage === pageStart + i
78
+ ? "bg-black text-white dark:bg-white dark:text-black"
79
+ : "bg-gray-200 dark:bg-zinc-700 hover:bg-gray-300 dark:hover:bg-zinc-600"
80
+ }`}
81
+ >
82
+ {pageStart + i + 1}
83
+ </button>
84
+ ))}
72
85
  </div>
73
86
  {pageEnd < totalPages && (
74
87
  <button onClick={() => goToPage(pageEnd)} className="cursor-pointer">
@@ -83,6 +96,7 @@ const Pagination = () => {
83
96
  ? "stroke-gray-200 fill-none dark:stroke-gray-700 cursor-not-allowed"
84
97
  : "stroke-black fill-none dark:stroke-white cursor-pointer"
85
98
  }`}
99
+ dimensions={{ width: 18, height: 18 }}
86
100
  />
87
101
  </button>
88
102
  <button onClick={goToEndPage} disabled={currentPage === totalPages - 1}>
@@ -93,14 +107,10 @@ const Pagination = () => {
93
107
  ? "stroke-gray-200 fill-none dark:stroke-gray-700 cursor-not-allowed"
94
108
  : "stroke-black fill-none dark:stroke-white cursor-pointer"
95
109
  }`}
110
+ dimensions={{ width: 18, height: 18 }}
96
111
  />
97
112
  </button>
98
113
  </div>
99
-
100
- <div className="flex text-xs">
101
- {currentPage + 1} of {totalPages} pages (
102
- {lazy ? pageSettings?.totalCount : workingDataSource.length}) items
103
- </div>
104
114
  </div>
105
115
  );
106
116
  };
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { lazy } from "react";
2
2
  import { useGridExport, useGridSearch } from "../hooks/GridHooks";
3
3
  import {
4
4
  exportToExcelHelper,
@@ -8,8 +8,13 @@ import Icon from "../../icon/Icon";
8
8
  import { search } from "../../icon/iconPaths";
9
9
 
10
10
  const GridToolbar = () => {
11
- const { searchParam, handleSearchInput, handleSearch, enableSearch } =
12
- useGridSearch();
11
+ const {
12
+ searchParam,
13
+ handleSearchInput,
14
+ handleSearch,
15
+ enableSearch,
16
+ onSearch,
17
+ } = useGridSearch();
13
18
 
14
19
  const {
15
20
  enableExcelExport,
@@ -20,6 +25,7 @@ const GridToolbar = () => {
20
25
  pdfName,
21
26
  pdfOptions,
22
27
  gridButtonClass,
28
+ onToolbarButtonClick,
23
29
  } = useGridExport();
24
30
 
25
31
  if (!enableSearch && !enableExcelExport && !enablePdfExport) {
@@ -45,12 +51,15 @@ const GridToolbar = () => {
45
51
  />
46
52
  <button
47
53
  className="rounded-lg w-10 flex items-center justify-center cursor-pointer"
48
- onClick={() => handleSearch(searchParam)}
54
+ onClick={() => {
55
+ handleSearch(searchParam);
56
+ if (onSearch) onSearch(searchParam); // Call the onSearch prop if provided
57
+ }}
49
58
  >
50
59
  <Icon
51
60
  elements={search}
52
61
  svgClass={"stroke-gray-500 fill-none dark:stroke-white"}
53
- />{" "}
62
+ />
54
63
  </button>
55
64
  </div>
56
65
  )}
@@ -62,7 +71,11 @@ const GridToolbar = () => {
62
71
  <button
63
72
  className={gridButtonClass}
64
73
  onClick={() => {
65
- exportToExcelHelper(workingDataSource, columns, excelName);
74
+ if (!lazy) {
75
+ exportToExcelHelper(workingDataSource, columns, excelName);
76
+ }
77
+
78
+ if (onToolbarButtonClick) onToolbarButtonClick("excelExport");
66
79
  }}
67
80
  >
68
81
  Export to Excel
@@ -73,12 +86,15 @@ const GridToolbar = () => {
73
86
  <button
74
87
  className={gridButtonClass}
75
88
  onClick={() => {
76
- exportToPDFHelper(
77
- workingDataSource,
78
- columns,
79
- pdfName,
80
- pdfOptions
81
- );
89
+ if (!lazy) {
90
+ exportToPDFHelper(
91
+ workingDataSource,
92
+ columns,
93
+ pdfName,
94
+ pdfOptions
95
+ );
96
+ }
97
+ if (onToolbarButtonClick) onToolbarButtonClick("pdfExport");
82
98
  }}
83
99
  >
84
100
  Export to PDF
@@ -38,6 +38,9 @@ export type GridProps = {
38
38
  pageStatus?: any;
39
39
  activeFilterArrayValue?: ActiveFilterArrayValue[] | any;
40
40
  searchParamValue?: (value: string) => void;
41
+ showTotalPages?: boolean;
42
+ onSearch?: (value: string) => void;
43
+ onToolbarButtonClick?: (action: string) => void;
41
44
  };
42
45
 
43
46
  interface GridColumn {
@@ -148,7 +148,9 @@ export const DatePicker = ({
148
148
  />
149
149
  <span className={!selectedDate ? "text-gray-400 text-sm" : ""}>
150
150
  {selectedDate ? (
151
- <span className="text-sm">{selectedDate.toLocaleDateString("en-GB")}</span>
151
+ <span className="text-sm">
152
+ {selectedDate.toLocaleDateString("en-GB")}
153
+ </span>
152
154
  ) : (
153
155
  placeholder
154
156
  )}
@@ -344,7 +346,7 @@ export const DatePicker = ({
344
346
  <button
345
347
  type="button"
346
348
  onClick={goToToday}
347
- className="text-black hover:text-blue-600 transition duration-150 ease-in-out"
349
+ className="text-black hover:text-blue-600 transition duration-150 ease-in-out dark:text-gray-500"
348
350
  >
349
351
  Today
350
352
  </button>
@@ -360,4 +362,4 @@ export const DatePicker = ({
360
362
  )}
361
363
  </div>
362
364
  );
363
- };
365
+ };