@gobolt/genesis 0.3.21 → 0.3.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.
Files changed (133) hide show
  1. package/dist/components/Button/components/Button/Button.d.ts +16 -0
  2. package/dist/components/Button/components/Button/Button.js +13 -0
  3. package/dist/components/Button/components/Button/styles.d.ts +1 -0
  4. package/dist/components/Button/components/Button/styles.js +118 -0
  5. package/dist/components/Button/constants/index.d.ts +163 -0
  6. package/dist/components/Button/constants/index.js +89 -0
  7. package/dist/components/Table/Table/Table.d.ts +51 -0
  8. package/dist/components/Table/Table/Table.js +14 -0
  9. package/dist/components/Table/Table/TableControls/CustomPagination.d.ts +13 -0
  10. package/dist/components/Table/Table/TableControls/CustomPagination.js +158 -0
  11. package/dist/components/Table/Table/TableControls/PaginationNumber.d.ts +7 -0
  12. package/dist/components/Table/Table/TableControls/PaginationNumber.js +30 -0
  13. package/dist/components/Table/Table/styles.d.ts +14 -0
  14. package/dist/components/Table/Table/styles.js +64 -0
  15. package/dist/components/Table/Table/useTable.d.ts +26 -0
  16. package/dist/components/Table/Table/useTable.js +141 -0
  17. package/dist/components/Table/Typography/Typography.d.ts +17 -0
  18. package/dist/components/Table/Typography/Typography.js +16 -0
  19. package/dist/components/Table/Typography/index.d.ts +2 -0
  20. package/dist/components/Table/Typography/index.js +1 -0
  21. package/dist/components/Table/Typography/styles.d.ts +3 -0
  22. package/dist/components/Table/Typography/styles.js +54 -0
  23. package/dist/components/TableWithControls/components/Badge/Badge.d.ts +16 -0
  24. package/dist/components/TableWithControls/components/Badge/Badge.js +28 -0
  25. package/dist/components/TableWithControls/components/Badge/index.d.ts +2 -0
  26. package/dist/components/TableWithControls/components/Badge/index.js +1 -0
  27. package/dist/components/TableWithControls/components/Badge/styles.d.ts +4 -0
  28. package/dist/components/TableWithControls/components/Badge/styles.js +46 -0
  29. package/dist/components/TableWithControls/components/Button/Button.d.ts +16 -0
  30. package/dist/components/TableWithControls/components/Button/Button.js +13 -0
  31. package/dist/components/TableWithControls/components/Button/IconButton.d.ts +8 -0
  32. package/dist/components/TableWithControls/components/Button/IconButton.js +9 -0
  33. package/dist/components/TableWithControls/components/Button/icon-button-styles.d.ts +1 -0
  34. package/dist/components/TableWithControls/components/Button/icon-button-styles.js +76 -0
  35. package/dist/components/TableWithControls/components/Button/index.d.ts +4 -0
  36. package/dist/components/TableWithControls/components/Button/index.js +2 -0
  37. package/dist/components/TableWithControls/components/Button/styles.d.ts +1 -0
  38. package/dist/components/TableWithControls/components/Button/styles.js +118 -0
  39. package/dist/components/TableWithControls/components/Input/Input.d.ts +13 -0
  40. package/dist/components/TableWithControls/components/Input/Input.js +34 -0
  41. package/dist/components/TableWithControls/components/Input/index.d.ts +2 -0
  42. package/dist/components/TableWithControls/components/Input/index.js +1 -0
  43. package/dist/components/TableWithControls/components/Input/styles.d.ts +1 -0
  44. package/dist/components/TableWithControls/components/Input/styles.js +180 -0
  45. package/dist/components/TableWithControls/components/Select/Select.d.ts +26 -0
  46. package/dist/components/TableWithControls/components/Select/Select.js +175 -0
  47. package/dist/components/TableWithControls/components/Select/SelectTrigger.d.ts +23 -0
  48. package/dist/components/TableWithControls/components/Select/SelectTrigger.js +103 -0
  49. package/dist/components/TableWithControls/components/Select/index.d.ts +2 -0
  50. package/dist/components/TableWithControls/components/Select/index.js +1 -0
  51. package/dist/components/TableWithControls/components/Table/Table.d.ts +51 -0
  52. package/dist/components/TableWithControls/components/Table/Table.js +14 -0
  53. package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.d.ts +13 -0
  54. package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.js +158 -0
  55. package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.d.ts +7 -0
  56. package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.js +30 -0
  57. package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.d.ts +18 -0
  58. package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.js +77 -0
  59. package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.d.ts +11 -0
  60. package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.js +43 -0
  61. package/dist/components/TableWithControls/components/Table/TableControls/TableControls.d.ts +14 -0
  62. package/dist/components/TableWithControls/components/Table/TableControls/TableControls.js +13 -0
  63. package/dist/components/TableWithControls/components/Table/TableControls/index.d.ts +2 -0
  64. package/dist/components/TableWithControls/components/Table/TableControls/index.js +1 -0
  65. package/dist/components/TableWithControls/components/Table/TablePagination.d.ts +13 -0
  66. package/dist/components/TableWithControls/components/Table/TablePagination.js +11 -0
  67. package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.d.ts +20 -0
  68. package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.js +301 -0
  69. package/dist/components/TableWithControls/components/Table/index.d.ts +6 -0
  70. package/dist/components/TableWithControls/components/Table/index.js +3 -0
  71. package/dist/components/TableWithControls/components/Table/styles.d.ts +14 -0
  72. package/dist/components/TableWithControls/components/Table/styles.js +64 -0
  73. package/dist/components/TableWithControls/components/Table/useTable.d.ts +26 -0
  74. package/dist/components/TableWithControls/components/Table/useTable.js +141 -0
  75. package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.d.ts +12 -0
  76. package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.js +20 -0
  77. package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.d.ts +29 -0
  78. package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.js +136 -0
  79. package/dist/components/TableWithControls/components/Tooltip/Tooltip.d.ts +7 -0
  80. package/dist/components/TableWithControls/components/Tooltip/Tooltip.js +8 -0
  81. package/dist/components/TableWithControls/components/Tooltip/index.d.ts +2 -0
  82. package/dist/components/TableWithControls/components/Tooltip/index.js +1 -0
  83. package/dist/components/TableWithControls/components/Tooltip/styles.d.ts +6 -0
  84. package/dist/components/TableWithControls/components/Tooltip/styles.js +26 -0
  85. package/dist/components/TableWithControls/components/Typography/Typography.d.ts +17 -0
  86. package/dist/components/TableWithControls/components/Typography/Typography.js +16 -0
  87. package/dist/components/TableWithControls/components/Typography/index.d.ts +2 -0
  88. package/dist/components/TableWithControls/components/Typography/index.js +1 -0
  89. package/dist/components/TableWithControls/components/Typography/styles.d.ts +3 -0
  90. package/dist/components/TableWithControls/components/Typography/styles.js +54 -0
  91. package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.d.ts +5 -0
  92. package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.js +9 -0
  93. package/dist/components/TableWithControls/components/UtilityButton/index.d.ts +2 -0
  94. package/dist/components/TableWithControls/components/UtilityButton/index.js +1 -0
  95. package/dist/components/TableWithControls/components/shared/DropdownChevron.d.ts +2 -0
  96. package/dist/components/TableWithControls/components/shared/DropdownChevron.js +7 -0
  97. package/dist/components/TableWithControls/constants/index.d.ts +163 -0
  98. package/dist/components/TableWithControls/constants/index.js +89 -0
  99. package/dist/components/TableWithControls/types/events.d.ts +22 -0
  100. package/dist/components/TableWithControls/types/events.js +1 -0
  101. package/dist/components/TableWithControls/utils/icon-util.d.ts +3 -0
  102. package/dist/components/TableWithControls/utils/icon-util.js +116 -0
  103. package/dist/components/UtilityButton/components/Button/Button.d.ts +16 -0
  104. package/dist/components/UtilityButton/components/Button/Button.js +13 -0
  105. package/dist/components/UtilityButton/components/Button/IconButton.d.ts +8 -0
  106. package/dist/components/UtilityButton/components/Button/IconButton.js +9 -0
  107. package/dist/components/UtilityButton/components/Button/icon-button-styles.d.ts +1 -0
  108. package/dist/components/UtilityButton/components/Button/icon-button-styles.js +76 -0
  109. package/dist/components/UtilityButton/components/Button/index.d.ts +4 -0
  110. package/dist/components/UtilityButton/components/Button/index.js +2 -0
  111. package/dist/components/UtilityButton/components/Button/styles.d.ts +1 -0
  112. package/dist/components/UtilityButton/components/Button/styles.js +118 -0
  113. package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.d.ts +5 -0
  114. package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.js +9 -0
  115. package/dist/components/UtilityButton/constants/index.d.ts +163 -0
  116. package/dist/components/UtilityButton/constants/index.js +89 -0
  117. package/dist/components/index.d.ts +6 -6
  118. package/dist/components/index.js +7 -0
  119. package/dist/components/index.ts +6 -6
  120. package/dist/constants/index.js +14 -14
  121. package/dist/index.d.ts +9 -9
  122. package/dist/index.js +10 -0
  123. package/dist/index.ts +9 -9
  124. package/package.json +1 -1
  125. package/dist/components/Button/Button.tsx +0 -59
  126. package/dist/components/Table/Table.tsx +0 -112
  127. package/dist/components/Table/useTable.ts +0 -194
  128. package/dist/components/TableWithControls/TableWithControls.tsx +0 -54
  129. package/dist/components/TableWithControls/useTableWithControls.tsx +0 -161
  130. package/dist/components/UtilityButton/UtilityButton.tsx +0 -36
  131. package/dist/constants/index.ts +0 -98
  132. package/dist/styles/theme/genesis-theme.types.ts +0 -297
  133. package/dist/utils/styled.ts +0 -52
@@ -0,0 +1,301 @@
1
+ import { Badge } from "@gobolt/genesis/components";
2
+ import React from "react";
3
+ // Helper function for title case
4
+ const startCase = (string_) => {
5
+ if (string_) {
6
+ return string_
7
+ .replaceAll(/([A-Z])/g, " $1")
8
+ .replace(/^./, (s) => s.toUpperCase());
9
+ }
10
+ return string_;
11
+ };
12
+ export const mockColumns = [
13
+ {
14
+ key: "number",
15
+ title: "Id",
16
+ dataIndex: "number",
17
+ },
18
+ {
19
+ key: "timeslot",
20
+ title: "Timeslot",
21
+ dataIndex: "timerange",
22
+ },
23
+ {
24
+ key: "status",
25
+ title: "Status",
26
+ dataIndex: "status",
27
+ render: (status) => {
28
+ const colorStateMap = {
29
+ in_progress: "warning",
30
+ scheduled: "generic",
31
+ completed: "success",
32
+ };
33
+ const statusLabel = status === "in_progress" ? "in progress" : status;
34
+ return React.createElement(Badge, {
35
+ label: startCase(statusLabel),
36
+ state: colorStateMap[status],
37
+ });
38
+ },
39
+ },
40
+ {
41
+ key: "address",
42
+ title: "Address",
43
+ render: (appointment) => {
44
+ const { address: { nickname, address }, } = appointment;
45
+ return nickname ? `${nickname} (${address})` : address;
46
+ },
47
+ },
48
+ {
49
+ title: "Type",
50
+ dataIndex: "job_subtype",
51
+ render: (jobSubtype) => {
52
+ const colorStateMap = {
53
+ delivery: "info",
54
+ pickup: "success",
55
+ };
56
+ return React.createElement(Badge, {
57
+ label: startCase(jobSubtype),
58
+ state: colorStateMap[jobSubtype],
59
+ });
60
+ },
61
+ },
62
+ ];
63
+ // Note: it's important that we don't show the Ant Design sorting since it controlled via the table controls
64
+ export const mockColumnsWithSortDisabled = mockColumns.map((column) => ({
65
+ ...column,
66
+ }));
67
+ export const mockDataSource = {
68
+ appointments: [
69
+ {
70
+ id: "1",
71
+ number: "1",
72
+ timerange: "9:00 AM - 10:00 AM",
73
+ status: "in_progress",
74
+ address: {
75
+ nickname: "Home",
76
+ address: "123 Main St",
77
+ },
78
+ job_subtype: "delivery",
79
+ },
80
+ {
81
+ id: "2",
82
+ number: "2",
83
+ timerange: "10:00 AM - 11:00 AM",
84
+ status: "scheduled",
85
+ address: {
86
+ nickname: "Work",
87
+ address: "456 Elm St",
88
+ },
89
+ job_subtype: "pickup",
90
+ },
91
+ {
92
+ id: "3",
93
+ number: "3",
94
+ timerange: "11:00 AM - 12:00 PM",
95
+ status: "scheduled",
96
+ address: {
97
+ nickname: "Store",
98
+ address: "789 Oak St",
99
+ },
100
+ job_subtype: "delivery",
101
+ },
102
+ {
103
+ id: "4",
104
+ number: "4",
105
+ timerange: "1:00 PM - 2:00 PM",
106
+ status: "scheduled",
107
+ address: {
108
+ nickname: "Office",
109
+ address: "321 Pine St",
110
+ },
111
+ job_subtype: "pickup",
112
+ },
113
+ {
114
+ id: "5",
115
+ number: "5",
116
+ timerange: "2:00 PM - 3:00 PM",
117
+ status: "scheduled",
118
+ address: {
119
+ nickname: "Library",
120
+ address: "555 Book Lane",
121
+ },
122
+ job_subtype: "delivery",
123
+ },
124
+ {
125
+ id: "6",
126
+ number: "6",
127
+ timerange: "3:00 PM - 4:00 PM",
128
+ status: "scheduled",
129
+ address: {
130
+ nickname: "Gym",
131
+ address: "777 Fitness Ave",
132
+ },
133
+ job_subtype: "pickup",
134
+ },
135
+ {
136
+ id: "7",
137
+ number: "7",
138
+ timerange: "4:00 PM - 5:00 PM",
139
+ status: "scheduled",
140
+ address: {
141
+ nickname: "Mall",
142
+ address: "888 Shopping Center",
143
+ },
144
+ job_subtype: "delivery",
145
+ },
146
+ {
147
+ id: "8",
148
+ number: "8",
149
+ timerange: "9:00 AM - 10:00 AM",
150
+ status: "completed",
151
+ address: {
152
+ nickname: "School",
153
+ address: "999 Education Rd",
154
+ },
155
+ job_subtype: "pickup",
156
+ },
157
+ {
158
+ id: "9",
159
+ number: "9",
160
+ timerange: "10:00 AM - 11:00 AM",
161
+ status: "scheduled",
162
+ address: {
163
+ nickname: "Restaurant",
164
+ address: "111 Food Court",
165
+ },
166
+ job_subtype: "delivery",
167
+ },
168
+ {
169
+ id: "10",
170
+ number: "10",
171
+ timerange: "11:00 AM - 12:00 PM",
172
+ status: "scheduled",
173
+ address: {
174
+ nickname: "Park",
175
+ address: "222 Green Ave",
176
+ },
177
+ job_subtype: "pickup",
178
+ },
179
+ {
180
+ id: "11",
181
+ number: "11",
182
+ timerange: "1:00 PM - 2:00 PM",
183
+ status: "scheduled",
184
+ address: {
185
+ nickname: "Beach",
186
+ address: "333 Shore Dr",
187
+ },
188
+ job_subtype: "delivery",
189
+ },
190
+ {
191
+ id: "12",
192
+ number: "12",
193
+ timerange: "2:00 PM - 3:00 PM",
194
+ status: "scheduled",
195
+ address: {
196
+ nickname: "Hotel",
197
+ address: "444 Stay Blvd",
198
+ },
199
+ job_subtype: "pickup",
200
+ },
201
+ {
202
+ id: "13",
203
+ number: "13",
204
+ timerange: "3:00 PM - 4:00 PM",
205
+ status: "scheduled",
206
+ address: {
207
+ nickname: "Airport",
208
+ address: "666 Flight Way",
209
+ },
210
+ job_subtype: "delivery",
211
+ },
212
+ {
213
+ id: "14",
214
+ number: "14",
215
+ timerange: "4:00 PM - 5:00 PM",
216
+ status: "cancelled",
217
+ address: {
218
+ nickname: "Stadium",
219
+ address: "777 Sports Complex",
220
+ },
221
+ job_subtype: "pickup",
222
+ },
223
+ {
224
+ id: "15",
225
+ number: "15",
226
+ timerange: "9:00 AM - 10:00 AM",
227
+ status: "scheduled",
228
+ address: {
229
+ nickname: "Theater",
230
+ address: "888 Show Ave",
231
+ },
232
+ job_subtype: "delivery",
233
+ },
234
+ {
235
+ id: "16",
236
+ number: "16",
237
+ timerange: "10:00 AM - 11:00 AM",
238
+ status: "scheduled",
239
+ address: {
240
+ nickname: "Museum",
241
+ address: "999 History Lane",
242
+ },
243
+ job_subtype: "pickup",
244
+ },
245
+ {
246
+ id: "17",
247
+ number: "17",
248
+ timerange: "11:00 AM - 12:00 PM",
249
+ status: "scheduled",
250
+ address: {
251
+ nickname: "Zoo",
252
+ address: "123 Animal Park",
253
+ },
254
+ job_subtype: "delivery",
255
+ },
256
+ {
257
+ id: "18",
258
+ number: "18",
259
+ timerange: "1:00 PM - 2:00 PM",
260
+ status: "scheduled",
261
+ address: {
262
+ nickname: "Bank",
263
+ address: "456 Money St",
264
+ },
265
+ job_subtype: "pickup",
266
+ },
267
+ {
268
+ id: "19",
269
+ number: "19",
270
+ timerange: "2:00 PM - 3:00 PM",
271
+ status: "scheduled",
272
+ address: {
273
+ nickname: "Post Office",
274
+ address: "789 Mail Road",
275
+ },
276
+ job_subtype: "delivery",
277
+ },
278
+ {
279
+ id: "20",
280
+ number: "20",
281
+ timerange: "3:00 PM - 4:00 PM",
282
+ status: "scheduled",
283
+ address: {
284
+ nickname: "Church",
285
+ address: "321 Faith Street",
286
+ },
287
+ job_subtype: "pickup",
288
+ },
289
+ {
290
+ id: "21",
291
+ number: "21",
292
+ timerange: "4:00 PM - 5:00 PM",
293
+ status: "scheduled",
294
+ address: {
295
+ nickname: "Pharmacy",
296
+ address: "654 Health Ave",
297
+ },
298
+ job_subtype: "delivery",
299
+ },
300
+ ],
301
+ };
@@ -0,0 +1,6 @@
1
+ export { default } from "./TablePagination";
2
+ export { default as Table } from "./Table";
3
+ export type { TableProps } from "./Table";
4
+ export type { TablePaginationProps } from "./TablePagination";
5
+ export { useTable } from "./useTable";
6
+ export type { UseTableConfig } from "./useTable";
@@ -0,0 +1,3 @@
1
+ export { default } from "./TablePagination";
2
+ export { default as Table } from "./Table";
3
+ export { useTable } from "./useTable";
@@ -0,0 +1,14 @@
1
+ import { TableProps } from "antd";
2
+ import { type GenesisTheme } from "@gobolt/genesis/styles/theme/genesis-theme.types";
3
+ export interface StyledTableProps<T = any> extends TableProps<T> {
4
+ theme?: GenesisTheme;
5
+ $isMainContentCell?: boolean;
6
+ }
7
+ export declare const getGenesisClass: ({ colors, borderRadius, sizing, typography, components }: {
8
+ colors: any;
9
+ borderRadius: any;
10
+ sizing: any;
11
+ typography: any;
12
+ components: any;
13
+ }, $isMainContentCell: any) => string;
14
+ export declare const Table: any;
@@ -0,0 +1,64 @@
1
+ import styled from "@gobolt/genesis/utils/styled";
2
+ import { Table as AntTable } from "antd";
3
+ export const getGenesisClass = ({ colors, borderRadius, sizing, typography, components }, $isMainContentCell) => {
4
+ // Log the hovered color and the entire tableCell object
5
+ return `
6
+ &.ant-table-wrapper {
7
+ // Add your custom styles here
8
+ }
9
+
10
+ .ant-table {
11
+ // Add your custom table styles here
12
+ }
13
+
14
+ .ant-table-cell {
15
+ font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
16
+ color: ${$isMainContentCell
17
+ ? colors.onsurface.copy
18
+ : colors.onsurface["copy-light"]} !important;
19
+ background-color: ${components.tableCell.surface} !important;
20
+ transition: background-color 0.2s ease;
21
+ }
22
+
23
+ .ant-table-tbody > tr:hover > td,
24
+ .ant-table-tbody > tr:hover > .ant-table-cell {
25
+ background-color: ${components.tableCell.hover} !important;
26
+ }
27
+
28
+ .ant-table-cell-selected {
29
+ background-color: ${components.tableCell.selected} !important;
30
+ }
31
+
32
+ .ant-table-thead > tr > th {
33
+ // Add your custom header styles here
34
+ font-family: 'Inter', sans-serif;
35
+ font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
36
+ font-weight: 400;
37
+ color: ${$isMainContentCell
38
+ ? colors.onsurface.copy
39
+ : colors.onsurface["copy-light"]} !important;
40
+ }
41
+
42
+ .ant-table-tbody > tr {
43
+ // Add your custom row styles here
44
+ }
45
+
46
+ .ant-table-tbody > tr > td {
47
+ // Add your custom cell styles here
48
+ font-family: 'Inter', sans-serif;
49
+ font-size: 14px;
50
+ color: ${colors.onsurface["copy-light"]};
51
+ }
52
+
53
+ .ant-table-tbody > tr.ant-table-row-selected > td,
54
+ .ant-table-tbody > tr.ant-table-row-selected > .ant-table-cell {
55
+ background-color: ${components.tableCell.selected} !important;
56
+ color: #fff !important;
57
+ }
58
+ `;
59
+ };
60
+ export const Table = styled(AntTable) `
61
+ ${({ theme, $isMainContentCell }) => {
62
+ return getGenesisClass(theme, $isMainContentCell);
63
+ }}
64
+ `;
@@ -0,0 +1,26 @@
1
+ import type { ColumnsType } from "antd/es/table";
2
+ import type { SelectionType } from "./Table";
3
+ export type UseTableConfig = {
4
+ columns: ColumnsType<any>;
5
+ filters?: Record<string, any>;
6
+ fetchUrl?: string;
7
+ fetchOptions?: RequestInit;
8
+ selectionType?: SelectionType;
9
+ simulateDelay?: number;
10
+ disableRowSelection?: (record: any) => unknown;
11
+ disableAutoFetch?: boolean;
12
+ dataSource?: any[];
13
+ };
14
+ export declare const useTable: <T extends Record<string, any>>(useTableConfig: any) => {
15
+ isLoading: boolean;
16
+ rowSelection: {
17
+ type: SelectionType;
18
+ onChange: (selectedRowKeys: React.Key[], selectedRows: T[]) => void;
19
+ getCheckboxProps: (record: any) => unknown;
20
+ };
21
+ selectedRows: T[];
22
+ updateDataSource: (newDataSource: T[]) => void;
23
+ dataSource: T[];
24
+ columns: ColumnsType<T>;
25
+ error: Error | null;
26
+ };
@@ -0,0 +1,141 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ // Function to sort data by field and order
3
+ const sortData = (data, sorter) => {
4
+ // Handle case when no sorting is applied
5
+ if (!sorter || (Array.isArray(sorter) && sorter.length === 0)) {
6
+ return [...data];
7
+ }
8
+ // Handle multiple sorters
9
+ if (Array.isArray(sorter)) {
10
+ return [...data].sort((a, b) => {
11
+ for (const sort of sorter) {
12
+ if (!sort.field)
13
+ continue;
14
+ const field = sort.field;
15
+ const aValue = a[field];
16
+ const bValue = b[field];
17
+ if (aValue < bValue)
18
+ return sort.order === "ascend" ? -1 : 1;
19
+ if (aValue > bValue)
20
+ return sort.order === "ascend" ? 1 : -1;
21
+ }
22
+ return 0;
23
+ });
24
+ }
25
+ // Handle single sorter
26
+ if (sorter.field) {
27
+ const field = sorter.field;
28
+ return [...data].sort((a, b) => {
29
+ const aValue = a[field];
30
+ const bValue = b[field];
31
+ if (sorter.order === "ascend") {
32
+ if (aValue < bValue)
33
+ return -1;
34
+ if (aValue > bValue)
35
+ return 1;
36
+ return 0;
37
+ }
38
+ if (sorter.order === "descend") {
39
+ if (aValue < bValue)
40
+ return 1;
41
+ if (aValue > bValue)
42
+ return -1;
43
+ return 0;
44
+ }
45
+ return 0;
46
+ });
47
+ }
48
+ return [...data];
49
+ };
50
+ /*
51
+ Example of disableRowSelection function which can be passed to the useTable hook
52
+ const disableRowSelection = (record: any) => ({
53
+ disabled: record.status === "completed", // Column configuration not to be checked
54
+ name: record.status.toString(),
55
+ });
56
+ */
57
+ const defaultRowSelection = (record) => ({
58
+ disabled: false, // Add your disable logic here
59
+ name: record.id,
60
+ });
61
+ export const useTable = (useTableConfig) => {
62
+ const [isLoading, setLoading] = useState(true);
63
+ const { columns, filters = null, fetchUrl = "/table/data", fetchOptions = {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ },
68
+ body: JSON.stringify(filters),
69
+ }, selectionType = "checkbox", simulateDelay = 0, disableRowSelection = defaultRowSelection, disableAutoFetch = false, dataSource: initialDataSource = [], } = useTableConfig;
70
+ // State to hold the original data and the current data
71
+ const [originalData, setOriginalData] = useState(initialDataSource);
72
+ const [data, setData] = useState({
73
+ dataSource: initialDataSource,
74
+ columns,
75
+ error: null,
76
+ });
77
+ const [selectedRows, setSelectedRows] = useState([]);
78
+ // Load initial data
79
+ useEffect(() => {
80
+ // If auto-fetch is disabled and we have initial data, skip fetching
81
+ if (disableAutoFetch && initialDataSource.length > 0) {
82
+ setLoading(false);
83
+ return;
84
+ }
85
+ const fetchData = async () => {
86
+ try {
87
+ const response = await fetch(fetchUrl, fetchOptions);
88
+ const result = await response.json();
89
+ const sourceData = result.data || [];
90
+ setOriginalData(sourceData);
91
+ setData({
92
+ dataSource: sourceData,
93
+ columns,
94
+ error: null,
95
+ });
96
+ }
97
+ catch (error) {
98
+ console.error("Error fetching table data:", error);
99
+ // Fallback to static data
100
+ setData({
101
+ dataSource: [],
102
+ columns,
103
+ error: error instanceof Error ? error : new Error(String(error)),
104
+ });
105
+ }
106
+ finally {
107
+ setLoading(false);
108
+ }
109
+ };
110
+ if (simulateDelay > 0) {
111
+ setTimeout(fetchData, simulateDelay);
112
+ }
113
+ else {
114
+ fetchData();
115
+ }
116
+ }, [fetchOptions, disableAutoFetch, initialDataSource]);
117
+ const handleRowSelection = useCallback((selectedRowKeys, selectedRows) => {
118
+ console.log("Row Selected:", selectedRowKeys, selectedRows);
119
+ setSelectedRows(selectedRows);
120
+ }, []);
121
+ // Function to manually update data source (for external data fetching)
122
+ const updateDataSource = useCallback((newDataSource) => {
123
+ setOriginalData(newDataSource);
124
+ setData((prev) => ({
125
+ ...prev,
126
+ dataSource: newDataSource,
127
+ }));
128
+ }, []);
129
+ const rowSelection = {
130
+ type: selectionType,
131
+ onChange: handleRowSelection,
132
+ getCheckboxProps: disableRowSelection,
133
+ };
134
+ return {
135
+ ...data,
136
+ isLoading,
137
+ rowSelection,
138
+ selectedRows,
139
+ updateDataSource,
140
+ };
141
+ };
@@ -0,0 +1,12 @@
1
+ import type { TableProps } from "../Table";
2
+ import { type TableControlsData } from "../Table/TableControls/TableControls";
3
+ export interface TableWithControlsProps {
4
+ tableControlsData: TableControlsData;
5
+ tableData: TableProps<Record<string, any>>;
6
+ onChange: (event: {
7
+ event: string;
8
+ payload: any;
9
+ }) => void;
10
+ }
11
+ declare const TableWithControls: ({ tableData, tableControlsData, onChange, }: TableWithControlsProps) => import("react/jsx-runtime").JSX.Element;
12
+ export default TableWithControls;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import TableControls from "../Table/TableControls";
3
+ import Table from "../Table";
4
+ const TableWithControls = ({ tableData, tableControlsData, onChange, }) => {
5
+ const { primaryTableRowData, secondaryTableRowData } = tableControlsData;
6
+ const { dataSource, columns, rowSelection } = tableData;
7
+ // handle changes from the table controls
8
+ const onTableControlsChange = (event) => {
9
+ onChange(event);
10
+ };
11
+ // handle changes from the table
12
+ const onTableChange = (pagination, filters, sorter) => {
13
+ onChange({
14
+ event: "tableChange",
15
+ payload: { pagination, filters, sorter },
16
+ });
17
+ };
18
+ return (_jsxs(_Fragment, { children: [_jsx(TableControls, { primaryTableRowData: primaryTableRowData, secondaryTableRowData: secondaryTableRowData, onChange: onTableControlsChange }), _jsx(Table, { dataSource: dataSource, columns: columns, rowSelection: rowSelection, onChange: onTableChange })] }));
19
+ };
20
+ export default TableWithControls;
@@ -0,0 +1,29 @@
1
+ import { type UseTableConfig } from "../Table/useTable";
2
+ import { ActionEvent, TableEventPayload } from "../../types/events";
3
+ export declare const useTableWithControls: (tableConfig: UseTableConfig) => {
4
+ onChange: (actionEvent: ActionEvent<TableEventPayload>) => void;
5
+ primaryTableRowData: {
6
+ sortOptions: {
7
+ value: string;
8
+ label: import("react/jsx-runtime").JSX.Element;
9
+ }[];
10
+ searchByPlaceholder: string;
11
+ isSortedAscending: boolean;
12
+ };
13
+ secondaryTableRowData: {
14
+ groups: {
15
+ orders: string[];
16
+ warehouse: string[];
17
+ availability: string[];
18
+ };
19
+ totalRecords: number;
20
+ };
21
+ dataSource: Record<string, any>[];
22
+ columns: import("antd").TableColumnsType<Record<string, any>>;
23
+ rowSelection: {
24
+ type: import("../Table/Table").SelectionType;
25
+ onChange: (selectedRowKeys: React.Key[], selectedRows: Record<string, any>[]) => void;
26
+ getCheckboxProps: (record: any) => unknown;
27
+ };
28
+ updateDataSource: (newDataSource: Record<string, any>[]) => void;
29
+ };