@algorithm-shift/design-system 1.2.46 → 1.2.47

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.d.mts CHANGED
@@ -247,7 +247,14 @@ declare const DateRange: ({ className, style, ...props }: DateRangeInputProps) =
247
247
 
248
248
  declare const TextInputGroup: ({ className, style, prepend, append, ...props }: TextInputGroupProps) => react_jsx_runtime.JSX.Element;
249
249
 
250
- declare const Table: ({ columns, data, rowActions, className, style, pagination, itemsPerPage, onPageChange, loading, totalRecords, ...props }: TableProps) => react_jsx_runtime.JSX.Element;
250
+ type PaginationMode = 'client' | 'server';
251
+ interface ExtendedTableProps extends TableProps {
252
+ paginationMode?: PaginationMode;
253
+ page?: number;
254
+ itemsPerPage?: number;
255
+ onPageChange?: (page: number) => void;
256
+ }
257
+ declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, page, loading, totalRecords, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
251
258
 
252
259
  interface CustomPaginationProps {
253
260
  totalPages: number;
package/dist/index.d.ts CHANGED
@@ -247,7 +247,14 @@ declare const DateRange: ({ className, style, ...props }: DateRangeInputProps) =
247
247
 
248
248
  declare const TextInputGroup: ({ className, style, prepend, append, ...props }: TextInputGroupProps) => react_jsx_runtime.JSX.Element;
249
249
 
250
- declare const Table: ({ columns, data, rowActions, className, style, pagination, itemsPerPage, onPageChange, loading, totalRecords, ...props }: TableProps) => react_jsx_runtime.JSX.Element;
250
+ type PaginationMode = 'client' | 'server';
251
+ interface ExtendedTableProps extends TableProps {
252
+ paginationMode?: PaginationMode;
253
+ page?: number;
254
+ itemsPerPage?: number;
255
+ onPageChange?: (page: number) => void;
256
+ }
257
+ declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, page, loading, totalRecords, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
251
258
 
252
259
  interface CustomPaginationProps {
253
260
  totalPages: number;
package/dist/index.js CHANGED
@@ -1944,6 +1944,9 @@ var TextInputGroup = ({ className, style, prepend, append, ...props }) => {
1944
1944
  };
1945
1945
  var TextInputGroup_default = TextInputGroup;
1946
1946
 
1947
+ // src/components/DataDisplay/Table/Table.tsx
1948
+ var import_react6 = require("react");
1949
+
1947
1950
  // src/components/ui/data-table.tsx
1948
1951
  var import_react_table = require("@tanstack/react-table");
1949
1952
 
@@ -2278,7 +2281,6 @@ var CustomPagination = ({
2278
2281
  var Pagination_default = CustomPagination;
2279
2282
 
2280
2283
  // src/components/DataDisplay/Table/Table.tsx
2281
- var import_react6 = require("react");
2282
2284
  var import_jsx_runtime44 = require("react/jsx-runtime");
2283
2285
  var Table2 = ({
2284
2286
  columns,
@@ -2287,8 +2289,10 @@ var Table2 = ({
2287
2289
  className,
2288
2290
  style,
2289
2291
  pagination = false,
2292
+ paginationMode = "client",
2290
2293
  itemsPerPage = 10,
2291
2294
  onPageChange,
2295
+ page,
2292
2296
  loading = false,
2293
2297
  totalRecords = 0,
2294
2298
  ...props
@@ -2296,14 +2300,29 @@ var Table2 = ({
2296
2300
  const rawColumns = Array.isArray(columns) ? columns : [];
2297
2301
  const rawData = Array.isArray(data) ? data : [];
2298
2302
  const rawRowActions = Array.isArray(rowActions) ? rowActions : [];
2299
- const [currentPage, setCurrentPage] = (0, import_react6.useState)(1);
2300
- const enablePagination = pagination && totalRecords > itemsPerPage;
2301
- const handlePageChange = (page) => {
2302
- setCurrentPage(page);
2303
- onPageChange?.(page);
2303
+ const isControlled = typeof page === "number";
2304
+ const [internalPage, setInternalPage] = (0, import_react6.useState)(1);
2305
+ const currentPage = isControlled ? page : internalPage;
2306
+ (0, import_react6.useEffect)(() => {
2307
+ if (isControlled) return;
2308
+ if (currentPage > 1 && !pagination) setInternalPage(1);
2309
+ }, [pagination, isControlled]);
2310
+ const enablePagination = pagination && (paginationMode === "server" ? totalRecords > itemsPerPage : rawData.length > itemsPerPage);
2311
+ const handlePageChange = (next) => {
2312
+ if (!isControlled) setInternalPage(next);
2313
+ onPageChange?.(next);
2304
2314
  };
2305
- const paginatedData = enablePagination ? rawData.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage) : rawData;
2306
- return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: `${className} space-y-3`, style, children: [
2315
+ const paginatedData = !enablePagination ? rawData : paginationMode === "server" ? rawData : rawData.slice(
2316
+ (currentPage - 1) * itemsPerPage,
2317
+ currentPage * itemsPerPage
2318
+ );
2319
+ const totalPages = enablePagination ? Math.max(
2320
+ 1,
2321
+ Math.ceil(
2322
+ (paginationMode === "server" ? totalRecords : rawData.length) / itemsPerPage
2323
+ )
2324
+ ) : 1;
2325
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: `${className || ""} space-y-3`, style, children: [
2307
2326
  /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
2308
2327
  DataTable,
2309
2328
  {
@@ -2317,7 +2336,7 @@ var Table2 = ({
2317
2336
  enablePagination && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
2318
2337
  Pagination_default,
2319
2338
  {
2320
- totalPages: Math.ceil(totalRecords / itemsPerPage),
2339
+ totalPages,
2321
2340
  currentPage,
2322
2341
  onPageChange: handlePageChange
2323
2342
  }