@algorithm-shift/design-system 1.2.86 → 1.2.88

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.mjs CHANGED
@@ -226,12 +226,17 @@ function Repeater({
226
226
  render,
227
227
  emptyFallback = null,
228
228
  wrapper,
229
- className
229
+ className,
230
+ loading = false,
231
+ loadingText = "Loading..."
230
232
  }) {
231
233
  const list = React3.useMemo(
232
234
  () => typeof count === "number" ? items.slice(0, count) : items,
233
235
  [items, count]
234
236
  );
237
+ if (loading) {
238
+ return /* @__PURE__ */ jsx10("div", { className, children: loadingText });
239
+ }
235
240
  if (!list.length) {
236
241
  return emptyFallback ? /* @__PURE__ */ jsx10(Fragment2, { children: emptyFallback }) : /* @__PURE__ */ jsx10("div", { className, children: "No items to display." });
237
242
  }
@@ -27717,6 +27722,31 @@ function useLazyDropdown(config) {
27717
27722
  setLoading(false);
27718
27723
  }
27719
27724
  }, [fetchApiData, transformToOptions]);
27725
+ const fetchValueItem = async () => {
27726
+ if (!configRef.current.apiUrl) return [];
27727
+ try {
27728
+ setLoading(true);
27729
+ const res = await axios.get(configRef.current.apiUrl, {
27730
+ params: { [configRef.current.dataKey]: configRef.current.value },
27731
+ withCredentials: true
27732
+ });
27733
+ if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
27734
+ const fetched = transformToOptions(res.data.data);
27735
+ setOptions((prev) => [...fetched, ...prev]);
27736
+ }
27737
+ } catch (err) {
27738
+ console.warn("\u26A0\uFE0F Failed to fetch default value for dropdown:", err);
27739
+ } finally {
27740
+ setLoading(false);
27741
+ }
27742
+ };
27743
+ useEffect13(() => {
27744
+ const cfg = configRef.current;
27745
+ if (!cfg.enabled || !cfg.value || cfg.dataSource !== "api" || !cfg.apiUrl) return;
27746
+ const valueExists = options.some((opt) => opt.value === cfg.value);
27747
+ if (valueExists) return;
27748
+ fetchValueItem();
27749
+ }, [config.value, config.dataKey, config.apiUrl, config.dataSource, transformToOptions]);
27720
27750
  const loadMore = useCallback2(() => {
27721
27751
  if (!loading && hasMore) {
27722
27752
  loadPage(page + 1, searchTerm);
@@ -27793,7 +27823,8 @@ function LazySelectDropdown({
27793
27823
  pageSize: pageSize || 10,
27794
27824
  dataKey,
27795
27825
  dataLabel,
27796
- initialData: options || []
27826
+ initialData: options || [],
27827
+ value
27797
27828
  });
27798
27829
  const selectedOption = lazyOptions.find((opt) => opt.value === value);
27799
27830
  useEffect14(() => {
@@ -27858,7 +27889,7 @@ function LazySelectDropdown({
27858
27889
  "div",
27859
27890
  {
27860
27891
  onMouseDown: (e) => e.stopPropagation(),
27861
- className: "absolute z-[9999] w-fit mt-1 bg-white border border-gray-300 rounded-lg shadow-lg max-h-60 overflow-y-auto",
27892
+ className: "absolute z-[900] w-fit mt-1 bg-white border border-gray-300 rounded-lg shadow-lg max-h-60 overflow-y-auto",
27862
27893
  style: {
27863
27894
  width: dropdownRef.current?.offsetWidth,
27864
27895
  top: dropdownRef.current ? dropdownRef.current.getBoundingClientRect().bottom + window.scrollY : 0,
@@ -29235,7 +29266,10 @@ var useDynamicColumns = (config, customRenderers = {}, customFormatters = {}) =>
29235
29266
  col.format,
29236
29267
  customFormatters
29237
29268
  );
29238
- }
29269
+ },
29270
+ enableSorting: col.enableSorting,
29271
+ enableColumnFilter: col.enableColumnFilter,
29272
+ meta: col.meta
29239
29273
  });
29240
29274
  });
29241
29275
  };
@@ -29258,37 +29292,13 @@ function DataTable({
29258
29292
  globalSearch,
29259
29293
  onCellClick,
29260
29294
  onDeleteRow,
29261
- enableDelete
29295
+ rowActions
29262
29296
  }) {
29263
29297
  const [columnFilters, setColumnFilters] = React9.useState([]);
29264
29298
  const [columnVisibility, setColumnVisibility] = React9.useState({});
29265
29299
  const [manualSort, setManualSort] = React9.useState(null);
29266
29300
  const [searchTerm, setSearchTerm] = React9.useState("");
29267
- const deleteColumn = React9.useMemo(() => ({
29268
- id: "delete",
29269
- header: "Actions",
29270
- cell: ({ row }) => /* @__PURE__ */ jsx53(
29271
- "button",
29272
- {
29273
- className: "px-3 py-1 text-[12px] bg-red-800 text-white rounded hover:bg-neutral-600 cursor-pointer",
29274
- onClick: (event) => {
29275
- event.stopPropagation();
29276
- if (onDeleteRow) {
29277
- onDeleteRow(row.original, "delete");
29278
- }
29279
- },
29280
- children: "Delete"
29281
- }
29282
- ),
29283
- meta: { isClickable: true }
29284
- }), [onDeleteRow]);
29285
- const combinedColumns = React9.useMemo(() => {
29286
- if (enableDelete) {
29287
- return [...columns, deleteColumn];
29288
- }
29289
- return columns;
29290
- }, [columns, enableDelete, deleteColumn]);
29291
- const dynamicCols = useDynamicColumns({ columns: combinedColumns });
29301
+ const dynamicCols = useDynamicColumns({ columns });
29292
29302
  const table = useReactTable({
29293
29303
  data,
29294
29304
  columns: dynamicCols,
@@ -29414,7 +29424,7 @@ function DataTable({
29414
29424
  ] })
29415
29425
  ] }),
29416
29426
  /* @__PURE__ */ jsxs31(Table3, { children: [
29417
- /* @__PURE__ */ jsx53(TableHeader, { children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsx53(TableRow, { children: hg.headers.map((header) => {
29427
+ /* @__PURE__ */ jsx53(TableHeader, { children: table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsx53(TableRow, { children: hg.headers.map((header, index) => {
29418
29428
  const canSort = header.column.getCanSort();
29419
29429
  const canFilter = header.column.getCanFilter();
29420
29430
  const sortDir = manualSort?.key === header.column.id ? manualSort.dir : null;
@@ -29494,26 +29504,49 @@ function DataTable({
29494
29504
  }
29495
29505
  )
29496
29506
  ] })
29497
- ] }) }, header.id);
29498
- }) }, hg.id)) }),
29499
- /* @__PURE__ */ jsx53(TableBody, { children: loading ? /* @__PURE__ */ jsx53(Fragment20, { children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ jsx53(TableRow, { children: combinedColumns.map((_2, j) => /* @__PURE__ */ jsx53(TableCell, { className: "p-3", children: /* @__PURE__ */ jsx53("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__ */ jsx53(TableRow, { children: row.getVisibleCells().map((cell) => {
29507
+ ] }) }, `header-${header.id}-${index}`);
29508
+ }) }, `header-group-${hg.id}`)) }),
29509
+ /* @__PURE__ */ jsx53(TableBody, { children: loading ? /* @__PURE__ */ jsx53(Fragment20, { children: Array.from({ length: 5 }).map((_, i) => /* @__PURE__ */ jsx53(TableRow, { children: dynamicCols.map((_2, j) => /* @__PURE__ */ jsx53(TableCell, { className: "p-3", children: /* @__PURE__ */ jsx53("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__ */ jsx53(TableRow, { children: row.getVisibleCells().map((cell, cellIndex, arr) => {
29500
29510
  const meta = cell.column.columnDef.meta || {};
29501
29511
  const isClickable = meta?.isClickable;
29502
- return /* @__PURE__ */ jsx53(
29512
+ const isLastCell = cellIndex === arr.length - 1;
29513
+ return /* @__PURE__ */ jsxs31(
29503
29514
  TableCell,
29504
29515
  {
29505
- className: `${meta?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100" : ""}`,
29516
+ className: `${meta?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100" : ""} relative`,
29506
29517
  style: meta?.cellStyle,
29507
29518
  onClick: () => {
29508
29519
  if (isClickable && onCellClick) {
29509
29520
  onCellClick(cell.row.original, cell.column.id);
29510
29521
  }
29511
29522
  },
29512
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
29523
+ children: [
29524
+ flexRender(cell.column.columnDef.cell, cell.getContext()),
29525
+ isLastCell && rowActions && rowActions.length > 0 && /* @__PURE__ */ jsx53("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) => {
29526
+ const isDelete = action.id === "delete" || action.icon === "delete";
29527
+ return /* @__PURE__ */ jsx53(
29528
+ "button",
29529
+ {
29530
+ 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"}`,
29531
+ onClick: (event) => {
29532
+ event.stopPropagation();
29533
+ if (isDelete) {
29534
+ onDeleteRow?.(cell.row.original, "delete");
29535
+ } else {
29536
+ onCellClick?.(cell.row.original, cell.column.id);
29537
+ }
29538
+ },
29539
+ title: action.header,
29540
+ children: action.header
29541
+ },
29542
+ action.id
29543
+ );
29544
+ }) })
29545
+ ]
29513
29546
  },
29514
- cell.id
29547
+ `cell-${cell.id}-${cellIndex}`
29515
29548
  );
29516
- }) }, row.id)) : /* @__PURE__ */ jsx53(TableRow, { children: /* @__PURE__ */ jsx53(TableCell, { colSpan: combinedColumns.length, className: "h-24 text-center", children: /* @__PURE__ */ jsx53("span", { className: "flex items-center justify-center py-10 w-full min-w-full text-gray-600 bg-gray-100", children: "No results." }) }) }) })
29549
+ }) }, row.id)) : /* @__PURE__ */ jsx53(TableRow, { children: /* @__PURE__ */ jsx53(TableCell, { colSpan: dynamicCols.length, className: "h-24 text-center", children: /* @__PURE__ */ jsx53("span", { className: "flex items-center justify-center py-10 w-full min-w-full text-gray-600 bg-gray-100", children: "No results." }) }) }) })
29517
29550
  ] }),
29518
29551
  pagination && /* @__PURE__ */ jsxs31("div", { className: "flex items-center justify-between py-3 px-2 text-sm w-full", children: [
29519
29552
  /* @__PURE__ */ jsxs31("div", { children: [
@@ -29580,7 +29613,6 @@ var Table4 = ({
29580
29613
  totalRecords = 0,
29581
29614
  globalSearch = false,
29582
29615
  onCellClick,
29583
- enableDelete,
29584
29616
  onDeleteRow,
29585
29617
  ...props
29586
29618
  }) => {
@@ -29612,8 +29644,7 @@ var Table4 = ({
29612
29644
  },
29613
29645
  onDeleteRow: (cell) => {
29614
29646
  onDeleteRow?.(cell.id);
29615
- },
29616
- enableDelete
29647
+ }
29617
29648
  }
29618
29649
  ) });
29619
29650
  };
@@ -29826,7 +29857,7 @@ var CustomPagination = ({
29826
29857
  var Pagination_default = CustomPagination;
29827
29858
 
29828
29859
  // src/components/Navigation/Tabs/Tabs.tsx
29829
- import { useCallback as useCallback3, useMemo as useMemo5, useState as useState8 } from "react";
29860
+ import { useCallback as useCallback3, useMemo as useMemo4, useState as useState8 } from "react";
29830
29861
  import Link5 from "next/link";
29831
29862
  import { useRouter } from "next/navigation";
29832
29863
  import { Fragment as Fragment21, jsx as jsx57, jsxs as jsxs34 } from "react/jsx-runtime";
@@ -29863,7 +29894,7 @@ var Tabs = ({ className, style, tabs, verticalMenu, pathname, canvasMode, isBuil
29863
29894
  });
29864
29895
  return sortMenus(rootMenus);
29865
29896
  }
29866
- const rawTabs = useMemo5(() => {
29897
+ const rawTabs = useMemo4(() => {
29867
29898
  if (!Array.isArray(tabs)) return [];
29868
29899
  if (source === "manual") return Array.isArray(tabs) ? tabs : [];
29869
29900
  return groupMenus(tabs);
@@ -30004,29 +30035,44 @@ var Tabs = ({ className, style, tabs, verticalMenu, pathname, canvasMode, isBuil
30004
30035
  var Tabs_default = Tabs;
30005
30036
 
30006
30037
  // src/components/Navigation/Stages/Stages.tsx
30007
- import React10 from "react";
30038
+ import React10, { useState as useState9 } from "react";
30008
30039
  import { jsx as jsx58, jsxs as jsxs35 } from "react/jsx-runtime";
30009
- var StagesComponent = ({ stages, isShowBtn, buttonText, className, style, onStageChange, currentStage }) => {
30040
+ var StagesComponent = ({ stages, isShowBtn, buttonText, className, style, onStageChange, currentStage, dataKey = "key", dataLabel = "header" }) => {
30041
+ const [activeStage, setActiveStage] = useState9(currentStage || (stages && stages.length > 0 ? stages[0].key : null));
30042
+ const nextStage = () => {
30043
+ if (!stages || stages.length === 0) return;
30044
+ const currentIndex = stages.findIndex((stage) => stage[dataKey] === activeStage);
30045
+ if (currentIndex < stages.length - 1) {
30046
+ const newStage = stages[currentIndex + 1];
30047
+ setActiveStage(newStage[dataKey]);
30048
+ onStageChange?.(newStage[dataKey]);
30049
+ }
30050
+ };
30051
+ const lastStage = stages && stages.length > 0 ? stages[stages.length - 1][dataKey] : null;
30052
+ const onStageClick = (stageKey) => {
30053
+ if (!stageKey || stageKey === activeStage || activeStage === lastStage) return;
30054
+ setActiveStage(stageKey);
30055
+ onStageChange?.(stageKey);
30056
+ };
30057
+ const isAllStagesCompleted = activeStage === lastStage;
30010
30058
  return /* @__PURE__ */ jsx58("div", { className, style, children: /* @__PURE__ */ jsxs35("div", { className: "flex items-center justify-between bg-red p-2 rounded-lg border border-gray-200 w-full", children: [
30011
30059
  /* @__PURE__ */ jsx58("div", { className: "flex items-center", children: /* @__PURE__ */ jsx58("button", { className: "p-2 hover:bg-gray-100 rounded", children: /* @__PURE__ */ jsx58("svg", { className: "w-4 h-4 text-gray-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx58("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 9l-7 7-7-7" }) }) }) }),
30012
30060
  /* @__PURE__ */ jsx58("div", { className: "flex items-center flex-1 px-2 flex-wrap gap-2", children: stages?.length > 0 && stages?.map((stage, index) => {
30013
- const currentIndex = stages.findIndex((s) => s.key === currentStage);
30014
- const isAllCompleted = currentStage === "completed";
30015
- const isCompleted = isAllCompleted || index < currentIndex;
30016
- const isActive = !isAllCompleted && index === currentIndex;
30061
+ const currentIndex = stages.findIndex((s) => s[dataKey] === activeStage);
30062
+ const isCompleted = isAllStagesCompleted || index < currentIndex;
30063
+ const isActive = !isAllStagesCompleted && index === currentIndex;
30017
30064
  return /* @__PURE__ */ jsxs35(React10.Fragment, { children: [
30018
30065
  /* @__PURE__ */ jsx58(
30019
30066
  "button",
30020
30067
  {
30021
30068
  className: `
30022
30069
  min-w-[120px] px-4 py-2 rounded-full text-sm font-medium transition-colors duration-200 whitespace-nowrap
30023
- ${isActive ? "bg-[#034486] text-white shadow-md" : isCompleted ? "bg-[#e0f2fe] text-[#034486] border border-[#034486]" : "bg-white text-gray-700 hover:bg-gray-100 border border-gray-200"}`,
30070
+ ${isActive ? "bg-green-700 text-white shadow-md" : isCompleted ? "bg-green-50 text-green-700 border border-green-700" : "bg-white text-gray-700 hover:bg-gray-100 border border-gray-200"}`,
30024
30071
  onClick: () => {
30025
- if (onStageChange) {
30026
- onStageChange(stage.key);
30027
- }
30072
+ if (isAllStagesCompleted) return;
30073
+ onStageClick(stage[dataKey]);
30028
30074
  },
30029
- children: stage.header
30075
+ children: stage[dataLabel]
30030
30076
  }
30031
30077
  ),
30032
30078
  index < stages.length - 1 && /* @__PURE__ */ jsx58("div", { className: "flex-shrink-0 w-3 h-px bg-gray-300" })
@@ -30035,9 +30081,9 @@ var StagesComponent = ({ stages, isShowBtn, buttonText, className, style, onStag
30035
30081
  isShowBtn && /* @__PURE__ */ jsx58("div", { className: "flex items-center", children: /* @__PURE__ */ jsx58(
30036
30082
  "button",
30037
30083
  {
30038
- className: "bg-[#034486] text-white px-6 py-2 rounded-lg text-sm font-medium transition-colors duration-200 shadow-sm",
30084
+ className: "bg-green-700 text-white px-6 py-2 rounded-lg text-sm font-medium transition-colors duration-200 shadow-sm",
30039
30085
  onClick: () => {
30040
- onStageChange?.("completed");
30086
+ nextStage();
30041
30087
  },
30042
30088
  children: buttonText
30043
30089
  }
@@ -30105,7 +30151,7 @@ import Link6 from "next/link";
30105
30151
  import Image4 from "next/image";
30106
30152
  import { useRouter as useRouter2 } from "next/navigation";
30107
30153
  import { DropdownMenuSeparator } from "@radix-ui/react-dropdown-menu";
30108
- import { useCallback as useCallback4, useMemo as useMemo6, useState as useState9 } from "react";
30154
+ import { useCallback as useCallback4, useMemo as useMemo5, useState as useState10 } from "react";
30109
30155
  import { Fragment as Fragment22, jsx as jsx64, jsxs as jsxs38 } from "react/jsx-runtime";
30110
30156
  function Navbar({
30111
30157
  style,
@@ -30126,8 +30172,8 @@ function Navbar({
30126
30172
  }) {
30127
30173
  const isMobileView = canvasMode === "mobile" || canvasMode === "tablet";
30128
30174
  const router = useRouter2();
30129
- const [showExitDialog, setShowExitDialog] = useState9(false);
30130
- const [pendingUrl, setPendingUrl] = useState9(null);
30175
+ const [showExitDialog, setShowExitDialog] = useState10(false);
30176
+ const [pendingUrl, setPendingUrl] = useState10(null);
30131
30177
  const handleBuilderExit = useCallback4(
30132
30178
  (e, url) => {
30133
30179
  if (isBuilder) {
@@ -30144,7 +30190,7 @@ function Navbar({
30144
30190
  router.push(pendingUrl);
30145
30191
  }
30146
30192
  };
30147
- const formatedMenu = useMemo6(() => {
30193
+ const formatedMenu = useMemo5(() => {
30148
30194
  if (source === "state" && navList && navList.length) {
30149
30195
  return navList.map((i) => ({ ...i, header: i.name || "Menu" }));
30150
30196
  }
@@ -30322,7 +30368,7 @@ var ChartComponent = ({ className, style, loading, ...props }) => {
30322
30368
  var BarChart_default = React12.memo(ChartComponent);
30323
30369
 
30324
30370
  // src/components/Chart/PieChart.tsx
30325
- import React13, { useEffect as useEffect25, useMemo as useMemo7, useState as useState10 } from "react";
30371
+ import React13, { useEffect as useEffect25, useMemo as useMemo6, useState as useState11 } from "react";
30326
30372
  import {
30327
30373
  PieChart,
30328
30374
  Pie,
@@ -30351,18 +30397,18 @@ var DonutChart = ({ className, style, loading, ...props }) => {
30351
30397
  const showLegends = props.showLegends ?? true;
30352
30398
  const labelType = props.labelType || "inside";
30353
30399
  const canvasMode = props.canvasMode;
30354
- const data = useMemo7(() => {
30400
+ const data = useMemo6(() => {
30355
30401
  if (!Array.isArray(props.data)) return [];
30356
30402
  return props.data.map((item) => ({ ...item, color: getRandomColor() }));
30357
30403
  }, [props.data]);
30358
- const total = useMemo7(() => data.reduce((sum, d) => sum + d.value, 0), [data]);
30404
+ const total = useMemo6(() => data.reduce((sum, d) => sum + d.value, 0), [data]);
30359
30405
  const forceMobile = canvasMode === "mobile" || canvasMode === "tablet";
30360
- const [mounted, setMounted] = useState10(false);
30406
+ const [mounted, setMounted] = useState11(false);
30361
30407
  useEffect25(() => {
30362
30408
  const timeout = setTimeout(() => setMounted(true), 100);
30363
30409
  return () => clearTimeout(timeout);
30364
30410
  }, []);
30365
- const renderLegends = useMemo7(() => {
30411
+ const renderLegends = useMemo6(() => {
30366
30412
  if (!showLegends) return null;
30367
30413
  return /* @__PURE__ */ jsx66(Fragment23, { children: data.map((d) => /* @__PURE__ */ jsxs40(
30368
30414
  "div",