gbs-add-block 0.0.87 → 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 +2 -2
- package/package.json +1 -1
- package/source/components/datagrid/context/GridContext.tsx +20 -4
- package/source/components/datagrid/hooks/GridHooks.tsx +4 -0
- package/source/components/datagrid/layout/GridBody.tsx +4 -1
- package/source/components/datagrid/layout/GridPagination.tsx +4 -2
- package/source/components/datagrid/layout/GridToolbar.tsx +1 -1
- package/source/components/datagrid/layout/index.tsx +3 -0
- package/source/components/datagrid/type.ts +9 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# GBS Building Blocks 2.0 (v0.0.
|
|
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.
|
|
9
|
+
## What's New 🎉 (Ver 0.0.90)
|
|
10
10
|
|
|
11
11
|
- Updated for bug fixes.
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -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;
|
|
@@ -92,6 +93,8 @@ export const GridProvider: React.FC<{
|
|
|
92
93
|
gridColumnStyle = "p-2 text-xs",
|
|
93
94
|
rowChange = () => {},
|
|
94
95
|
pageStatus = () => {},
|
|
96
|
+
activeFilterArrayValue = [],
|
|
97
|
+
searchParamValue = () => {},
|
|
95
98
|
} = props;
|
|
96
99
|
|
|
97
100
|
// States Handling Grid
|
|
@@ -133,9 +136,13 @@ export const GridProvider: React.FC<{
|
|
|
133
136
|
const handleDataSource = async () => {
|
|
134
137
|
if (Array.isArray(dataSource) && dataSource.length > 0) {
|
|
135
138
|
setWorkingDataSource(dataSource);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
|
|
140
|
+
// if lazy is true, then totalPages will be taken from pageSettings
|
|
141
|
+
const totalPages =
|
|
142
|
+
lazy && pageSettings.totalCount
|
|
143
|
+
? Math.ceil(pageSettings.totalCount / pageSettings.pageNumber)
|
|
144
|
+
: Math.ceil(dataSource.length / pageSettings.pageNumber);
|
|
145
|
+
|
|
139
146
|
setTotalPages(totalPages);
|
|
140
147
|
setPageEnd(Math.min(10, totalPages));
|
|
141
148
|
} else if (typeof dataSource === "string") {
|
|
@@ -158,6 +165,7 @@ export const GridProvider: React.FC<{
|
|
|
158
165
|
}
|
|
159
166
|
}, [columns]);
|
|
160
167
|
|
|
168
|
+
// Adds Search Column
|
|
161
169
|
useEffect(() => {
|
|
162
170
|
if (!columns || columns.length === 0) {
|
|
163
171
|
if (
|
|
@@ -228,9 +236,12 @@ export const GridProvider: React.FC<{
|
|
|
228
236
|
|
|
229
237
|
// *** Search Functions
|
|
230
238
|
const handleSearchInput = (e: any) => {
|
|
239
|
+
const searchValue = e.target.value;
|
|
240
|
+
if (searchParamValue) searchParamValue(searchValue);
|
|
241
|
+
|
|
231
242
|
if (!lazy) {
|
|
232
|
-
const searchValue = e.target.value;
|
|
233
243
|
setSearchParam(searchValue);
|
|
244
|
+
|
|
234
245
|
if (searchValue === "") {
|
|
235
246
|
setWorkingDataSource(
|
|
236
247
|
fallbackSourceData.length > 0 ? fallbackSourceData : dataSource
|
|
@@ -289,6 +300,8 @@ export const GridProvider: React.FC<{
|
|
|
289
300
|
setWorkingColumns(updatedColumns);
|
|
290
301
|
setWorkingDataSource(updatedFullDataSource);
|
|
291
302
|
setActiveFilterArray(updatedActiveFilterArray);
|
|
303
|
+
if (activeFilterArrayValue)
|
|
304
|
+
activeFilterArrayValue(updatedActiveFilterArray);
|
|
292
305
|
resetPage(updatedFullDataSource);
|
|
293
306
|
}
|
|
294
307
|
|
|
@@ -305,6 +318,8 @@ export const GridProvider: React.FC<{
|
|
|
305
318
|
setWorkingColumns(updatedColumns);
|
|
306
319
|
setWorkingDataSource(updatedDataSource);
|
|
307
320
|
setActiveFilterArray(updatedActiveFilterArray);
|
|
321
|
+
if (activeFilterArrayValue)
|
|
322
|
+
activeFilterArrayValue(updatedActiveFilterArray);
|
|
308
323
|
resetPage(updatedDataSource);
|
|
309
324
|
}
|
|
310
325
|
|
|
@@ -370,6 +385,7 @@ export const GridProvider: React.FC<{
|
|
|
370
385
|
goToEndPage,
|
|
371
386
|
goToFirstPage,
|
|
372
387
|
goToPage,
|
|
388
|
+
lazy,
|
|
373
389
|
|
|
374
390
|
// Search methods
|
|
375
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 =
|
|
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 (
|
|
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
|
-
|
|
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"
|
|
@@ -26,6 +26,7 @@ const GridContent = forwardRef((_, ref) => {
|
|
|
26
26
|
prevPage,
|
|
27
27
|
goToFirstPage,
|
|
28
28
|
goToEndPage,
|
|
29
|
+
activeFilterArray,
|
|
29
30
|
} = useGridContext();
|
|
30
31
|
|
|
31
32
|
// Making Grid Functions Accessible in Parent
|
|
@@ -41,6 +42,7 @@ const GridContent = forwardRef((_, ref) => {
|
|
|
41
42
|
handleSearch,
|
|
42
43
|
handleApplyFilter,
|
|
43
44
|
clearFilter,
|
|
45
|
+
getActiveFilters: () => activeFilterArray,
|
|
44
46
|
};
|
|
45
47
|
},
|
|
46
48
|
[
|
|
@@ -52,6 +54,7 @@ const GridContent = forwardRef((_, ref) => {
|
|
|
52
54
|
handleSearch,
|
|
53
55
|
handleApplyFilter,
|
|
54
56
|
clearFilter,
|
|
57
|
+
activeFilterArray,
|
|
55
58
|
]
|
|
56
59
|
);
|
|
57
60
|
|
|
@@ -2,6 +2,13 @@ import { ChangeEvent } from "react";
|
|
|
2
2
|
|
|
3
3
|
interface PageSettingsProps {
|
|
4
4
|
pageNumber: number;
|
|
5
|
+
totalCount?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface ActiveFilterArrayValue {
|
|
9
|
+
filterColumn: string;
|
|
10
|
+
filterCondition: string;
|
|
11
|
+
filterValue: string;
|
|
5
12
|
}
|
|
6
13
|
|
|
7
14
|
export type GridProps = {
|
|
@@ -29,6 +36,8 @@ export type GridProps = {
|
|
|
29
36
|
gridColumnStyle?: string;
|
|
30
37
|
rowChange?: any;
|
|
31
38
|
pageStatus?: any;
|
|
39
|
+
activeFilterArrayValue?: ActiveFilterArrayValue[] | any;
|
|
40
|
+
searchParamValue?: (value: string) => void;
|
|
32
41
|
};
|
|
33
42
|
|
|
34
43
|
interface GridColumn {
|