infinity-ui-elements 1.7.6 → 1.7.8

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.esm.js CHANGED
@@ -2835,43 +2835,44 @@ const tableCellVariants = cva("text-body-medium-regular border-b border-surface-
2835
2835
  },
2836
2836
  });
2837
2837
 
2838
- function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName, isDetailPanelOpen, visibleHeadersCount, onToggleAllRows, isAllRowsSelected, isSomeRowsSelected, isBodyScrollable = false, }) {
2839
- return (jsx("thead", { className: cn(showHeaderBackground && "bg-surface-fill-neutral-moderate", stickyHeader && "sticky top-0 z-10"), children: headerGroups.map((headerGroup) => (jsxs("tr", { className: cn(isBodyScrollable && "table w-full table-fixed"), children: [enableRowSelection && enableSelectAll && (jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground && "bg-surface-fill-neutral-moderate", "w-10 rounded-tl-xlarge rounded-bl-xlarge", headerClassName), children: jsx(Checkbox, { checked: isAllRowsSelected, isIndeterminate: isSomeRowsSelected, onChange: onToggleAllRows, "aria-label": "Select all rows" }) })), headerGroup.headers.map((header, index) => {
2840
- const shouldHideColumn = isDetailPanelOpen && index >= visibleHeadersCount;
2841
- const isLastVisibleColumn = isDetailPanelOpen
2842
- ? index === visibleHeadersCount - 1
2843
- : index === headerGroup.headers.length - 1;
2844
- return (jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground &&
2845
- "bg-surface-fill-neutral-moderate border-none", !enableRowSelection && index === 0 && "rounded-tl-xlarge ", isLastVisibleColumn && "rounded-tr-xlarge", header.column.columnDef.meta?.headerClassName, headerClassName, "transition-all duration-300 ease-in-out", shouldHideColumn
2846
- ? "opacity-0 translate-x-8 pointer-events-none"
2847
- : "opacity-100 translate-x-0"), style: {
2848
- width: header.getSize(),
2849
- minWidth: header.column.columnDef.minSize,
2850
- maxWidth: header.column.columnDef.maxSize,
2851
- }, children: header.isPlaceholder ? null : (jsxs("div", { className: cn("flex items-center gap-2", header.column.getCanSort() && "cursor-pointer select-none"), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), header.column.getCanSort() && (jsx("span", { className: "text-surface-ink-neutral-muted", children: {
2852
- asc: "",
2853
- desc: "",
2854
- }[header.column.getIsSorted()] ?? "↕" }))] })) }, header.id));
2855
- })] }, headerGroup.id))) }));
2838
+ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName, isDetailPanelOpen, visibleHeadersCount, onToggleAllRows, isAllRowsSelected, isSomeRowsSelected, }) {
2839
+ const headerHeight = {
2840
+ small: 32,
2841
+ medium: 40,
2842
+ large: 48,
2843
+ }[size] ?? 40;
2844
+ return (jsx("thead", { className: cn(showHeaderBackground && "bg-surface-fill-neutral-moderate", stickyHeader && "sticky top-0 z-10"), children: headerGroups.map((headerGroup, groupIndex) => {
2845
+ const stickyTop = stickyHeader ? groupIndex * headerHeight : undefined;
2846
+ return (jsxs("tr", { children: [enableRowSelection && enableSelectAll && (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: jsx(Checkbox, { checked: isAllRowsSelected, isIndeterminate: isSomeRowsSelected, onChange: onToggleAllRows, "aria-label": "Select all rows" }) })), headerGroup.headers.map((header, index) => {
2847
+ const shouldHideColumn = isDetailPanelOpen && index >= visibleHeadersCount;
2848
+ const isLastVisibleColumn = isDetailPanelOpen
2849
+ ? index === visibleHeadersCount - 1
2850
+ : index === headerGroup.headers.length - 1;
2851
+ return (jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground &&
2852
+ "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
2853
+ ? "opacity-0 translate-x-8 pointer-events-none"
2854
+ : "opacity-100 translate-x-0"), style: {
2855
+ width: header.getSize(),
2856
+ minWidth: header.column.columnDef.minSize,
2857
+ maxWidth: header.column.columnDef.maxSize,
2858
+ top: stickyTop,
2859
+ }, children: header.isPlaceholder ? null : (jsxs("div", { className: cn("flex items-center gap-2", header.column.getCanSort() &&
2860
+ "cursor-pointer select-none"), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), header.column.getCanSort() && (jsx("span", { className: "text-surface-ink-neutral-muted", children: {
2861
+ asc: "↑",
2862
+ desc: "↓",
2863
+ }[header.column.getIsSorted()] ?? "↕" }))] })) }, header.id));
2864
+ })] }, headerGroup.id));
2865
+ }) }));
2856
2866
  }
2857
2867
 
2858
- function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName, isDetailPanelOpen, visibleHeadersCount, effectiveSelectedRowId, onRowClick, getRowClassName, handleRowClick, maxBodyHeight, }) {
2868
+ function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName, isDetailPanelOpen, visibleHeadersCount, effectiveSelectedRowId, onRowClick, getRowClassName, handleRowClick, }) {
2859
2869
  const [focusedCell, setFocusedCell] = React.useState(null);
2860
2870
  const [hoveredRow, setHoveredRow] = React.useState(null);
2861
- const bodyStyle = React.useMemo(() => {
2862
- if (!maxBodyHeight)
2863
- return undefined;
2864
- return {
2865
- maxHeight: typeof maxBodyHeight === "number"
2866
- ? `${maxBodyHeight}px`
2867
- : maxBodyHeight,
2868
- };
2869
- }, [maxBodyHeight]);
2870
- return (jsx("tbody", { className: cn("bg-surface-fill-neutral-intense", maxBodyHeight && "block overflow-y-auto"), style: bodyStyle, children: rows.map((row) => {
2871
+ return (jsx("tbody", { className: cn("bg-surface-fill-neutral-intense"), children: rows.map((row) => {
2871
2872
  const isRowSelected = row.id === effectiveSelectedRowId;
2872
2873
  const isRowHovered = hoveredRow === row.id;
2873
2874
  const handleClick = () => handleRowClick(row.original, row.id);
2874
- return (jsxs("tr", { className: cn(maxBodyHeight && "table w-full table-fixed", variant === "striped" &&
2875
+ return (jsxs("tr", { className: cn(variant === "striped" &&
2875
2876
  row.index % 2 === 1 &&
2876
2877
  "bg-surface-fill-neutral-moderate", onRowClick && "cursor-pointer", isRowSelected && "bg-action-fill-primary-faded", isRowHovered &&
2877
2878
  showRowHover &&
@@ -2949,6 +2950,13 @@ function TableComponent({ className, wrapperClassName, containerClassName, varia
2949
2950
  ? headers.length - hideColumnsOnDetailOpen
2950
2951
  : headers.length;
2951
2952
  }, [isDetailPanelOpen, headers.length, hideColumnsOnDetailOpen]);
2953
+ const containerStyle = React.useMemo(() => {
2954
+ if (!maxHeight)
2955
+ return undefined;
2956
+ return {
2957
+ maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight,
2958
+ };
2959
+ }, [maxHeight]);
2952
2960
  // ==================== Callbacks ====================
2953
2961
  const getRowClassName = React.useCallback((row) => {
2954
2962
  if (typeof rowClassName === "function") {
@@ -2997,7 +3005,7 @@ function TableComponent({ className, wrapperClassName, containerClassName, varia
2997
3005
  return renderDefaultEmptyState({ colSpan: table.getAllColumns().length });
2998
3006
  };
2999
3007
  // ==================== Render ====================
3000
- return (jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children: jsxs("div", { className: cn("relative", enableHorizontalScroll ? "overflow-x-auto" : "overflow-x-hidden", containerClassName), children: [jsxs("table", { className: cn(tableVariants({ variant, size }), className), children: [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(), isBodyScrollable: Boolean(maxHeight) }), isLoading ? (jsx("tbody", { children: renderLoadingState() })) : !hasData ? (jsx("tbody", { children: renderEmptyState() })) : (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, maxBodyHeight: maxHeight }))] }), detailPanel && (jsx(DetailPanel, { isOpen: isDetailPanelOpen, content: detailPanel, data: getSelectedRowData(), onClose: handleDetailPanelClose }))] }) }));
3008
+ return (jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children: jsxs("div", { className: cn("relative", enableHorizontalScroll ? "overflow-x-auto" : "overflow-x-hidden", maxHeight && "overflow-y-auto", containerClassName), style: containerStyle, children: [jsxs("table", { className: cn(tableVariants({ variant, size }), className), children: [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() }), isLoading ? (jsx("tbody", { children: renderLoadingState() })) : !hasData ? (jsx("tbody", { children: renderEmptyState() })) : (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 }))] }), detailPanel && (jsx(DetailPanel, { isOpen: isDetailPanelOpen, content: detailPanel, data: getSelectedRowData(), onClose: handleDetailPanelClose }))] }) }));
3001
3009
  }
3002
3010
  // ==================== Export ====================
3003
3011
  const Table = React.forwardRef(TableComponent);