@designa8/vibedesign-attio-internal-v1-2-176b 0.1.2 → 0.1.3
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 +1 -1
- package/dist/index.cjs +147 -56
- package/dist/index.js +161 -70
- package/package.json +1 -1
- package/src/atoms/DataTable/DataTable.tsx +27 -3
- package/src/atoms/DataTable/preview.tsx +68 -2
- package/src/atoms/DataTableDesktop/DataTableDesktop.tsx +56 -18
- package/src/atoms/DataTableMobile/DataTableMobile.tsx +117 -45
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @designa8/vibedesign-attio-internal-v1-2-176b
|
|
2
2
|
|
|
3
|
-
Complete design system generated by Atoms Design, version **0.1.
|
|
3
|
+
Complete design system generated by Atoms Design, version **0.1.3**.
|
|
4
4
|
Tokens, atoms, molecules, organisms, and templates — import from the package root;
|
|
5
5
|
never hardcode visual values in consumer code.
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -3245,6 +3245,7 @@ function DataTableDesktopInner({
|
|
|
3245
3245
|
views,
|
|
3246
3246
|
view,
|
|
3247
3247
|
onViewChange,
|
|
3248
|
+
toolbarStart,
|
|
3248
3249
|
filters = [],
|
|
3249
3250
|
onRemoveFilter,
|
|
3250
3251
|
onClearFilters,
|
|
@@ -3254,7 +3255,11 @@ function DataTableDesktopInner({
|
|
|
3254
3255
|
onSortChange,
|
|
3255
3256
|
selectedIds,
|
|
3256
3257
|
onSelectionChange,
|
|
3258
|
+
onRowClick,
|
|
3259
|
+
countLabel = (count) => `${count} records`,
|
|
3257
3260
|
pageSize = 10,
|
|
3261
|
+
page: pageProp,
|
|
3262
|
+
onPageChange,
|
|
3258
3263
|
emptyTitle = "No companies yet",
|
|
3259
3264
|
emptyDescription = "Import companies to get started.",
|
|
3260
3265
|
importLabel = "Import companies",
|
|
@@ -3275,14 +3280,19 @@ function DataTableDesktopInner({
|
|
|
3275
3280
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3276
3281
|
onSelectionChange?.(ids);
|
|
3277
3282
|
};
|
|
3278
|
-
const [
|
|
3283
|
+
const [innerPage, setInnerPage] = React33.useState(1);
|
|
3284
|
+
const page = pageProp ?? innerPage;
|
|
3285
|
+
const setPage = (next) => {
|
|
3286
|
+
if (pageProp === void 0) setInnerPage(next);
|
|
3287
|
+
onPageChange?.(next);
|
|
3288
|
+
};
|
|
3279
3289
|
const sorted = React33.useMemo(() => {
|
|
3280
3290
|
if (!sort) return rows;
|
|
3281
3291
|
const out = [...rows].sort((a, b) => compare(a[sort.key], b[sort.key]));
|
|
3282
3292
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
3283
3293
|
}, [rows, sort]);
|
|
3284
3294
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3285
|
-
const safePage = Math.min(page, pageCount);
|
|
3295
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
3286
3296
|
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3287
3297
|
const allIds = rows.map((r) => r.id);
|
|
3288
3298
|
const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
|
|
@@ -3296,7 +3306,8 @@ function DataTableDesktopInner({
|
|
|
3296
3306
|
...rest,
|
|
3297
3307
|
children: [
|
|
3298
3308
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex items-center gap-sm border-b border-hairline px-base py-sm", children: [
|
|
3299
|
-
|
|
3309
|
+
toolbarStart ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "min-w-0 flex-1", children: toolbarStart }) : null,
|
|
3310
|
+
views && views.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: cn31("min-w-0", toolbarStart ? "w-2/5 shrink-0" : "w-2/5"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
3300
3311
|
Dropdown,
|
|
3301
3312
|
{
|
|
3302
3313
|
"aria-label": "View",
|
|
@@ -3306,7 +3317,7 @@ function DataTableDesktopInner({
|
|
|
3306
3317
|
onValueChange: onViewChange
|
|
3307
3318
|
}
|
|
3308
3319
|
) }) : null,
|
|
3309
|
-
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "ml-auto flex items-center gap-xs", children: [
|
|
3320
|
+
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "ml-auto flex shrink-0 items-center gap-xs", children: [
|
|
3310
3321
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("span", { className: "relative inline-flex", children: [
|
|
3311
3322
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
3312
3323
|
IconButton,
|
|
@@ -3376,24 +3387,38 @@ function DataTableDesktopInner({
|
|
|
3376
3387
|
c.key
|
|
3377
3388
|
))
|
|
3378
3389
|
] }) }),
|
|
3379
|
-
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)("tbody", { children: visible.map((row) =>
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3390
|
+
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)("tbody", { children: visible.map((row) => {
|
|
3391
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
3392
|
+
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
|
3393
|
+
TableRow,
|
|
3394
|
+
{
|
|
3395
|
+
selectable: true,
|
|
3396
|
+
selected: selected.includes(row.id),
|
|
3397
|
+
onSelectedChange: (v) => setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id)),
|
|
3398
|
+
rowLabel,
|
|
3399
|
+
align: columns.map((c) => c.align),
|
|
3400
|
+
cells: columns.map((c) => c.render ? c.render(row) : row[c.key]),
|
|
3401
|
+
...onRowClick ? {
|
|
3402
|
+
onClick: () => onRowClick(row),
|
|
3403
|
+
tabIndex: 0,
|
|
3404
|
+
"aria-label": `Open ${rowLabel}`,
|
|
3405
|
+
onKeyDown: (event) => {
|
|
3406
|
+
if (event.key === "Enter") {
|
|
3407
|
+
event.preventDefault();
|
|
3408
|
+
onRowClick(row);
|
|
3409
|
+
}
|
|
3410
|
+
},
|
|
3411
|
+
className: "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue"
|
|
3412
|
+
} : {}
|
|
3413
|
+
},
|
|
3414
|
+
row.id
|
|
3415
|
+
);
|
|
3416
|
+
}) })
|
|
3391
3417
|
] }) }),
|
|
3392
3418
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: "flex items-center gap-base border-t border-hairline px-base py-sm", children: [
|
|
3393
3419
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("span", { className: "shrink-0 whitespace-nowrap text-body-sm text-muted", children: [
|
|
3394
3420
|
selected.length > 0 ? `${selected.length} selected \xB7 ` : "",
|
|
3395
|
-
rows.length
|
|
3396
|
-
" count"
|
|
3421
|
+
countLabel(rows.length)
|
|
3397
3422
|
] }),
|
|
3398
3423
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: "ml-auto flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Pagination, { pageCount, page: safePage, onPageChange: setPage, size: "sm" }) })
|
|
3399
3424
|
] })
|
|
@@ -3417,12 +3442,19 @@ function DataTableMobileInner({
|
|
|
3417
3442
|
columns,
|
|
3418
3443
|
rows,
|
|
3419
3444
|
rowLabelKey,
|
|
3445
|
+
toolbarStart,
|
|
3420
3446
|
filters = [],
|
|
3421
3447
|
onRemoveFilter,
|
|
3422
3448
|
sort: sortProp,
|
|
3423
3449
|
onSortChange,
|
|
3424
3450
|
selectedIds,
|
|
3425
3451
|
onSelectionChange,
|
|
3452
|
+
onRowClick,
|
|
3453
|
+
mobileDescription,
|
|
3454
|
+
countLabel = (count) => `${count} records`,
|
|
3455
|
+
pageSize = 10,
|
|
3456
|
+
page: pageProp,
|
|
3457
|
+
onPageChange,
|
|
3426
3458
|
emptyTitle = "No companies yet",
|
|
3427
3459
|
emptyDescription = "Import companies to get started.",
|
|
3428
3460
|
importLabel = "Import companies",
|
|
@@ -3445,11 +3477,20 @@ function DataTableMobileInner({
|
|
|
3445
3477
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3446
3478
|
onSelectionChange?.(ids);
|
|
3447
3479
|
};
|
|
3480
|
+
const [innerPage, setInnerPage] = React34.useState(1);
|
|
3481
|
+
const page = pageProp ?? innerPage;
|
|
3482
|
+
const setPage = (next) => {
|
|
3483
|
+
if (pageProp === void 0) setInnerPage(next);
|
|
3484
|
+
onPageChange?.(next);
|
|
3485
|
+
};
|
|
3448
3486
|
const sorted = React34.useMemo(() => {
|
|
3449
3487
|
if (!sort) return rows;
|
|
3450
3488
|
const out = [...rows].sort((a, b) => compare2(a[sort.key], b[sort.key]));
|
|
3451
3489
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
3452
3490
|
}, [rows, sort]);
|
|
3491
|
+
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3492
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
3493
|
+
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3453
3494
|
const allIds = rows.map((r) => r.id);
|
|
3454
3495
|
const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
|
|
3455
3496
|
const someSelected = !allSelected && allIds.some((id) => selected.includes(id));
|
|
@@ -3461,48 +3502,79 @@ function DataTableMobileInner({
|
|
|
3461
3502
|
className: cn32("flex w-full flex-col overflow-hidden rounded-xl border border-hairline bg-surface shadow-card", className),
|
|
3462
3503
|
...rest,
|
|
3463
3504
|
children: [
|
|
3505
|
+
toolbarStart ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "flex items-center gap-sm border-b border-hairline px-md py-sm", children: toolbarStart }) : null,
|
|
3464
3506
|
filters.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "flex flex-wrap items-center gap-sm border-b border-hairline px-md py-sm", children: filters.map((f) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Chip, { size: "sm", label: f.label, icon: "funnel", onRemove: () => onRemoveFilter?.(f.id) }, f.id)) }) : null,
|
|
3465
3507
|
rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex flex-col items-center justify-center gap-sm px-base py-xl text-center", children: [
|
|
3466
3508
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Icon, { name: "database", size: 24, className: "text-muted" }),
|
|
3467
3509
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("p", { className: "m-0 text-label-md text-ink", children: emptyTitle }),
|
|
3468
3510
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("p", { className: "m-0 text-body-sm text-muted", children: emptyDescription }),
|
|
3469
3511
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Button, { variant: "secondary", size: "lg", onClick: onImport, leadingIcon: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Icon, { name: "download", size: 16 }), children: importLabel })
|
|
3470
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime34.
|
|
3471
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("
|
|
3472
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3512
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
|
3513
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "w-full overflow-x-auto", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("table", { className: "w-full border-collapse", "aria-label": label, children: [
|
|
3514
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("tr", { children: [
|
|
3515
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("th", { scope: "col", className: "w-10 border-b border-hairline bg-surface py-0 pl-base pr-xs text-left align-middle", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3516
|
+
Checkbox,
|
|
3517
|
+
{
|
|
3518
|
+
"aria-label": allSelected ? "Deselect all rows" : "Select all rows",
|
|
3519
|
+
checked: allSelected,
|
|
3520
|
+
indeterminate: someSelected,
|
|
3521
|
+
onCheckedChange: (v) => setSelected(v ? allIds : []),
|
|
3522
|
+
className: "flex"
|
|
3523
|
+
}
|
|
3524
|
+
) }),
|
|
3525
|
+
col ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3526
|
+
TableHeaderCell,
|
|
3527
|
+
{
|
|
3528
|
+
label: col.label,
|
|
3529
|
+
icon: col.icon,
|
|
3530
|
+
className: "min-w-0",
|
|
3531
|
+
sort: sort?.key === col.key ? sort.direction : "none",
|
|
3532
|
+
onSortChange: col.sortable ? (next) => setSort(next === "none" ? null : { key: col.key, direction: next }) : void 0
|
|
3533
|
+
}
|
|
3534
|
+
) : null
|
|
3535
|
+
] }) }),
|
|
3536
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("tbody", { children: visible.map((row) => {
|
|
3537
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
3538
|
+
const content = col ? col.render ? col.render(row) : row[col.key] : null;
|
|
3539
|
+
const description = mobileDescription?.(row);
|
|
3540
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
3541
|
+
TableRow,
|
|
3542
|
+
{
|
|
3543
|
+
selectable: true,
|
|
3544
|
+
selected: selected.includes(row.id),
|
|
3545
|
+
onSelectedChange: (v) => setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id)),
|
|
3546
|
+
rowLabel,
|
|
3547
|
+
className: "[&>td]:h-11",
|
|
3548
|
+
cells: [
|
|
3549
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("span", { className: "flex min-w-0 flex-col gap-xxs", children: [
|
|
3550
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "min-w-0", children: content }),
|
|
3551
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: "min-w-0 text-body-sm text-muted", children: description })
|
|
3552
|
+
] }) : content
|
|
3553
|
+
],
|
|
3554
|
+
...onRowClick ? {
|
|
3555
|
+
onClick: () => onRowClick(row),
|
|
3556
|
+
tabIndex: 0,
|
|
3557
|
+
"aria-label": `Open ${rowLabel}`,
|
|
3558
|
+
onKeyDown: (event) => {
|
|
3559
|
+
if (event.key === "Enter") {
|
|
3560
|
+
event.preventDefault();
|
|
3561
|
+
onRowClick(row);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
} : {}
|
|
3565
|
+
},
|
|
3566
|
+
row.id
|
|
3567
|
+
);
|
|
3568
|
+
}) })
|
|
3492
3569
|
] }) }),
|
|
3493
|
-
/* @__PURE__ */ (0, import_jsx_runtime34.
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
cells: [col ? col.render ? col.render(row) : row[col.key] : null]
|
|
3502
|
-
},
|
|
3503
|
-
row.id
|
|
3504
|
-
)) })
|
|
3505
|
-
] }) })
|
|
3570
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: "flex items-center gap-base border-t border-hairline px-md py-sm", children: [
|
|
3571
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("span", { className: "shrink-0 whitespace-nowrap text-body-sm text-muted", children: [
|
|
3572
|
+
selected.length > 0 ? `${selected.length} selected \xB7 ` : "",
|
|
3573
|
+
countLabel(rows.length)
|
|
3574
|
+
] }),
|
|
3575
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: "ml-auto flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Pagination, { pageCount, page: safePage, onPageChange: setPage, size: "sm" }) })
|
|
3576
|
+
] })
|
|
3577
|
+
] })
|
|
3506
3578
|
]
|
|
3507
3579
|
}
|
|
3508
3580
|
);
|
|
@@ -3514,7 +3586,18 @@ DataTableMobile.displayName = "DataTableMobile";
|
|
|
3514
3586
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
3515
3587
|
var cn33 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3516
3588
|
var DataTable = React35.forwardRef(
|
|
3517
|
-
({
|
|
3589
|
+
({
|
|
3590
|
+
sort,
|
|
3591
|
+
onSortChange,
|
|
3592
|
+
selectedIds,
|
|
3593
|
+
onSelectionChange,
|
|
3594
|
+
page,
|
|
3595
|
+
onPageChange,
|
|
3596
|
+
mobileDescription,
|
|
3597
|
+
rootClassName,
|
|
3598
|
+
className,
|
|
3599
|
+
...rest
|
|
3600
|
+
}, ref) => {
|
|
3518
3601
|
const [innerSort, setInnerSort] = React35.useState(null);
|
|
3519
3602
|
const currentSort = sort === void 0 ? innerSort : sort;
|
|
3520
3603
|
const changeSort = (s) => {
|
|
@@ -3527,17 +3610,25 @@ var DataTable = React35.forwardRef(
|
|
|
3527
3610
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3528
3611
|
onSelectionChange?.(ids);
|
|
3529
3612
|
};
|
|
3613
|
+
const [innerPage, setInnerPage] = React35.useState(1);
|
|
3614
|
+
const currentPage = page ?? innerPage;
|
|
3615
|
+
const changePage = (next) => {
|
|
3616
|
+
if (page === void 0) setInnerPage(next);
|
|
3617
|
+
onPageChange?.(next);
|
|
3618
|
+
};
|
|
3530
3619
|
const shared = {
|
|
3531
3620
|
...rest,
|
|
3532
3621
|
className,
|
|
3533
3622
|
sort: currentSort,
|
|
3534
3623
|
onSortChange: changeSort,
|
|
3535
3624
|
selectedIds: currentSel,
|
|
3536
|
-
onSelectionChange: changeSel
|
|
3625
|
+
onSelectionChange: changeSel,
|
|
3626
|
+
page: currentPage,
|
|
3627
|
+
onPageChange: changePage
|
|
3537
3628
|
};
|
|
3538
3629
|
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { ref, className: cn33("w-full rounded-xl", rootClassName), children: [
|
|
3539
3630
|
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "hidden md:block", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DataTableDesktop, { ...shared }) }),
|
|
3540
|
-
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "md:hidden", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DataTableMobile, { ...shared }) })
|
|
3631
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: "md:hidden", children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(DataTableMobile, { ...shared, mobileDescription }) })
|
|
3541
3632
|
] });
|
|
3542
3633
|
}
|
|
3543
3634
|
);
|
package/dist/index.js
CHANGED
|
@@ -3126,6 +3126,7 @@ function DataTableDesktopInner({
|
|
|
3126
3126
|
views,
|
|
3127
3127
|
view,
|
|
3128
3128
|
onViewChange,
|
|
3129
|
+
toolbarStart,
|
|
3129
3130
|
filters = [],
|
|
3130
3131
|
onRemoveFilter,
|
|
3131
3132
|
onClearFilters,
|
|
@@ -3135,7 +3136,11 @@ function DataTableDesktopInner({
|
|
|
3135
3136
|
onSortChange,
|
|
3136
3137
|
selectedIds,
|
|
3137
3138
|
onSelectionChange,
|
|
3139
|
+
onRowClick,
|
|
3140
|
+
countLabel = (count) => `${count} records`,
|
|
3138
3141
|
pageSize = 10,
|
|
3142
|
+
page: pageProp,
|
|
3143
|
+
onPageChange,
|
|
3139
3144
|
emptyTitle = "No companies yet",
|
|
3140
3145
|
emptyDescription = "Import companies to get started.",
|
|
3141
3146
|
importLabel = "Import companies",
|
|
@@ -3156,14 +3161,19 @@ function DataTableDesktopInner({
|
|
|
3156
3161
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3157
3162
|
onSelectionChange?.(ids);
|
|
3158
3163
|
};
|
|
3159
|
-
const [
|
|
3164
|
+
const [innerPage, setInnerPage] = React33.useState(1);
|
|
3165
|
+
const page = pageProp ?? innerPage;
|
|
3166
|
+
const setPage = (next) => {
|
|
3167
|
+
if (pageProp === void 0) setInnerPage(next);
|
|
3168
|
+
onPageChange?.(next);
|
|
3169
|
+
};
|
|
3160
3170
|
const sorted = React33.useMemo(() => {
|
|
3161
3171
|
if (!sort) return rows;
|
|
3162
3172
|
const out = [...rows].sort((a, b) => compare(a[sort.key], b[sort.key]));
|
|
3163
3173
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
3164
3174
|
}, [rows, sort]);
|
|
3165
3175
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3166
|
-
const safePage = Math.min(page, pageCount);
|
|
3176
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
3167
3177
|
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3168
3178
|
const allIds = rows.map((r) => r.id);
|
|
3169
3179
|
const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
|
|
@@ -3177,7 +3187,8 @@ function DataTableDesktopInner({
|
|
|
3177
3187
|
...rest,
|
|
3178
3188
|
children: [
|
|
3179
3189
|
/* @__PURE__ */ jsxs29("div", { className: "flex items-center gap-sm border-b border-hairline px-base py-sm", children: [
|
|
3180
|
-
|
|
3190
|
+
toolbarStart ? /* @__PURE__ */ jsx33("div", { className: "min-w-0 flex-1", children: toolbarStart }) : null,
|
|
3191
|
+
views && views.length > 0 ? /* @__PURE__ */ jsx33("div", { className: cn31("min-w-0", toolbarStart ? "w-2/5 shrink-0" : "w-2/5"), children: /* @__PURE__ */ jsx33(
|
|
3181
3192
|
Dropdown,
|
|
3182
3193
|
{
|
|
3183
3194
|
"aria-label": "View",
|
|
@@ -3187,7 +3198,7 @@ function DataTableDesktopInner({
|
|
|
3187
3198
|
onValueChange: onViewChange
|
|
3188
3199
|
}
|
|
3189
3200
|
) }) : null,
|
|
3190
|
-
/* @__PURE__ */ jsxs29("div", { className: "ml-auto flex items-center gap-xs", children: [
|
|
3201
|
+
/* @__PURE__ */ jsxs29("div", { className: "ml-auto flex shrink-0 items-center gap-xs", children: [
|
|
3191
3202
|
/* @__PURE__ */ jsxs29("span", { className: "relative inline-flex", children: [
|
|
3192
3203
|
/* @__PURE__ */ jsx33(
|
|
3193
3204
|
IconButton,
|
|
@@ -3257,24 +3268,38 @@ function DataTableDesktopInner({
|
|
|
3257
3268
|
c.key
|
|
3258
3269
|
))
|
|
3259
3270
|
] }) }),
|
|
3260
|
-
/* @__PURE__ */ jsx33("tbody", { children: visible.map((row) =>
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3271
|
+
/* @__PURE__ */ jsx33("tbody", { children: visible.map((row) => {
|
|
3272
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
3273
|
+
return /* @__PURE__ */ jsx33(
|
|
3274
|
+
TableRow,
|
|
3275
|
+
{
|
|
3276
|
+
selectable: true,
|
|
3277
|
+
selected: selected.includes(row.id),
|
|
3278
|
+
onSelectedChange: (v) => setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id)),
|
|
3279
|
+
rowLabel,
|
|
3280
|
+
align: columns.map((c) => c.align),
|
|
3281
|
+
cells: columns.map((c) => c.render ? c.render(row) : row[c.key]),
|
|
3282
|
+
...onRowClick ? {
|
|
3283
|
+
onClick: () => onRowClick(row),
|
|
3284
|
+
tabIndex: 0,
|
|
3285
|
+
"aria-label": `Open ${rowLabel}`,
|
|
3286
|
+
onKeyDown: (event) => {
|
|
3287
|
+
if (event.key === "Enter") {
|
|
3288
|
+
event.preventDefault();
|
|
3289
|
+
onRowClick(row);
|
|
3290
|
+
}
|
|
3291
|
+
},
|
|
3292
|
+
className: "cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue"
|
|
3293
|
+
} : {}
|
|
3294
|
+
},
|
|
3295
|
+
row.id
|
|
3296
|
+
);
|
|
3297
|
+
}) })
|
|
3272
3298
|
] }) }),
|
|
3273
3299
|
/* @__PURE__ */ jsxs29("div", { className: "flex items-center gap-base border-t border-hairline px-base py-sm", children: [
|
|
3274
3300
|
/* @__PURE__ */ jsxs29("span", { className: "shrink-0 whitespace-nowrap text-body-sm text-muted", children: [
|
|
3275
3301
|
selected.length > 0 ? `${selected.length} selected \xB7 ` : "",
|
|
3276
|
-
rows.length
|
|
3277
|
-
" count"
|
|
3302
|
+
countLabel(rows.length)
|
|
3278
3303
|
] }),
|
|
3279
3304
|
/* @__PURE__ */ jsx33("div", { className: "ml-auto flex justify-end", children: /* @__PURE__ */ jsx33(Pagination, { pageCount, page: safePage, onPageChange: setPage, size: "sm" }) })
|
|
3280
3305
|
] })
|
|
@@ -3288,7 +3313,7 @@ DataTableDesktop.displayName = "DataTableDesktop";
|
|
|
3288
3313
|
|
|
3289
3314
|
// virtual-pkg:src/atoms/DataTableMobile/DataTableMobile.tsx
|
|
3290
3315
|
import * as React34 from "react";
|
|
3291
|
-
import { jsx as jsx34, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
3316
|
+
import { Fragment as Fragment7, jsx as jsx34, jsxs as jsxs30 } from "react/jsx-runtime";
|
|
3292
3317
|
var cn32 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3293
3318
|
function compare2(a, b) {
|
|
3294
3319
|
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
@@ -3298,12 +3323,19 @@ function DataTableMobileInner({
|
|
|
3298
3323
|
columns,
|
|
3299
3324
|
rows,
|
|
3300
3325
|
rowLabelKey,
|
|
3326
|
+
toolbarStart,
|
|
3301
3327
|
filters = [],
|
|
3302
3328
|
onRemoveFilter,
|
|
3303
3329
|
sort: sortProp,
|
|
3304
3330
|
onSortChange,
|
|
3305
3331
|
selectedIds,
|
|
3306
3332
|
onSelectionChange,
|
|
3333
|
+
onRowClick,
|
|
3334
|
+
mobileDescription,
|
|
3335
|
+
countLabel = (count) => `${count} records`,
|
|
3336
|
+
pageSize = 10,
|
|
3337
|
+
page: pageProp,
|
|
3338
|
+
onPageChange,
|
|
3307
3339
|
emptyTitle = "No companies yet",
|
|
3308
3340
|
emptyDescription = "Import companies to get started.",
|
|
3309
3341
|
importLabel = "Import companies",
|
|
@@ -3326,11 +3358,20 @@ function DataTableMobileInner({
|
|
|
3326
3358
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3327
3359
|
onSelectionChange?.(ids);
|
|
3328
3360
|
};
|
|
3361
|
+
const [innerPage, setInnerPage] = React34.useState(1);
|
|
3362
|
+
const page = pageProp ?? innerPage;
|
|
3363
|
+
const setPage = (next) => {
|
|
3364
|
+
if (pageProp === void 0) setInnerPage(next);
|
|
3365
|
+
onPageChange?.(next);
|
|
3366
|
+
};
|
|
3329
3367
|
const sorted = React34.useMemo(() => {
|
|
3330
3368
|
if (!sort) return rows;
|
|
3331
3369
|
const out = [...rows].sort((a, b) => compare2(a[sort.key], b[sort.key]));
|
|
3332
3370
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
3333
3371
|
}, [rows, sort]);
|
|
3372
|
+
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
3373
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
3374
|
+
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
3334
3375
|
const allIds = rows.map((r) => r.id);
|
|
3335
3376
|
const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
|
|
3336
3377
|
const someSelected = !allSelected && allIds.some((id) => selected.includes(id));
|
|
@@ -3342,48 +3383,79 @@ function DataTableMobileInner({
|
|
|
3342
3383
|
className: cn32("flex w-full flex-col overflow-hidden rounded-xl border border-hairline bg-surface shadow-card", className),
|
|
3343
3384
|
...rest,
|
|
3344
3385
|
children: [
|
|
3386
|
+
toolbarStart ? /* @__PURE__ */ jsx34("div", { className: "flex items-center gap-sm border-b border-hairline px-md py-sm", children: toolbarStart }) : null,
|
|
3345
3387
|
filters.length > 0 ? /* @__PURE__ */ jsx34("div", { className: "flex flex-wrap items-center gap-sm border-b border-hairline px-md py-sm", children: filters.map((f) => /* @__PURE__ */ jsx34(Chip, { size: "sm", label: f.label, icon: "funnel", onRemove: () => onRemoveFilter?.(f.id) }, f.id)) }) : null,
|
|
3346
3388
|
rows.length === 0 ? /* @__PURE__ */ jsxs30("div", { className: "flex flex-col items-center justify-center gap-sm px-base py-xl text-center", children: [
|
|
3347
3389
|
/* @__PURE__ */ jsx34(Icon, { name: "database", size: 24, className: "text-muted" }),
|
|
3348
3390
|
/* @__PURE__ */ jsx34("p", { className: "m-0 text-label-md text-ink", children: emptyTitle }),
|
|
3349
3391
|
/* @__PURE__ */ jsx34("p", { className: "m-0 text-body-sm text-muted", children: emptyDescription }),
|
|
3350
3392
|
/* @__PURE__ */ jsx34(Button, { variant: "secondary", size: "lg", onClick: onImport, leadingIcon: /* @__PURE__ */ jsx34(Icon, { name: "download", size: 16 }), children: importLabel })
|
|
3351
|
-
] }) : /* @__PURE__ */
|
|
3352
|
-
/* @__PURE__ */ jsx34("
|
|
3353
|
-
/* @__PURE__ */ jsx34("
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3393
|
+
] }) : /* @__PURE__ */ jsxs30(Fragment7, { children: [
|
|
3394
|
+
/* @__PURE__ */ jsx34("div", { className: "w-full overflow-x-auto", children: /* @__PURE__ */ jsxs30("table", { className: "w-full border-collapse", "aria-label": label, children: [
|
|
3395
|
+
/* @__PURE__ */ jsx34("thead", { children: /* @__PURE__ */ jsxs30("tr", { children: [
|
|
3396
|
+
/* @__PURE__ */ jsx34("th", { scope: "col", className: "w-10 border-b border-hairline bg-surface py-0 pl-base pr-xs text-left align-middle", children: /* @__PURE__ */ jsx34(
|
|
3397
|
+
Checkbox,
|
|
3398
|
+
{
|
|
3399
|
+
"aria-label": allSelected ? "Deselect all rows" : "Select all rows",
|
|
3400
|
+
checked: allSelected,
|
|
3401
|
+
indeterminate: someSelected,
|
|
3402
|
+
onCheckedChange: (v) => setSelected(v ? allIds : []),
|
|
3403
|
+
className: "flex"
|
|
3404
|
+
}
|
|
3405
|
+
) }),
|
|
3406
|
+
col ? /* @__PURE__ */ jsx34(
|
|
3407
|
+
TableHeaderCell,
|
|
3408
|
+
{
|
|
3409
|
+
label: col.label,
|
|
3410
|
+
icon: col.icon,
|
|
3411
|
+
className: "min-w-0",
|
|
3412
|
+
sort: sort?.key === col.key ? sort.direction : "none",
|
|
3413
|
+
onSortChange: col.sortable ? (next) => setSort(next === "none" ? null : { key: col.key, direction: next }) : void 0
|
|
3414
|
+
}
|
|
3415
|
+
) : null
|
|
3416
|
+
] }) }),
|
|
3417
|
+
/* @__PURE__ */ jsx34("tbody", { children: visible.map((row) => {
|
|
3418
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
3419
|
+
const content = col ? col.render ? col.render(row) : row[col.key] : null;
|
|
3420
|
+
const description = mobileDescription?.(row);
|
|
3421
|
+
return /* @__PURE__ */ jsx34(
|
|
3422
|
+
TableRow,
|
|
3423
|
+
{
|
|
3424
|
+
selectable: true,
|
|
3425
|
+
selected: selected.includes(row.id),
|
|
3426
|
+
onSelectedChange: (v) => setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id)),
|
|
3427
|
+
rowLabel,
|
|
3428
|
+
className: "[&>td]:h-11",
|
|
3429
|
+
cells: [
|
|
3430
|
+
description ? /* @__PURE__ */ jsxs30("span", { className: "flex min-w-0 flex-col gap-xxs", children: [
|
|
3431
|
+
/* @__PURE__ */ jsx34("span", { className: "min-w-0", children: content }),
|
|
3432
|
+
/* @__PURE__ */ jsx34("span", { className: "min-w-0 text-body-sm text-muted", children: description })
|
|
3433
|
+
] }) : content
|
|
3434
|
+
],
|
|
3435
|
+
...onRowClick ? {
|
|
3436
|
+
onClick: () => onRowClick(row),
|
|
3437
|
+
tabIndex: 0,
|
|
3438
|
+
"aria-label": `Open ${rowLabel}`,
|
|
3439
|
+
onKeyDown: (event) => {
|
|
3440
|
+
if (event.key === "Enter") {
|
|
3441
|
+
event.preventDefault();
|
|
3442
|
+
onRowClick(row);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
} : {}
|
|
3446
|
+
},
|
|
3447
|
+
row.id
|
|
3448
|
+
);
|
|
3449
|
+
}) })
|
|
3373
3450
|
] }) }),
|
|
3374
|
-
/* @__PURE__ */
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
cells: [col ? col.render ? col.render(row) : row[col.key] : null]
|
|
3383
|
-
},
|
|
3384
|
-
row.id
|
|
3385
|
-
)) })
|
|
3386
|
-
] }) })
|
|
3451
|
+
/* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-base border-t border-hairline px-md py-sm", children: [
|
|
3452
|
+
/* @__PURE__ */ jsxs30("span", { className: "shrink-0 whitespace-nowrap text-body-sm text-muted", children: [
|
|
3453
|
+
selected.length > 0 ? `${selected.length} selected \xB7 ` : "",
|
|
3454
|
+
countLabel(rows.length)
|
|
3455
|
+
] }),
|
|
3456
|
+
/* @__PURE__ */ jsx34("div", { className: "ml-auto flex justify-end", children: /* @__PURE__ */ jsx34(Pagination, { pageCount, page: safePage, onPageChange: setPage, size: "sm" }) })
|
|
3457
|
+
] })
|
|
3458
|
+
] })
|
|
3387
3459
|
]
|
|
3388
3460
|
}
|
|
3389
3461
|
);
|
|
@@ -3395,7 +3467,18 @@ DataTableMobile.displayName = "DataTableMobile";
|
|
|
3395
3467
|
import { jsx as jsx35, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
3396
3468
|
var cn33 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3397
3469
|
var DataTable = React35.forwardRef(
|
|
3398
|
-
({
|
|
3470
|
+
({
|
|
3471
|
+
sort,
|
|
3472
|
+
onSortChange,
|
|
3473
|
+
selectedIds,
|
|
3474
|
+
onSelectionChange,
|
|
3475
|
+
page,
|
|
3476
|
+
onPageChange,
|
|
3477
|
+
mobileDescription,
|
|
3478
|
+
rootClassName,
|
|
3479
|
+
className,
|
|
3480
|
+
...rest
|
|
3481
|
+
}, ref) => {
|
|
3399
3482
|
const [innerSort, setInnerSort] = React35.useState(null);
|
|
3400
3483
|
const currentSort = sort === void 0 ? innerSort : sort;
|
|
3401
3484
|
const changeSort = (s) => {
|
|
@@ -3408,17 +3491,25 @@ var DataTable = React35.forwardRef(
|
|
|
3408
3491
|
if (selectedIds === void 0) setInnerSel(ids);
|
|
3409
3492
|
onSelectionChange?.(ids);
|
|
3410
3493
|
};
|
|
3494
|
+
const [innerPage, setInnerPage] = React35.useState(1);
|
|
3495
|
+
const currentPage = page ?? innerPage;
|
|
3496
|
+
const changePage = (next) => {
|
|
3497
|
+
if (page === void 0) setInnerPage(next);
|
|
3498
|
+
onPageChange?.(next);
|
|
3499
|
+
};
|
|
3411
3500
|
const shared = {
|
|
3412
3501
|
...rest,
|
|
3413
3502
|
className,
|
|
3414
3503
|
sort: currentSort,
|
|
3415
3504
|
onSortChange: changeSort,
|
|
3416
3505
|
selectedIds: currentSel,
|
|
3417
|
-
onSelectionChange: changeSel
|
|
3506
|
+
onSelectionChange: changeSel,
|
|
3507
|
+
page: currentPage,
|
|
3508
|
+
onPageChange: changePage
|
|
3418
3509
|
};
|
|
3419
3510
|
return /* @__PURE__ */ jsxs31("div", { ref, className: cn33("w-full rounded-xl", rootClassName), children: [
|
|
3420
3511
|
/* @__PURE__ */ jsx35("div", { className: "hidden md:block", children: /* @__PURE__ */ jsx35(DataTableDesktop, { ...shared }) }),
|
|
3421
|
-
/* @__PURE__ */ jsx35("div", { className: "md:hidden", children: /* @__PURE__ */ jsx35(DataTableMobile, { ...shared }) })
|
|
3512
|
+
/* @__PURE__ */ jsx35("div", { className: "md:hidden", children: /* @__PURE__ */ jsx35(DataTableMobile, { ...shared, mobileDescription }) })
|
|
3422
3513
|
] });
|
|
3423
3514
|
}
|
|
3424
3515
|
);
|
|
@@ -3939,7 +4030,7 @@ var ProgressBar = React39.forwardRef(
|
|
|
3939
4030
|
ProgressBar.displayName = "ProgressBar";
|
|
3940
4031
|
|
|
3941
4032
|
// virtual-pkg:src/atoms/FileUpload/FileUpload.tsx
|
|
3942
|
-
import { Fragment as
|
|
4033
|
+
import { Fragment as Fragment8, jsx as jsx40, jsxs as jsxs36 } from "react/jsx-runtime";
|
|
3943
4034
|
var cn38 = (...parts) => parts.filter(Boolean).join(" ");
|
|
3944
4035
|
var formatBytes = (bytes) => {
|
|
3945
4036
|
if (bytes < 1024) return `${bytes} B`;
|
|
@@ -4029,7 +4120,7 @@ var FileUpload = React40.forwardRef(
|
|
|
4029
4120
|
className: cn38("transition-transform duration-200 ease-out", dragging ? "-translate-y-0.5 text-primary" : "text-body")
|
|
4030
4121
|
}
|
|
4031
4122
|
),
|
|
4032
|
-
dragging ? /* @__PURE__ */ jsx40("span", { className: "text-label-sm text-primary", children: dropText }) : /* @__PURE__ */ jsxs36(
|
|
4123
|
+
dragging ? /* @__PURE__ */ jsx40("span", { className: "text-label-sm text-primary", children: dropText }) : /* @__PURE__ */ jsxs36(Fragment8, { children: [
|
|
4033
4124
|
/* @__PURE__ */ jsx40(Button, { variant: "ghost", size: "sm", disabled, onClick: browse, "aria-controls": inputId, children: title }),
|
|
4034
4125
|
/* @__PURE__ */ jsx40("span", { className: "text-caption text-muted", children: description })
|
|
4035
4126
|
] })
|
|
@@ -4074,7 +4165,7 @@ var FileUpload = React40.forwardRef(
|
|
|
4074
4165
|
/* @__PURE__ */ jsx40("p", { className: "truncate text-label-sm text-ink", children: file.name }),
|
|
4075
4166
|
/* @__PURE__ */ jsx40("p", { className: "text-caption text-muted", children: file.status === "error" && file.error ? file.error : formatBytes(file.size) })
|
|
4076
4167
|
] }),
|
|
4077
|
-
file.status === "uploading" ? /* @__PURE__ */ jsxs36(
|
|
4168
|
+
file.status === "uploading" ? /* @__PURE__ */ jsxs36(Fragment8, { children: [
|
|
4078
4169
|
/* @__PURE__ */ jsx40("div", { className: "w-24 shrink-0 rounded-none", children: /* @__PURE__ */ jsx40(ProgressBar, { value: file.progress ?? 0, size: "md", label: `Uploading ${file.name}` }) }),
|
|
4079
4170
|
onRemove ? /* @__PURE__ */ jsx40(
|
|
4080
4171
|
IconButton,
|
|
@@ -5560,7 +5651,7 @@ NavbarDesktop.displayName = "NavbarDesktop";
|
|
|
5560
5651
|
|
|
5561
5652
|
// virtual-pkg:src/atoms/NavbarMobile/NavbarMobile.tsx
|
|
5562
5653
|
import * as React56 from "react";
|
|
5563
|
-
import { Fragment as
|
|
5654
|
+
import { Fragment as Fragment11, jsx as jsx56, jsxs as jsxs52 } from "react/jsx-runtime";
|
|
5564
5655
|
var cn54 = (...parts) => parts.filter(Boolean).join(" ");
|
|
5565
5656
|
var DEFAULT_ITEMS2 = [
|
|
5566
5657
|
{ label: "Home", href: "#home", icon: "house" },
|
|
@@ -5659,7 +5750,7 @@ var NavbarMobile = React56.forwardRef(
|
|
|
5659
5750
|
}
|
|
5660
5751
|
) }, item.href);
|
|
5661
5752
|
}) }) }),
|
|
5662
|
-
secondaryActions.length > 0 ? /* @__PURE__ */ jsxs52(
|
|
5753
|
+
secondaryActions.length > 0 ? /* @__PURE__ */ jsxs52(Fragment11, { children: [
|
|
5663
5754
|
/* @__PURE__ */ jsx56(Divider, { className: "my-sm", decorative: true }),
|
|
5664
5755
|
/* @__PURE__ */ jsx56("div", { className: "flex flex-col gap-xxs", children: secondaryActions.map((a) => /* @__PURE__ */ jsx56(
|
|
5665
5756
|
Button,
|
|
@@ -5738,7 +5829,7 @@ import * as React60 from "react";
|
|
|
5738
5829
|
// virtual-pkg:src/atoms/NavigationMenuDesktop/NavigationMenuDesktop.tsx
|
|
5739
5830
|
import * as React58 from "react";
|
|
5740
5831
|
import { createPortal as createPortal7 } from "react-dom";
|
|
5741
|
-
import { Fragment as
|
|
5832
|
+
import { Fragment as Fragment12, jsx as jsx58, jsxs as jsxs54 } from "react/jsx-runtime";
|
|
5742
5833
|
var cn56 = (...parts) => parts.filter(Boolean).join(" ");
|
|
5743
5834
|
var DEFAULT_NAV_ENTRIES = [
|
|
5744
5835
|
{ id: "home", label: "Home", icon: "house", href: "#home" },
|
|
@@ -5944,7 +6035,7 @@ var NavigationMenuDesktop = React58.forwardRef(
|
|
|
5944
6035
|
) }, e.id);
|
|
5945
6036
|
}) }),
|
|
5946
6037
|
mounted ? createPortal7(
|
|
5947
|
-
/* @__PURE__ */ jsx58(
|
|
6038
|
+
/* @__PURE__ */ jsx58(Fragment12, { children: entries.filter((e) => e.menu || e.mega).map((e) => {
|
|
5948
6039
|
const open = openId === e.id;
|
|
5949
6040
|
const p = pos[e.id];
|
|
5950
6041
|
return /* @__PURE__ */ jsxs54(
|
|
@@ -6242,7 +6333,7 @@ NavigationMenu.displayName = "NavigationMenu";
|
|
|
6242
6333
|
|
|
6243
6334
|
// virtual-pkg:src/atoms/NotificationFeed/NotificationFeed.tsx
|
|
6244
6335
|
import * as React61 from "react";
|
|
6245
|
-
import { Fragment as
|
|
6336
|
+
import { Fragment as Fragment14, jsx as jsx61, jsxs as jsxs57 } from "react/jsx-runtime";
|
|
6246
6337
|
var cn59 = (...parts) => parts.filter(Boolean).join(" ");
|
|
6247
6338
|
var kindIcon = {
|
|
6248
6339
|
assignment: "circle-check",
|
|
@@ -6250,7 +6341,7 @@ var kindIcon = {
|
|
|
6250
6341
|
update: "bell"
|
|
6251
6342
|
};
|
|
6252
6343
|
function Segments({ parts }) {
|
|
6253
|
-
return /* @__PURE__ */ jsx61(
|
|
6344
|
+
return /* @__PURE__ */ jsx61(Fragment14, { children: parts.map(
|
|
6254
6345
|
(p, i) => typeof p === "string" ? /* @__PURE__ */ jsx61(React61.Fragment, { children: p }, i) : "strong" in p ? /* @__PURE__ */ jsx61("span", { className: "text-label-md text-ink", children: p.strong }, i) : /* @__PURE__ */ jsx61("span", { className: "text-link-blue", children: p.mention }, i)
|
|
6255
6346
|
) });
|
|
6256
6347
|
}
|
|
@@ -8339,7 +8430,7 @@ TestimonialBlock.displayName = "TestimonialBlock";
|
|
|
8339
8430
|
|
|
8340
8431
|
// virtual-pkg:src/atoms/Toast/Toast.tsx
|
|
8341
8432
|
import * as React79 from "react";
|
|
8342
|
-
import { Fragment as
|
|
8433
|
+
import { Fragment as Fragment16, jsx as jsx79, jsxs as jsxs74 } from "react/jsx-runtime";
|
|
8343
8434
|
var cn77 = (...parts) => parts.filter(Boolean).join(" ");
|
|
8344
8435
|
var markBg = {
|
|
8345
8436
|
success: "bg-semantic-success",
|
|
@@ -8405,7 +8496,7 @@ var Toast = React79.forwardRef(
|
|
|
8405
8496
|
}
|
|
8406
8497
|
) : null,
|
|
8407
8498
|
/* @__PURE__ */ jsx79("span", { className: "min-w-0 flex-1 truncate text-label-md text-ink", children: title }),
|
|
8408
|
-
actionLabel ? /* @__PURE__ */ jsxs74(
|
|
8499
|
+
actionLabel ? /* @__PURE__ */ jsxs74(Fragment16, { children: [
|
|
8409
8500
|
/* @__PURE__ */ jsx79(Divider, { orientation: "vertical", tone: "strong", className: "my-xs" }),
|
|
8410
8501
|
/* @__PURE__ */ jsx79(
|
|
8411
8502
|
Button,
|
|
@@ -8438,7 +8529,7 @@ Toast.displayName = "Toast";
|
|
|
8438
8529
|
// virtual-pkg:src/atoms/Tooltip/Tooltip.tsx
|
|
8439
8530
|
import * as React80 from "react";
|
|
8440
8531
|
import { createPortal as createPortal8 } from "react-dom";
|
|
8441
|
-
import { Fragment as
|
|
8532
|
+
import { Fragment as Fragment17, jsx as jsx80, jsxs as jsxs75 } from "react/jsx-runtime";
|
|
8442
8533
|
var cn78 = (...parts) => parts.filter(Boolean).join(" ");
|
|
8443
8534
|
var anchorTransform = {
|
|
8444
8535
|
top: "translate(-50%, -100%)",
|
|
@@ -8624,7 +8715,7 @@ var Tooltip = React80.forwardRef(
|
|
|
8624
8715
|
)
|
|
8625
8716
|
}
|
|
8626
8717
|
);
|
|
8627
|
-
return /* @__PURE__ */ jsxs75(
|
|
8718
|
+
return /* @__PURE__ */ jsxs75(Fragment17, { children: [
|
|
8628
8719
|
trigger,
|
|
8629
8720
|
mounted ? createPortal8(panel, document.body) : null
|
|
8630
8721
|
] });
|
package/package.json
CHANGED
|
@@ -13,11 +13,27 @@ const cn = (...parts: Array<string | false | null | undefined>) =>
|
|
|
13
13
|
export interface DataTableProps extends DataTableDesktopProps<DataTableRecord> {
|
|
14
14
|
/** Classes for the outer wrapper. */
|
|
15
15
|
rootClassName?: string;
|
|
16
|
+
/** Muted second line under the first column's content in the mobile layout. */
|
|
17
|
+
mobileDescription?: (row: DataTableRecord) => React.ReactNode;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
/** Responsive data table: the Desktop layout from `md` up, the Mobile layout below. Sort and
|
|
20
|
+
/** Responsive data table: the Desktop layout from `md` up, the Mobile layout below. Sort, selection and paging are shared. */
|
|
19
21
|
export const DataTable = React.forwardRef<HTMLDivElement, DataTableProps>(
|
|
20
|
-
(
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
sort,
|
|
25
|
+
onSortChange,
|
|
26
|
+
selectedIds,
|
|
27
|
+
onSelectionChange,
|
|
28
|
+
page,
|
|
29
|
+
onPageChange,
|
|
30
|
+
mobileDescription,
|
|
31
|
+
rootClassName,
|
|
32
|
+
className,
|
|
33
|
+
...rest
|
|
34
|
+
},
|
|
35
|
+
ref,
|
|
36
|
+
) => {
|
|
21
37
|
const [innerSort, setInnerSort] = React.useState<DataTableSortState | null>(null);
|
|
22
38
|
const currentSort = sort === undefined ? innerSort : sort;
|
|
23
39
|
const changeSort = (s: DataTableSortState | null) => {
|
|
@@ -30,6 +46,12 @@ export const DataTable = React.forwardRef<HTMLDivElement, DataTableProps>(
|
|
|
30
46
|
if (selectedIds === undefined) setInnerSel(ids);
|
|
31
47
|
onSelectionChange?.(ids);
|
|
32
48
|
};
|
|
49
|
+
const [innerPage, setInnerPage] = React.useState(1);
|
|
50
|
+
const currentPage = page ?? innerPage;
|
|
51
|
+
const changePage = (next: number) => {
|
|
52
|
+
if (page === undefined) setInnerPage(next);
|
|
53
|
+
onPageChange?.(next);
|
|
54
|
+
};
|
|
33
55
|
const shared = {
|
|
34
56
|
...rest,
|
|
35
57
|
className,
|
|
@@ -37,6 +59,8 @@ export const DataTable = React.forwardRef<HTMLDivElement, DataTableProps>(
|
|
|
37
59
|
onSortChange: changeSort,
|
|
38
60
|
selectedIds: currentSel,
|
|
39
61
|
onSelectionChange: changeSel,
|
|
62
|
+
page: currentPage,
|
|
63
|
+
onPageChange: changePage,
|
|
40
64
|
};
|
|
41
65
|
return (
|
|
42
66
|
<div ref={ref} className={cn("w-full rounded-xl", rootClassName)}>
|
|
@@ -44,7 +68,7 @@ export const DataTable = React.forwardRef<HTMLDivElement, DataTableProps>(
|
|
|
44
68
|
<DataTableDesktop {...shared} />
|
|
45
69
|
</div>
|
|
46
70
|
<div className="md:hidden">
|
|
47
|
-
<DataTableMobile {...shared} />
|
|
71
|
+
<DataTableMobile {...shared} mobileDescription={mobileDescription} />
|
|
48
72
|
</div>
|
|
49
73
|
</div>
|
|
50
74
|
);
|
|
@@ -1,21 +1,76 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DataTable } from "./DataTable";
|
|
3
3
|
import { Avatar } from "../Avatar";
|
|
4
|
+
import { Button } from "../Button";
|
|
5
|
+
import { SearchBar } from "../SearchBar";
|
|
4
6
|
|
|
5
7
|
const rows = [
|
|
6
8
|
{ id: "1", company: "Northwind", location: "United Kingdom", strength: "Weak" },
|
|
7
9
|
{ id: "2", company: "Lumen", location: "United Kingdom", strength: "Weak" },
|
|
8
10
|
{ id: "3", company: "Atlas", location: "France", strength: "Strong" },
|
|
11
|
+
{ id: "4", company: "Meridian", location: "Germany", strength: "Medium" },
|
|
12
|
+
{ id: "5", company: "Harbor", location: "Netherlands", strength: "Strong" },
|
|
13
|
+
{ id: "6", company: "Vantage", location: "Spain", strength: "Weak" },
|
|
14
|
+
{ id: "7", company: "Solace", location: "Ireland", strength: "Medium" },
|
|
15
|
+
{ id: "8", company: "Kestrel", location: "France", strength: "Strong" },
|
|
16
|
+
{ id: "9", company: "Pinewood", location: "Germany", strength: "Weak" },
|
|
17
|
+
{ id: "10", company: "Alto", location: "Italy", strength: "Medium" },
|
|
18
|
+
{ id: "11", company: "Copperfield", location: "United Kingdom", strength: "Strong" },
|
|
19
|
+
{ id: "12", company: "Nimbus", location: "Sweden", strength: "Weak" },
|
|
9
20
|
];
|
|
10
21
|
|
|
11
22
|
export default function DataTablePreview() {
|
|
12
23
|
const [selected, setSelected] = React.useState<string[]>([]);
|
|
13
24
|
const [view, setView] = React.useState("eu");
|
|
25
|
+
const [query, setQuery] = React.useState("");
|
|
26
|
+
const [page, setPage] = React.useState(1);
|
|
27
|
+
const [opened, setOpened] = React.useState<string | null>(null);
|
|
28
|
+
|
|
29
|
+
const filtered = query
|
|
30
|
+
? rows.filter((r) => r.company.toLowerCase().includes(query.toLowerCase()))
|
|
31
|
+
: rows;
|
|
32
|
+
|
|
14
33
|
return (
|
|
15
|
-
<div className="w-full p-lg">
|
|
34
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
35
|
+
<div className="flex w-full flex-wrap items-center justify-between gap-sm">
|
|
36
|
+
<p className="m-0 text-body-sm text-muted">
|
|
37
|
+
{opened ? `Opened record: ${opened}` : "Click a row, or focus it and press Enter."}
|
|
38
|
+
</p>
|
|
39
|
+
<Button
|
|
40
|
+
variant="secondary"
|
|
41
|
+
size="sm"
|
|
42
|
+
onClick={() => {
|
|
43
|
+
setQuery("");
|
|
44
|
+
setPage(1);
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
Clear search and reset page
|
|
48
|
+
</Button>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
16
51
|
<DataTable
|
|
17
52
|
label="Companies"
|
|
18
|
-
rows={
|
|
53
|
+
rows={filtered}
|
|
54
|
+
pageSize={5}
|
|
55
|
+
page={page}
|
|
56
|
+
onPageChange={setPage}
|
|
57
|
+
onRowClick={(row) => setOpened(String(row.company))}
|
|
58
|
+
countLabel={(count) => `${count} companies`}
|
|
59
|
+
mobileDescription={(row) => `${String(row.location)} · ${String(row.strength)} connection`}
|
|
60
|
+
toolbarStart={
|
|
61
|
+
<div className="min-w-0 w-full">
|
|
62
|
+
<SearchBar
|
|
63
|
+
size="sm"
|
|
64
|
+
value={query}
|
|
65
|
+
onValueChange={(next) => {
|
|
66
|
+
setQuery(next);
|
|
67
|
+
setPage(1);
|
|
68
|
+
}}
|
|
69
|
+
placeholder="Search companies"
|
|
70
|
+
shortcut={null}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
}
|
|
19
74
|
views={[
|
|
20
75
|
{ value: "eu", label: "UK, French and German companies", icon: "layout-grid", iconTone: "success" },
|
|
21
76
|
{ value: "all", label: "All companies", icon: "layout-grid", iconTone: "success" },
|
|
@@ -40,6 +95,17 @@ export default function DataTablePreview() {
|
|
|
40
95
|
{ key: "strength", label: "Connection strength", icon: "zap", sortable: true },
|
|
41
96
|
]}
|
|
42
97
|
/>
|
|
98
|
+
|
|
99
|
+
<DataTable
|
|
100
|
+
label="Companies (without row click)"
|
|
101
|
+
rows={rows.slice(0, 3)}
|
|
102
|
+
views={[{ value: "eu", label: "All companies", icon: "layout-grid", iconTone: "success" }]}
|
|
103
|
+
view="eu"
|
|
104
|
+
columns={[
|
|
105
|
+
{ key: "company", label: "Company", sortable: true },
|
|
106
|
+
{ key: "location", label: "Primary location", icon: "map-pin" },
|
|
107
|
+
]}
|
|
108
|
+
/>
|
|
43
109
|
</div>
|
|
44
110
|
);
|
|
45
111
|
}
|
|
@@ -45,6 +45,8 @@ export interface DataTableDesktopProps<R extends DataTableRecord = DataTableReco
|
|
|
45
45
|
views?: DropdownOption[];
|
|
46
46
|
view?: string;
|
|
47
47
|
onViewChange?: (view: string) => void;
|
|
48
|
+
/** Content pinned to the start of the toolbar row (for example a search field and filters). */
|
|
49
|
+
toolbarStart?: React.ReactNode;
|
|
48
50
|
/** Active filters, shown as removable chips under the toolbar. */
|
|
49
51
|
filters?: DataTableFilter[];
|
|
50
52
|
onRemoveFilter?: (id: string) => void;
|
|
@@ -57,7 +59,14 @@ export interface DataTableDesktopProps<R extends DataTableRecord = DataTableReco
|
|
|
57
59
|
/** Controlled selection. */
|
|
58
60
|
selectedIds?: string[];
|
|
59
61
|
onSelectionChange?: (ids: string[]) => void;
|
|
62
|
+
/** Fires when a row (not its checkbox) is clicked or Entered. */
|
|
63
|
+
onRowClick?: (row: R) => void;
|
|
64
|
+
/** Footer count text; defaults to "n records". */
|
|
65
|
+
countLabel?: (count: number) => string;
|
|
60
66
|
pageSize?: number;
|
|
67
|
+
/** Controlled page (1-based). Leave undefined for uncontrolled paging. */
|
|
68
|
+
page?: number;
|
|
69
|
+
onPageChange?: (page: number) => void;
|
|
61
70
|
/** Empty state. */
|
|
62
71
|
emptyTitle?: string;
|
|
63
72
|
emptyDescription?: string;
|
|
@@ -80,6 +89,7 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
80
89
|
views,
|
|
81
90
|
view,
|
|
82
91
|
onViewChange,
|
|
92
|
+
toolbarStart,
|
|
83
93
|
filters = [],
|
|
84
94
|
onRemoveFilter,
|
|
85
95
|
onClearFilters,
|
|
@@ -89,7 +99,11 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
89
99
|
onSortChange,
|
|
90
100
|
selectedIds,
|
|
91
101
|
onSelectionChange,
|
|
102
|
+
onRowClick,
|
|
103
|
+
countLabel = (count: number) => `${count} records`,
|
|
92
104
|
pageSize = 10,
|
|
105
|
+
page: pageProp,
|
|
106
|
+
onPageChange,
|
|
93
107
|
emptyTitle = "No companies yet",
|
|
94
108
|
emptyDescription = "Import companies to get started.",
|
|
95
109
|
importLabel = "Import companies",
|
|
@@ -112,7 +126,12 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
112
126
|
if (selectedIds === undefined) setInnerSel(ids);
|
|
113
127
|
onSelectionChange?.(ids);
|
|
114
128
|
};
|
|
115
|
-
const [
|
|
129
|
+
const [innerPage, setInnerPage] = React.useState(1);
|
|
130
|
+
const page = pageProp ?? innerPage;
|
|
131
|
+
const setPage = (next: number) => {
|
|
132
|
+
if (pageProp === undefined) setInnerPage(next);
|
|
133
|
+
onPageChange?.(next);
|
|
134
|
+
};
|
|
116
135
|
|
|
117
136
|
const sorted = React.useMemo(() => {
|
|
118
137
|
if (!sort) return rows;
|
|
@@ -120,7 +139,7 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
120
139
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
121
140
|
}, [rows, sort]);
|
|
122
141
|
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
123
|
-
const safePage = Math.min(page, pageCount);
|
|
142
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
124
143
|
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
125
144
|
|
|
126
145
|
const allIds = rows.map((r) => r.id);
|
|
@@ -135,8 +154,9 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
135
154
|
{...rest}
|
|
136
155
|
>
|
|
137
156
|
<div className="flex items-center gap-sm border-b border-hairline px-base py-sm">
|
|
157
|
+
{toolbarStart ? <div className="min-w-0 flex-1">{toolbarStart}</div> : null}
|
|
138
158
|
{views && views.length > 0 ? (
|
|
139
|
-
<div className="min-w-0 w-2/5">
|
|
159
|
+
<div className={cn("min-w-0", toolbarStart ? "w-2/5 shrink-0" : "w-2/5")}>
|
|
140
160
|
<Dropdown
|
|
141
161
|
aria-label="View"
|
|
142
162
|
size="md"
|
|
@@ -146,7 +166,7 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
146
166
|
/>
|
|
147
167
|
</div>
|
|
148
168
|
) : null}
|
|
149
|
-
<div className="ml-auto flex items-center gap-xs">
|
|
169
|
+
<div className="ml-auto flex shrink-0 items-center gap-xs">
|
|
150
170
|
<span className="relative inline-flex">
|
|
151
171
|
<IconButton
|
|
152
172
|
icon="sliders-horizontal"
|
|
@@ -229,26 +249,44 @@ export function DataTableDesktopInner<R extends DataTableRecord>(
|
|
|
229
249
|
</tr>
|
|
230
250
|
</thead>
|
|
231
251
|
<tbody>
|
|
232
|
-
{visible.map((row) =>
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
{visible.map((row) => {
|
|
253
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
254
|
+
return (
|
|
255
|
+
<TableRow
|
|
256
|
+
key={row.id}
|
|
257
|
+
selectable
|
|
258
|
+
selected={selected.includes(row.id)}
|
|
259
|
+
onSelectedChange={(v) =>
|
|
260
|
+
setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id))
|
|
261
|
+
}
|
|
262
|
+
rowLabel={rowLabel}
|
|
263
|
+
align={columns.map((c) => c.align)}
|
|
264
|
+
cells={columns.map((c) => (c.render ? c.render(row) : (row[c.key] as React.ReactNode)))}
|
|
265
|
+
{...(onRowClick
|
|
266
|
+
? {
|
|
267
|
+
onClick: () => onRowClick(row),
|
|
268
|
+
tabIndex: 0,
|
|
269
|
+
"aria-label": `Open ${rowLabel}`,
|
|
270
|
+
onKeyDown: (event: React.KeyboardEvent<HTMLTableRowElement>) => {
|
|
271
|
+
if (event.key === "Enter") {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
onRowClick(row);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
className:
|
|
277
|
+
"cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
|
|
278
|
+
}
|
|
279
|
+
: {})}
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
})}
|
|
245
283
|
</tbody>
|
|
246
284
|
</table>
|
|
247
285
|
</div>
|
|
248
286
|
<div className="flex items-center gap-base border-t border-hairline px-base py-sm">
|
|
249
287
|
<span className="shrink-0 whitespace-nowrap text-body-sm text-muted">
|
|
250
288
|
{selected.length > 0 ? `${selected.length} selected · ` : ""}
|
|
251
|
-
{rows.length}
|
|
289
|
+
{countLabel(rows.length)}
|
|
252
290
|
</span>
|
|
253
291
|
<div className="ml-auto flex justify-end">
|
|
254
292
|
<Pagination pageCount={pageCount} page={safePage} onPageChange={setPage} size="sm" />
|
|
@@ -3,6 +3,7 @@ import { Button } from "../Button";
|
|
|
3
3
|
import { Checkbox } from "../Checkbox";
|
|
4
4
|
import { Chip } from "../Chip";
|
|
5
5
|
import { Icon, type IconName } from "../Icon";
|
|
6
|
+
import { Pagination } from "../Pagination";
|
|
6
7
|
import { TableHeaderCell, type TableSort } from "../TableHeaderCell";
|
|
7
8
|
import { TableRow } from "../TableRow";
|
|
8
9
|
|
|
@@ -26,6 +27,8 @@ export interface DataTableMobileProps<R extends DataTableMobileRecord = DataTabl
|
|
|
26
27
|
columns: DataTableMobileColumn<R>[];
|
|
27
28
|
rows: R[];
|
|
28
29
|
rowLabelKey?: string;
|
|
30
|
+
/** Rendered as a toolbar row above the list (for example a search field). */
|
|
31
|
+
toolbarStart?: React.ReactNode;
|
|
29
32
|
filters?: Array<{ id: string; label: string }>;
|
|
30
33
|
onRemoveFilter?: (id: string) => void;
|
|
31
34
|
onClearFilters?: () => void;
|
|
@@ -33,6 +36,16 @@ export interface DataTableMobileProps<R extends DataTableMobileRecord = DataTabl
|
|
|
33
36
|
onSortChange?: (sort: { key: string; direction: Exclude<TableSort, "none"> } | null) => void;
|
|
34
37
|
selectedIds?: string[];
|
|
35
38
|
onSelectionChange?: (ids: string[]) => void;
|
|
39
|
+
/** Fires when a row (not its checkbox) is tapped or Entered. */
|
|
40
|
+
onRowClick?: (row: R) => void;
|
|
41
|
+
/** Muted second line under the first column's content. */
|
|
42
|
+
mobileDescription?: (row: R) => React.ReactNode;
|
|
43
|
+
/** Footer count text; defaults to "n records". */
|
|
44
|
+
countLabel?: (count: number) => string;
|
|
45
|
+
pageSize?: number;
|
|
46
|
+
/** Controlled page (1-based). Leave undefined for uncontrolled paging. */
|
|
47
|
+
page?: number;
|
|
48
|
+
onPageChange?: (page: number) => void;
|
|
36
49
|
emptyTitle?: string;
|
|
37
50
|
emptyDescription?: string;
|
|
38
51
|
importLabel?: string;
|
|
@@ -50,12 +63,19 @@ export function DataTableMobileInner<R extends DataTableMobileRecord>(
|
|
|
50
63
|
columns,
|
|
51
64
|
rows,
|
|
52
65
|
rowLabelKey,
|
|
66
|
+
toolbarStart,
|
|
53
67
|
filters = [],
|
|
54
68
|
onRemoveFilter,
|
|
55
69
|
sort: sortProp,
|
|
56
70
|
onSortChange,
|
|
57
71
|
selectedIds,
|
|
58
72
|
onSelectionChange,
|
|
73
|
+
onRowClick,
|
|
74
|
+
mobileDescription,
|
|
75
|
+
countLabel = (count: number) => `${count} records`,
|
|
76
|
+
pageSize = 10,
|
|
77
|
+
page: pageProp,
|
|
78
|
+
onPageChange,
|
|
59
79
|
emptyTitle = "No companies yet",
|
|
60
80
|
emptyDescription = "Import companies to get started.",
|
|
61
81
|
importLabel = "Import companies",
|
|
@@ -80,6 +100,12 @@ export function DataTableMobileInner<R extends DataTableMobileRecord>(
|
|
|
80
100
|
if (selectedIds === undefined) setInnerSel(ids);
|
|
81
101
|
onSelectionChange?.(ids);
|
|
82
102
|
};
|
|
103
|
+
const [innerPage, setInnerPage] = React.useState(1);
|
|
104
|
+
const page = pageProp ?? innerPage;
|
|
105
|
+
const setPage = (next: number) => {
|
|
106
|
+
if (pageProp === undefined) setInnerPage(next);
|
|
107
|
+
onPageChange?.(next);
|
|
108
|
+
};
|
|
83
109
|
|
|
84
110
|
const sorted = React.useMemo(() => {
|
|
85
111
|
if (!sort) return rows;
|
|
@@ -87,6 +113,10 @@ export function DataTableMobileInner<R extends DataTableMobileRecord>(
|
|
|
87
113
|
return sort.direction === "descending" ? out.reverse() : out;
|
|
88
114
|
}, [rows, sort]);
|
|
89
115
|
|
|
116
|
+
const pageCount = Math.max(1, Math.ceil(sorted.length / pageSize));
|
|
117
|
+
const safePage = Math.min(Math.max(page, 1), pageCount);
|
|
118
|
+
const visible = sorted.slice((safePage - 1) * pageSize, safePage * pageSize);
|
|
119
|
+
|
|
90
120
|
const allIds = rows.map((r) => r.id);
|
|
91
121
|
const allSelected = allIds.length > 0 && allIds.every((id) => selected.includes(id));
|
|
92
122
|
const someSelected = !allSelected && allIds.some((id) => selected.includes(id));
|
|
@@ -98,6 +128,10 @@ export function DataTableMobileInner<R extends DataTableMobileRecord>(
|
|
|
98
128
|
className={cn("flex w-full flex-col overflow-hidden rounded-xl border border-hairline bg-surface shadow-card", className)}
|
|
99
129
|
{...rest}
|
|
100
130
|
>
|
|
131
|
+
{toolbarStart ? (
|
|
132
|
+
<div className="flex items-center gap-sm border-b border-hairline px-md py-sm">{toolbarStart}</div>
|
|
133
|
+
) : null}
|
|
134
|
+
|
|
101
135
|
{filters.length > 0 ? (
|
|
102
136
|
<div className="flex flex-wrap items-center gap-sm border-b border-hairline px-md py-sm">
|
|
103
137
|
{filters.map((f) => (
|
|
@@ -116,51 +150,89 @@ export function DataTableMobileInner<R extends DataTableMobileRecord>(
|
|
|
116
150
|
</Button>
|
|
117
151
|
</div>
|
|
118
152
|
) : (
|
|
119
|
-
|
|
120
|
-
<
|
|
121
|
-
<
|
|
122
|
-
<
|
|
123
|
-
<
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
<>
|
|
154
|
+
<div className="w-full overflow-x-auto">
|
|
155
|
+
<table className="w-full border-collapse" aria-label={label}>
|
|
156
|
+
<thead>
|
|
157
|
+
<tr>
|
|
158
|
+
<th scope="col" className="w-10 border-b border-hairline bg-surface py-0 pl-base pr-xs text-left align-middle">
|
|
159
|
+
<Checkbox
|
|
160
|
+
aria-label={allSelected ? "Deselect all rows" : "Select all rows"}
|
|
161
|
+
checked={allSelected}
|
|
162
|
+
indeterminate={someSelected}
|
|
163
|
+
onCheckedChange={(v) => setSelected(v ? allIds : [])}
|
|
164
|
+
className="flex"
|
|
165
|
+
/>
|
|
166
|
+
</th>
|
|
167
|
+
{col ? (
|
|
168
|
+
<TableHeaderCell
|
|
169
|
+
label={col.label}
|
|
170
|
+
icon={col.icon}
|
|
171
|
+
className="min-w-0"
|
|
172
|
+
sort={sort?.key === col.key ? sort.direction : "none"}
|
|
173
|
+
onSortChange={
|
|
174
|
+
col.sortable
|
|
175
|
+
? (next) => setSort(next === "none" ? null : { key: col.key, direction: next })
|
|
176
|
+
: undefined
|
|
177
|
+
}
|
|
178
|
+
/>
|
|
179
|
+
) : null}
|
|
180
|
+
</tr>
|
|
181
|
+
</thead>
|
|
182
|
+
<tbody>
|
|
183
|
+
{visible.map((row) => {
|
|
184
|
+
const rowLabel = labelKey ? String(row[labelKey] ?? row.id) : row.id;
|
|
185
|
+
const content = col ? (col.render ? col.render(row) : (row[col.key] as React.ReactNode)) : null;
|
|
186
|
+
const description = mobileDescription?.(row);
|
|
187
|
+
return (
|
|
188
|
+
<TableRow
|
|
189
|
+
key={row.id}
|
|
190
|
+
selectable
|
|
191
|
+
selected={selected.includes(row.id)}
|
|
192
|
+
onSelectedChange={(v) =>
|
|
193
|
+
setSelected(v ? [...selected, row.id] : selected.filter((id) => id !== row.id))
|
|
194
|
+
}
|
|
195
|
+
rowLabel={rowLabel}
|
|
196
|
+
className="[&>td]:h-11"
|
|
197
|
+
cells={[
|
|
198
|
+
description ? (
|
|
199
|
+
<span className="flex min-w-0 flex-col gap-xxs">
|
|
200
|
+
<span className="min-w-0">{content}</span>
|
|
201
|
+
<span className="min-w-0 text-body-sm text-muted">{description}</span>
|
|
202
|
+
</span>
|
|
203
|
+
) : (
|
|
204
|
+
content
|
|
205
|
+
),
|
|
206
|
+
]}
|
|
207
|
+
{...(onRowClick
|
|
208
|
+
? {
|
|
209
|
+
onClick: () => onRowClick(row),
|
|
210
|
+
tabIndex: 0,
|
|
211
|
+
"aria-label": `Open ${rowLabel}`,
|
|
212
|
+
onKeyDown: (event: React.KeyboardEvent<HTMLTableRowElement>) => {
|
|
213
|
+
if (event.key === "Enter") {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
onRowClick(row);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
}
|
|
219
|
+
: {})}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</tbody>
|
|
224
|
+
</table>
|
|
225
|
+
</div>
|
|
226
|
+
<div className="flex items-center gap-base border-t border-hairline px-md py-sm">
|
|
227
|
+
<span className="shrink-0 whitespace-nowrap text-body-sm text-muted">
|
|
228
|
+
{selected.length > 0 ? `${selected.length} selected · ` : ""}
|
|
229
|
+
{countLabel(rows.length)}
|
|
230
|
+
</span>
|
|
231
|
+
<div className="ml-auto flex justify-end">
|
|
232
|
+
<Pagination pageCount={pageCount} page={safePage} onPageChange={setPage} size="sm" />
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
</>
|
|
164
236
|
)}
|
|
165
237
|
</div>
|
|
166
238
|
);
|