@jinaan/uikit 0.1.40 → 0.1.42
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/data-table.d.ts +3 -1
- package/dist/data-table.d.ts.map +1 -1
- package/dist/index.js +462 -452
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data-table.tsx +90 -74
package/package.json
CHANGED
package/src/data-table.tsx
CHANGED
|
@@ -125,6 +125,8 @@ interface DataTableProps<T> {
|
|
|
125
125
|
filters?: DataTableFilter<T>[];
|
|
126
126
|
toolbarStart?: ReactNode;
|
|
127
127
|
toolbarEnd?: ReactNode;
|
|
128
|
+
/** Show the "Columns" visibility/reorder picker in the toolbar. Default true. */
|
|
129
|
+
columnPicker?: boolean;
|
|
128
130
|
|
|
129
131
|
tabs?: TabDef[];
|
|
130
132
|
activeTab?: string;
|
|
@@ -211,6 +213,7 @@ export function DataTable<T>({
|
|
|
211
213
|
filters,
|
|
212
214
|
toolbarStart,
|
|
213
215
|
toolbarEnd,
|
|
216
|
+
columnPicker = true,
|
|
214
217
|
tabs,
|
|
215
218
|
activeTab,
|
|
216
219
|
onTabChange,
|
|
@@ -484,84 +487,86 @@ export function DataTable<T>({
|
|
|
484
487
|
/>
|
|
485
488
|
)}
|
|
486
489
|
{toolbarStart}
|
|
487
|
-
|
|
488
|
-
<
|
|
489
|
-
<
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
key={c.id}
|
|
505
|
-
checked
|
|
506
|
-
draggable={!pinned}
|
|
507
|
-
onDragStart={(e) => {
|
|
508
|
-
if (pinned) {
|
|
509
|
-
e.preventDefault();
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
e.dataTransfer.effectAllowed = "move";
|
|
513
|
-
e.dataTransfer.setData("text/plain", c.id);
|
|
514
|
-
setDragId(c.id);
|
|
515
|
-
}}
|
|
516
|
-
onDragOver={(e) => {
|
|
517
|
-
if (dragId) {
|
|
518
|
-
e.preventDefault();
|
|
519
|
-
moveBefore(dragId, c.id);
|
|
520
|
-
}
|
|
521
|
-
}}
|
|
522
|
-
onDrop={(e) => e.preventDefault()}
|
|
523
|
-
onDragEnd={() => setDragId(null)}
|
|
524
|
-
onCheckedChange={(next) => {
|
|
525
|
-
if (!next && !pinned) {
|
|
526
|
-
setHidden((prev) => ({ ...prev, [c.id]: true }));
|
|
527
|
-
}
|
|
528
|
-
}}
|
|
529
|
-
onSelect={(e) => e.preventDefault()}
|
|
530
|
-
className="justify-between"
|
|
531
|
-
>
|
|
532
|
-
<span className="truncate">{c.header}</span>
|
|
533
|
-
{pinned ? (
|
|
534
|
-
<Lock className="size-3.5 shrink-0 text-subtle" aria-hidden />
|
|
535
|
-
) : (
|
|
536
|
-
<DotsSixVertical
|
|
537
|
-
aria-hidden
|
|
538
|
-
className={cn(
|
|
539
|
-
"size-3.5 shrink-0",
|
|
540
|
-
dragId === c.id ? "text-primary" : "text-subtle",
|
|
541
|
-
)}
|
|
542
|
-
/>
|
|
543
|
-
)}
|
|
544
|
-
</DropdownMenuCheckboxItem>
|
|
545
|
-
);
|
|
546
|
-
})}
|
|
547
|
-
{hiddenColumns.length > 0 ? (
|
|
548
|
-
<>
|
|
549
|
-
<DropdownMenuSeparator />
|
|
550
|
-
<DropdownMenuLabel className="text-[13px]">Available columns</DropdownMenuLabel>
|
|
551
|
-
{hiddenColumns.map((c) => (
|
|
490
|
+
{columnPicker && (
|
|
491
|
+
<DropdownMenu>
|
|
492
|
+
<DropdownMenuTrigger asChild>
|
|
493
|
+
<Button
|
|
494
|
+
variant="secondary"
|
|
495
|
+
size="md"
|
|
496
|
+
leadingIcon={<ColumnsIcon />}
|
|
497
|
+
trailingIcon={<DropdownMenuChevron />}
|
|
498
|
+
>
|
|
499
|
+
Columns
|
|
500
|
+
</Button>
|
|
501
|
+
</DropdownMenuTrigger>
|
|
502
|
+
<DropdownMenuContent align="end" className="w-54">
|
|
503
|
+
<DropdownMenuLabel className="text-[13px]">Active columns</DropdownMenuLabel>
|
|
504
|
+
{visibleColumns.map((c) => {
|
|
505
|
+
const pinned = isPinned(c);
|
|
506
|
+
return (
|
|
552
507
|
<DropdownMenuCheckboxItem
|
|
553
508
|
key={c.id}
|
|
554
|
-
checked
|
|
555
|
-
|
|
509
|
+
checked
|
|
510
|
+
draggable={!pinned}
|
|
511
|
+
onDragStart={(e) => {
|
|
512
|
+
if (pinned) {
|
|
513
|
+
e.preventDefault();
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
e.dataTransfer.effectAllowed = "move";
|
|
517
|
+
e.dataTransfer.setData("text/plain", c.id);
|
|
518
|
+
setDragId(c.id);
|
|
519
|
+
}}
|
|
520
|
+
onDragOver={(e) => {
|
|
521
|
+
if (dragId) {
|
|
522
|
+
e.preventDefault();
|
|
523
|
+
moveBefore(dragId, c.id);
|
|
524
|
+
}
|
|
525
|
+
}}
|
|
526
|
+
onDrop={(e) => e.preventDefault()}
|
|
527
|
+
onDragEnd={() => setDragId(null)}
|
|
528
|
+
onCheckedChange={(next) => {
|
|
529
|
+
if (!next && !pinned) {
|
|
530
|
+
setHidden((prev) => ({ ...prev, [c.id]: true }));
|
|
531
|
+
}
|
|
532
|
+
}}
|
|
556
533
|
onSelect={(e) => e.preventDefault()}
|
|
534
|
+
className="justify-between"
|
|
557
535
|
>
|
|
558
|
-
{c.header}
|
|
536
|
+
<span className="truncate">{c.header}</span>
|
|
537
|
+
{pinned ? (
|
|
538
|
+
<Lock className="size-3.5 shrink-0 text-subtle" aria-hidden />
|
|
539
|
+
) : (
|
|
540
|
+
<DotsSixVertical
|
|
541
|
+
aria-hidden
|
|
542
|
+
className={cn(
|
|
543
|
+
"size-3.5 shrink-0",
|
|
544
|
+
dragId === c.id ? "text-primary" : "text-subtle",
|
|
545
|
+
)}
|
|
546
|
+
/>
|
|
547
|
+
)}
|
|
559
548
|
</DropdownMenuCheckboxItem>
|
|
560
|
-
)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
549
|
+
);
|
|
550
|
+
})}
|
|
551
|
+
{hiddenColumns.length > 0 ? (
|
|
552
|
+
<>
|
|
553
|
+
<DropdownMenuSeparator />
|
|
554
|
+
<DropdownMenuLabel className="text-[13px]">Available columns</DropdownMenuLabel>
|
|
555
|
+
{hiddenColumns.map((c) => (
|
|
556
|
+
<DropdownMenuCheckboxItem
|
|
557
|
+
key={c.id}
|
|
558
|
+
checked={false}
|
|
559
|
+
onCheckedChange={() => showColumn(c.id)}
|
|
560
|
+
onSelect={(e) => e.preventDefault()}
|
|
561
|
+
>
|
|
562
|
+
{c.header}
|
|
563
|
+
</DropdownMenuCheckboxItem>
|
|
564
|
+
))}
|
|
565
|
+
</>
|
|
566
|
+
) : null}
|
|
567
|
+
</DropdownMenuContent>
|
|
568
|
+
</DropdownMenu>
|
|
569
|
+
)}
|
|
565
570
|
{filters && filters.length > 0 ? (
|
|
566
571
|
<DropdownMenu>
|
|
567
572
|
<DropdownMenuTrigger asChild>
|
|
@@ -894,7 +899,18 @@ export function DataTable<T>({
|
|
|
894
899
|
</TableCell>
|
|
895
900
|
))}
|
|
896
901
|
{rowActions && (
|
|
897
|
-
<TableCell
|
|
902
|
+
<TableCell
|
|
903
|
+
className="w-44 px-4 text-right"
|
|
904
|
+
onClick={(e) => {
|
|
905
|
+
// Dead-zone fix: only swallow clicks on the
|
|
906
|
+
// action controls themselves (menus, buttons);
|
|
907
|
+
// the cell's padding stays part of the clickable
|
|
908
|
+
// row.
|
|
909
|
+
if ((e.target as HTMLElement).closest("button, a, input, [role='menuitem']")) {
|
|
910
|
+
e.stopPropagation();
|
|
911
|
+
}
|
|
912
|
+
}}
|
|
913
|
+
>
|
|
898
914
|
{rowActions(row)}
|
|
899
915
|
</TableCell>
|
|
900
916
|
)}
|