@manusiakemos/laravel-tanstack-react 0.1.0 → 0.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/README.md +284 -33
- package/dist/index.cjs +638 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +364 -4
- package/dist/index.d.ts +364 -4
- package/dist/index.js +623 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -1
- package/src/components/DataTable.tsx +166 -0
- package/src/components/DataTableFilter.tsx +217 -0
- package/src/components/DataTablePagination.tsx +271 -0
- package/src/components/DataTableSearch.tsx +173 -0
- package/src/components/layouts/DataTableSplitLayout.tsx +153 -0
- package/src/components/ui/button.tsx +49 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/select.tsx +27 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/hooks/useDataTable.ts +1 -1
- package/src/index.ts +60 -2
- package/src/lib/cn.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
|
|
2
|
-
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
1
|
+
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
2
|
+
import { forwardRef, useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
3
|
+
import { ArrowUp, ArrowDown, ChevronsUpDown, Search, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight } from 'lucide-react';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
import { cva } from 'class-variance-authority';
|
|
3
8
|
|
|
4
9
|
// src/hooks/useDataTable.ts
|
|
5
10
|
|
|
@@ -203,7 +208,622 @@ function useDataTable(options) {
|
|
|
203
208
|
});
|
|
204
209
|
return { table, data, meta, loading, error, refetch };
|
|
205
210
|
}
|
|
211
|
+
function cn(...inputs) {
|
|
212
|
+
return twMerge(clsx(inputs));
|
|
213
|
+
}
|
|
214
|
+
var Table = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { className: "relative w-full overflow-auto", children: /* @__PURE__ */ jsx(
|
|
215
|
+
"table",
|
|
216
|
+
{
|
|
217
|
+
ref,
|
|
218
|
+
className: cn("w-full caption-bottom text-sm", className),
|
|
219
|
+
...props
|
|
220
|
+
}
|
|
221
|
+
) }));
|
|
222
|
+
Table.displayName = "Table";
|
|
223
|
+
var TableHeader = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
|
|
224
|
+
TableHeader.displayName = "TableHeader";
|
|
225
|
+
var TableBody = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
226
|
+
"tbody",
|
|
227
|
+
{
|
|
228
|
+
ref,
|
|
229
|
+
className: cn("[&_tr:last-child]:border-0", className),
|
|
230
|
+
...props
|
|
231
|
+
}
|
|
232
|
+
));
|
|
233
|
+
TableBody.displayName = "TableBody";
|
|
234
|
+
var TableFooter = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
235
|
+
"tfoot",
|
|
236
|
+
{
|
|
237
|
+
ref,
|
|
238
|
+
className: cn(
|
|
239
|
+
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
|
240
|
+
className
|
|
241
|
+
),
|
|
242
|
+
...props
|
|
243
|
+
}
|
|
244
|
+
));
|
|
245
|
+
TableFooter.displayName = "TableFooter";
|
|
246
|
+
var TableRow = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
247
|
+
"tr",
|
|
248
|
+
{
|
|
249
|
+
ref,
|
|
250
|
+
className: cn(
|
|
251
|
+
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
|
252
|
+
className
|
|
253
|
+
),
|
|
254
|
+
...props
|
|
255
|
+
}
|
|
256
|
+
));
|
|
257
|
+
TableRow.displayName = "TableRow";
|
|
258
|
+
var TableHead = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
259
|
+
"th",
|
|
260
|
+
{
|
|
261
|
+
ref,
|
|
262
|
+
className: cn(
|
|
263
|
+
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
|
|
264
|
+
className
|
|
265
|
+
),
|
|
266
|
+
...props
|
|
267
|
+
}
|
|
268
|
+
));
|
|
269
|
+
TableHead.displayName = "TableHead";
|
|
270
|
+
var TableCell = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
271
|
+
"td",
|
|
272
|
+
{
|
|
273
|
+
ref,
|
|
274
|
+
className: cn(
|
|
275
|
+
"p-4 align-middle [&:has([role=checkbox])]:pr-0",
|
|
276
|
+
className
|
|
277
|
+
),
|
|
278
|
+
...props
|
|
279
|
+
}
|
|
280
|
+
));
|
|
281
|
+
TableCell.displayName = "TableCell";
|
|
282
|
+
var TableCaption = forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
283
|
+
"caption",
|
|
284
|
+
{
|
|
285
|
+
ref,
|
|
286
|
+
className: cn("mt-4 text-sm text-muted-foreground", className),
|
|
287
|
+
...props
|
|
288
|
+
}
|
|
289
|
+
));
|
|
290
|
+
TableCaption.displayName = "TableCaption";
|
|
291
|
+
function DataTable(props) {
|
|
292
|
+
const {
|
|
293
|
+
table,
|
|
294
|
+
loading = false,
|
|
295
|
+
emptyMessage = "No results.",
|
|
296
|
+
loadingMessage = "Loading...",
|
|
297
|
+
className,
|
|
298
|
+
classNames,
|
|
299
|
+
onRowClick
|
|
300
|
+
} = props;
|
|
301
|
+
const columnCount = table.getAllColumns().length;
|
|
302
|
+
const rows = table.getRowModel().rows;
|
|
303
|
+
return /* @__PURE__ */ jsx("div", { className: cn("rounded-md border", className, classNames?.root), children: /* @__PURE__ */ jsxs(Table, { className: classNames?.table, children: [
|
|
304
|
+
/* @__PURE__ */ jsx(TableHeader, { className: classNames?.header, children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { className: classNames?.headerRow, children: headerGroup.headers.map((header) => {
|
|
305
|
+
const canSort = header.column.getCanSort();
|
|
306
|
+
const sortDir = header.column.getIsSorted();
|
|
307
|
+
return /* @__PURE__ */ jsx(
|
|
308
|
+
TableHead,
|
|
309
|
+
{
|
|
310
|
+
className: cn(
|
|
311
|
+
canSort && "cursor-pointer select-none",
|
|
312
|
+
classNames?.head
|
|
313
|
+
),
|
|
314
|
+
onClick: canSort ? header.column.getToggleSortingHandler() : void 0,
|
|
315
|
+
children: header.isPlaceholder ? null : /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1", children: [
|
|
316
|
+
flexRender(
|
|
317
|
+
header.column.columnDef.header,
|
|
318
|
+
header.getContext()
|
|
319
|
+
),
|
|
320
|
+
canSort && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: sortDir === "asc" ? /* @__PURE__ */ jsx(ArrowUp, { className: "h-3.5 w-3.5" }) : sortDir === "desc" ? /* @__PURE__ */ jsx(ArrowDown, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx(ChevronsUpDown, { className: "h-3.5 w-3.5 opacity-50" }) })
|
|
321
|
+
] })
|
|
322
|
+
},
|
|
323
|
+
header.id
|
|
324
|
+
);
|
|
325
|
+
}) }, headerGroup.id)) }),
|
|
326
|
+
/* @__PURE__ */ jsx(TableBody, { className: classNames?.body, children: loading ? /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(
|
|
327
|
+
TableCell,
|
|
328
|
+
{
|
|
329
|
+
colSpan: columnCount,
|
|
330
|
+
className: cn(
|
|
331
|
+
"h-24 text-center text-muted-foreground",
|
|
332
|
+
classNames?.loading
|
|
333
|
+
),
|
|
334
|
+
children: loadingMessage
|
|
335
|
+
}
|
|
336
|
+
) }) : rows.length === 0 ? /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(
|
|
337
|
+
TableCell,
|
|
338
|
+
{
|
|
339
|
+
colSpan: columnCount,
|
|
340
|
+
className: cn(
|
|
341
|
+
"h-24 text-center text-muted-foreground",
|
|
342
|
+
classNames?.empty
|
|
343
|
+
),
|
|
344
|
+
children: emptyMessage
|
|
345
|
+
}
|
|
346
|
+
) }) : rows.map((row) => /* @__PURE__ */ jsx(
|
|
347
|
+
TableRow,
|
|
348
|
+
{
|
|
349
|
+
className: cn(
|
|
350
|
+
onRowClick && "cursor-pointer",
|
|
351
|
+
classNames?.row
|
|
352
|
+
),
|
|
353
|
+
onClick: onRowClick ? () => onRowClick(row.original) : void 0,
|
|
354
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, { className: classNames?.cell, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
355
|
+
},
|
|
356
|
+
row.id
|
|
357
|
+
)) })
|
|
358
|
+
] }) });
|
|
359
|
+
}
|
|
360
|
+
var buttonVariants = cva(
|
|
361
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
362
|
+
{
|
|
363
|
+
variants: {
|
|
364
|
+
variant: {
|
|
365
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
366
|
+
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
367
|
+
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
368
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
369
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
370
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
371
|
+
},
|
|
372
|
+
size: {
|
|
373
|
+
default: "h-10 px-4 py-2",
|
|
374
|
+
sm: "h-9 rounded-md px-3",
|
|
375
|
+
lg: "h-11 rounded-md px-8",
|
|
376
|
+
icon: "h-10 w-10"
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
defaultVariants: {
|
|
380
|
+
variant: "default",
|
|
381
|
+
size: "default"
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
var Button = forwardRef(
|
|
386
|
+
({ className, variant, size, type = "button", ...props }, ref) => /* @__PURE__ */ jsx(
|
|
387
|
+
"button",
|
|
388
|
+
{
|
|
389
|
+
ref,
|
|
390
|
+
type,
|
|
391
|
+
className: cn(buttonVariants({ variant, size }), className),
|
|
392
|
+
...props
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
);
|
|
396
|
+
Button.displayName = "Button";
|
|
397
|
+
var Input = forwardRef(
|
|
398
|
+
({ className, type = "text", ...props }, ref) => /* @__PURE__ */ jsx(
|
|
399
|
+
"input",
|
|
400
|
+
{
|
|
401
|
+
ref,
|
|
402
|
+
type,
|
|
403
|
+
className: cn(
|
|
404
|
+
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
405
|
+
className
|
|
406
|
+
),
|
|
407
|
+
...props
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
);
|
|
411
|
+
Input.displayName = "Input";
|
|
412
|
+
var DEFAULT_DEBOUNCE_MS = 300;
|
|
413
|
+
function DataTableSearch(props) {
|
|
414
|
+
const {
|
|
415
|
+
table,
|
|
416
|
+
debounce = true,
|
|
417
|
+
placeholder = "Search...",
|
|
418
|
+
submitLabel,
|
|
419
|
+
className,
|
|
420
|
+
inputClassName,
|
|
421
|
+
buttonClassName,
|
|
422
|
+
inputProps,
|
|
423
|
+
onSearch,
|
|
424
|
+
render
|
|
425
|
+
} = props;
|
|
426
|
+
const isDebounced = debounce !== false;
|
|
427
|
+
const debounceMs = typeof debounce === "number" ? debounce : DEFAULT_DEBOUNCE_MS;
|
|
428
|
+
const appliedValue = table.getState().globalFilter ?? "";
|
|
429
|
+
const [value, setValue] = useState(appliedValue);
|
|
430
|
+
const debounced = useDebouncedValue(value, debounceMs);
|
|
431
|
+
const commit = (next) => {
|
|
432
|
+
if (next === appliedValue) return;
|
|
433
|
+
table.setGlobalFilter(next);
|
|
434
|
+
onSearch?.(next);
|
|
435
|
+
};
|
|
436
|
+
useEffect(() => {
|
|
437
|
+
if (!isDebounced) return;
|
|
438
|
+
commit(debounced);
|
|
439
|
+
}, [debounced, isDebounced, table]);
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
setValue(appliedValue);
|
|
442
|
+
}, [appliedValue]);
|
|
443
|
+
const submit = () => commit(value);
|
|
444
|
+
if (render) {
|
|
445
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({ value, setValue, submit, appliedValue }) });
|
|
446
|
+
}
|
|
447
|
+
const handleFormSubmit = (e) => {
|
|
448
|
+
e.preventDefault();
|
|
449
|
+
submit();
|
|
450
|
+
};
|
|
451
|
+
if (isDebounced) {
|
|
452
|
+
return /* @__PURE__ */ jsx(
|
|
453
|
+
Input,
|
|
454
|
+
{
|
|
455
|
+
type: "search",
|
|
456
|
+
value,
|
|
457
|
+
onChange: (e) => setValue(e.target.value),
|
|
458
|
+
placeholder,
|
|
459
|
+
className: cn(className, inputClassName),
|
|
460
|
+
...inputProps
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
return /* @__PURE__ */ jsxs(
|
|
465
|
+
"form",
|
|
466
|
+
{
|
|
467
|
+
onSubmit: handleFormSubmit,
|
|
468
|
+
className: cn("flex w-full max-w-md items-center gap-2", className),
|
|
469
|
+
children: [
|
|
470
|
+
/* @__PURE__ */ jsx(
|
|
471
|
+
Input,
|
|
472
|
+
{
|
|
473
|
+
type: "search",
|
|
474
|
+
value,
|
|
475
|
+
onChange: (e) => setValue(e.target.value),
|
|
476
|
+
placeholder,
|
|
477
|
+
className: inputClassName,
|
|
478
|
+
...inputProps
|
|
479
|
+
}
|
|
480
|
+
),
|
|
481
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", className: buttonClassName, children: submitLabel ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
482
|
+
/* @__PURE__ */ jsx(Search, { className: "h-4 w-4", "aria-hidden": "true" }),
|
|
483
|
+
/* @__PURE__ */ jsx("span", { children: "Search" })
|
|
484
|
+
] }) })
|
|
485
|
+
]
|
|
486
|
+
}
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
var Select = forwardRef(
|
|
490
|
+
({ className, multiple, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
491
|
+
"select",
|
|
492
|
+
{
|
|
493
|
+
ref,
|
|
494
|
+
multiple,
|
|
495
|
+
className: cn(
|
|
496
|
+
"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
497
|
+
multiple ? "min-h-[6rem]" : "h-10",
|
|
498
|
+
className
|
|
499
|
+
),
|
|
500
|
+
...props
|
|
501
|
+
}
|
|
502
|
+
)
|
|
503
|
+
);
|
|
504
|
+
Select.displayName = "Select";
|
|
505
|
+
var DEFAULT_PAGE_SIZES = [10, 25, 50, 100];
|
|
506
|
+
function DataTablePagination(props) {
|
|
507
|
+
const {
|
|
508
|
+
table,
|
|
509
|
+
meta = null,
|
|
510
|
+
showPageSize = false,
|
|
511
|
+
pageSizeOptions = DEFAULT_PAGE_SIZES,
|
|
512
|
+
showFirstLast = false,
|
|
513
|
+
hideSummary = false,
|
|
514
|
+
labels,
|
|
515
|
+
className,
|
|
516
|
+
classNames,
|
|
517
|
+
buttonProps,
|
|
518
|
+
selectProps,
|
|
519
|
+
render
|
|
520
|
+
} = props;
|
|
521
|
+
const state = table.getState().pagination;
|
|
522
|
+
const pageIndex = state.pageIndex;
|
|
523
|
+
const pageSize = state.pageSize;
|
|
524
|
+
const pageCount = table.getPageCount();
|
|
525
|
+
const canPreviousPage = table.getCanPreviousPage();
|
|
526
|
+
const canNextPage = table.getCanNextPage();
|
|
527
|
+
const goToFirst = () => table.setPageIndex(0);
|
|
528
|
+
const goToPrevious = () => table.previousPage();
|
|
529
|
+
const goToNext = () => table.nextPage();
|
|
530
|
+
const goToLast = () => table.setPageIndex(Math.max(0, pageCount - 1));
|
|
531
|
+
const setPageSize = (size) => table.setPageSize(size);
|
|
532
|
+
if (render) {
|
|
533
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
534
|
+
table,
|
|
535
|
+
meta,
|
|
536
|
+
pageIndex,
|
|
537
|
+
pageCount,
|
|
538
|
+
pageSize,
|
|
539
|
+
canPreviousPage,
|
|
540
|
+
canNextPage,
|
|
541
|
+
goToFirst,
|
|
542
|
+
goToPrevious,
|
|
543
|
+
goToNext,
|
|
544
|
+
goToLast,
|
|
545
|
+
setPageSize
|
|
546
|
+
}) });
|
|
547
|
+
}
|
|
548
|
+
const filtered = meta?.filtered ?? 0;
|
|
549
|
+
const total = meta?.total ?? null;
|
|
550
|
+
const summaryNode = labels?.summary ? labels.summary({ pageIndex, pageCount, pageSize, filtered, total }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
551
|
+
labels?.page ?? "Page",
|
|
552
|
+
" ",
|
|
553
|
+
pageIndex + 1,
|
|
554
|
+
" ",
|
|
555
|
+
labels?.of ?? "of",
|
|
556
|
+
" ",
|
|
557
|
+
Math.max(1, pageCount),
|
|
558
|
+
meta ? ` \xB7 ${filtered} rows` : null
|
|
559
|
+
] });
|
|
560
|
+
return /* @__PURE__ */ jsxs(
|
|
561
|
+
"div",
|
|
562
|
+
{
|
|
563
|
+
className: cn(
|
|
564
|
+
"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
|
|
565
|
+
className,
|
|
566
|
+
classNames?.root
|
|
567
|
+
),
|
|
568
|
+
children: [
|
|
569
|
+
!hideSummary && /* @__PURE__ */ jsx(
|
|
570
|
+
"div",
|
|
571
|
+
{
|
|
572
|
+
className: cn(
|
|
573
|
+
"text-sm text-muted-foreground",
|
|
574
|
+
classNames?.info
|
|
575
|
+
),
|
|
576
|
+
children: summaryNode
|
|
577
|
+
}
|
|
578
|
+
),
|
|
579
|
+
/* @__PURE__ */ jsxs(
|
|
580
|
+
"div",
|
|
581
|
+
{
|
|
582
|
+
className: cn(
|
|
583
|
+
"flex items-center gap-2",
|
|
584
|
+
classNames?.controls
|
|
585
|
+
),
|
|
586
|
+
children: [
|
|
587
|
+
showPageSize && /* @__PURE__ */ jsxs(
|
|
588
|
+
"label",
|
|
589
|
+
{
|
|
590
|
+
className: cn(
|
|
591
|
+
"flex items-center gap-2 text-sm text-muted-foreground",
|
|
592
|
+
classNames?.pageSize
|
|
593
|
+
),
|
|
594
|
+
children: [
|
|
595
|
+
/* @__PURE__ */ jsx("span", { children: labels?.rowsPerPage ?? "Rows per page:" }),
|
|
596
|
+
/* @__PURE__ */ jsx(
|
|
597
|
+
Select,
|
|
598
|
+
{
|
|
599
|
+
value: pageSize,
|
|
600
|
+
onChange: (e) => setPageSize(Number(e.target.value)),
|
|
601
|
+
className: cn("h-9 w-[5rem]", classNames?.select),
|
|
602
|
+
...selectProps,
|
|
603
|
+
children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx("option", { value: size, children: size }, size))
|
|
604
|
+
}
|
|
605
|
+
)
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
),
|
|
609
|
+
showFirstLast && /* @__PURE__ */ jsx(
|
|
610
|
+
Button,
|
|
611
|
+
{
|
|
612
|
+
variant: "outline",
|
|
613
|
+
size: "icon",
|
|
614
|
+
onClick: goToFirst,
|
|
615
|
+
disabled: !canPreviousPage,
|
|
616
|
+
className: classNames?.button,
|
|
617
|
+
"aria-label": "Go to first page",
|
|
618
|
+
...buttonProps,
|
|
619
|
+
children: labels?.first ?? /* @__PURE__ */ jsx(ChevronsLeft, { className: "h-4 w-4" })
|
|
620
|
+
}
|
|
621
|
+
),
|
|
622
|
+
/* @__PURE__ */ jsx(
|
|
623
|
+
Button,
|
|
624
|
+
{
|
|
625
|
+
variant: "outline",
|
|
626
|
+
onClick: goToPrevious,
|
|
627
|
+
disabled: !canPreviousPage,
|
|
628
|
+
className: classNames?.button,
|
|
629
|
+
"aria-label": "Go to previous page",
|
|
630
|
+
...buttonProps,
|
|
631
|
+
children: labels?.previous ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
632
|
+
/* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" }),
|
|
633
|
+
/* @__PURE__ */ jsx("span", { children: "Previous" })
|
|
634
|
+
] })
|
|
635
|
+
}
|
|
636
|
+
),
|
|
637
|
+
/* @__PURE__ */ jsx(
|
|
638
|
+
Button,
|
|
639
|
+
{
|
|
640
|
+
variant: "outline",
|
|
641
|
+
onClick: goToNext,
|
|
642
|
+
disabled: !canNextPage,
|
|
643
|
+
className: classNames?.button,
|
|
644
|
+
"aria-label": "Go to next page",
|
|
645
|
+
...buttonProps,
|
|
646
|
+
children: labels?.next ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
647
|
+
/* @__PURE__ */ jsx("span", { children: "Next" }),
|
|
648
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" })
|
|
649
|
+
] })
|
|
650
|
+
}
|
|
651
|
+
),
|
|
652
|
+
showFirstLast && /* @__PURE__ */ jsx(
|
|
653
|
+
Button,
|
|
654
|
+
{
|
|
655
|
+
variant: "outline",
|
|
656
|
+
size: "icon",
|
|
657
|
+
onClick: goToLast,
|
|
658
|
+
disabled: !canNextPage,
|
|
659
|
+
className: classNames?.button,
|
|
660
|
+
"aria-label": "Go to last page",
|
|
661
|
+
...buttonProps,
|
|
662
|
+
children: labels?.last ?? /* @__PURE__ */ jsx(ChevronsRight, { className: "h-4 w-4" })
|
|
663
|
+
}
|
|
664
|
+
)
|
|
665
|
+
]
|
|
666
|
+
}
|
|
667
|
+
)
|
|
668
|
+
]
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
function DataTableFilter(props) {
|
|
673
|
+
const { table, columnId, className, render } = props;
|
|
674
|
+
const column = table.getColumn(columnId);
|
|
675
|
+
if (!column) {
|
|
676
|
+
if (typeof console !== "undefined") {
|
|
677
|
+
console.warn(
|
|
678
|
+
`[DataTableFilter] Column "${columnId}" not found on table. Make sure a column with this id exists.`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
const value = column.getFilterValue();
|
|
684
|
+
const setValue = (next) => {
|
|
685
|
+
if (next === void 0 || next === "" || Array.isArray(next) && next.length === 0) {
|
|
686
|
+
column.setFilterValue(void 0);
|
|
687
|
+
} else {
|
|
688
|
+
column.setFilterValue(next);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
if (render) {
|
|
692
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({ value, setValue, column, table }) });
|
|
693
|
+
}
|
|
694
|
+
if (props.type === "multiselect") {
|
|
695
|
+
const arrayValue = Array.isArray(value) ? value : value ? [String(value)] : [];
|
|
696
|
+
return /* @__PURE__ */ jsx(
|
|
697
|
+
Select,
|
|
698
|
+
{
|
|
699
|
+
multiple: true,
|
|
700
|
+
value: arrayValue,
|
|
701
|
+
onChange: (e) => {
|
|
702
|
+
const selected = Array.from(e.target.selectedOptions).map((o) => o.value);
|
|
703
|
+
setValue(selected);
|
|
704
|
+
},
|
|
705
|
+
className: cn("w-auto min-w-[10rem]", className),
|
|
706
|
+
...props.selectProps,
|
|
707
|
+
children: props.options.map((opt) => /* @__PURE__ */ jsx("option", { value: opt.value, children: opt.label }, opt.value))
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
if (props.type === "input") {
|
|
712
|
+
return /* @__PURE__ */ jsx(
|
|
713
|
+
Input,
|
|
714
|
+
{
|
|
715
|
+
type: "text",
|
|
716
|
+
value: typeof value === "string" ? value : "",
|
|
717
|
+
onChange: (e) => setValue(e.target.value),
|
|
718
|
+
placeholder: props.placeholder,
|
|
719
|
+
className: cn("w-auto min-w-[10rem]", className),
|
|
720
|
+
...props.inputProps
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
if ("options" in props && props.options) {
|
|
725
|
+
const includeEmpty = props.includeEmptyOption ?? true;
|
|
726
|
+
return /* @__PURE__ */ jsxs(
|
|
727
|
+
Select,
|
|
728
|
+
{
|
|
729
|
+
value: typeof value === "string" ? value : "",
|
|
730
|
+
onChange: (e) => setValue(e.target.value),
|
|
731
|
+
className: cn("w-auto min-w-[10rem]", className),
|
|
732
|
+
...props.selectProps,
|
|
733
|
+
children: [
|
|
734
|
+
includeEmpty && /* @__PURE__ */ jsx("option", { value: "", children: props.placeholder ?? "All" }),
|
|
735
|
+
props.options.map((opt) => /* @__PURE__ */ jsx("option", { value: opt.value, children: opt.label }, opt.value))
|
|
736
|
+
]
|
|
737
|
+
}
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
if (typeof console !== "undefined") {
|
|
741
|
+
console.warn(
|
|
742
|
+
`[DataTableFilter] No "options" or "render" prop provided for column "${columnId}". Nothing will render.`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
function DataTableSplitLayout(props) {
|
|
748
|
+
const {
|
|
749
|
+
table,
|
|
750
|
+
meta = null,
|
|
751
|
+
loading = false,
|
|
752
|
+
filters,
|
|
753
|
+
actions,
|
|
754
|
+
search,
|
|
755
|
+
searchProps,
|
|
756
|
+
tableProps,
|
|
757
|
+
paginationProps,
|
|
758
|
+
className,
|
|
759
|
+
classNames
|
|
760
|
+
} = props;
|
|
761
|
+
const searchNode = search ?? /* @__PURE__ */ jsx(
|
|
762
|
+
DataTableSearch,
|
|
763
|
+
{
|
|
764
|
+
table,
|
|
765
|
+
placeholder: "Search...",
|
|
766
|
+
className: "w-full max-w-md",
|
|
767
|
+
...searchProps
|
|
768
|
+
}
|
|
769
|
+
);
|
|
770
|
+
return /* @__PURE__ */ jsxs(
|
|
771
|
+
"div",
|
|
772
|
+
{
|
|
773
|
+
className: cn(
|
|
774
|
+
"flex flex-col gap-4",
|
|
775
|
+
className,
|
|
776
|
+
classNames?.root
|
|
777
|
+
),
|
|
778
|
+
children: [
|
|
779
|
+
/* @__PURE__ */ jsxs(
|
|
780
|
+
"div",
|
|
781
|
+
{
|
|
782
|
+
className: cn(
|
|
783
|
+
"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
|
|
784
|
+
classNames?.toolbar
|
|
785
|
+
),
|
|
786
|
+
children: [
|
|
787
|
+
/* @__PURE__ */ jsx(
|
|
788
|
+
"div",
|
|
789
|
+
{
|
|
790
|
+
className: cn(
|
|
791
|
+
"flex-1 min-w-0",
|
|
792
|
+
classNames?.toolbarLeft
|
|
793
|
+
),
|
|
794
|
+
children: searchNode
|
|
795
|
+
}
|
|
796
|
+
),
|
|
797
|
+
(filters || actions) && /* @__PURE__ */ jsxs(
|
|
798
|
+
"div",
|
|
799
|
+
{
|
|
800
|
+
className: cn(
|
|
801
|
+
"flex flex-wrap items-center gap-2",
|
|
802
|
+
classNames?.toolbarRight
|
|
803
|
+
),
|
|
804
|
+
children: [
|
|
805
|
+
filters,
|
|
806
|
+
actions
|
|
807
|
+
]
|
|
808
|
+
}
|
|
809
|
+
)
|
|
810
|
+
]
|
|
811
|
+
}
|
|
812
|
+
),
|
|
813
|
+
/* @__PURE__ */ jsx("div", { className: classNames?.body, children: /* @__PURE__ */ jsx(DataTable, { table, loading, ...tableProps }) }),
|
|
814
|
+
/* @__PURE__ */ jsx("div", { className: classNames?.footer, children: /* @__PURE__ */ jsx(
|
|
815
|
+
DataTablePagination,
|
|
816
|
+
{
|
|
817
|
+
table,
|
|
818
|
+
meta,
|
|
819
|
+
...paginationProps
|
|
820
|
+
}
|
|
821
|
+
) })
|
|
822
|
+
]
|
|
823
|
+
}
|
|
824
|
+
);
|
|
825
|
+
}
|
|
206
826
|
|
|
207
|
-
export { DataTableError, buildQueryString, defaultFetcher, useDataTable, useDebouncedValue };
|
|
827
|
+
export { Button, DataTable, DataTableError, DataTableFilter, DataTablePagination, DataTableSearch, DataTableSplitLayout, Input, Select, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, buildQueryString, buttonVariants, cn, defaultFetcher, useDataTable, useDebouncedValue };
|
|
208
828
|
//# sourceMappingURL=index.js.map
|
|
209
829
|
//# sourceMappingURL=index.js.map
|