@algorithm-shift/design-system 1.2.86 → 1.2.87

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
@@ -195,7 +195,7 @@ interface NavbarProps extends ElementProps {
195
195
  showName?: boolean;
196
196
  imageUrl?: string;
197
197
  altText?: string;
198
- canvasMode?: 'desktop' | 'tablet' | 'mobile';
198
+ canvasMode?: 'desktop' | 'tablet' | 'mobile' | string;
199
199
  list?: Record<string, any>;
200
200
  profileMenu?: Record<string, any>;
201
201
  userName?: string;
@@ -256,8 +256,10 @@ interface RepeaterProps<T> {
256
256
  emptyFallback?: React__default.ReactNode;
257
257
  wrapper?: (children: React__default.ReactNode) => React__default.ReactNode;
258
258
  className?: string;
259
+ loading?: boolean;
260
+ loadingText?: string;
259
261
  }
260
- declare function Repeater<T>({ items, count, render, emptyFallback, wrapper, className, }: RepeaterProps<T>): react_jsx_runtime.JSX.Element;
262
+ declare function Repeater<T>({ items, count, render, emptyFallback, wrapper, className, loading, loadingText, }: RepeaterProps<T>): react_jsx_runtime.JSX.Element;
261
263
  declare const _default$2: typeof Repeater;
262
264
 
263
265
  declare const ButtonWrapper: ({ className, style, textContent, loadingText, loading, ...props }: ButtonProps) => react_jsx_runtime.JSX.Element;
@@ -367,7 +369,7 @@ interface ExtendedTableProps extends TableProps {
367
369
  enableDelete?: boolean;
368
370
  }
369
371
 
370
- declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, onSortChange, onFilterChange, onGlobalSearch, page, loading, totalRecords, globalSearch, onCellClick, enableDelete, onDeleteRow, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
372
+ declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, onSortChange, onFilterChange, onGlobalSearch, page, loading, totalRecords, globalSearch, onCellClick, onDeleteRow, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
371
373
 
372
374
  declare const CustomPagination: ({ totalPages, currentPage, onPageChange, maxVisiblePages, perPage, }: CustomPaginationProps) => react_jsx_runtime.JSX.Element;
373
375
 
package/dist/index.d.ts CHANGED
@@ -195,7 +195,7 @@ interface NavbarProps extends ElementProps {
195
195
  showName?: boolean;
196
196
  imageUrl?: string;
197
197
  altText?: string;
198
- canvasMode?: 'desktop' | 'tablet' | 'mobile';
198
+ canvasMode?: 'desktop' | 'tablet' | 'mobile' | string;
199
199
  list?: Record<string, any>;
200
200
  profileMenu?: Record<string, any>;
201
201
  userName?: string;
@@ -256,8 +256,10 @@ interface RepeaterProps<T> {
256
256
  emptyFallback?: React__default.ReactNode;
257
257
  wrapper?: (children: React__default.ReactNode) => React__default.ReactNode;
258
258
  className?: string;
259
+ loading?: boolean;
260
+ loadingText?: string;
259
261
  }
260
- declare function Repeater<T>({ items, count, render, emptyFallback, wrapper, className, }: RepeaterProps<T>): react_jsx_runtime.JSX.Element;
262
+ declare function Repeater<T>({ items, count, render, emptyFallback, wrapper, className, loading, loadingText, }: RepeaterProps<T>): react_jsx_runtime.JSX.Element;
261
263
  declare const _default$2: typeof Repeater;
262
264
 
263
265
  declare const ButtonWrapper: ({ className, style, textContent, loadingText, loading, ...props }: ButtonProps) => react_jsx_runtime.JSX.Element;
@@ -367,7 +369,7 @@ interface ExtendedTableProps extends TableProps {
367
369
  enableDelete?: boolean;
368
370
  }
369
371
 
370
- declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, onSortChange, onFilterChange, onGlobalSearch, page, loading, totalRecords, globalSearch, onCellClick, enableDelete, onDeleteRow, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
372
+ declare const Table: ({ columns, data, rowActions, className, style, pagination, paginationMode, itemsPerPage, onPageChange, onSortChange, onFilterChange, onGlobalSearch, page, loading, totalRecords, globalSearch, onCellClick, onDeleteRow, ...props }: ExtendedTableProps) => react_jsx_runtime.JSX.Element;
371
373
 
372
374
  declare const CustomPagination: ({ totalPages, currentPage, onPageChange, maxVisiblePages, perPage, }: CustomPaginationProps) => react_jsx_runtime.JSX.Element;
373
375
 
package/dist/index.js CHANGED
@@ -323,12 +323,17 @@ function Repeater({
323
323
  render,
324
324
  emptyFallback = null,
325
325
  wrapper,
326
- className
326
+ className,
327
+ loading = false,
328
+ loadingText = "Loading..."
327
329
  }) {
328
330
  const list = import_react4.default.useMemo(
329
331
  () => typeof count === "number" ? items.slice(0, count) : items,
330
332
  [items, count]
331
333
  );
334
+ if (loading) {
335
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, children: loadingText });
336
+ }
332
337
  if (!list.length) {
333
338
  return emptyFallback ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: emptyFallback }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, children: "No items to display." });
334
339
  }
@@ -27814,6 +27819,31 @@ function useLazyDropdown(config) {
27814
27819
  setLoading(false);
27815
27820
  }
27816
27821
  }, [fetchApiData, transformToOptions]);
27822
+ const fetchValueItem = async () => {
27823
+ if (!configRef.current.apiUrl) return [];
27824
+ try {
27825
+ setLoading(true);
27826
+ const res = await import_axios.default.get(configRef.current.apiUrl, {
27827
+ params: { [configRef.current.dataKey]: configRef.current.value },
27828
+ withCredentials: true
27829
+ });
27830
+ if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
27831
+ const fetched = transformToOptions(res.data.data);
27832
+ setOptions((prev) => [...fetched, ...prev]);
27833
+ }
27834
+ } catch (err) {
27835
+ console.warn("\u26A0\uFE0F Failed to fetch default value for dropdown:", err);
27836
+ } finally {
27837
+ setLoading(false);
27838
+ }
27839
+ };
27840
+ (0, import_react19.useEffect)(() => {
27841
+ const cfg = configRef.current;
27842
+ if (!cfg.enabled || !cfg.value || cfg.dataSource !== "api" || !cfg.apiUrl) return;
27843
+ const valueExists = options.some((opt) => opt.value === cfg.value);
27844
+ if (valueExists) return;
27845
+ fetchValueItem();
27846
+ }, [config.value, config.dataKey, config.apiUrl, config.dataSource, transformToOptions]);
27817
27847
  const loadMore = (0, import_react19.useCallback)(() => {
27818
27848
  if (!loading && hasMore) {
27819
27849
  loadPage(page + 1, searchTerm);
@@ -27890,7 +27920,8 @@ function LazySelectDropdown({
27890
27920
  pageSize: pageSize || 10,
27891
27921
  dataKey,
27892
27922
  dataLabel,
27893
- initialData: options || []
27923
+ initialData: options || [],
27924
+ value
27894
27925
  });
27895
27926
  const selectedOption = lazyOptions.find((opt) => opt.value === value);
27896
27927
  (0, import_react20.useEffect)(() => {
@@ -27955,7 +27986,7 @@ function LazySelectDropdown({
27955
27986
  "div",
27956
27987
  {
27957
27988
  onMouseDown: (e) => e.stopPropagation(),
27958
- className: "absolute z-[9999] w-fit mt-1 bg-white border border-gray-300 rounded-lg shadow-lg max-h-60 overflow-y-auto",
27989
+ className: "absolute z-[900] w-fit mt-1 bg-white border border-gray-300 rounded-lg shadow-lg max-h-60 overflow-y-auto",
27959
27990
  style: {
27960
27991
  width: dropdownRef.current?.offsetWidth,
27961
27992
  top: dropdownRef.current ? dropdownRef.current.getBoundingClientRect().bottom + window.scrollY : 0,
@@ -29326,7 +29357,10 @@ var useDynamicColumns = (config, customRenderers = {}, customFormatters = {}) =>
29326
29357
  col.format,
29327
29358
  customFormatters
29328
29359
  );
29329
- }
29360
+ },
29361
+ enableSorting: col.enableSorting,
29362
+ enableColumnFilter: col.enableColumnFilter,
29363
+ meta: col.meta
29330
29364
  });
29331
29365
  });
29332
29366
  };
@@ -29349,37 +29383,13 @@ function DataTable({
29349
29383
  globalSearch,
29350
29384
  onCellClick,
29351
29385
  onDeleteRow,
29352
- enableDelete
29386
+ rowActions
29353
29387
  }) {
29354
29388
  const [columnFilters, setColumnFilters] = React9.useState([]);
29355
29389
  const [columnVisibility, setColumnVisibility] = React9.useState({});
29356
29390
  const [manualSort, setManualSort] = React9.useState(null);
29357
29391
  const [searchTerm, setSearchTerm] = React9.useState("");
29358
- const deleteColumn = React9.useMemo(() => ({
29359
- id: "delete",
29360
- header: "Actions",
29361
- cell: ({ row }) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
29362
- "button",
29363
- {
29364
- className: "px-3 py-1 text-[12px] bg-red-800 text-white rounded hover:bg-neutral-600 cursor-pointer",
29365
- onClick: (event) => {
29366
- event.stopPropagation();
29367
- if (onDeleteRow) {
29368
- onDeleteRow(row.original, "delete");
29369
- }
29370
- },
29371
- children: "Delete"
29372
- }
29373
- ),
29374
- meta: { isClickable: true }
29375
- }), [onDeleteRow]);
29376
- const combinedColumns = React9.useMemo(() => {
29377
- if (enableDelete) {
29378
- return [...columns, deleteColumn];
29379
- }
29380
- return columns;
29381
- }, [columns, enableDelete, deleteColumn]);
29382
- const dynamicCols = useDynamicColumns({ columns: combinedColumns });
29392
+ const dynamicCols = useDynamicColumns({ columns });
29383
29393
  const table = (0, import_react_table2.useReactTable)({
29384
29394
  data,
29385
29395
  columns: dynamicCols,
@@ -29505,7 +29515,7 @@ function DataTable({
29505
29515
  ] })
29506
29516
  ] }),
29507
29517
  /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(Table3, { children: [
29508
- /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableHeader, { children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: hg.headers.map((header) => {
29518
+ /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableHeader, { children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: hg.headers.map((header, index) => {
29509
29519
  const canSort = header.column.getCanSort();
29510
29520
  const canFilter = header.column.getCanFilter();
29511
29521
  const sortDir = manualSort?.key === header.column.id ? manualSort.dir : null;
@@ -29585,26 +29595,49 @@ function DataTable({
29585
29595
  }
29586
29596
  )
29587
29597
  ] })
29588
- ] }) }, header.id);
29589
- }) }, hg.id)) }),
29590
- /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableBody, { children: loading ? /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(import_jsx_runtime53.Fragment, { children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: combinedColumns.map((_2, j) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableCell, { className: "p-3", children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("span", { className: "h-4 bg-gray-200 rounded w-3/4 block animate-pulse" }) }, j)) }, i)) }) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: row.getVisibleCells().map((cell) => {
29598
+ ] }) }, `header-${header.id}-${index}`);
29599
+ }) }, `header-group-${hg.id}`)) }),
29600
+ /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableBody, { children: loading ? /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(import_jsx_runtime53.Fragment, { children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: dynamicCols.map((_2, j) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableCell, { className: "p-3", children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("span", { className: "h-4 bg-gray-200 rounded w-3/4 block animate-pulse" }) }, j)) }, i)) }) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: row.getVisibleCells().map((cell, cellIndex, arr) => {
29591
29601
  const meta = cell.column.columnDef.meta || {};
29592
29602
  const isClickable = meta?.isClickable;
29593
- return /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
29603
+ const isLastCell = cellIndex === arr.length - 1;
29604
+ return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(
29594
29605
  TableCell,
29595
29606
  {
29596
- className: `${meta?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100" : ""}`,
29607
+ className: `${meta?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100" : ""} relative`,
29597
29608
  style: meta?.cellStyle,
29598
29609
  onClick: () => {
29599
29610
  if (isClickable && onCellClick) {
29600
29611
  onCellClick(cell.row.original, cell.column.id);
29601
29612
  }
29602
29613
  },
29603
- children: (0, import_react_table2.flexRender)(cell.column.columnDef.cell, cell.getContext())
29614
+ children: [
29615
+ (0, import_react_table2.flexRender)(cell.column.columnDef.cell, cell.getContext()),
29616
+ isLastCell && rowActions && rowActions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("div", { className: "absolute bg-[#fff] p-1 px-4 inset-y-0 right-0 flex items-center opacity-0 group-hover:opacity-100 transition-opacity duration-200 shadow-lg rounded", children: rowActions.map((action) => {
29617
+ const isDelete = action.id === "delete" || action.icon === "delete";
29618
+ return /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
29619
+ "button",
29620
+ {
29621
+ className: `ml-2 px-2 py-1 text-[12px] rounded cursor-pointer ${isDelete ? "bg-red-800 text-white hover:bg-neutral-600" : "bg-gray-300 hover:bg-gray-400"}`,
29622
+ onClick: (event) => {
29623
+ event.stopPropagation();
29624
+ if (isDelete) {
29625
+ onDeleteRow?.(cell.row.original, "delete");
29626
+ } else {
29627
+ onCellClick?.(cell.row.original, cell.column.id);
29628
+ }
29629
+ },
29630
+ title: action.header,
29631
+ children: action.header
29632
+ },
29633
+ action.id
29634
+ );
29635
+ }) })
29636
+ ]
29604
29637
  },
29605
- cell.id
29638
+ `cell-${cell.id}-${cellIndex}`
29606
29639
  );
29607
- }) }, row.id)) : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableCell, { colSpan: combinedColumns.length, className: "h-24 text-center", children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("span", { className: "flex items-center justify-center py-10 w-full min-w-full text-gray-600 bg-gray-100", children: "No results." }) }) }) })
29640
+ }) }, row.id)) : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(TableCell, { colSpan: dynamicCols.length, className: "h-24 text-center", children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("span", { className: "flex items-center justify-center py-10 w-full min-w-full text-gray-600 bg-gray-100", children: "No results." }) }) }) })
29608
29641
  ] }),
29609
29642
  pagination && /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)("div", { className: "flex items-center justify-between py-3 px-2 text-sm w-full", children: [
29610
29643
  /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)("div", { children: [
@@ -29671,7 +29704,6 @@ var Table4 = ({
29671
29704
  totalRecords = 0,
29672
29705
  globalSearch = false,
29673
29706
  onCellClick,
29674
- enableDelete,
29675
29707
  onDeleteRow,
29676
29708
  ...props
29677
29709
  }) => {
@@ -29703,8 +29735,7 @@ var Table4 = ({
29703
29735
  },
29704
29736
  onDeleteRow: (cell) => {
29705
29737
  onDeleteRow?.(cell.id);
29706
- },
29707
- enableDelete
29738
+ }
29708
29739
  }
29709
29740
  ) });
29710
29741
  };