@a2v2ai/uikit 1.0.1 → 1.1.1
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/DataTable/DataTable.tsx +95 -36
- package/package.json +1 -1
package/DataTable/DataTable.tsx
CHANGED
|
@@ -16,6 +16,14 @@ import {
|
|
|
16
16
|
PaginationNext,
|
|
17
17
|
PaginationPrevious,
|
|
18
18
|
} from "../Pagination/Pagination"
|
|
19
|
+
import {
|
|
20
|
+
Select,
|
|
21
|
+
SelectContent,
|
|
22
|
+
SelectItem,
|
|
23
|
+
SelectTrigger,
|
|
24
|
+
SelectValue,
|
|
25
|
+
} from "../Select/Select"
|
|
26
|
+
import { Typography } from "../Typography/Typography"
|
|
19
27
|
import { Skeleton } from "../Skeleton/Skeleton"
|
|
20
28
|
|
|
21
29
|
interface DataTableColumn<T> {
|
|
@@ -33,6 +41,8 @@ interface DataTablePagination {
|
|
|
33
41
|
pageSize: number
|
|
34
42
|
total: number
|
|
35
43
|
onChange: (page: number) => void
|
|
44
|
+
pageSizeOptions?: number[]
|
|
45
|
+
onPageSizeChange?: (size: number) => void
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
interface DataTableScroll {
|
|
@@ -48,6 +58,8 @@ interface DataTableProps<T extends object> {
|
|
|
48
58
|
scroll?: DataTableScroll
|
|
49
59
|
loading?: boolean
|
|
50
60
|
loadingRows?: number
|
|
61
|
+
onRowClick?: (record: T, index: number) => void
|
|
62
|
+
rowsPerPageLabel?: string
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
const getPageNumbers = (current: number, totalPages: number): (number | "ellipsis")[] => {
|
|
@@ -86,6 +98,8 @@ const DataTable = <T extends object>({
|
|
|
86
98
|
scroll,
|
|
87
99
|
loading,
|
|
88
100
|
loadingRows = 5,
|
|
101
|
+
onRowClick,
|
|
102
|
+
rowsPerPageLabel = "Rows per page",
|
|
89
103
|
}: DataTableProps<T>) => {
|
|
90
104
|
const getRowKey = (record: T): string => {
|
|
91
105
|
if (typeof rowKey === "function") {
|
|
@@ -136,7 +150,13 @@ const DataTable = <T extends object>({
|
|
|
136
150
|
</TableRow>
|
|
137
151
|
))
|
|
138
152
|
: dataSource.map((record, index) => (
|
|
139
|
-
<TableRow
|
|
153
|
+
<TableRow
|
|
154
|
+
key={getRowKey(record)}
|
|
155
|
+
onClick={
|
|
156
|
+
onRowClick ? () => onRowClick(record, index) : undefined
|
|
157
|
+
}
|
|
158
|
+
className={onRowClick ? "cursor-pointer" : undefined}
|
|
159
|
+
>
|
|
140
160
|
{columns.map((column) => (
|
|
141
161
|
<TableCell key={column.key}>
|
|
142
162
|
{getCellValue(record, column, index)}
|
|
@@ -161,42 +181,81 @@ const DataTable = <T extends object>({
|
|
|
161
181
|
tableContent
|
|
162
182
|
)}
|
|
163
183
|
|
|
164
|
-
{pagination &&
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
{pagination &&
|
|
185
|
+
((pagination.pageSizeOptions && pagination.pageSizeOptions.length > 0) ||
|
|
186
|
+
totalPages > 1) && (
|
|
187
|
+
<div className="mt-4 flex items-center justify-center gap-6">
|
|
188
|
+
{pagination.pageSizeOptions &&
|
|
189
|
+
pagination.pageSizeOptions.length > 0 && (
|
|
190
|
+
<div className="flex items-center gap-2">
|
|
191
|
+
<Typography
|
|
192
|
+
variant="body3"
|
|
193
|
+
color="main-700"
|
|
194
|
+
className="whitespace-nowrap"
|
|
195
|
+
>
|
|
196
|
+
{rowsPerPageLabel}
|
|
197
|
+
</Typography>
|
|
198
|
+
{/* Fixed-width wrapper: SelectTrigger has its own w-full wrapper. */}
|
|
199
|
+
<div className="w-20">
|
|
200
|
+
<Select
|
|
201
|
+
value={String(pagination.pageSize)}
|
|
202
|
+
onValueChange={(value) =>
|
|
203
|
+
pagination.onPageSizeChange?.(Number(value))
|
|
204
|
+
}
|
|
183
205
|
>
|
|
184
|
-
{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
<SelectTrigger size="small" aria-label={rowsPerPageLabel}>
|
|
207
|
+
<SelectValue />
|
|
208
|
+
</SelectTrigger>
|
|
209
|
+
<SelectContent>
|
|
210
|
+
{pagination.pageSizeOptions.map((option) => (
|
|
211
|
+
<SelectItem key={option} value={String(option)}>
|
|
212
|
+
{option}
|
|
213
|
+
</SelectItem>
|
|
214
|
+
))}
|
|
215
|
+
</SelectContent>
|
|
216
|
+
</Select>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
)}
|
|
220
|
+
|
|
221
|
+
{totalPages > 1 && (
|
|
222
|
+
<Pagination className="mx-0 w-auto justify-end">
|
|
223
|
+
<PaginationContent>
|
|
224
|
+
<PaginationItem>
|
|
225
|
+
<PaginationPrevious
|
|
226
|
+
disabled={pagination.current === 1}
|
|
227
|
+
onClick={() => pagination.onChange(pagination.current - 1)}
|
|
228
|
+
/>
|
|
229
|
+
</PaginationItem>
|
|
230
|
+
|
|
231
|
+
{pageNumbers.map((page, index) => (
|
|
232
|
+
<PaginationItem key={index}>
|
|
233
|
+
{page === "ellipsis" ? (
|
|
234
|
+
<PaginationEllipsis />
|
|
235
|
+
) : (
|
|
236
|
+
<PaginationLink
|
|
237
|
+
isActive={page === pagination.current}
|
|
238
|
+
onClick={() => pagination.onChange(page)}
|
|
239
|
+
>
|
|
240
|
+
{page}
|
|
241
|
+
</PaginationLink>
|
|
242
|
+
)}
|
|
243
|
+
</PaginationItem>
|
|
244
|
+
))}
|
|
245
|
+
|
|
246
|
+
<PaginationItem>
|
|
247
|
+
<PaginationNext
|
|
248
|
+
disabled={pagination.current === totalPages}
|
|
249
|
+
onClick={() =>
|
|
250
|
+
pagination.onChange(pagination.current + 1)
|
|
251
|
+
}
|
|
252
|
+
/>
|
|
253
|
+
</PaginationItem>
|
|
254
|
+
</PaginationContent>
|
|
255
|
+
</Pagination>
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
)}
|
|
200
259
|
</div>
|
|
201
260
|
)
|
|
202
261
|
}
|