infinity-ui-elements 1.7.12 → 1.7.13

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
@@ -2860,7 +2860,7 @@ const tableCellVariants = classVarianceAuthority.cva("text-body-medium-regular b
2860
2860
  },
2861
2861
  });
2862
2862
 
2863
- function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName, isDetailPanelOpen, visibleHeadersCount, onToggleAllRows, isAllRowsSelected, isSomeRowsSelected, getColumnStyle, }) {
2863
+ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName, onToggleAllRows, isAllRowsSelected, isSomeRowsSelected, getColumnStyle, }) {
2864
2864
  const headerHeight = {
2865
2865
  small: 32,
2866
2866
  medium: 40,
@@ -2869,20 +2869,18 @@ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHe
2869
2869
  return (jsxRuntime.jsx("thead", { className: cn(showHeaderBackground ? "bg-surface-fill-neutral-moderate" : "bg-white", stickyHeader && "sticky top-0 z-10"), children: headerGroups.map((headerGroup, groupIndex) => {
2870
2870
  const stickyTop = stickyHeader ? groupIndex * headerHeight : undefined;
2871
2871
  return (jsxRuntime.jsxs("tr", { children: [enableRowSelection && enableSelectAll && (jsxRuntime.jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground && "bg-surface-fill-neutral-moderate", stickyHeader && "sticky z-20", "w-10 rounded-tl-xlarge rounded-bl-xlarge", headerClassName), style: { top: stickyTop }, children: jsxRuntime.jsx(Checkbox, { checked: isAllRowsSelected, isIndeterminate: isSomeRowsSelected, onChange: onToggleAllRows, "aria-label": "Select all rows" }) })), headerGroup.headers.map((header, index) => {
2872
- const shouldHideColumn = isDetailPanelOpen && index >= visibleHeadersCount;
2873
- const isLastVisibleColumn = isDetailPanelOpen
2874
- ? index === visibleHeadersCount - 1
2875
- : index === headerGroup.headers.length - 1;
2872
+ const isFirstColumn = index === 0;
2873
+ const isLastColumn = index === headerGroup.headers.length - 1;
2876
2874
  return (jsxRuntime.jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground &&
2877
- "bg-surface-fill-neutral-moderate border-none", stickyHeader && "sticky z-20", !enableRowSelection && index === 0 && "rounded-tl-xlarge ", isLastVisibleColumn && "rounded-tr-xlarge", header.column.columnDef.meta?.headerClassName, headerClassName, "transition-all duration-300 ease-in-out", shouldHideColumn
2878
- ? "opacity-0 translate-x-8 pointer-events-none"
2879
- : "opacity-100 translate-x-0"), style: {
2875
+ "bg-surface-fill-neutral-moderate border-none", stickyHeader && "sticky z-20", !enableRowSelection && index === 0 && "rounded-tl-xlarge ", isLastColumn && "rounded-tr-xlarge", header.column.columnDef.meta?.headerClassName, headerClassName), style: {
2880
2876
  ...getColumnStyle(header.column.id, {
2881
2877
  width: header.getSize(),
2882
2878
  minWidth: header.column.columnDef.minSize,
2883
2879
  maxWidth: header.column.columnDef.maxSize,
2884
2880
  }),
2885
2881
  top: stickyTop,
2882
+ ...(isFirstColumn && { paddingLeft: "24px" }),
2883
+ ...(isLastColumn && { paddingRight: "24px" }),
2886
2884
  }, children: header.isPlaceholder ? null : (jsxRuntime.jsxs("div", { className: cn("flex items-center gap-2", header.column.getCanSort() &&
2887
2885
  "cursor-pointer select-none"), onClick: header.column.getToggleSortingHandler(), children: [reactTable.flexRender(header.column.columnDef.header, header.getContext()), header.column.getCanSort() && (jsxRuntime.jsx("span", { className: "text-surface-ink-neutral-muted", children: {
2888
2886
  asc: "↑",
@@ -2892,42 +2890,41 @@ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHe
2892
2890
  }) }));
2893
2891
  }
2894
2892
 
2895
- function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName, isDetailPanelOpen, visibleHeadersCount, effectiveSelectedRowId, onRowClick, getRowClassName, handleRowClick, getColumnStyle, }) {
2893
+ function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName, onRowClick, getRowClassName, handleRowClick, getColumnStyle, }) {
2896
2894
  const [focusedCell, setFocusedCell] = React__namespace.useState(null);
2897
2895
  const [hoveredRow, setHoveredRow] = React__namespace.useState(null);
2898
2896
  return (jsxRuntime.jsx("tbody", { className: cn("bg-surface-fill-neutral-intense"), children: rows.map((row) => {
2899
- const isRowSelected = row.id === effectiveSelectedRowId;
2900
2897
  const isRowHovered = hoveredRow === row.id;
2901
- const handleClick = () => handleRowClick(row.original, row.id);
2898
+ const handleClick = () => handleRowClick(row.original);
2902
2899
  return (jsxRuntime.jsxs("tr", { className: cn(variant === "striped" &&
2903
2900
  row.index % 2 === 1 &&
2904
- "bg-surface-fill-neutral-moderate", onRowClick && "cursor-pointer", isRowSelected && "bg-action-fill-primary-faded", isRowHovered &&
2901
+ "bg-surface-fill-neutral-moderate", onRowClick && "cursor-pointer", isRowHovered &&
2905
2902
  showRowHover &&
2906
- "bg-surface-fill-neutral-moderate", getRowClassName(row.original)), onClick: handleClick, onMouseEnter: () => setHoveredRow(row.id), onMouseLeave: () => setHoveredRow(null), children: [enableRowSelection && (jsxRuntime.jsx("td", { className: cn(tableCellVariants({ size }), "w-10", cellClassName), children: jsxRuntime.jsx(Checkbox, { checked: row.getIsSelected(), isIndeterminate: row.getIsSomeSelected(), onChange: row.getToggleSelectedHandler(), onClick: (e) => e.stopPropagation(), "aria-label": `Select row ${row.id}` }) })), row.getVisibleCells().map((cell, cellIndex) => {
2907
- const shouldHideColumn = isDetailPanelOpen && cellIndex >= visibleHeadersCount;
2903
+ "bg-surface-fill-neutral-moderate", getRowClassName(row.original)), onClick: handleClick, onMouseEnter: () => setHoveredRow(row.id), onMouseLeave: () => setHoveredRow(null), children: [enableRowSelection && (jsxRuntime.jsx("td", { className: cn(tableCellVariants({ size }), "w-10", cellClassName), style: {
2904
+ paddingTop: "20px",
2905
+ paddingBottom: "20px",
2906
+ }, children: jsxRuntime.jsx(Checkbox, { checked: row.getIsSelected(), isIndeterminate: row.getIsSomeSelected(), onChange: row.getToggleSelectedHandler(), onClick: (e) => e.stopPropagation(), "aria-label": `Select row ${row.id}` }) })), row.getVisibleCells().map((cell, cellIndex) => {
2908
2907
  const isCellFocused = focusedCell?.rowId === row.id &&
2909
2908
  focusedCell?.cellId === cell.id;
2910
2909
  const cellState = isCellFocused ? "focus" : "default";
2911
- return (jsxRuntime.jsx("td", { className: cn(tableCellVariants({ size, state: cellState }), cell.column.columnDef.meta?.cellClassName, cellClassName, "transition-all duration-300 ease-in-out", shouldHideColumn
2912
- ? "opacity-0 translate-x-8 pointer-events-none"
2913
- : "opacity-100 translate-x-0"), style: getColumnStyle(cell.column.id, {
2914
- width: cell.column.getSize(),
2915
- minWidth: cell.column.columnDef.minSize,
2916
- maxWidth: cell.column.columnDef.maxSize,
2917
- }), tabIndex: 0, onFocus: () => setFocusedCell({ rowId: row.id, cellId: cell.id }), onBlur: () => setFocusedCell(null), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2910
+ const visibleCells = row.getVisibleCells();
2911
+ const isFirstCell = cellIndex === 0;
2912
+ const isLastCell = cellIndex === visibleCells.length - 1;
2913
+ return (jsxRuntime.jsx("td", { className: cn(tableCellVariants({ size, state: cellState }), cell.column.columnDef.meta?.cellClassName, cellClassName), style: {
2914
+ ...getColumnStyle(cell.column.id, {
2915
+ width: cell.column.getSize(),
2916
+ minWidth: cell.column.columnDef.minSize,
2917
+ maxWidth: cell.column.columnDef.maxSize,
2918
+ }),
2919
+ paddingTop: "20px",
2920
+ paddingBottom: "20px",
2921
+ ...(isFirstCell && { paddingLeft: "24px" }),
2922
+ ...(isLastCell && { paddingRight: "24px" }),
2923
+ }, tabIndex: 0, onFocus: () => setFocusedCell({ rowId: row.id, cellId: cell.id }), onBlur: () => setFocusedCell(null), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2918
2924
  })] }, row.id));
2919
2925
  }) }));
2920
2926
  }
2921
2927
 
2922
- function DetailPanel({ isOpen, content, data, onClose, }) {
2923
- return (jsxRuntime.jsx("div", { className: cn("absolute top-0 right-0 h-full z-20 transition-all duration-300 ease-in-out", isOpen
2924
- ? "translate-x-0 opacity-100"
2925
- : "translate-x-full opacity-0 pointer-events-none"), style: { width: "332px", paddingLeft: "12px" }, children: jsxRuntime.jsx("div", { className: "w-full h-full bg-white border border-surface-outline-neutral-muted rounded-tr-xlarge rounded-br-xlarge overflow-hidden", children: jsxRuntime.jsx("div", { className: "w-full h-full overflow-auto", children: data && (jsxRuntime.jsxs("div", { className: "relative h-full", children: [jsxRuntime.jsx("button", { onClick: (e) => {
2926
- e.stopPropagation();
2927
- onClose();
2928
- }, className: "absolute top-4 right-4 z-10 p-2 rounded-medium hover:bg-surface-fill-neutral-faded transition-colors", "aria-label": "Close detail panel", children: jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", className: "text-surface-ink-neutral-muted", children: jsxRuntime.jsx("path", { d: "M12 4L4 12M4 4l8 8", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) }), content(data)] })) }) }) }));
2929
- }
2930
-
2931
2928
  function renderDefaultLoadingState({ colSpan }) {
2932
2929
  return (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: colSpan, className: "text-center py-12 text-surface-ink-neutral-muted", children: jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-2", children: [jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-action-fill-primary-default" }), jsxRuntime.jsx("span", { children: "Loading..." })] }) }) }));
2933
2930
  }
@@ -2936,47 +2933,10 @@ function renderDefaultEmptyState({ colSpan }) {
2936
2933
  }
2937
2934
 
2938
2935
  // ==================== Component ====================
2939
- function TableComponent({ className, wrapperClassName, containerClassName, variant, size = "medium", table, enableRowSelection = false, enableSelectAll = false, isLoading = false, loading, loadingComponent, emptyComponent, enableHorizontalScroll = false, stickyHeader = false, maxHeight, showRowHover = true, onRowClick, rowClassName, headerClassName, cellClassName, showHeaderBackground = true, detailPanel, hideColumnsOnDetailOpen = 3, selectedRowId, onRowSelectionChange, loadingSkeletonRows, loadingSkeletonHeight, columnWidths, columnMinWidths, columnMaxWidths, ...props }, ref) {
2940
- // ==================== State ====================
2941
- const [internalSelectedRowId, setInternalSelectedRowId] = React__namespace.useState(null);
2942
- const selectedRowIdRef = React__namespace.useRef(null);
2943
- const effectiveSelectedRowId = selectedRowId !== undefined ? selectedRowId : internalSelectedRowId;
2944
- const isDetailPanelOpen = Boolean(effectiveSelectedRowId);
2945
- // ==================== Effects ====================
2946
- // Keep ref in sync
2947
- React__namespace.useEffect(() => {
2948
- selectedRowIdRef.current = effectiveSelectedRowId;
2949
- }, [effectiveSelectedRowId]);
2950
- // Clear selection if selected row is not in current data
2951
- React__namespace.useEffect(() => {
2952
- if (effectiveSelectedRowId) {
2953
- const rowExists = table
2954
- .getRowModel()
2955
- .rows.some((r) => r.id === effectiveSelectedRowId);
2956
- if (!rowExists) {
2957
- if (selectedRowId === undefined) {
2958
- setInternalSelectedRowId(null);
2959
- }
2960
- if (onRowSelectionChange) {
2961
- onRowSelectionChange(null);
2962
- }
2963
- }
2964
- }
2965
- }, [
2966
- table.getRowModel().rows,
2967
- effectiveSelectedRowId,
2968
- selectedRowId,
2969
- onRowSelectionChange,
2970
- ]);
2936
+ function TableComponent({ className, wrapperClassName, containerClassName, variant, size = "medium", table, enableRowSelection = false, enableSelectAll = false, isLoading = false, loading, loadingComponent, emptyComponent, enableHorizontalScroll = false, stickyHeader = false, maxHeight, showRowHover = true, onRowClick, rowClassName, headerClassName, cellClassName, showHeaderBackground = true, loadingSkeletonRows, loadingSkeletonHeight, columnWidths, columnMinWidths, columnMaxWidths, ...props }, ref) {
2971
2937
  // ==================== Computed Values ====================
2972
2938
  const hasData = table.getRowModel().rows?.length > 0;
2973
2939
  const headerGroups = table.getHeaderGroups();
2974
- const headers = headerGroups[0]?.headers || [];
2975
- const visibleHeadersCount = React__namespace.useMemo(() => {
2976
- return isDetailPanelOpen
2977
- ? headers.length - hideColumnsOnDetailOpen
2978
- : headers.length;
2979
- }, [isDetailPanelOpen, headers.length, hideColumnsOnDetailOpen]);
2980
2940
  const normalizeSizeValue = (value) => {
2981
2941
  if (value === undefined)
2982
2942
  return undefined;
@@ -3043,42 +3003,18 @@ function TableComponent({ className, wrapperClassName, containerClassName, varia
3043
3003
  }
3044
3004
  return rowClassName || "";
3045
3005
  }, [rowClassName]);
3046
- const handleRowClickInternal = React__namespace.useCallback((row, rowId) => {
3047
- const currentSelectedId = selectedRowIdRef.current;
3048
- const newSelectedId = currentSelectedId === rowId ? null : rowId;
3049
- if (selectedRowId === undefined) {
3050
- setInternalSelectedRowId(newSelectedId);
3051
- }
3052
- if (onRowSelectionChange) {
3053
- onRowSelectionChange(newSelectedId);
3054
- }
3006
+ const handleRowClickInternal = React__namespace.useCallback((row) => {
3055
3007
  if (onRowClick) {
3056
3008
  onRowClick(row);
3057
3009
  }
3058
- }, [selectedRowId, onRowSelectionChange, onRowClick]);
3059
- const getSelectedRowData = () => {
3060
- if (!effectiveSelectedRowId)
3061
- return null;
3062
- const row = table
3063
- .getRowModel()
3064
- .rows.find((r) => r.id === effectiveSelectedRowId);
3065
- return row ? row.original : null;
3066
- };
3067
- const handleDetailPanelClose = () => {
3068
- if (selectedRowId === undefined) {
3069
- setInternalSelectedRowId(null);
3070
- }
3071
- if (onRowSelectionChange) {
3072
- onRowSelectionChange(null);
3073
- }
3074
- };
3010
+ }, [onRowClick]);
3075
3011
  const renderEmptyState = () => {
3076
3012
  if (emptyComponent)
3077
3013
  return emptyComponent;
3078
3014
  return renderDefaultEmptyState({ colSpan: table.getAllColumns().length });
3079
3015
  };
3080
3016
  // ==================== Render ====================
3081
- return (jsxRuntime.jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children: jsxRuntime.jsxs("div", { className: cn("relative", enableHorizontalScroll ? "overflow-x-auto" : "overflow-x-hidden", maxHeight && "overflow-y-auto", containerClassName), style: containerStyle, children: [jsxRuntime.jsxs("table", { className: cn(tableVariants({ variant, size }), className), children: [jsxRuntime.jsx(TableHeader, { headerGroups: headerGroups, enableRowSelection: enableRowSelection, enableSelectAll: enableSelectAll, showHeaderBackground: showHeaderBackground, stickyHeader: stickyHeader, size: size || "medium", headerClassName: headerClassName, isDetailPanelOpen: isDetailPanelOpen, visibleHeadersCount: visibleHeadersCount, onToggleAllRows: (e) => table.getToggleAllRowsSelectedHandler()(e), isAllRowsSelected: table.getIsAllRowsSelected(), isSomeRowsSelected: table.getIsSomeRowsSelected(), getColumnStyle: getColumnStyle }), resolvedLoading ? (jsxRuntime.jsx("tbody", { children: renderLoadingContent() })) : !hasData ? (jsxRuntime.jsx("tbody", { children: renderEmptyState() })) : (jsxRuntime.jsx(TableBody, { rows: table.getRowModel().rows, enableRowSelection: enableRowSelection, size: size || "medium", variant: variant || "default", showRowHover: showRowHover, cellClassName: cellClassName, isDetailPanelOpen: isDetailPanelOpen, visibleHeadersCount: visibleHeadersCount, effectiveSelectedRowId: effectiveSelectedRowId, onRowClick: onRowClick, getRowClassName: getRowClassName, handleRowClick: handleRowClickInternal, getColumnStyle: getColumnStyle }))] }), detailPanel && (jsxRuntime.jsx(DetailPanel, { isOpen: isDetailPanelOpen, content: detailPanel, data: getSelectedRowData(), onClose: handleDetailPanelClose }))] }) }));
3017
+ return (jsxRuntime.jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children: jsxRuntime.jsx("div", { className: cn("relative", enableHorizontalScroll ? "overflow-x-auto" : "overflow-x-hidden", maxHeight && "overflow-y-auto", containerClassName), style: containerStyle, children: jsxRuntime.jsxs("table", { className: cn(tableVariants({ variant, size }), className), children: [jsxRuntime.jsx(TableHeader, { headerGroups: headerGroups, enableRowSelection: enableRowSelection, enableSelectAll: enableSelectAll, showHeaderBackground: showHeaderBackground, stickyHeader: stickyHeader, size: size || "medium", headerClassName: headerClassName, onToggleAllRows: (e) => table.getToggleAllRowsSelectedHandler()(e), isAllRowsSelected: table.getIsAllRowsSelected(), isSomeRowsSelected: table.getIsSomeRowsSelected(), getColumnStyle: getColumnStyle }), resolvedLoading ? (jsxRuntime.jsx("tbody", { children: renderLoadingContent() })) : !hasData ? (jsxRuntime.jsx("tbody", { children: renderEmptyState() })) : (jsxRuntime.jsx(TableBody, { rows: table.getRowModel().rows, enableRowSelection: enableRowSelection, size: size || "medium", variant: variant || "default", showRowHover: showRowHover, cellClassName: cellClassName, onRowClick: onRowClick, getRowClassName: getRowClassName, handleRowClick: handleRowClickInternal, getColumnStyle: getColumnStyle }))] }) }) }));
3082
3018
  }
3083
3019
  // ==================== Export ====================
3084
3020
  const Table = React__namespace.forwardRef(TableComponent);