pixelize-design-library 1.0.21 → 1.0.23
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/dist/index.d.ts +22 -1
- package/dist/index.js +44 -25
- package/package.json +1 -1
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/src/App.tsx +0 -10
- package/src/Components/Apexcharts/ApexBarChart/ApexBarChart.stories.tsx +0 -39
- package/src/Components/Apexcharts/ApexBarChart/ApexBarChart.tsx +0 -80
- package/src/Components/Apexcharts/ApexBarChart/ApexBarChartProps.tsx +0 -20
- package/src/Components/Apexcharts/ApexPieChart/ApexPieChart.stories.tsx +0 -33
- package/src/Components/Apexcharts/ApexPieChart/ApexPieChart.tsx +0 -43
- package/src/Components/Apexcharts/ApexPieChart/ApexPieChartProps.tsx +0 -17
- package/src/Components/Breadcrumbs/Breadcrumbs.stories.tsx +0 -26
- package/src/Components/Breadcrumbs/Breadcrumbs.tsx +0 -26
- package/src/Components/Breadcrumbs/BreadcrumbsProps.tsx +0 -12
- package/src/Components/Button/Button.stories.tsx +0 -32
- package/src/Components/Button/Button.tsx +0 -26
- package/src/Components/Button/ButtonProps.tsx +0 -10
- package/src/Components/ButtonGroupIcon/ButtonGoupIconProps.tsx +0 -14
- package/src/Components/ButtonGroupIcon/ButtonGroupIcon.stories.tsx +0 -37
- package/src/Components/ButtonGroupIcon/ButtonGroupIcon.tsx +0 -26
- package/src/Components/Checkbox/Checkbox.stories.tsx +0 -45
- package/src/Components/Checkbox/Checkbox.tsx +0 -29
- package/src/Components/Checkbox/CheckboxProps.tsx +0 -9
- package/src/Components/Input/TextInput.stories.tsx +0 -45
- package/src/Components/Input/TextInput.tsx +0 -70
- package/src/Components/Input/TextInputProps.tsx +0 -27
- package/src/Components/InputTextArea/InputTextArea.stories.tsx +0 -49
- package/src/Components/InputTextArea/InputTextArea.tsx +0 -36
- package/src/Components/InputTextArea/InputTextAreaProps.tsx +0 -11
- package/src/Components/Loading/Loading.stories.tsx +0 -25
- package/src/Components/Loading/Loading.tsx +0 -38
- package/src/Components/Loading/LoadingProps.tsx +0 -1
- package/src/Components/Modal/Modal.stories.tsx +0 -106
- package/src/Components/Modal/Modal.tsx +0 -45
- package/src/Components/Modal/ModalProps.tsx +0 -12
- package/src/Components/NavigationBar/NavBar.stories.tsx +0 -26
- package/src/Components/NavigationBar/NavigationBar.tsx +0 -56
- package/src/Components/NavigationBar/NavigationBarProps.tsx +0 -13
- package/src/Components/NumberInput/NumberInput.stories.tsx +0 -31
- package/src/Components/NumberInput/NumberInput.tsx +0 -56
- package/src/Components/NumberInput/NumberInputProps.tsx +0 -28
- package/src/Components/PinInput/PinInput.stories.tsx +0 -40
- package/src/Components/PinInput/PinInput.tsx +0 -49
- package/src/Components/PinInput/PinInputProps.tsx +0 -33
- package/src/Components/ProfileCard/ProfileCard.stories.tsx +0 -30
- package/src/Components/ProfileCard/ProfileCard.tsx +0 -59
- package/src/Components/ProfileCard/ProfileCardProps.tsx +0 -41
- package/src/Components/ProfilePhotoViewer/ProfilePhotoViewer.stories.tsx +0 -25
- package/src/Components/ProfilePhotoViewer/ProfilePhotoViewer.tsx +0 -69
- package/src/Components/ProfilePhotoViewer/ProfilePhotoViewerProps.tsx +0 -14
- package/src/Components/ProgressBar/ProgressBar.stories.tsx +0 -46
- package/src/Components/ProgressBar/ProgressBar.tsx +0 -33
- package/src/Components/ProgressBar/ProgressBarProps.tsx +0 -7
- package/src/Components/RadioButton/RadioButton.stories.tsx +0 -46
- package/src/Components/RadioButton/RadioButton.tsx +0 -63
- package/src/Components/RadioButton/RadioButtonProps.tsx +0 -10
- package/src/Components/Select/Select.stories.tsx +0 -57
- package/src/Components/Select/Select.tsx +0 -46
- package/src/Components/Select/SelectProps.tsx +0 -15
- package/src/Components/SideBar/SideBar.tsx +0 -143
- package/src/Components/SideBar/SideBarProps.tsx +0 -18
- package/src/Components/SideBar/Sidebar.stories.tsx +0 -80
- package/src/Components/Skeletons/Skeleton.stories.tsx +0 -63
- package/src/Components/Skeletons/SkeletonProps.tsx +0 -23
- package/src/Components/Skeletons/Skeletons.tsx +0 -52
- package/src/Components/Table/Table.stories.tsx +0 -47
- package/src/Components/Table/Table.tsx +0 -517
- package/src/Components/Table/TableProps.tsx +0 -36
- package/src/Components/Toaster/Toaster.stories.tsx +0 -58
- package/src/Components/Toaster/Toaster.tsx +0 -34
- package/src/Components/Toaster/ToasterProps.tsx +0 -15
- package/src/Components/ToolTip/ToolTip.stories.tsx +0 -39
- package/src/Components/ToolTip/ToolTip.tsx +0 -62
- package/src/Components/ToolTip/ToolTipProps.tsx +0 -45
- package/src/Layout.tsx +0 -499
- package/src/Theme/Dark/theme.ts +0 -278
- package/src/Theme/Default/theme.ts +0 -301
- package/src/Theme/index.ts +0 -4
- package/src/bootstrap.tsx +0 -13
- package/src/index.ts +0 -29
- package/src/index.tsx +0 -22
- package/src/types/pixelize-design-library.d.ts +0 -4
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Button,
|
|
5
|
-
ChakraProvider,
|
|
6
|
-
Checkbox,
|
|
7
|
-
Flex,
|
|
8
|
-
Input,
|
|
9
|
-
Menu,
|
|
10
|
-
MenuButton,
|
|
11
|
-
MenuItem,
|
|
12
|
-
MenuList,
|
|
13
|
-
Popover,
|
|
14
|
-
PopoverBody,
|
|
15
|
-
PopoverContent,
|
|
16
|
-
PopoverTrigger,
|
|
17
|
-
Select,
|
|
18
|
-
Spinner,
|
|
19
|
-
TableContainer,
|
|
20
|
-
Text,
|
|
21
|
-
} from "@chakra-ui/react";
|
|
22
|
-
import {
|
|
23
|
-
Table as ChakraTable,
|
|
24
|
-
Tbody,
|
|
25
|
-
Td,
|
|
26
|
-
Th,
|
|
27
|
-
Thead,
|
|
28
|
-
Tr,
|
|
29
|
-
} from "@chakra-ui/react";
|
|
30
|
-
|
|
31
|
-
import { TableProps } from "./TableProps";
|
|
32
|
-
import { useState } from "react";
|
|
33
|
-
import {
|
|
34
|
-
ArrowDownIcon,
|
|
35
|
-
ArrowUpIcon,
|
|
36
|
-
ChevronDownIcon,
|
|
37
|
-
HamburgerIcon,
|
|
38
|
-
} from "@chakra-ui/icons";
|
|
39
|
-
|
|
40
|
-
export default function Table({
|
|
41
|
-
data,
|
|
42
|
-
headers,
|
|
43
|
-
tableHeaderBgColor = "#3182ce",
|
|
44
|
-
tableHeaderColor = "white",
|
|
45
|
-
handleExportChange,
|
|
46
|
-
exportOptions,
|
|
47
|
-
exportLabel,
|
|
48
|
-
isLoading,
|
|
49
|
-
loadingContaxt,
|
|
50
|
-
loadingBoxStyle,
|
|
51
|
-
}: TableProps) {
|
|
52
|
-
const [currentPage, setCurrentPage] = useState(0);
|
|
53
|
-
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
54
|
-
const [sortField, setSortField] = useState<string | null>(null);
|
|
55
|
-
const [sortDirection, setSortDirection] = useState<"asc" | "desc" | null>(
|
|
56
|
-
null
|
|
57
|
-
);
|
|
58
|
-
const [isPopoverOpen, setPopoverOpen] = useState(false);
|
|
59
|
-
const [activeHeader, setActiveHeader] = useState<string | null>(null);
|
|
60
|
-
const [searchTerms, setSearchTerms] = useState<Record<string, string>>({});
|
|
61
|
-
const [searchOperation, setSearchOperation] = useState<
|
|
62
|
-
Record<string, string>
|
|
63
|
-
>({});
|
|
64
|
-
const [betweenValues, setBetweenValues] = useState<
|
|
65
|
-
Record<string, { min: string; max: string }>
|
|
66
|
-
>({});
|
|
67
|
-
const [hoveredHeaderIndex, setHoveredHeaderIndex] = useState<number | null>(
|
|
68
|
-
null
|
|
69
|
-
);
|
|
70
|
-
const [visibleColumns, setVisibleColumns] = useState<Record<string, boolean>>(
|
|
71
|
-
headers.reduce((acc, curr) => ({ ...acc, [curr.label]: true }), {})
|
|
72
|
-
);
|
|
73
|
-
if (isLoading) {
|
|
74
|
-
return (
|
|
75
|
-
<ChakraProvider>
|
|
76
|
-
<Box width="full" overflowX="auto" style={loadingBoxStyle}>
|
|
77
|
-
{loadingContaxt ? loadingContaxt :
|
|
78
|
-
<Spinner thickness='4px' speed='0.65s' emptyColor='gray.200' color='blue.500' size='xl' />
|
|
79
|
-
}
|
|
80
|
-
</Box>
|
|
81
|
-
</ChakraProvider>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const handlePageSizeChange = (
|
|
86
|
-
event: React.ChangeEvent<HTMLSelectElement>
|
|
87
|
-
) => {
|
|
88
|
-
setRowsPerPage(Number(event.target.value));
|
|
89
|
-
setCurrentPage(0);
|
|
90
|
-
};
|
|
91
|
-
const pageSizeOptions = [5, 10, 20, 50, 100].filter(
|
|
92
|
-
(size) => size <= data.length
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const sortedData = [...data].sort((a, b) => {
|
|
96
|
-
if (!sortField) return 0;
|
|
97
|
-
if (a[sortField] < b[sortField]) return sortDirection === "asc" ? -1 : 1;
|
|
98
|
-
if (a[sortField] > b[sortField]) return sortDirection === "asc" ? 1 : -1;
|
|
99
|
-
return 0;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const handleSort = (field: string) => {
|
|
103
|
-
setSortField(field);
|
|
104
|
-
setSortDirection(sortDirection === "asc" ? "desc" : "asc");
|
|
105
|
-
};
|
|
106
|
-
const handleSearchOperation = (header: string, operation: string) => {
|
|
107
|
-
setSearchOperation((prev) => ({ ...prev, [header]: operation }));
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const handleSearch = (field: string, term: string) => {
|
|
111
|
-
if (searchOperation[field] === "between") {
|
|
112
|
-
setBetweenValues((prev) => ({
|
|
113
|
-
...prev,
|
|
114
|
-
[field]: { min: term.split("-")[0], max: term.split("-")[1] },
|
|
115
|
-
}));
|
|
116
|
-
} else {
|
|
117
|
-
setSearchTerms((prev) => ({ ...prev, [field]: term }));
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const handleHeaderClick = (header: string) => {
|
|
122
|
-
setActiveHeader(header);
|
|
123
|
-
setPopoverOpen(true);
|
|
124
|
-
};
|
|
125
|
-
const closePopover = () => {
|
|
126
|
-
setPopoverOpen(false);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const filteredData = sortedData.filter((item) => {
|
|
130
|
-
return Object.keys(searchTerms).every((key) => {
|
|
131
|
-
const term = searchTerms[key].toLowerCase();
|
|
132
|
-
const value = String(item[key]).toLowerCase();
|
|
133
|
-
const operation = searchOperation[key] || "contains";
|
|
134
|
-
|
|
135
|
-
switch (operation) {
|
|
136
|
-
case "contains":
|
|
137
|
-
return value.includes(term);
|
|
138
|
-
case "notContains":
|
|
139
|
-
return !value.includes(term);
|
|
140
|
-
case "equals":
|
|
141
|
-
return value === term;
|
|
142
|
-
case "notEquals":
|
|
143
|
-
return value !== term;
|
|
144
|
-
case "beginsWith":
|
|
145
|
-
return value.startsWith(term);
|
|
146
|
-
case "endsWith":
|
|
147
|
-
return value.endsWith(term);
|
|
148
|
-
case "greaterThan":
|
|
149
|
-
return Number(value) > Number(term);
|
|
150
|
-
case "greaterThanOrEqual":
|
|
151
|
-
return Number(value) >= Number(term);
|
|
152
|
-
case "lessThan":
|
|
153
|
-
return Number(value) < Number(term);
|
|
154
|
-
case "lessThanOrEqual":
|
|
155
|
-
return Number(value) <= Number(term);
|
|
156
|
-
case "between":
|
|
157
|
-
const { min, max } = betweenValues[key] || {};
|
|
158
|
-
return Number(value) >= Number(min) && Number(value) <= Number(max);
|
|
159
|
-
case "blank":
|
|
160
|
-
return value === "";
|
|
161
|
-
case "notBlank":
|
|
162
|
-
return value !== "";
|
|
163
|
-
default:
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const pages = Math.ceil(filteredData.length / rowsPerPage);
|
|
170
|
-
const startRow = currentPage * rowsPerPage;
|
|
171
|
-
const endRow = startRow + rowsPerPage;
|
|
172
|
-
|
|
173
|
-
const getFieldType = (header: string) => {
|
|
174
|
-
for (const row of data) {
|
|
175
|
-
if (row[header] !== null) {
|
|
176
|
-
return typeof row[header];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return "string";
|
|
180
|
-
};
|
|
181
|
-
const searchFeatures = (header: string) => {
|
|
182
|
-
const fieldType = getFieldType(header);
|
|
183
|
-
return (
|
|
184
|
-
<>
|
|
185
|
-
<Select
|
|
186
|
-
value={searchOperation[header] || "notBlank"}
|
|
187
|
-
onChange={(e) => handleSearchOperation(header, e.target.value)}
|
|
188
|
-
style={{ background: "#3182ce", color: "white" }}
|
|
189
|
-
>
|
|
190
|
-
{fieldType === "number" ? (
|
|
191
|
-
<>
|
|
192
|
-
<option value="equals">Equals</option>
|
|
193
|
-
<option value="notEquals">Does not equal</option>
|
|
194
|
-
<option value="greaterThan">Greater than</option>
|
|
195
|
-
<option value="greaterThanOrEqual">
|
|
196
|
-
Greater than or equal to
|
|
197
|
-
</option>
|
|
198
|
-
<option value="lessThan">Less than</option>
|
|
199
|
-
<option value="lessThanOrEqual">Less than or equal to</option>
|
|
200
|
-
<option value="between">Between</option>
|
|
201
|
-
<option value="blank">Blank</option>
|
|
202
|
-
<option value="notBlank">Not blank</option>
|
|
203
|
-
</>
|
|
204
|
-
) : (
|
|
205
|
-
<>
|
|
206
|
-
<option value="contains">Contains</option>
|
|
207
|
-
<option value="notContains">Does not contain</option>
|
|
208
|
-
<option value="equals">Equals</option>
|
|
209
|
-
<option value="notEquals">Does not equal</option>
|
|
210
|
-
<option value="beginsWith">Begins with</option>
|
|
211
|
-
<option value="endsWith">Ends with</option>
|
|
212
|
-
<option value="blank">Blank</option>
|
|
213
|
-
<option value="notBlank">Not blank</option>
|
|
214
|
-
</>
|
|
215
|
-
)}
|
|
216
|
-
</Select>
|
|
217
|
-
<br />
|
|
218
|
-
{searchOperation[header] === "between" && fieldType === "number" ? (
|
|
219
|
-
<>
|
|
220
|
-
<Input
|
|
221
|
-
value={betweenValues[header]?.min || ""}
|
|
222
|
-
onChange={(e) =>
|
|
223
|
-
setBetweenValues((prev) => ({
|
|
224
|
-
...prev,
|
|
225
|
-
[header]: { ...prev[header], min: e.target.value },
|
|
226
|
-
}))
|
|
227
|
-
}
|
|
228
|
-
placeholder="Min..."
|
|
229
|
-
background="white"
|
|
230
|
-
color="black"
|
|
231
|
-
/>
|
|
232
|
-
<br />
|
|
233
|
-
<br />
|
|
234
|
-
<Input
|
|
235
|
-
value={betweenValues[header]?.max || ""}
|
|
236
|
-
onChange={(e) =>
|
|
237
|
-
setBetweenValues((prev) => ({
|
|
238
|
-
...prev,
|
|
239
|
-
[header]: { ...prev[header], max: e.target.value },
|
|
240
|
-
}))
|
|
241
|
-
}
|
|
242
|
-
placeholder="Max..."
|
|
243
|
-
background="white"
|
|
244
|
-
color="black"
|
|
245
|
-
/>
|
|
246
|
-
</>
|
|
247
|
-
) : (
|
|
248
|
-
<Input
|
|
249
|
-
value={searchTerms[header] || ""}
|
|
250
|
-
onChange={(e) => handleSearch(header, e.target.value)}
|
|
251
|
-
placeholder="Search..."
|
|
252
|
-
background="white"
|
|
253
|
-
color="black"
|
|
254
|
-
/>
|
|
255
|
-
)}
|
|
256
|
-
</>
|
|
257
|
-
);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const handleColumnVisibilityChange = (header: string) => {
|
|
262
|
-
setVisibleColumns((prev) => ({ ...prev, [header]: !prev[header] }));
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
function calculateLeftOffset(headers: any, currentIndex: number) {
|
|
266
|
-
let offset = 0;
|
|
267
|
-
for (let i = 0; i < currentIndex; i++) {
|
|
268
|
-
if (headers[i].columnFreeze) {
|
|
269
|
-
offset += 100;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return offset;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const handleMouseEnter = (index: number) => setHoveredHeaderIndex(index);
|
|
276
|
-
const handleMouseLeave = () => {
|
|
277
|
-
setHoveredHeaderIndex(null);
|
|
278
|
-
closePopover();
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
return (
|
|
282
|
-
<ChakraProvider>
|
|
283
|
-
<div style={{ width: "97%" }}>
|
|
284
|
-
<Box display="flex" justifyContent="flex-end">
|
|
285
|
-
{exportOptions && exportOptions.length > 0 && (
|
|
286
|
-
<Select
|
|
287
|
-
placeholder="Exports"
|
|
288
|
-
width={160}
|
|
289
|
-
onChange={(e) => {
|
|
290
|
-
handleExportChange && handleExportChange(e.target.value);
|
|
291
|
-
}}
|
|
292
|
-
value={exportLabel}
|
|
293
|
-
>
|
|
294
|
-
{exportOptions.map((option) => (
|
|
295
|
-
<option key={option.value} value={option.value}>
|
|
296
|
-
{option.label}
|
|
297
|
-
</option>
|
|
298
|
-
))}
|
|
299
|
-
</Select>
|
|
300
|
-
)}
|
|
301
|
-
</Box>
|
|
302
|
-
<br />
|
|
303
|
-
<TableContainer>
|
|
304
|
-
<ChakraTable
|
|
305
|
-
variant="simple"
|
|
306
|
-
colorScheme="teal"
|
|
307
|
-
size={"md"}
|
|
308
|
-
overflowX={"scroll"}
|
|
309
|
-
>
|
|
310
|
-
<Thead background={tableHeaderBgColor}>
|
|
311
|
-
<Tr>
|
|
312
|
-
{headers.map((header, index) => {
|
|
313
|
-
const isFrozen = header.columnFreeze;
|
|
314
|
-
const leftOffset = calculateLeftOffset(headers, index);
|
|
315
|
-
return (
|
|
316
|
-
visibleColumns[header.label] && (
|
|
317
|
-
<Th
|
|
318
|
-
key={index}
|
|
319
|
-
style={{
|
|
320
|
-
textTransform: "capitalize",
|
|
321
|
-
color: tableHeaderColor,
|
|
322
|
-
fontSize: "medium",
|
|
323
|
-
fontWeight: 600,
|
|
324
|
-
position: isFrozen ? "sticky" : undefined,
|
|
325
|
-
left: isFrozen
|
|
326
|
-
? `${leftOffset === 0 ? leftOffset : leftOffset - 4}px`
|
|
327
|
-
: undefined,
|
|
328
|
-
zIndex: isFrozen ? 2 : 1,
|
|
329
|
-
background: tableHeaderBgColor,
|
|
330
|
-
textAlign: "center",
|
|
331
|
-
}}
|
|
332
|
-
onMouseEnter={() => handleMouseEnter(index)}
|
|
333
|
-
onMouseLeave={handleMouseLeave}
|
|
334
|
-
>
|
|
335
|
-
{header.sort ? (
|
|
336
|
-
<Button
|
|
337
|
-
onClick={() => handleSort(header.label)}
|
|
338
|
-
style={{
|
|
339
|
-
textTransform: "capitalize",
|
|
340
|
-
color: "white",
|
|
341
|
-
background: "none",
|
|
342
|
-
}}
|
|
343
|
-
>
|
|
344
|
-
{header.label}
|
|
345
|
-
{sortField === header.label &&
|
|
346
|
-
(sortDirection === "asc" ? (
|
|
347
|
-
<ArrowUpIcon w={15} h={15} />
|
|
348
|
-
) : (
|
|
349
|
-
<ArrowDownIcon w={15} h={15} />
|
|
350
|
-
))}
|
|
351
|
-
</Button>
|
|
352
|
-
) : (
|
|
353
|
-
<span>{header.label}</span>
|
|
354
|
-
)}
|
|
355
|
-
{header.search && (
|
|
356
|
-
<Popover
|
|
357
|
-
isOpen={
|
|
358
|
-
activeHeader === header.label && isPopoverOpen
|
|
359
|
-
}
|
|
360
|
-
onClose={closePopover}
|
|
361
|
-
placement="bottom-start"
|
|
362
|
-
closeOnBlur={false}
|
|
363
|
-
>
|
|
364
|
-
<PopoverTrigger>
|
|
365
|
-
<HamburgerIcon
|
|
366
|
-
w={15}
|
|
367
|
-
h={15}
|
|
368
|
-
onClick={() => handleHeaderClick(header.label)}
|
|
369
|
-
style={{
|
|
370
|
-
cursor: "pointer",
|
|
371
|
-
display:
|
|
372
|
-
hoveredHeaderIndex === index
|
|
373
|
-
? "inline"
|
|
374
|
-
: "none",
|
|
375
|
-
}}
|
|
376
|
-
/>
|
|
377
|
-
</PopoverTrigger>
|
|
378
|
-
<PopoverContent width={200} zIndex={3}>
|
|
379
|
-
<PopoverBody background={"#deeefd"}>
|
|
380
|
-
{searchFeatures(header.label)}
|
|
381
|
-
</PopoverBody>
|
|
382
|
-
</PopoverContent>
|
|
383
|
-
</Popover>
|
|
384
|
-
)}
|
|
385
|
-
</Th>
|
|
386
|
-
)
|
|
387
|
-
);
|
|
388
|
-
})}
|
|
389
|
-
</Tr>
|
|
390
|
-
</Thead>
|
|
391
|
-
<Tbody>
|
|
392
|
-
{filteredData.slice(startRow, endRow).map((row, index) => (
|
|
393
|
-
<Tr
|
|
394
|
-
key={index}
|
|
395
|
-
style={{
|
|
396
|
-
backgroundColor: index % 2 === 0 ? "#f7f7f7" : "white",
|
|
397
|
-
}}
|
|
398
|
-
border={"none"}
|
|
399
|
-
>
|
|
400
|
-
{headers.map((header, headerIndex) => {
|
|
401
|
-
const isFrozen = header.columnFreeze;
|
|
402
|
-
const leftOffset = calculateLeftOffset(
|
|
403
|
-
headers,
|
|
404
|
-
headerIndex
|
|
405
|
-
);
|
|
406
|
-
return (
|
|
407
|
-
visibleColumns[header.label] && (
|
|
408
|
-
<Td
|
|
409
|
-
key={headerIndex}
|
|
410
|
-
style={{
|
|
411
|
-
border: "none",
|
|
412
|
-
textAlign: "center",
|
|
413
|
-
position: isFrozen ? "sticky" : undefined,
|
|
414
|
-
left: isFrozen
|
|
415
|
-
? `${leftOffset === 0 ? leftOffset : leftOffset - 4}px`
|
|
416
|
-
: undefined,
|
|
417
|
-
zIndex: isFrozen ? 1 : 0,
|
|
418
|
-
backgroundColor:
|
|
419
|
-
index % 2 === 0 ? "#f7f7f7" : "white",
|
|
420
|
-
}}
|
|
421
|
-
// onClick={() => handleCellClick(row, header)}
|
|
422
|
-
>
|
|
423
|
-
{typeof header.accessor_function === "function" &&
|
|
424
|
-
header.accessor_key in row
|
|
425
|
-
? header.accessor_function(row[header.accessor_key])
|
|
426
|
-
: row[header.accessor_key]}
|
|
427
|
-
</Td>
|
|
428
|
-
)
|
|
429
|
-
);
|
|
430
|
-
})}
|
|
431
|
-
</Tr>
|
|
432
|
-
))}
|
|
433
|
-
</Tbody>
|
|
434
|
-
</ChakraTable>
|
|
435
|
-
</TableContainer>
|
|
436
|
-
<Flex justify="flex-end" align="center" mt={4}>
|
|
437
|
-
<Flex mr={4}>
|
|
438
|
-
<Menu>
|
|
439
|
-
<MenuButton
|
|
440
|
-
as={Button}
|
|
441
|
-
rightIcon={<ChevronDownIcon />}
|
|
442
|
-
colorScheme={"blue"}
|
|
443
|
-
variant="outline"
|
|
444
|
-
>
|
|
445
|
-
Visiblity
|
|
446
|
-
</MenuButton>
|
|
447
|
-
<MenuList height={150} overflow={"scroll"} zIndex={"2"}>
|
|
448
|
-
{headers.map((header, index) => (
|
|
449
|
-
<MenuItem key={index}>
|
|
450
|
-
<Checkbox
|
|
451
|
-
isChecked={visibleColumns[header.label]}
|
|
452
|
-
onChange={() =>
|
|
453
|
-
handleColumnVisibilityChange(header.label)
|
|
454
|
-
}
|
|
455
|
-
>
|
|
456
|
-
{header.label}
|
|
457
|
-
</Checkbox>
|
|
458
|
-
</MenuItem>
|
|
459
|
-
))}
|
|
460
|
-
</MenuList>
|
|
461
|
-
</Menu>
|
|
462
|
-
</Flex>
|
|
463
|
-
<Text mr={4}>
|
|
464
|
-
{startRow + 1} to {endRow} of {filteredData.length}
|
|
465
|
-
</Text>
|
|
466
|
-
<Select
|
|
467
|
-
onChange={handlePageSizeChange}
|
|
468
|
-
value={rowsPerPage}
|
|
469
|
-
mr={4}
|
|
470
|
-
width={20}
|
|
471
|
-
>
|
|
472
|
-
{pageSizeOptions.map((size, index) => (
|
|
473
|
-
<option key={index} value={size}>
|
|
474
|
-
{size}
|
|
475
|
-
</option>
|
|
476
|
-
))}
|
|
477
|
-
</Select>
|
|
478
|
-
<Flex>
|
|
479
|
-
<Button
|
|
480
|
-
mx={1}
|
|
481
|
-
disabled={currentPage === 0}
|
|
482
|
-
onClick={() => setCurrentPage(0)}
|
|
483
|
-
>
|
|
484
|
-
{"<<"}
|
|
485
|
-
</Button>
|
|
486
|
-
<Button
|
|
487
|
-
mx={1}
|
|
488
|
-
disabled={currentPage === 0}
|
|
489
|
-
onClick={() => currentPage > 0 && setCurrentPage(currentPage - 1)}
|
|
490
|
-
>
|
|
491
|
-
{"<"}
|
|
492
|
-
</Button>
|
|
493
|
-
<Text mx={1} mt={2}>
|
|
494
|
-
Page {currentPage + 1} of {pages}
|
|
495
|
-
</Text>
|
|
496
|
-
<Button
|
|
497
|
-
mx={1}
|
|
498
|
-
disabled={currentPage > pages}
|
|
499
|
-
onClick={() =>
|
|
500
|
-
currentPage < pages - 1 && setCurrentPage(currentPage + 1)
|
|
501
|
-
}
|
|
502
|
-
>
|
|
503
|
-
{">"}
|
|
504
|
-
</Button>
|
|
505
|
-
<Button
|
|
506
|
-
mx={1}
|
|
507
|
-
disabled={currentPage >= pages - 1}
|
|
508
|
-
onClick={() => setCurrentPage(pages - 1)}
|
|
509
|
-
>
|
|
510
|
-
{">>"}
|
|
511
|
-
</Button>
|
|
512
|
-
</Flex>
|
|
513
|
-
</Flex>
|
|
514
|
-
</div>
|
|
515
|
-
</ChakraProvider>
|
|
516
|
-
);
|
|
517
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
export type TableProps = {
|
|
4
|
-
data: DataObject[];
|
|
5
|
-
headers: TableHeader[];
|
|
6
|
-
// handleCellClick?: (row: any, header: any) => void;
|
|
7
|
-
tableHeaderBgColor?: string;
|
|
8
|
-
tableHeaderColor?: string;
|
|
9
|
-
handleExportChange?: (value: string) => void | undefined;
|
|
10
|
-
exportOptions?: ExportOption[];
|
|
11
|
-
exportLabel?: string;
|
|
12
|
-
isLoading?: boolean;
|
|
13
|
-
loadingType?: 'skeleton' | 'spinner';
|
|
14
|
-
loadingContaxt?: ReactNode;
|
|
15
|
-
loadingBoxStyle?: React.CSSProperties;
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
export type DataObject = {
|
|
19
|
-
id: number;
|
|
20
|
-
name: string;
|
|
21
|
-
email: string;
|
|
22
|
-
role: string;
|
|
23
|
-
[key: string]: string | number;
|
|
24
|
-
}
|
|
25
|
-
export type TableHeader = {
|
|
26
|
-
label: string;
|
|
27
|
-
accessor_key: string;
|
|
28
|
-
sort?: boolean;
|
|
29
|
-
search?: boolean;
|
|
30
|
-
columnFreeze?: boolean;
|
|
31
|
-
accessor_function?: (data: string | number) => JSX.Element | string | number;
|
|
32
|
-
}
|
|
33
|
-
export type ExportOption = {
|
|
34
|
-
label: string;
|
|
35
|
-
value: string;
|
|
36
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Toaster.stories.tsx
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Meta, StoryFn } from '@storybook/react';
|
|
4
|
-
import ToasterProvider, { useToaster } from './Toaster';
|
|
5
|
-
import { Button, ChakraProvider } from '@chakra-ui/react';
|
|
6
|
-
import { ToasterToastProps } from './ToasterProps';
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
title: 'Components/Toaster/ToasterProvider',
|
|
10
|
-
component: ToasterProvider,
|
|
11
|
-
argTypes: {
|
|
12
|
-
title: {
|
|
13
|
-
control: 'text',
|
|
14
|
-
defaultValue: 'Test',
|
|
15
|
-
},
|
|
16
|
-
status: {
|
|
17
|
-
control: 'select',
|
|
18
|
-
options: ['info', 'warning', 'success', 'error'],
|
|
19
|
-
defaultValue: 'info',
|
|
20
|
-
},
|
|
21
|
-
position: {
|
|
22
|
-
control: 'select',
|
|
23
|
-
options: ['top', 'top-right', 'top-left', 'bottom', 'bottom-right', 'bottom-left'],
|
|
24
|
-
defaultValue: 'bottom-right',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
} as Meta;
|
|
28
|
-
|
|
29
|
-
interface StoryProps {
|
|
30
|
-
title: string;
|
|
31
|
-
status: 'info' | 'warning' | 'success' | 'error';
|
|
32
|
-
position: 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const Template: StoryFn<StoryProps> = ({ title, status, position }) => {
|
|
36
|
-
const ShowToastButton = () => {
|
|
37
|
-
const { showToast } = useToaster();
|
|
38
|
-
return (
|
|
39
|
-
<Button onClick={() => showToast({
|
|
40
|
-
title,
|
|
41
|
-
description: 'This is a test toast',
|
|
42
|
-
status,
|
|
43
|
-
position,
|
|
44
|
-
})}>
|
|
45
|
-
Show Toast
|
|
46
|
-
</Button>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
return (
|
|
50
|
-
<ToasterProvider>
|
|
51
|
-
<ChakraProvider>
|
|
52
|
-
<ShowToastButton />
|
|
53
|
-
</ChakraProvider>
|
|
54
|
-
</ToasterProvider>
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const Default = Template.bind({});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { createContext, useContext } from 'react'
|
|
3
|
-
import { useToast } from '@chakra-ui/react'
|
|
4
|
-
import { ToasterChildren, ToasterContextType, ToasterToastProps } from './ToasterProps'
|
|
5
|
-
|
|
6
|
-
const ToasterContext = createContext<ToasterContextType | undefined>(undefined);
|
|
7
|
-
|
|
8
|
-
export default function ToasterProvider({ children }: ToasterChildren) {
|
|
9
|
-
const toast = useToast();
|
|
10
|
-
const showToast: ToasterContextType["showToast"] = ({ title, description, status, duration = 5000, isClosable = true, position, onClose }: ToasterToastProps) => {
|
|
11
|
-
toast({
|
|
12
|
-
title: title,
|
|
13
|
-
description: description,
|
|
14
|
-
status: status,
|
|
15
|
-
duration: duration,
|
|
16
|
-
isClosable: isClosable,
|
|
17
|
-
position: position,
|
|
18
|
-
onCloseComplete: onClose
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
return (
|
|
22
|
-
<ToasterContext.Provider value={{ showToast }}>
|
|
23
|
-
{children}
|
|
24
|
-
</ToasterContext.Provider>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const useToaster = () => {
|
|
29
|
-
const context = useContext(ToasterContext);
|
|
30
|
-
if (!context) {
|
|
31
|
-
throw new Error("useToaster must be used within a ToasterProvider")
|
|
32
|
-
}
|
|
33
|
-
return context;
|
|
34
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ToastProps } from "@chakra-ui/react";
|
|
2
|
-
import React, { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export type ToasterToastProps = Pick<ToastProps, 'description' | 'title' | 'isClosable' | 'duration' | 'children' | 'onClose'> & {
|
|
5
|
-
position?: "top" | "bottom" | "top-right" | "top-left" | "bottom-right" | "bottom-left"
|
|
6
|
-
status?: "success" | "error" | "warning" | "info" | "loading"
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface ToasterContextType {
|
|
10
|
-
showToast: (children: ToasterToastProps) => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ToasterChildren {
|
|
14
|
-
children: ReactNode;
|
|
15
|
-
}
|