@underverse-ui/underverse 0.1.26 → 0.1.28

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/index.cjs CHANGED
@@ -7147,6 +7147,7 @@ function DataTable({
7147
7147
  total = 0,
7148
7148
  page = 1,
7149
7149
  pageSize = 20,
7150
+ pageSizeOptions,
7150
7151
  onQueryChange,
7151
7152
  caption,
7152
7153
  toolbar,
@@ -7165,6 +7166,12 @@ function DataTable({
7165
7166
  const [curPage, setCurPage] = import_react21.default.useState(page);
7166
7167
  const [curPageSize, setCurPageSize] = import_react21.default.useState(pageSize);
7167
7168
  const debouncedFilters = useDebounced(filters, 350);
7169
+ import_react21.default.useEffect(() => {
7170
+ setCurPage(page);
7171
+ }, [page]);
7172
+ import_react21.default.useEffect(() => {
7173
+ setCurPageSize(pageSize);
7174
+ }, [pageSize]);
7168
7175
  import_react21.default.useEffect(() => {
7169
7176
  if (!onQueryChange) return;
7170
7177
  onQueryChange({ filters: debouncedFilters, sort, page: curPage, pageSize: curPageSize });
@@ -7326,6 +7333,12 @@ function DataTable({
7326
7333
  },
7327
7334
  col.key
7328
7335
  )) });
7336
+ const isServerMode = Boolean(onQueryChange);
7337
+ const displayedData = isServerMode ? data : import_react21.default.useMemo(() => {
7338
+ const start = (curPage - 1) * curPageSize;
7339
+ return data.slice(start, start + curPageSize);
7340
+ }, [data, curPage, curPageSize]);
7341
+ const totalItems = isServerMode ? total : data.length;
7329
7342
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: cn("space-y-2", className), children: [
7330
7343
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "flex items-center justify-between gap-4 mb-1", children: [
7331
7344
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "text-sm text-muted-foreground", children: caption }),
@@ -7397,7 +7410,7 @@ function DataTable({
7397
7410
  )
7398
7411
  ] }),
7399
7412
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "text-sm", children: "Loading..." })
7400
- ] }) }) }) : !data || data.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableCell, { colSpan: visibleColumns.length, className: "text-center py-6 text-muted-foreground", children: "No data" }) }) : data.map((row, idx) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableRow, { className: cn(densityRowClass, striped && idx % 2 === 0 && "bg-muted/30"), children: visibleColumns.map((col) => {
7413
+ ] }) }) }) : !displayedData || displayedData.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableCell, { colSpan: visibleColumns.length, className: "text-center py-6 text-muted-foreground", children: "No data" }) }) : displayedData.map((row, idx) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(TableRow, { className: cn(densityRowClass, striped && idx % 2 === 0 && "bg-muted/30"), children: visibleColumns.map((col) => {
7401
7414
  const value = col.dataIndex ? row[col.dataIndex] : void 0;
7402
7415
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7403
7416
  TableCell,
@@ -7417,16 +7430,21 @@ function DataTable({
7417
7430
  ]
7418
7431
  }
7419
7432
  ) }),
7420
- total > 0 && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "border-t bg-muted/30 p-4 rounded-b-lg", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7433
+ totalItems > 0 && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "border-t bg-muted/30 p-4 rounded-b-lg", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7421
7434
  Pagination,
7422
7435
  {
7423
7436
  page: curPage,
7424
- totalPages: Math.ceil(total / curPageSize),
7437
+ totalPages: Math.ceil(totalItems / curPageSize),
7425
7438
  onChange: (p) => setCurPage(p),
7426
7439
  className: "",
7427
7440
  showInfo: true,
7428
- totalItems: total,
7429
- pageSize: curPageSize
7441
+ totalItems,
7442
+ pageSize: curPageSize,
7443
+ pageSizeOptions,
7444
+ onPageSizeChange: (s) => {
7445
+ setCurPage(1);
7446
+ setCurPageSize(s);
7447
+ }
7430
7448
  }
7431
7449
  ) })
7432
7450
  ] });