@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.cjs
CHANGED
|
@@ -32134,7 +32134,7 @@ function Skeleton({ count = 1, wrapper: Wrapper, className: customClassName, con
|
|
|
32134
32134
|
: elements));
|
|
32135
32135
|
}
|
|
32136
32136
|
|
|
32137
|
-
function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow =
|
|
32137
|
+
function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow = 2, onRowClick, onStateChange = () => { }, onLoadMore, ...props }) {
|
|
32138
32138
|
const [tableCustomFilter, setTableCustomFilter] = React.useState({});
|
|
32139
32139
|
const convertedChildren = React.Children.toArray(children);
|
|
32140
32140
|
const header = convertedChildren.find((child) => child.type === DataTableToolbar) || null;
|
|
@@ -32142,18 +32142,40 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32142
32142
|
const detail = convertedChildren.find((child) => child.type === TableDetailContainer) ||
|
|
32143
32143
|
null;
|
|
32144
32144
|
const [tableState, setTableState] = React.useState({});
|
|
32145
|
-
const
|
|
32146
|
-
|
|
32147
|
-
|
|
32145
|
+
const observerRef = React.useRef(null);
|
|
32146
|
+
const lastRowRef = React.useRef(null);
|
|
32147
|
+
React.useEffect(() => {
|
|
32148
|
+
if (!onLoadMore)
|
|
32149
|
+
return;
|
|
32150
|
+
const observer = new IntersectionObserver((entries) => {
|
|
32151
|
+
if (entries[0].isIntersecting && !isLoading) {
|
|
32152
|
+
onLoadMore();
|
|
32153
|
+
}
|
|
32154
|
+
}, { threshold: 0.1 });
|
|
32155
|
+
observerRef.current = observer;
|
|
32156
|
+
return () => observer.disconnect();
|
|
32157
|
+
}, [onLoadMore]);
|
|
32158
|
+
React.useEffect(() => {
|
|
32159
|
+
const observer = observerRef.current;
|
|
32160
|
+
const lastRow = lastRowRef.current;
|
|
32161
|
+
if (observer && lastRow) {
|
|
32162
|
+
observer.disconnect();
|
|
32163
|
+
observer.observe(lastRow);
|
|
32164
|
+
}
|
|
32165
|
+
return () => {
|
|
32166
|
+
if (observer && lastRow) {
|
|
32167
|
+
observer.unobserve(lastRow);
|
|
32168
|
+
}
|
|
32169
|
+
};
|
|
32170
|
+
}, [isLoading]);
|
|
32171
|
+
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}`))));
|
|
32148
32172
|
const { filteredColumns, addFilterColumn, removeFilterColumn, resetColumns } = useTableColumn();
|
|
32149
32173
|
const columnWithCustomFilter = React.useMemo(() => columns.map((col) => {
|
|
32150
32174
|
const colId = col.id || col?.accessorKey;
|
|
32151
32175
|
const filterFn = colId && tableCustomFilter.hasOwnProperty(colId)
|
|
32152
32176
|
? tableCustomFilter[colId]
|
|
32153
32177
|
: undefined;
|
|
32154
|
-
const cell =
|
|
32155
|
-
? () => (jsxRuntimeExports.jsx(Skeleton, { containerClassName: styles$4.flex1, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" }))
|
|
32156
|
-
: col.cell;
|
|
32178
|
+
const { cell } = col;
|
|
32157
32179
|
return {
|
|
32158
32180
|
...col,
|
|
32159
32181
|
cell,
|
|
@@ -32169,7 +32191,7 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32169
32191
|
setTableCustomFilter((old) => ({ ...old, [id]: filterFn }));
|
|
32170
32192
|
};
|
|
32171
32193
|
const table = useReactTable({
|
|
32172
|
-
data
|
|
32194
|
+
data,
|
|
32173
32195
|
columns: columnWithCustomFilter,
|
|
32174
32196
|
globalFilterFn: "auto",
|
|
32175
32197
|
enableRowSelection: true,
|
|
@@ -32217,11 +32239,14 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
|
|
|
32217
32239
|
}[header.column.getIsSorted()] ?? jsxRuntimeExports.jsx(CaretSortIcon, {})
|
|
32218
32240
|
: null] }) }, `${header.id}_${index}`));
|
|
32219
32241
|
}) }, headerGroup.id)))
|
|
32220
|
-
: null }), jsxRuntimeExports.
|
|
32221
|
-
|
|
32222
|
-
|
|
32223
|
-
|
|
32224
|
-
|
|
32242
|
+
: 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
|
|
32243
|
+
? ""
|
|
32244
|
+
: `${styles$4.tRow} ${onRowClick ? styles$4.tRowClick : ""}`, ref: rowIndex === table.getRowModel().rows.length - 1
|
|
32245
|
+
? lastRowRef
|
|
32246
|
+
: null, children: row.getVisibleCells().map((cell, index) => (jsxRuntimeExports.jsx(Table.Cell, { style: {
|
|
32247
|
+
...(cell.column.columnDef?.meta?.style ?? {}),
|
|
32248
|
+
}, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `${cell.id}_${index}`))) }, row.id)))) : (!isLoading ?
|
|
32249
|
+
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] }) }));
|
|
32225
32250
|
}
|
|
32226
32251
|
const DataTable = Object.assign(DataTableRoot, {
|
|
32227
32252
|
Toolbar: DataTableToolbar,
|