gbs-add-block 0.0.88 → 0.0.90

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.88)
1
+ # GBS Building Blocks 2.0 (v0.0.90)
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.88)
9
+ ## What's New 🎉 (Ver 0.0.90)
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.88",
3
+ "version": "0.0.90",
4
4
  "description": "React Component Library",
5
5
  "type": "module",
6
6
  "files": [
@@ -31,6 +31,7 @@ interface GridContextType {
31
31
  goToEndPage: () => void;
32
32
  goToFirstPage: () => void;
33
33
  goToPage: (page: number) => void;
34
+ lazy: boolean;
34
35
 
35
36
  // Search methods
36
37
  handleSearchInput: (e: any) => void;
@@ -93,6 +94,7 @@ export const GridProvider: React.FC<{
93
94
  rowChange = () => {},
94
95
  pageStatus = () => {},
95
96
  activeFilterArrayValue = [],
97
+ searchParamValue = () => {},
96
98
  } = props;
97
99
 
98
100
  // States Handling Grid
@@ -137,8 +139,8 @@ export const GridProvider: React.FC<{
137
139
 
138
140
  // if lazy is true, then totalPages will be taken from pageSettings
139
141
  const totalPages =
140
- lazy && pageSettings.totalPages
141
- ? pageSettings.totalPages
142
+ lazy && pageSettings.totalCount
143
+ ? Math.ceil(pageSettings.totalCount / pageSettings.pageNumber)
142
144
  : Math.ceil(dataSource.length / pageSettings.pageNumber);
143
145
 
144
146
  setTotalPages(totalPages);
@@ -163,6 +165,7 @@ export const GridProvider: React.FC<{
163
165
  }
164
166
  }, [columns]);
165
167
 
168
+ // Adds Search Column
166
169
  useEffect(() => {
167
170
  if (!columns || columns.length === 0) {
168
171
  if (
@@ -233,9 +236,12 @@ export const GridProvider: React.FC<{
233
236
 
234
237
  // *** Search Functions
235
238
  const handleSearchInput = (e: any) => {
239
+ const searchValue = e.target.value;
240
+ if (searchParamValue) searchParamValue(searchValue);
241
+
236
242
  if (!lazy) {
237
- const searchValue = e.target.value;
238
243
  setSearchParam(searchValue);
244
+
239
245
  if (searchValue === "") {
240
246
  setWorkingDataSource(
241
247
  fallbackSourceData.length > 0 ? fallbackSourceData : dataSource
@@ -379,6 +385,7 @@ export const GridProvider: React.FC<{
379
385
  goToEndPage,
380
386
  goToFirstPage,
381
387
  goToPage,
388
+ lazy,
382
389
 
383
390
  // Search methods
384
391
  handleSearchInput,
@@ -13,6 +13,8 @@ export const useGridPagination = () => {
13
13
  nextPage,
14
14
  goToEndPage,
15
15
  workingDataSource,
16
+ lazy,
17
+ pageSettings,
16
18
  } = useGridContext();
17
19
 
18
20
  return {
@@ -26,6 +28,8 @@ export const useGridPagination = () => {
26
28
  nextPage,
27
29
  goToEndPage,
28
30
  workingDataSource,
31
+ lazy,
32
+ pageSettings,
29
33
  };
30
34
  };
31
35
 
@@ -17,6 +17,7 @@ const GridBody = () => {
17
17
  gridColumnStyle,
18
18
  gridColumnStyleSelectAll,
19
19
  rowChange,
20
+ lazy,
20
21
  } = useGridContext();
21
22
 
22
23
  const renderCell = (rowData: any, column: Column, rowIndex: number) => {
@@ -53,7 +54,9 @@ const GridBody = () => {
53
54
 
54
55
  const displayStart = currentPage * pageSettings.pageNumber;
55
56
  const displayEnd = displayStart + pageSettings.pageNumber;
56
- const displayData = workingDataSource.slice(displayStart, displayEnd);
57
+ const displayData = lazy
58
+ ? workingDataSource
59
+ : workingDataSource.slice(displayStart, displayEnd);
57
60
 
58
61
  return (
59
62
  <div className="overflow-x-auto">
@@ -20,6 +20,8 @@ const Pagination = () => {
20
20
  nextPage,
21
21
  goToEndPage,
22
22
  workingDataSource,
23
+ lazy,
24
+ pageSettings,
23
25
  } = useGridPagination();
24
26
 
25
27
  return (
@@ -96,8 +98,8 @@ const Pagination = () => {
96
98
  </div>
97
99
 
98
100
  <div className="flex text-xs">
99
- {currentPage + 1} of {totalPages} pages ({workingDataSource.length})
100
- items
101
+ {currentPage + 1} of {totalPages} pages (
102
+ {lazy ? pageSettings?.totalCount : workingDataSource.length}) items
101
103
  </div>
102
104
  </div>
103
105
  );
@@ -33,7 +33,7 @@ const GridToolbar = () => {
33
33
  <div className="flex">
34
34
  <input
35
35
  type="search"
36
- value={searchParam}
36
+ defaultValue={searchParam}
37
37
  onChange={handleSearchInput}
38
38
  placeholder="Search..."
39
39
  className="outline-none p-2 text-xs rounded-lg max-sm:hidden dark:bg-zinc-800 bg-zinc-200"
@@ -2,7 +2,7 @@ import { ChangeEvent } from "react";
2
2
 
3
3
  interface PageSettingsProps {
4
4
  pageNumber: number;
5
- totalPages?: number;
5
+ totalCount?: number;
6
6
  }
7
7
 
8
8
  interface ActiveFilterArrayValue {
@@ -37,6 +37,7 @@ export type GridProps = {
37
37
  rowChange?: any;
38
38
  pageStatus?: any;
39
39
  activeFilterArrayValue?: ActiveFilterArrayValue[] | any;
40
+ searchParamValue?: (value: string) => void;
40
41
  };
41
42
 
42
43
  interface GridColumn {