@raystack/apsara 0.18.6 → 0.19.1
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.cjs +38 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -13
- package/dist/index.js.map +1 -1
- package/dist/table/datatable.d.ts +2 -1
- package/dist/table/datatable.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32114,7 +32114,7 @@ function Skeleton({ count = 1, wrapper: Wrapper, className: customClassName, con
|
|
|
32114
32114
|
: elements));
|
|
32115
32115
|
}
|
|
32116
32116
|
|
|
32117
|
-
function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow =
|
|
32117
|
+
function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow = 2, onRowClick, onStateChange = () => { }, onLoadMore, ...props }) {
|
|
32118
32118
|
const [tableCustomFilter, setTableCustomFilter] = useState({});
|
|
32119
32119
|
const convertedChildren = Children.toArray(children);
|
|
32120
32120
|
const header = convertedChildren.find((child) => child.type === DataTableToolbar) || null;
|
|
@@ -32122,18 +32122,40 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32122
32122
|
const detail = convertedChildren.find((child) => child.type === TableDetailContainer) ||
|
|
32123
32123
|
null;
|
|
32124
32124
|
const [tableState, setTableState] = useState({});
|
|
32125
|
-
const
|
|
32126
|
-
|
|
32127
|
-
|
|
32125
|
+
const observerRef = useRef(null);
|
|
32126
|
+
const lastRowRef = useRef(null);
|
|
32127
|
+
useEffect(() => {
|
|
32128
|
+
if (!onLoadMore)
|
|
32129
|
+
return;
|
|
32130
|
+
const observer = new IntersectionObserver((entries) => {
|
|
32131
|
+
if (entries[0].isIntersecting && !isLoading) {
|
|
32132
|
+
onLoadMore();
|
|
32133
|
+
}
|
|
32134
|
+
}, { threshold: 0.1 });
|
|
32135
|
+
observerRef.current = observer;
|
|
32136
|
+
return () => observer.disconnect();
|
|
32137
|
+
}, [onLoadMore]);
|
|
32138
|
+
useEffect(() => {
|
|
32139
|
+
const observer = observerRef.current;
|
|
32140
|
+
const lastRow = lastRowRef.current;
|
|
32141
|
+
if (observer && lastRow) {
|
|
32142
|
+
observer.disconnect();
|
|
32143
|
+
observer.observe(lastRow);
|
|
32144
|
+
}
|
|
32145
|
+
return () => {
|
|
32146
|
+
if (observer && lastRow) {
|
|
32147
|
+
observer.unobserve(lastRow);
|
|
32148
|
+
}
|
|
32149
|
+
};
|
|
32150
|
+
}, [isLoading]);
|
|
32151
|
+
const getLoader = (loaderRow, columns) => ([...new Array(loaderRow)].map((_, rowIndex) => (jsxRuntimeExports.jsx(Table.Row, { children: columns.map((_, colIndex) => (jsxRuntimeExports.jsx(Table.Cell, { children: jsxRuntimeExports.jsx(Skeleton, { containerClassName: styles$4.flex1, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" }) }, `col_${colIndex}`))) }, `row_${rowIndex}`))));
|
|
32128
32152
|
const { filteredColumns, addFilterColumn, removeFilterColumn, resetColumns } = useTableColumn();
|
|
32129
32153
|
const columnWithCustomFilter = useMemo(() => columns.map((col) => {
|
|
32130
32154
|
const colId = col.id || col?.accessorKey;
|
|
32131
32155
|
const filterFn = colId && tableCustomFilter.hasOwnProperty(colId)
|
|
32132
32156
|
? tableCustomFilter[colId]
|
|
32133
32157
|
: undefined;
|
|
32134
|
-
const cell =
|
|
32135
|
-
? () => (jsxRuntimeExports.jsx(Skeleton, { containerClassName: styles$4.flex1, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" }))
|
|
32136
|
-
: col.cell;
|
|
32158
|
+
const { cell } = col;
|
|
32137
32159
|
return {
|
|
32138
32160
|
...col,
|
|
32139
32161
|
cell,
|
|
@@ -32149,7 +32171,7 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32149
32171
|
setTableCustomFilter((old) => ({ ...old, [id]: filterFn }));
|
|
32150
32172
|
};
|
|
32151
32173
|
const table = useReactTable({
|
|
32152
|
-
data
|
|
32174
|
+
data,
|
|
32153
32175
|
columns: columnWithCustomFilter,
|
|
32154
32176
|
globalFilterFn: "auto",
|
|
32155
32177
|
enableRowSelection: true,
|
|
@@ -32197,11 +32219,14 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32197
32219
|
}[header.column.getIsSorted()] ?? jsxRuntimeExports.jsx(CaretSortIcon, {})
|
|
32198
32220
|
: null] }) }, `${header.id}_${index}`));
|
|
32199
32221
|
}) }, headerGroup.id)))
|
|
32200
|
-
: null }), jsxRuntimeExports.
|
|
32201
|
-
|
|
32202
|
-
|
|
32203
|
-
|
|
32204
|
-
|
|
32222
|
+
: null }), jsxRuntimeExports.jsxs(Table.Body, { children: [table.getRowModel().rows?.length ? (table.getRowModel().rows.map((row, rowIndex) => (jsxRuntimeExports.jsx(Table.Row, { "data-state": row.getIsSelected() && "selected", onClick: () => onRowClick?.(row.original), className: isLoading
|
|
32223
|
+
? ""
|
|
32224
|
+
: `${styles$4.tRow} ${onRowClick ? styles$4.tRowClick : ""}`, ref: rowIndex === table.getRowModel().rows.length - 1
|
|
32225
|
+
? lastRowRef
|
|
32226
|
+
: null, children: row.getVisibleCells().map((cell, index) => (jsxRuntimeExports.jsx(Table.Cell, { style: {
|
|
32227
|
+
...(cell.column.columnDef?.meta?.style ?? {}),
|
|
32228
|
+
}, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `${cell.id}_${index}`))) }, row.id)))) : (!isLoading ?
|
|
32229
|
+
jsxRuntimeExports.jsx(Table.Row, { children: jsxRuntimeExports.jsx(Table.Cell, { colSpan: columns.length, children: emptyState || "No results." }) }) : jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {})), isLoading && getLoader(loaderRow, columns)] })] }), detail] })] }), footer] }) }));
|
|
32205
32230
|
}
|
|
32206
32231
|
const DataTable = Object.assign(DataTableRoot, {
|
|
32207
32232
|
Toolbar: DataTableToolbar,
|