gbs-add-block 0.0.93 → 0.0.96
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 +22 -15
- package/source/components/datagrid/hooks/GridHooks.tsx +4 -1
- package/source/components/datagrid/layout/GridBody.tsx +4 -1
- package/source/components/datagrid/layout/GridPagination.tsx +30 -20
- package/source/components/datagrid/layout/GridToolbar.tsx +12 -4
- package/source/components/datagrid/type.ts +2 -0
- package/source/components/datepicker/index.tsx +5 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# GBS Building Blocks 2.0 (v0.0.
|
|
1
|
+
# GBS Building Blocks 2.0 (v0.0.96)
|
|
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.96)
|
|
10
10
|
|
|
11
11
|
- Updated for bug fixes.
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -64,6 +64,8 @@ interface GridContextType {
|
|
|
64
64
|
gridColumnStyleSelectAll: string;
|
|
65
65
|
gridColumnStyle: string;
|
|
66
66
|
rowChange: (rowData: any) => void;
|
|
67
|
+
showTotalPages?: boolean;
|
|
68
|
+
onSearch?: (searchParam: string) => void;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
const GridContext = createContext<GridContextType | undefined>(undefined);
|
|
@@ -83,7 +85,7 @@ export const GridProvider: React.FC<{
|
|
|
83
85
|
enablePdfExport = false,
|
|
84
86
|
pdfName = "data",
|
|
85
87
|
pdfOptions = {},
|
|
86
|
-
gridButtonClass = "px-1 py-2 text-xs rounded bg-zinc-200 dark:bg-zinc-700",
|
|
88
|
+
gridButtonClass = "px-1 py-2 text-xs rounded bg-zinc-200 dark:bg-zinc-700 cursor-pointer",
|
|
87
89
|
selectAll = false,
|
|
88
90
|
onSelectRow,
|
|
89
91
|
isFetching,
|
|
@@ -95,6 +97,8 @@ export const GridProvider: React.FC<{
|
|
|
95
97
|
pageStatus = () => {},
|
|
96
98
|
activeFilterArrayValue = [],
|
|
97
99
|
searchParamValue = () => {},
|
|
100
|
+
showTotalPages = false,
|
|
101
|
+
onSearch = () => {},
|
|
98
102
|
} = props;
|
|
99
103
|
|
|
100
104
|
// States Handling Grid
|
|
@@ -134,7 +138,7 @@ export const GridProvider: React.FC<{
|
|
|
134
138
|
// Calculates total pages and determine dataSource type
|
|
135
139
|
useEffect(() => {
|
|
136
140
|
const handleDataSource = async () => {
|
|
137
|
-
if (Array.isArray(dataSource)
|
|
141
|
+
if (Array.isArray(dataSource)) {
|
|
138
142
|
setWorkingDataSource(dataSource);
|
|
139
143
|
|
|
140
144
|
// if lazy is true, then totalPages will be taken from pageSettings
|
|
@@ -238,11 +242,10 @@ export const GridProvider: React.FC<{
|
|
|
238
242
|
const handleSearchInput = (e: any) => {
|
|
239
243
|
const searchValue = e.target.value;
|
|
240
244
|
if (searchParamValue) searchParamValue(searchValue);
|
|
245
|
+
setSearchParam(searchValue);
|
|
241
246
|
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (searchValue === "") {
|
|
247
|
+
if (searchValue === "") {
|
|
248
|
+
if (!lazy) {
|
|
246
249
|
setWorkingDataSource(
|
|
247
250
|
fallbackSourceData.length > 0 ? fallbackSourceData : dataSource
|
|
248
251
|
);
|
|
@@ -256,15 +259,17 @@ export const GridProvider: React.FC<{
|
|
|
256
259
|
};
|
|
257
260
|
|
|
258
261
|
const handleSearch = (searchParam: string) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
262
|
+
if (!lazy) {
|
|
263
|
+
const filteredData = workingDataSource.filter((item: any) =>
|
|
264
|
+
Object.values(item).some((val: any) => {
|
|
265
|
+
const trimmedVal = val.toString().toLowerCase().trim();
|
|
266
|
+
const trimmedSearchParam = searchParam.toLowerCase().trim();
|
|
267
|
+
return trimmedVal.includes(trimmedSearchParam);
|
|
268
|
+
})
|
|
269
|
+
);
|
|
270
|
+
setWorkingDataSource(filteredData);
|
|
271
|
+
resetPage(filteredData);
|
|
272
|
+
}
|
|
268
273
|
};
|
|
269
274
|
|
|
270
275
|
// *** Filter Functions
|
|
@@ -418,6 +423,8 @@ export const GridProvider: React.FC<{
|
|
|
418
423
|
gridColumnStyleSelectAll,
|
|
419
424
|
gridColumnStyle,
|
|
420
425
|
rowChange,
|
|
426
|
+
showTotalPages,
|
|
427
|
+
onSearch,
|
|
421
428
|
};
|
|
422
429
|
|
|
423
430
|
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,12 +31,13 @@ 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 } =
|
|
40
|
+
const { searchParam, handleSearchInput, handleSearch, enableSearch, onSearch } =
|
|
39
41
|
useGridContext();
|
|
40
42
|
|
|
41
43
|
return {
|
|
@@ -43,6 +45,7 @@ export const useGridSearch = () => {
|
|
|
43
45
|
handleSearchInput,
|
|
44
46
|
handleSearch,
|
|
45
47
|
enableSearch,
|
|
48
|
+
onSearch,
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
51
|
|
|
@@ -123,7 +123,10 @@ const GridBody = () => {
|
|
|
123
123
|
</tr>
|
|
124
124
|
) : displayData.length === 0 ? (
|
|
125
125
|
<tr>
|
|
126
|
-
<td
|
|
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
|
|
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
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
};
|
|
@@ -8,8 +8,13 @@ import Icon from "../../icon/Icon";
|
|
|
8
8
|
import { search } from "../../icon/iconPaths";
|
|
9
9
|
|
|
10
10
|
const GridToolbar = () => {
|
|
11
|
-
const {
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
searchParam,
|
|
13
|
+
handleSearchInput,
|
|
14
|
+
handleSearch,
|
|
15
|
+
enableSearch,
|
|
16
|
+
onSearch,
|
|
17
|
+
} = useGridSearch();
|
|
13
18
|
|
|
14
19
|
const {
|
|
15
20
|
enableExcelExport,
|
|
@@ -45,12 +50,15 @@ const GridToolbar = () => {
|
|
|
45
50
|
/>
|
|
46
51
|
<button
|
|
47
52
|
className="rounded-lg w-10 flex items-center justify-center cursor-pointer"
|
|
48
|
-
onClick={() =>
|
|
53
|
+
onClick={() => {
|
|
54
|
+
handleSearch(searchParam);
|
|
55
|
+
if (onSearch) onSearch(searchParam); // Call the onSearch prop if provided
|
|
56
|
+
}}
|
|
49
57
|
>
|
|
50
58
|
<Icon
|
|
51
59
|
elements={search}
|
|
52
60
|
svgClass={"stroke-gray-500 fill-none dark:stroke-white"}
|
|
53
|
-
/>
|
|
61
|
+
/>
|
|
54
62
|
</button>
|
|
55
63
|
</div>
|
|
56
64
|
)}
|
|
@@ -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">
|
|
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
|
+
};
|