@algorithm-shift/design-system 1.2.46 → 1.2.48

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.ts CHANGED
@@ -97,7 +97,6 @@ interface TableProps extends ElementProps {
97
97
  data?: Record<string, any>;
98
98
  pagination?: boolean;
99
99
  itemsPerPage?: number;
100
- onPageChange?: (page: number) => void;
101
100
  loading?: boolean;
102
101
  cellClickEnabled?: (cellData: Record<string, any>, columnId: string) => boolean;
103
102
  onCellClick?: (cellData: Record<string, any>, columnId: string) => void;
@@ -247,15 +246,31 @@ declare const DateRange: ({ className, style, ...props }: DateRangeInputProps) =
247
246
 
248
247
  declare const TextInputGroup: ({ className, style, prepend, append, ...props }: TextInputGroupProps) => react_jsx_runtime.JSX.Element;
249
248
 
250
- declare const Table: ({ columns, data, rowActions, className, style, pagination, itemsPerPage, onPageChange, loading, totalRecords, ...props }: TableProps) => react_jsx_runtime.JSX.Element;
251
-
252
- interface CustomPaginationProps {
253
- totalPages: number;
254
- currentPage: number;
255
- onPageChange: (page: number) => void;
256
- maxVisiblePages?: number;
249
+ interface PageChangeProps {
250
+ page: number;
251
+ itemsPerPage: number;
252
+ }
253
+
254
+ interface CustomPaginationProps {
255
+ totalPages: number;
256
+ currentPage: number;
257
+ onPageChange: (props: PageChangeProps) => void;
258
+ maxVisiblePages?: number;
259
+ perPage: number;
260
+ }
261
+
262
+ type PaginationMode = 'client' | 'server';
263
+
264
+ interface ExtendedTableProps extends TableProps {
265
+ paginationMode?: PaginationMode;
266
+ page?: number;
267
+ itemsPerPage?: number;
268
+ onPageChange?: (props: PageChangeProps) => void;
257
269
  }
258
- declare const CustomPagination: ({ totalPages, currentPage, onPageChange, maxVisiblePages, }: CustomPaginationProps) => react_jsx_runtime.JSX.Element;
270
+
271
+ declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, page, loading, totalRecords, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
272
+
273
+ declare const CustomPagination: ({ totalPages, currentPage, onPageChange, maxVisiblePages, perPage, }: CustomPaginationProps) => react_jsx_runtime.JSX.Element;
259
274
 
260
275
  declare const Tabs: ({ className, style, tabs, verticalMenu, LinkComponent, pathname, canvasMode }: TabsProps) => react_jsx_runtime.JSX.Element;
261
276
 
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
 
@@ -2212,7 +2215,8 @@ var CustomPagination = ({
2212
2215
  totalPages,
2213
2216
  currentPage,
2214
2217
  onPageChange,
2215
- maxVisiblePages = 5
2218
+ maxVisiblePages = 5,
2219
+ perPage
2216
2220
  }) => {
2217
2221
  const getPageNumbers = () => {
2218
2222
  const pages = [];
@@ -2245,40 +2249,65 @@ var CustomPagination = ({
2245
2249
  };
2246
2250
  const handlePageChange = (page) => {
2247
2251
  if (page >= 1 && page <= totalPages && page !== currentPage) {
2248
- onPageChange(page);
2252
+ onPageChange({
2253
+ page,
2254
+ itemsPerPage: perPage
2255
+ });
2249
2256
  }
2250
2257
  };
2251
2258
  const pageNumbers = getPageNumbers();
2252
- return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Pagination, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(PaginationContent, { children: [
2253
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2254
- PaginationPrevious,
2255
- {
2256
- onClick: () => handlePageChange(currentPage - 1),
2257
- className: currentPage === 1 ? "pointer-events-none opacity-50" : "cursor-pointer"
2258
- }
2259
- ) }),
2260
- pageNumbers.map((pageNumber, index) => /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: pageNumber === "..." ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationEllipsis, {}) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2261
- PaginationLink,
2262
- {
2263
- onClick: () => handlePageChange(pageNumber),
2264
- isActive: currentPage === pageNumber,
2265
- className: "cursor-pointer",
2266
- children: pageNumber
2267
- }
2268
- ) }, index)),
2269
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2270
- PaginationNext,
2271
- {
2272
- onClick: () => handlePageChange(currentPage + 1),
2273
- className: currentPage === totalPages ? "pointer-events-none opacity-50" : "cursor-pointer"
2274
- }
2275
- ) })
2276
- ] }) });
2259
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "flex flex-col gap-4 items-center", children: [
2260
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "flex items-center gap-2", children: [
2261
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-sm text-muted-foreground", children: "Items per page:" }),
2262
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
2263
+ Select,
2264
+ {
2265
+ value: String(perPage),
2266
+ onValueChange: (value) => {
2267
+ onPageChange({ page: 1, itemsPerPage: Number(value) });
2268
+ },
2269
+ children: [
2270
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectTrigger, { className: "w-[100px]", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectValue, { placeholder: "Select" }) }),
2271
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(SelectContent, { children: [
2272
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectItem, { value: "5", children: "5" }),
2273
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectItem, { value: "10", children: "10" }),
2274
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectItem, { value: "20", children: "20" }),
2275
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SelectItem, { value: "50", children: "50" })
2276
+ ] })
2277
+ ]
2278
+ }
2279
+ )
2280
+ ] }),
2281
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Pagination, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(PaginationContent, { children: [
2282
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2283
+ PaginationPrevious,
2284
+ {
2285
+ onClick: () => handlePageChange(currentPage - 1),
2286
+ className: currentPage === 1 ? "pointer-events-none opacity-50" : "cursor-pointer"
2287
+ }
2288
+ ) }),
2289
+ pageNumbers.map((pageNumber, index) => /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: pageNumber === "..." ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationEllipsis, {}) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2290
+ PaginationLink,
2291
+ {
2292
+ onClick: () => handlePageChange(pageNumber),
2293
+ isActive: currentPage === pageNumber,
2294
+ className: "cursor-pointer",
2295
+ children: pageNumber
2296
+ }
2297
+ ) }, index)),
2298
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PaginationItem, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
2299
+ PaginationNext,
2300
+ {
2301
+ onClick: () => handlePageChange(currentPage + 1),
2302
+ className: currentPage === totalPages ? "pointer-events-none opacity-50" : "cursor-pointer"
2303
+ }
2304
+ ) })
2305
+ ] }) })
2306
+ ] });
2277
2307
  };
2278
2308
  var Pagination_default = CustomPagination;
2279
2309
 
2280
2310
  // src/components/DataDisplay/Table/Table.tsx
2281
- var import_react6 = require("react");
2282
2311
  var import_jsx_runtime44 = require("react/jsx-runtime");
2283
2312
  var Table2 = ({
2284
2313
  columns,
@@ -2287,23 +2316,41 @@ var Table2 = ({
2287
2316
  className,
2288
2317
  style,
2289
2318
  pagination = false,
2319
+ paginationMode = "client",
2290
2320
  itemsPerPage = 10,
2291
2321
  onPageChange,
2322
+ page,
2292
2323
  loading = false,
2293
2324
  totalRecords = 0,
2294
2325
  ...props
2295
2326
  }) => {
2327
+ const [perPage, setPerPage] = (0, import_react6.useState)(itemsPerPage);
2296
2328
  const rawColumns = Array.isArray(columns) ? columns : [];
2297
2329
  const rawData = Array.isArray(data) ? data : [];
2298
2330
  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);
2331
+ const isControlled = typeof page === "number";
2332
+ const [internalPage, setInternalPage] = (0, import_react6.useState)(1);
2333
+ const currentPage = isControlled ? page : internalPage;
2334
+ (0, import_react6.useEffect)(() => {
2335
+ if (isControlled) return;
2336
+ if (currentPage > 1 && !pagination) setInternalPage(1);
2337
+ }, [pagination, isControlled]);
2338
+ const enablePagination = pagination && (paginationMode === "server" ? totalRecords > perPage : rawData.length > perPage);
2339
+ const handlePageChange = ({ page: page2, itemsPerPage: itemsPerPage2 }) => {
2340
+ if (!isControlled) setInternalPage(page2);
2341
+ onPageChange?.({ page: page2, itemsPerPage: itemsPerPage2 });
2304
2342
  };
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: [
2343
+ const paginatedData = !enablePagination ? rawData : paginationMode === "server" ? rawData : rawData.slice(
2344
+ (currentPage - 1) * perPage,
2345
+ currentPage * perPage
2346
+ );
2347
+ const totalPages = enablePagination ? Math.max(
2348
+ 1,
2349
+ Math.ceil(
2350
+ (paginationMode === "server" ? totalRecords : rawData.length) / perPage
2351
+ )
2352
+ ) : 1;
2353
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: `${className || ""} space-y-3`, style, children: [
2307
2354
  /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
2308
2355
  DataTable,
2309
2356
  {
@@ -2317,7 +2364,8 @@ var Table2 = ({
2317
2364
  enablePagination && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
2318
2365
  Pagination_default,
2319
2366
  {
2320
- totalPages: Math.ceil(totalRecords / itemsPerPage),
2367
+ perPage,
2368
+ totalPages,
2321
2369
  currentPage,
2322
2370
  onPageChange: handlePageChange
2323
2371
  }