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/components/Table/Table.d.ts +1 -5
- package/dist/components/Table/Table.d.ts.map +1 -1
- package/dist/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/components/Table/TableBody.d.ts +2 -5
- package/dist/components/Table/TableBody.d.ts.map +1 -1
- package/dist/components/Table/TableHeader.d.ts +1 -3
- package/dist/components/Table/TableHeader.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +31 -95
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +31 -95
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2839,7 +2839,7 @@ const tableCellVariants = cva("text-body-medium-regular border-b border-surface-
|
|
|
2839
2839
|
},
|
|
2840
2840
|
});
|
|
2841
2841
|
|
|
2842
|
-
function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName,
|
|
2842
|
+
function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHeaderBackground, stickyHeader, size, headerClassName, onToggleAllRows, isAllRowsSelected, isSomeRowsSelected, getColumnStyle, }) {
|
|
2843
2843
|
const headerHeight = {
|
|
2844
2844
|
small: 32,
|
|
2845
2845
|
medium: 40,
|
|
@@ -2848,20 +2848,18 @@ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHe
|
|
|
2848
2848
|
return (jsx("thead", { className: cn(showHeaderBackground ? "bg-surface-fill-neutral-moderate" : "bg-white", stickyHeader && "sticky top-0 z-10"), children: headerGroups.map((headerGroup, groupIndex) => {
|
|
2849
2849
|
const stickyTop = stickyHeader ? groupIndex * headerHeight : undefined;
|
|
2850
2850
|
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) => {
|
|
2851
|
-
const
|
|
2852
|
-
const
|
|
2853
|
-
? index === visibleHeadersCount - 1
|
|
2854
|
-
: index === headerGroup.headers.length - 1;
|
|
2851
|
+
const isFirstColumn = index === 0;
|
|
2852
|
+
const isLastColumn = index === headerGroup.headers.length - 1;
|
|
2855
2853
|
return (jsx("th", { className: cn(tableHeaderVariants({ size }), showHeaderBackground &&
|
|
2856
|
-
"bg-surface-fill-neutral-moderate border-none", stickyHeader && "sticky z-20", !enableRowSelection && index === 0 && "rounded-tl-xlarge ",
|
|
2857
|
-
? "opacity-0 translate-x-8 pointer-events-none"
|
|
2858
|
-
: "opacity-100 translate-x-0"), style: {
|
|
2854
|
+
"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: {
|
|
2859
2855
|
...getColumnStyle(header.column.id, {
|
|
2860
2856
|
width: header.getSize(),
|
|
2861
2857
|
minWidth: header.column.columnDef.minSize,
|
|
2862
2858
|
maxWidth: header.column.columnDef.maxSize,
|
|
2863
2859
|
}),
|
|
2864
2860
|
top: stickyTop,
|
|
2861
|
+
...(isFirstColumn && { paddingLeft: "24px" }),
|
|
2862
|
+
...(isLastColumn && { paddingRight: "24px" }),
|
|
2865
2863
|
}, children: header.isPlaceholder ? null : (jsxs("div", { className: cn("flex items-center gap-2", header.column.getCanSort() &&
|
|
2866
2864
|
"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: {
|
|
2867
2865
|
asc: "↑",
|
|
@@ -2871,42 +2869,41 @@ function TableHeader({ headerGroups, enableRowSelection, enableSelectAll, showHe
|
|
|
2871
2869
|
}) }));
|
|
2872
2870
|
}
|
|
2873
2871
|
|
|
2874
|
-
function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName,
|
|
2872
|
+
function TableBody({ rows, enableRowSelection, size, variant, showRowHover, cellClassName, onRowClick, getRowClassName, handleRowClick, getColumnStyle, }) {
|
|
2875
2873
|
const [focusedCell, setFocusedCell] = React.useState(null);
|
|
2876
2874
|
const [hoveredRow, setHoveredRow] = React.useState(null);
|
|
2877
2875
|
return (jsx("tbody", { className: cn("bg-surface-fill-neutral-intense"), children: rows.map((row) => {
|
|
2878
|
-
const isRowSelected = row.id === effectiveSelectedRowId;
|
|
2879
2876
|
const isRowHovered = hoveredRow === row.id;
|
|
2880
|
-
const handleClick = () => handleRowClick(row.original
|
|
2877
|
+
const handleClick = () => handleRowClick(row.original);
|
|
2881
2878
|
return (jsxs("tr", { className: cn(variant === "striped" &&
|
|
2882
2879
|
row.index % 2 === 1 &&
|
|
2883
|
-
"bg-surface-fill-neutral-moderate", onRowClick && "cursor-pointer",
|
|
2880
|
+
"bg-surface-fill-neutral-moderate", onRowClick && "cursor-pointer", isRowHovered &&
|
|
2884
2881
|
showRowHover &&
|
|
2885
|
-
"bg-surface-fill-neutral-moderate", getRowClassName(row.original)), onClick: handleClick, onMouseEnter: () => setHoveredRow(row.id), onMouseLeave: () => setHoveredRow(null), children: [enableRowSelection && (jsx("td", { className: cn(tableCellVariants({ size }), "w-10", cellClassName),
|
|
2886
|
-
|
|
2882
|
+
"bg-surface-fill-neutral-moderate", getRowClassName(row.original)), onClick: handleClick, onMouseEnter: () => setHoveredRow(row.id), onMouseLeave: () => setHoveredRow(null), children: [enableRowSelection && (jsx("td", { className: cn(tableCellVariants({ size }), "w-10", cellClassName), style: {
|
|
2883
|
+
paddingTop: "20px",
|
|
2884
|
+
paddingBottom: "20px",
|
|
2885
|
+
}, children: 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) => {
|
|
2887
2886
|
const isCellFocused = focusedCell?.rowId === row.id &&
|
|
2888
2887
|
focusedCell?.cellId === cell.id;
|
|
2889
2888
|
const cellState = isCellFocused ? "focus" : "default";
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2889
|
+
const visibleCells = row.getVisibleCells();
|
|
2890
|
+
const isFirstCell = cellIndex === 0;
|
|
2891
|
+
const isLastCell = cellIndex === visibleCells.length - 1;
|
|
2892
|
+
return (jsx("td", { className: cn(tableCellVariants({ size, state: cellState }), cell.column.columnDef.meta?.cellClassName, cellClassName), style: {
|
|
2893
|
+
...getColumnStyle(cell.column.id, {
|
|
2894
|
+
width: cell.column.getSize(),
|
|
2895
|
+
minWidth: cell.column.columnDef.minSize,
|
|
2896
|
+
maxWidth: cell.column.columnDef.maxSize,
|
|
2897
|
+
}),
|
|
2898
|
+
paddingTop: "20px",
|
|
2899
|
+
paddingBottom: "20px",
|
|
2900
|
+
...(isFirstCell && { paddingLeft: "24px" }),
|
|
2901
|
+
...(isLastCell && { paddingRight: "24px" }),
|
|
2902
|
+
}, tabIndex: 0, onFocus: () => setFocusedCell({ rowId: row.id, cellId: cell.id }), onBlur: () => setFocusedCell(null), children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
|
|
2897
2903
|
})] }, row.id));
|
|
2898
2904
|
}) }));
|
|
2899
2905
|
}
|
|
2900
2906
|
|
|
2901
|
-
function DetailPanel({ isOpen, content, data, onClose, }) {
|
|
2902
|
-
return (jsx("div", { className: cn("absolute top-0 right-0 h-full z-20 transition-all duration-300 ease-in-out", isOpen
|
|
2903
|
-
? "translate-x-0 opacity-100"
|
|
2904
|
-
: "translate-x-full opacity-0 pointer-events-none"), style: { width: "332px", paddingLeft: "12px" }, children: jsx("div", { className: "w-full h-full bg-white border border-surface-outline-neutral-muted rounded-tr-xlarge rounded-br-xlarge overflow-hidden", children: jsx("div", { className: "w-full h-full overflow-auto", children: data && (jsxs("div", { className: "relative h-full", children: [jsx("button", { onClick: (e) => {
|
|
2905
|
-
e.stopPropagation();
|
|
2906
|
-
onClose();
|
|
2907
|
-
}, 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: jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", className: "text-surface-ink-neutral-muted", children: jsx("path", { d: "M12 4L4 12M4 4l8 8", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) }), content(data)] })) }) }) }));
|
|
2908
|
-
}
|
|
2909
|
-
|
|
2910
2907
|
function renderDefaultLoadingState({ colSpan }) {
|
|
2911
2908
|
return (jsx("tr", { children: jsx("td", { colSpan: colSpan, className: "text-center py-12 text-surface-ink-neutral-muted", children: jsxs("div", { className: "flex items-center justify-center gap-2", children: [jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-action-fill-primary-default" }), jsx("span", { children: "Loading..." })] }) }) }));
|
|
2912
2909
|
}
|
|
@@ -2915,47 +2912,10 @@ function renderDefaultEmptyState({ colSpan }) {
|
|
|
2915
2912
|
}
|
|
2916
2913
|
|
|
2917
2914
|
// ==================== Component ====================
|
|
2918
|
-
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,
|
|
2919
|
-
// ==================== State ====================
|
|
2920
|
-
const [internalSelectedRowId, setInternalSelectedRowId] = React.useState(null);
|
|
2921
|
-
const selectedRowIdRef = React.useRef(null);
|
|
2922
|
-
const effectiveSelectedRowId = selectedRowId !== undefined ? selectedRowId : internalSelectedRowId;
|
|
2923
|
-
const isDetailPanelOpen = Boolean(effectiveSelectedRowId);
|
|
2924
|
-
// ==================== Effects ====================
|
|
2925
|
-
// Keep ref in sync
|
|
2926
|
-
React.useEffect(() => {
|
|
2927
|
-
selectedRowIdRef.current = effectiveSelectedRowId;
|
|
2928
|
-
}, [effectiveSelectedRowId]);
|
|
2929
|
-
// Clear selection if selected row is not in current data
|
|
2930
|
-
React.useEffect(() => {
|
|
2931
|
-
if (effectiveSelectedRowId) {
|
|
2932
|
-
const rowExists = table
|
|
2933
|
-
.getRowModel()
|
|
2934
|
-
.rows.some((r) => r.id === effectiveSelectedRowId);
|
|
2935
|
-
if (!rowExists) {
|
|
2936
|
-
if (selectedRowId === undefined) {
|
|
2937
|
-
setInternalSelectedRowId(null);
|
|
2938
|
-
}
|
|
2939
|
-
if (onRowSelectionChange) {
|
|
2940
|
-
onRowSelectionChange(null);
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
}, [
|
|
2945
|
-
table.getRowModel().rows,
|
|
2946
|
-
effectiveSelectedRowId,
|
|
2947
|
-
selectedRowId,
|
|
2948
|
-
onRowSelectionChange,
|
|
2949
|
-
]);
|
|
2915
|
+
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) {
|
|
2950
2916
|
// ==================== Computed Values ====================
|
|
2951
2917
|
const hasData = table.getRowModel().rows?.length > 0;
|
|
2952
2918
|
const headerGroups = table.getHeaderGroups();
|
|
2953
|
-
const headers = headerGroups[0]?.headers || [];
|
|
2954
|
-
const visibleHeadersCount = React.useMemo(() => {
|
|
2955
|
-
return isDetailPanelOpen
|
|
2956
|
-
? headers.length - hideColumnsOnDetailOpen
|
|
2957
|
-
: headers.length;
|
|
2958
|
-
}, [isDetailPanelOpen, headers.length, hideColumnsOnDetailOpen]);
|
|
2959
2919
|
const normalizeSizeValue = (value) => {
|
|
2960
2920
|
if (value === undefined)
|
|
2961
2921
|
return undefined;
|
|
@@ -3022,42 +2982,18 @@ function TableComponent({ className, wrapperClassName, containerClassName, varia
|
|
|
3022
2982
|
}
|
|
3023
2983
|
return rowClassName || "";
|
|
3024
2984
|
}, [rowClassName]);
|
|
3025
|
-
const handleRowClickInternal = React.useCallback((row
|
|
3026
|
-
const currentSelectedId = selectedRowIdRef.current;
|
|
3027
|
-
const newSelectedId = currentSelectedId === rowId ? null : rowId;
|
|
3028
|
-
if (selectedRowId === undefined) {
|
|
3029
|
-
setInternalSelectedRowId(newSelectedId);
|
|
3030
|
-
}
|
|
3031
|
-
if (onRowSelectionChange) {
|
|
3032
|
-
onRowSelectionChange(newSelectedId);
|
|
3033
|
-
}
|
|
2985
|
+
const handleRowClickInternal = React.useCallback((row) => {
|
|
3034
2986
|
if (onRowClick) {
|
|
3035
2987
|
onRowClick(row);
|
|
3036
2988
|
}
|
|
3037
|
-
}, [
|
|
3038
|
-
const getSelectedRowData = () => {
|
|
3039
|
-
if (!effectiveSelectedRowId)
|
|
3040
|
-
return null;
|
|
3041
|
-
const row = table
|
|
3042
|
-
.getRowModel()
|
|
3043
|
-
.rows.find((r) => r.id === effectiveSelectedRowId);
|
|
3044
|
-
return row ? row.original : null;
|
|
3045
|
-
};
|
|
3046
|
-
const handleDetailPanelClose = () => {
|
|
3047
|
-
if (selectedRowId === undefined) {
|
|
3048
|
-
setInternalSelectedRowId(null);
|
|
3049
|
-
}
|
|
3050
|
-
if (onRowSelectionChange) {
|
|
3051
|
-
onRowSelectionChange(null);
|
|
3052
|
-
}
|
|
3053
|
-
};
|
|
2989
|
+
}, [onRowClick]);
|
|
3054
2990
|
const renderEmptyState = () => {
|
|
3055
2991
|
if (emptyComponent)
|
|
3056
2992
|
return emptyComponent;
|
|
3057
2993
|
return renderDefaultEmptyState({ colSpan: table.getAllColumns().length });
|
|
3058
2994
|
};
|
|
3059
2995
|
// ==================== Render ====================
|
|
3060
|
-
return (jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children:
|
|
2996
|
+
return (jsx("div", { ref: ref, className: cn("w-full", wrapperClassName), ...props, children: jsx("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, onToggleAllRows: (e) => table.getToggleAllRowsSelectedHandler()(e), isAllRowsSelected: table.getIsAllRowsSelected(), isSomeRowsSelected: table.getIsSomeRowsSelected(), getColumnStyle: getColumnStyle }), resolvedLoading ? (jsx("tbody", { children: renderLoadingContent() })) : !hasData ? (jsx("tbody", { children: renderEmptyState() })) : (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 }))] }) }) }));
|
|
3061
2997
|
}
|
|
3062
2998
|
// ==================== Export ====================
|
|
3063
2999
|
const Table = React.forwardRef(TableComponent);
|