@algorithm-shift/design-system 1.2.958 → 1.2.960

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.js CHANGED
@@ -27770,13 +27770,25 @@ function useLazyDropdown(config) {
27770
27770
  (0, import_react19.useEffect)(() => {
27771
27771
  configRef.current = config;
27772
27772
  }, [config]);
27773
+ function getValueByPath2(obj, path) {
27774
+ if (!obj || !path) return void 0;
27775
+ const parts = path.split(/\.|__/);
27776
+ return parts.reduce((acc, key) => acc?.[key], obj);
27777
+ }
27773
27778
  const transformToOptions = (0, import_react19.useCallback)((data) => {
27774
27779
  if (!data || !Array.isArray(data)) return [];
27775
27780
  const cfg = configRef.current;
27776
- return data.map((item) => ({
27777
- value: item[cfg.dataKey] ?? item.id ?? "",
27778
- label: item[cfg.dataLabel] ?? item.name ?? item.label ?? ""
27779
- }));
27781
+ return data.map((item) => {
27782
+ const value = getValueByPath2(item, cfg.dataKey) ?? item.id ?? "";
27783
+ let label = "";
27784
+ if (cfg.dataLabel) {
27785
+ label = getValueByPath2(item, cfg.dataLabel) ?? item.name ?? item.label ?? "";
27786
+ }
27787
+ return {
27788
+ value,
27789
+ label
27790
+ };
27791
+ });
27780
27792
  }, []);
27781
27793
  const fetchApiData = (0, import_react19.useCallback)(async (pageNum, term) => {
27782
27794
  if (!configRef.current.apiUrl) return [];
@@ -29068,9 +29080,12 @@ var valueFormatter = (value, format2, customFormatters = {}) => {
29068
29080
  switch (type) {
29069
29081
  case "date":
29070
29082
  return dayjs_setup_default(value).format(arg || "YYYY-MM-DD");
29071
- case "datetime":
29083
+ case "datetimenumber":
29072
29084
  const parsed = dayjs_setup_default(value).isValid() ? dayjs_setup_default(value).utc() : dayjs_setup_default(value);
29073
29085
  return parsed.format("YYYY-MM-DD hh:mm");
29086
+ case "datetime":
29087
+ const formated = dayjs_setup_default(value).isValid() ? dayjs_setup_default(value).utc() : dayjs_setup_default(value);
29088
+ return formated.format("DD MMM YYYY hh:mm A");
29074
29089
  case "days":
29075
29090
  return `${dayjs_setup_default().diff(dayjs_setup_default(value), "day")} days`;
29076
29091
  case "months":
@@ -29356,6 +29371,7 @@ function DataTable({
29356
29371
  const [searchTerm, setSearchTerm] = React9.useState("");
29357
29372
  const tableData = Array.isArray(data) ? data : [];
29358
29373
  const dynamicCols = useDynamicColumns({ columns });
29374
+ const [localPageSize, setLocalPageSize] = React9.useState(pageSize);
29359
29375
  const table = (0, import_react_table2.useReactTable)({
29360
29376
  data: tableData,
29361
29377
  columns: dynamicCols,
@@ -29404,36 +29420,48 @@ function DataTable({
29404
29420
  return [];
29405
29421
  };
29406
29422
  const pageCount = table.getPageCount() === 0 ? 1 : table.getPageCount();
29423
+ const handlePageSizeChange = (e) => {
29424
+ const newSize = Number(e.target.value);
29425
+ const currentPageIndex = table.getState().pagination.pageIndex;
29426
+ onPageChange?.(currentPageIndex, newSize);
29427
+ setLocalPageSize(newSize);
29428
+ };
29407
29429
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "overflow-hidden rounded-md w-full", children: [
29408
- /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: `flex ${globalSearch ? "justify-between" : "justify-end"} p-2 bg-gray-50`, children: [
29409
- globalSearch && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center gap-2 w-full max-w-sm", children: [
29410
- /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "relative w-full", children: [
29430
+ !loading && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex justify-between p-2 bg-gray-50", children: [
29431
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center gap-4 w-full", children: [
29432
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("p", { className: "text-sm font-medium", children: [
29433
+ "Total Records : ",
29434
+ totalRecords.toLocaleString("en-IN") || 0
29435
+ ] }),
29436
+ globalSearch && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center gap-2 w-full max-w-sm", children: [
29437
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "relative w-full", children: [
29438
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
29439
+ "input",
29440
+ {
29441
+ type: "text",
29442
+ placeholder: "Search...",
29443
+ value: searchTerm,
29444
+ onChange: (e) => setSearchTerm(e.target.value),
29445
+ onKeyDown: (e) => {
29446
+ if (e.key === "Enter" && onGlobalSearch) {
29447
+ onGlobalSearch(searchTerm.trim());
29448
+ }
29449
+ },
29450
+ className: "border border-gray-300 rounded-md text-sm px-3 py-2 pl-8 w-full focus:outline-none focus:ring-1 focus:ring-[#12715B]"
29451
+ }
29452
+ ),
29453
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(Search, { className: "absolute left-2 top-2.5 text-gray-400", size: 16 })
29454
+ ] }),
29411
29455
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
29412
- "input",
29456
+ Button,
29413
29457
  {
29414
- type: "text",
29415
- placeholder: "Search...",
29416
- value: searchTerm,
29417
- onChange: (e) => setSearchTerm(e.target.value),
29418
- onKeyDown: (e) => {
29419
- if (e.key === "Enter" && onGlobalSearch) {
29420
- onGlobalSearch(searchTerm.trim());
29421
- }
29422
- },
29423
- className: "border border-gray-300 rounded-md text-sm px-3 py-2 pl-8 w-full focus:outline-none focus:ring-1 focus:ring-[#12715B]"
29458
+ size: "sm",
29459
+ className: "bg-[#12715B] text-white text-xs h-auto py-2 px-3",
29460
+ onClick: () => onGlobalSearch?.(searchTerm.trim()),
29461
+ children: "Search"
29424
29462
  }
29425
- ),
29426
- /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(Search, { className: "absolute left-2 top-2.5 text-gray-400", size: 16 })
29427
- ] }),
29428
- /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
29429
- Button,
29430
- {
29431
- size: "sm",
29432
- className: "bg-[#12715B] text-white text-xs h-auto py-2 px-3",
29433
- onClick: () => onGlobalSearch?.(searchTerm.trim()),
29434
- children: "Search"
29435
- }
29436
- )
29463
+ )
29464
+ ] })
29437
29465
  ] }),
29438
29466
  /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(Popover, { children: [
29439
29467
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
@@ -29623,12 +29651,26 @@ function DataTable({
29623
29651
  );
29624
29652
  }) }, row.id)) : /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(TableRow, { children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(TableCell, { colSpan: dynamicCols.length, className: "h-24 text-center", children: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)("span", { className: "flex items-center justify-center py-10 w-full min-w-full text-gray-600 bg-gray-100", children: "No results." }) }) }) })
29625
29653
  ] }),
29626
- pagination && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center justify-between py-3 px-2 text-sm w-full", children: [
29627
- /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { children: [
29628
- "Page ",
29629
- table.getState().pagination.pageIndex + 1,
29630
- " of ",
29631
- pageCount
29654
+ pagination && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center justify-between py-3 text-sm w-full", children: [
29655
+ !loading && /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex gap-2 items-center", children: [
29656
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
29657
+ "select",
29658
+ {
29659
+ value: localPageSize,
29660
+ onChange: handlePageSizeChange,
29661
+ className: "ml-2 border rounded py-1 text-sm cursor-pointer border-blue-600",
29662
+ children: [10, 20, 50, 100].map((size) => /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("option", { value: size, children: [
29663
+ size,
29664
+ " / page"
29665
+ ] }, size))
29666
+ }
29667
+ ),
29668
+ /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { children: [
29669
+ "Page ",
29670
+ table.getState().pagination.pageIndex + 1,
29671
+ " of ",
29672
+ pageCount
29673
+ ] })
29632
29674
  ] }),
29633
29675
  /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)("div", { className: "flex items-center gap-2", children: [
29634
29676
  /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(