erp-pos-ecommerce-shared 0.1.4 → 0.1.6

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.
@@ -6,7 +6,7 @@ import { s as TblProductsImage, o as ITableFilterConfig, g as IFilterSelectOptio
6
6
  import * as z from 'zod';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import { ColumnDef, useReactTable, Row } from '@tanstack/react-table';
9
- import { D as DataTableConfig, S as ServerTableState } from './datatable.interface-DFSQWdXd.js';
9
+ import { D as DataTableConfig, S as ServerTableState, T as TableHeaderStyle } from './datatable.interface-DbB5oxj-.js';
10
10
  import { T as TableQueryParams } from './types-CiX8AkJA.js';
11
11
 
12
12
  interface CreateEditFormProps<T> {
@@ -142,8 +142,8 @@ interface DataTableProps$1<TData> {
142
142
  enableRowCheck?: boolean;
143
143
  /** Called when row selection changes */
144
144
  onSelectionChange?: (selectedRows: TData[]) => void;
145
- /** Header background color. Use light-dark(light, dark) for theme-aware colors */
146
- headerBgColor?: string;
145
+ /** Header style: color string (legacy) or { bgColor, textColor, fontWeight?, fontSize?, padding? } */
146
+ headerBgColor?: string | TableHeaderStyle;
147
147
  /** Column actions to display per row */
148
148
  columnActions?: (row: TData) => React.ReactNode;
149
149
  /** List menu actions to display per row */
@@ -250,8 +250,8 @@ interface DataTableProps<TData> {
250
250
  onClick: () => void;
251
251
  Icon?: React$1.ElementType;
252
252
  }[];
253
- /** Header background color. Use light-dark(light, dark) for theme-aware colors */
254
- headerBgColor?: string;
253
+ /** Header style: color string (legacy) or { bgColor, textColor, fontWeight?, fontSize?, padding? } */
254
+ headerBgColor?: string | TableHeaderStyle;
255
255
  /** Whether the table is loading (shows skeleton rows instead of data) */
256
256
  loading?: boolean;
257
257
  /** Number of skeleton rows to show when loading */
@@ -267,19 +267,15 @@ declare const SimpleDataTable: <TData>({ table, withBorder, borderRadius, SortIc
267
267
 
268
268
  interface TableSkeletonProps {
269
269
  /** Number of skeleton rows to show */
270
- rows?: number;
271
- /** Number of columns (excluding checkbox column if canCheck) */
272
- columns?: number;
273
- /** Whether to show a checkbox column */
270
+ rowCount: number;
271
+ /** Number of data columns (excluding checkbox and actions) */
272
+ columnCount: number;
273
+ /** Whether to show the checkbox column */
274
274
  canCheck?: boolean;
275
- /** Whether to show the border */
276
- withBorder?: boolean;
277
- /** Border radius */
278
- borderRadius?: "xs" | "sm" | "md" | "lg" | "xl" | number;
279
- /** Height of each skeleton row */
280
- rowHeight?: number;
275
+ /** Whether to show the actions column */
276
+ hasActionsColumn?: boolean;
281
277
  }
282
- declare const TableSkeleton: ({ rows, columns, canCheck, withBorder, borderRadius, rowHeight, }: TableSkeletonProps) => react_jsx_runtime.JSX.Element;
278
+ declare const TableSkeleton: ({ rowCount, columnCount, canCheck, hasActionsColumn, }: TableSkeletonProps) => react_jsx_runtime.JSX.Element;
283
279
 
284
280
  /** Shape that the query must return for TablePage to work correctly. */
285
281
  interface PaginatedResponse<TRow> {
@@ -329,9 +325,9 @@ interface TablePageProps<TRow> {
329
325
  */
330
326
  enableRowSelection?: boolean;
331
327
  /**
332
- * Header background color
328
+ * Header style: color string (legacy) or { bgColor, textColor, fontWeight?, fontSize?, padding? }
333
329
  */
334
- headerBgColor?: string;
330
+ headerBgColor?: TableHeaderStyle;
335
331
  /**
336
332
  * Column actions to display per row
337
333
  */
@@ -1,5 +1,5 @@
1
1
  import { useMutation, useQuery } from '@tanstack/react-query';
2
- import { Text, Group, Box, rem, Button, ScrollArea, Image, ActionIcon, TagsInput, Switch, MultiSelect, Select, NumberInput, PasswordInput, TextInput, LoadingOverlay, Stepper, Flex, Container, Title, Card, Pagination, Stack, Paper, Table, Skeleton, Menu, Popover, Checkbox, UnstyledButton } from '@mantine/core';
2
+ import { Text, Group, Box, rem, Button, ScrollArea, Image, ActionIcon, TagsInput, Switch, MultiSelect, Select, NumberInput, PasswordInput, TextInput, LoadingOverlay, Stepper, Flex, Container, Title, Card, Pagination, Table, Skeleton, Stack, Paper, Menu, Popover, Checkbox, UnstyledButton } from '@mantine/core';
3
3
  import { useForm } from '@tanstack/react-form';
4
4
  import axios, { isAxiosError } from 'axios';
5
5
  import { useRef, useMemo, useState, useEffect, useCallback } from 'react';
@@ -1284,9 +1284,33 @@ function useDataTable({
1284
1284
  selectedRows
1285
1285
  };
1286
1286
  }
1287
-
1288
- // src/components/table/TableHeader.module.css
1289
- var TableHeader_default = {};
1287
+ var defaultHeaderTextColor = "light-dark(var(--mantine-color-dimmed), var(--mantine-color-gray-4))";
1288
+ var defaultHeaderHoverBg = "light-dark(var(--mantine-color-gray-2), var(--mantine-color-dark-2))";
1289
+ function normalizeHeaderStyle(value) {
1290
+ if (value == null) {
1291
+ return {
1292
+ bgColor: defaultHeaderBgColor,
1293
+ textColor: defaultHeaderTextColor,
1294
+ hoverBgColor: defaultHeaderHoverBg
1295
+ };
1296
+ }
1297
+ if (typeof value === "string") {
1298
+ return {
1299
+ bgColor: value,
1300
+ textColor: defaultHeaderTextColor,
1301
+ hoverBgColor: defaultHeaderHoverBg
1302
+ };
1303
+ }
1304
+ return {
1305
+ bgColor: value.bgColor ?? defaultHeaderBgColor,
1306
+ textColor: value.textColor ?? defaultHeaderTextColor,
1307
+ hoverBgColor: value.hoverBgColor ?? defaultHeaderHoverBg,
1308
+ hoverTextColor: value.hoverTextColor ?? value.textColor ?? defaultHeaderTextColor,
1309
+ fontWeight: value.fontWeight,
1310
+ fontSize: value.fontSize,
1311
+ padding: value.padding
1312
+ };
1313
+ }
1290
1314
  var TableHeader = ({
1291
1315
  table,
1292
1316
  SortIcon,
@@ -1294,18 +1318,33 @@ var TableHeader = ({
1294
1318
  SortIconDesc,
1295
1319
  canCheck = false,
1296
1320
  hasActionsColumn = false,
1297
- headerBgColor = defaultHeaderBgColor
1321
+ headerBgColor
1298
1322
  }) => {
1323
+ const [hoveredHeaderId, setHoveredHeaderId] = useState(null);
1324
+ const style = normalizeHeaderStyle(headerBgColor);
1325
+ const bgColor = style.bgColor ?? defaultHeaderBgColor;
1326
+ const hoverBg = style.hoverBgColor ?? defaultHeaderHoverBg;
1327
+ const hoverText = style.hoverTextColor ?? style.textColor ?? defaultHeaderTextColor;
1299
1328
  const getSortIcon = (sortState) => {
1300
1329
  if (sortState === "asc") return SortIconAsc;
1301
1330
  if (sortState === "desc") return SortIconDesc;
1302
1331
  return SortIcon;
1303
1332
  };
1333
+ const baseButtonStyle = {
1334
+ padding: style.padding ?? "4px 10px",
1335
+ fontSize: style.fontSize ?? 14,
1336
+ fontWeight: style.fontWeight ?? 700,
1337
+ display: "flex",
1338
+ alignItems: "center",
1339
+ gap: 4,
1340
+ transition: "background-color 0.1s ease, color 0.1s ease",
1341
+ borderRadius: "var(--mantine-radius-lg)"
1342
+ };
1304
1343
  return /* @__PURE__ */ jsx(Table.Thead, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs(Table.Tr, { children: [
1305
1344
  canCheck && /* @__PURE__ */ jsx(
1306
1345
  Table.Th,
1307
1346
  {
1308
- bg: headerBgColor,
1347
+ bg: bgColor,
1309
1348
  w: 10,
1310
1349
  styles: {
1311
1350
  th: {
@@ -1331,20 +1370,18 @@ var TableHeader = ({
1331
1370
  const canSort = header.column.getCanSort();
1332
1371
  const sortState = header.column.getIsSorted();
1333
1372
  const Icon = canSort ? getSortIcon(sortState) : null;
1334
- return /* @__PURE__ */ jsx(Table.Th, { bg: headerBgColor, children: /* @__PURE__ */ jsxs(
1373
+ const isHovered = hoveredHeaderId === header.id;
1374
+ return /* @__PURE__ */ jsx(Table.Th, { bg: bgColor, children: /* @__PURE__ */ jsxs(
1335
1375
  UnstyledButton,
1336
1376
  {
1337
- className: TableHeader_default.tableHeader,
1338
1377
  style: {
1339
- padding: "4px 10px",
1340
- fontSize: 14,
1341
- fontWeight: 700,
1342
- display: "flex",
1343
- alignItems: "center",
1344
- color: "light-dark(var(--mantine-color-dimmed), var(--mantine-color-gray-4))",
1345
- gap: 4
1378
+ ...baseButtonStyle,
1379
+ color: isHovered ? hoverText : style.textColor ?? defaultHeaderTextColor,
1380
+ backgroundColor: isHovered ? hoverBg : void 0
1346
1381
  },
1347
1382
  onClick: header.column.getToggleSortingHandler(),
1383
+ onMouseEnter: () => setHoveredHeaderId(header.id),
1384
+ onMouseLeave: () => setHoveredHeaderId(null),
1348
1385
  children: [
1349
1386
  header.isPlaceholder ? null : flexRender(
1350
1387
  header.column.columnDef.header,
@@ -1355,7 +1392,7 @@ var TableHeader = ({
1355
1392
  }
1356
1393
  ) }, header.id);
1357
1394
  }),
1358
- hasActionsColumn && /* @__PURE__ */ jsx(Table.Th, { bg: headerBgColor })
1395
+ hasActionsColumn && /* @__PURE__ */ jsx(Table.Th, { bg: bgColor })
1359
1396
  ] }, headerGroup.id)) });
1360
1397
  };
1361
1398
  var TableBody = ({
@@ -1367,11 +1404,21 @@ var TableBody = ({
1367
1404
  onRowClick,
1368
1405
  onRowHover
1369
1406
  }) => {
1407
+ const [hoveredRowId, setHoveredRowId] = useState(null);
1370
1408
  return /* @__PURE__ */ jsx(Table.Tbody, { children: table.getRowModel().rows.map((row) => /* @__PURE__ */ jsxs(
1371
1409
  Table.Tr,
1372
1410
  {
1373
- style: onRowClick ? { cursor: "pointer" } : void 0,
1374
- onMouseEnter: () => onRowHover?.(row.original),
1411
+ style: {
1412
+ ...onRowClick ? { cursor: "pointer" } : {},
1413
+ ...hoveredRowId === row.id ? {
1414
+ backgroundColor: "light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-5))"
1415
+ } : {}
1416
+ },
1417
+ onMouseEnter: () => {
1418
+ setHoveredRowId(row.id);
1419
+ onRowHover?.(row.original);
1420
+ },
1421
+ onMouseLeave: () => setHoveredRowId(null),
1375
1422
  children: [
1376
1423
  canCheck && /* @__PURE__ */ jsx(
1377
1424
  Table.Td,
@@ -1423,7 +1470,7 @@ var TableBody = ({
1423
1470
  Menu.Item,
1424
1471
  {
1425
1472
  onClick: action.onClick,
1426
- rightSection: action.Icon && /* @__PURE__ */ jsx(action.Icon, {}),
1473
+ leftSection: action.Icon && /* @__PURE__ */ jsx(action.Icon, {}),
1427
1474
  children: action.label
1428
1475
  },
1429
1476
  action.label
@@ -1435,6 +1482,26 @@ var TableBody = ({
1435
1482
  row.id
1436
1483
  )) });
1437
1484
  };
1485
+ var cellStyle = { minHeight: 40, verticalAlign: "middle" };
1486
+ var TableSkeleton = ({
1487
+ rowCount,
1488
+ columnCount,
1489
+ canCheck = false,
1490
+ hasActionsColumn = false
1491
+ }) => {
1492
+ return /* @__PURE__ */ jsx(Table.Tbody, { children: Array.from({ length: rowCount }).map((_, rowIdx) => /* @__PURE__ */ jsxs(Table.Tr, { children: [
1493
+ canCheck && /* @__PURE__ */ jsx(Table.Td, { style: cellStyle, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 18, radius: "sm" }) }),
1494
+ Array.from({ length: columnCount }).map((_2, colIdx) => /* @__PURE__ */ jsx(Table.Td, { style: cellStyle, children: /* @__PURE__ */ jsx(
1495
+ Skeleton,
1496
+ {
1497
+ height: 16,
1498
+ width: colIdx === columnCount - 1 ? 40 : `${60 + colIdx % 2 * 15}%`,
1499
+ radius: "sm"
1500
+ }
1501
+ ) }, colIdx)),
1502
+ hasActionsColumn && /* @__PURE__ */ jsx(Table.Td, { style: cellStyle, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 32, radius: "sm" }) })
1503
+ ] }, rowIdx)) });
1504
+ };
1438
1505
  var EmptyState = ({
1439
1506
  title = "No hay datos disponibles",
1440
1507
  description = "No se encontraron elementos para mostrar. Intenta ajustar los filtros o agrega nuevos elementos.",
@@ -1541,63 +1608,68 @@ var SimpleDataTable = ({
1541
1608
  }) => {
1542
1609
  const dataColumnsCount = table.getAllLeafColumns().length;
1543
1610
  const hasActionsColumn = !!(columnActions || listMenuActions);
1544
- return /* @__PURE__ */ jsx(Paper, { withBorder, radius: borderRadius, children: /* @__PURE__ */ jsxs(Table, { children: [
1545
- /* @__PURE__ */ jsx(
1546
- TableHeader,
1547
- {
1548
- canCheck,
1549
- table,
1550
- SortIcon,
1551
- SortIconAsc,
1552
- SortIconDesc,
1553
- hasActionsColumn,
1554
- headerBgColor
1555
- }
1556
- ),
1557
- loading ? /* @__PURE__ */ jsx(Table.Tbody, { children: Array.from({ length: skeletonRowCount }).map((_, rowIdx) => /* @__PURE__ */ jsxs(Table.Tr, { children: [
1558
- canCheck && /* @__PURE__ */ jsx(Table.Td, { style: { minHeight: 40, verticalAlign: "middle" }, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 18, radius: "sm" }) }),
1559
- Array.from({ length: dataColumnsCount }).map((_2, colIdx) => /* @__PURE__ */ jsx(
1560
- Table.Td,
1561
- {
1562
- style: { minHeight: 40, verticalAlign: "middle" },
1563
- children: /* @__PURE__ */ jsx(
1564
- Skeleton,
1565
- {
1566
- height: 16,
1567
- width: colIdx === dataColumnsCount - 1 ? 40 : `${60 + colIdx % 2 * 15}%`,
1568
- radius: "sm"
1569
- }
1570
- )
1571
- },
1572
- colIdx
1573
- )),
1574
- hasActionsColumn && /* @__PURE__ */ jsx(Table.Td, { style: { minHeight: 40, verticalAlign: "middle" }, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 32, radius: "sm" }) })
1575
- ] }, rowIdx)) }) : table.getRowCount() > 0 ? /* @__PURE__ */ jsx(
1576
- TableBody,
1577
- {
1578
- onRowClick,
1579
- onRowHover,
1580
- table,
1581
- canCheck,
1582
- columnActions,
1583
- listMenuActions
1584
- }
1585
- ) : /* @__PURE__ */ jsx(Table.Tbody, { children: /* @__PURE__ */ jsx(Table.Tr, { children: /* @__PURE__ */ jsx(
1586
- Table.Td,
1587
- {
1588
- colSpan: (table.getHeaderGroups()[0]?.headers.length ?? 1) + (canCheck ? 1 : 0),
1589
- children: /* @__PURE__ */ jsx(
1590
- Flex,
1611
+ const headerBg = typeof headerBgColor === "string" ? headerBgColor : headerBgColor?.bgColor ?? defaultHeaderBgColor;
1612
+ return /* @__PURE__ */ jsx(Paper, { withBorder, radius: borderRadius, children: /* @__PURE__ */ jsx(ScrollArea, { h: 600, type: "scroll", scrollbarSize: 8, children: /* @__PURE__ */ jsxs(
1613
+ Table,
1614
+ {
1615
+ styles: {
1616
+ thead: {
1617
+ position: "sticky",
1618
+ top: 0,
1619
+ zIndex: 1,
1620
+ background: headerBg,
1621
+ boxShadow: "0 1px 0 0 light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4))"
1622
+ }
1623
+ },
1624
+ children: [
1625
+ /* @__PURE__ */ jsx(
1626
+ TableHeader,
1591
1627
  {
1592
- justify: "center",
1593
- align: "center",
1594
- style: { minHeight: 200 },
1595
- children: emptyState
1628
+ canCheck,
1629
+ table,
1630
+ SortIcon,
1631
+ SortIconAsc,
1632
+ SortIconDesc,
1633
+ hasActionsColumn,
1634
+ headerBgColor
1596
1635
  }
1597
- )
1598
- }
1599
- ) }) })
1600
- ] }) });
1636
+ ),
1637
+ loading ? /* @__PURE__ */ jsx(
1638
+ TableSkeleton,
1639
+ {
1640
+ rowCount: skeletonRowCount,
1641
+ columnCount: dataColumnsCount,
1642
+ canCheck,
1643
+ hasActionsColumn
1644
+ }
1645
+ ) : table.getRowCount() > 0 ? /* @__PURE__ */ jsx(
1646
+ TableBody,
1647
+ {
1648
+ onRowClick,
1649
+ onRowHover,
1650
+ table,
1651
+ canCheck,
1652
+ columnActions,
1653
+ listMenuActions
1654
+ }
1655
+ ) : /* @__PURE__ */ jsx(Table.Tbody, { children: /* @__PURE__ */ jsx(Table.Tr, { children: /* @__PURE__ */ jsx(
1656
+ Table.Td,
1657
+ {
1658
+ colSpan: (table.getHeaderGroups()[0]?.headers.length ?? 1) + (canCheck ? 1 : 0),
1659
+ children: /* @__PURE__ */ jsx(
1660
+ Flex,
1661
+ {
1662
+ justify: "center",
1663
+ align: "center",
1664
+ style: { minHeight: 200 },
1665
+ children: emptyState
1666
+ }
1667
+ )
1668
+ }
1669
+ ) }) })
1670
+ ]
1671
+ }
1672
+ ) }) });
1601
1673
  };
1602
1674
  var SearchInput = ({
1603
1675
  value,
@@ -1703,7 +1775,19 @@ var FilterSelect = ({
1703
1775
  radius: "md",
1704
1776
  variant: "filled",
1705
1777
  leftSection: Icon ? /* @__PURE__ */ jsx(Icon, { size: 15 }) : null,
1706
- rightSection: selectedOption ? /* @__PURE__ */ jsx(ActionIcon, { variant: "subtle", radius: "md", onClick: handleClear, children: /* @__PURE__ */ jsx(X, { size: 12 }) }) : open ? /* @__PURE__ */ jsx(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 12 }),
1778
+ rightSection: selectedOption ? /* @__PURE__ */ jsx(
1779
+ ActionIcon,
1780
+ {
1781
+ component: "div",
1782
+ variant: "subtle",
1783
+ radius: "md",
1784
+ onClick: (event) => {
1785
+ event.stopPropagation();
1786
+ handleClear();
1787
+ },
1788
+ children: /* @__PURE__ */ jsx(X, { size: 12 })
1789
+ }
1790
+ ) : open ? /* @__PURE__ */ jsx(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 12 }),
1707
1791
  size: "sm",
1708
1792
  styles: {
1709
1793
  root: {
@@ -1791,7 +1875,16 @@ var FilterDate = ({
1791
1875
  radius: "md",
1792
1876
  variant: "filled",
1793
1877
  leftSection: /* @__PURE__ */ jsx(CalendarDays, { size: 14 }),
1794
- rightSection: value ? /* @__PURE__ */ jsx(ActionIcon, { radius: "md", variant: "subtle", onClick: handleClear, children: /* @__PURE__ */ jsx(X, { size: 12 }) }) : open ? /* @__PURE__ */ jsx(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 12 }),
1878
+ rightSection: value ? /* @__PURE__ */ jsx(
1879
+ ActionIcon,
1880
+ {
1881
+ component: "div",
1882
+ radius: "md",
1883
+ variant: "subtle",
1884
+ onClick: (event) => handleClear(event),
1885
+ children: /* @__PURE__ */ jsx(X, { size: 12 })
1886
+ }
1887
+ ) : open ? /* @__PURE__ */ jsx(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 12 }),
1795
1888
  size: "sm",
1796
1889
  onClick: () => setOpen((o) => !o),
1797
1890
  styles: {
@@ -1920,27 +2013,6 @@ var DataTable = ({
1920
2013
  ] })
1921
2014
  ] });
1922
2015
  };
1923
- var TableSkeleton = ({
1924
- rows = 10,
1925
- columns = 4,
1926
- canCheck = false,
1927
- withBorder,
1928
- borderRadius = "md",
1929
- rowHeight = 40
1930
- }) => {
1931
- const totalColumns = columns + (canCheck ? 1 : 0);
1932
- return /* @__PURE__ */ jsx(Paper, { withBorder, radius: borderRadius, children: /* @__PURE__ */ jsxs(Table, { children: [
1933
- /* @__PURE__ */ jsx(Table.Thead, { children: /* @__PURE__ */ jsx(Table.Tr, { children: Array.from({ length: totalColumns }).map((_, i) => /* @__PURE__ */ jsx(Table.Th, {}, i)) }) }),
1934
- /* @__PURE__ */ jsx(Table.Tbody, { children: Array.from({ length: rows }).map((_, rowIdx) => /* @__PURE__ */ jsx(Table.Tr, { children: Array.from({ length: totalColumns }).map((_2, colIdx) => /* @__PURE__ */ jsx(Table.Td, { children: /* @__PURE__ */ jsx(
1935
- Skeleton,
1936
- {
1937
- height: rowHeight - 16,
1938
- width: colIdx === 0 && canCheck ? 24 : colIdx === totalColumns - 1 ? 48 : `${70 + colIdx % 2 * 10}%`,
1939
- radius: "sm"
1940
- }
1941
- ) }, colIdx)) }, rowIdx)) })
1942
- ] }) });
1943
- };
1944
2016
  var TablePage = ({
1945
2017
  getQueryOptions,
1946
2018
  title,
@@ -1973,7 +2045,7 @@ var TablePage = ({
1973
2045
  });
1974
2046
  }, []);
1975
2047
  const { data, isLoading } = useQuery(getQueryOptions(tableParams));
1976
- return /* @__PURE__ */ jsxs("div", { children: [
2048
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: "sm", children: [
1977
2049
  /* @__PURE__ */ jsx(Title, { order: 1, children: title }),
1978
2050
  /* @__PURE__ */ jsx(
1979
2051
  DataTable,