@trackunit/react-table 0.0.207 → 0.0.210

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/index.cjs.js CHANGED
@@ -345,8 +345,8 @@ const Table = (_a) => {
345
345
  rowHeight,
346
346
  });
347
347
  const hasResults = props.getRowModel().rows.length > 0;
348
- return (jsxRuntime.jsxs(reactComponents.Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex", children: props.headerRightActions })] })), jsxRuntime.jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxRuntime.jsxs(reactTableBaseComponents.TableRoot, { style: {
349
- height: getTotalSize() > 0 ? getTotalSize() : "100%",
348
+ return (jsxRuntime.jsxs(reactComponents.Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxRuntime.jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsxRuntime.jsx("div", { className: "flex", children: props.headerLeftActions }), jsxRuntime.jsx("div", { className: "flex", children: props.headerRightActions })] })), jsxRuntime.jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxRuntime.jsxs(reactTableBaseComponents.TableRoot, { style: {
349
+ height: hasResults ? "auto" : "100%",
350
350
  width: "100%",
351
351
  position: "relative",
352
352
  }, children: [jsxRuntime.jsx(reactTableBaseComponents.Thead, { className: "z-default", children: props.getHeaderGroups().map(headerGroup => (jsxRuntime.jsx(reactTableBaseComponents.Tr, { className: "flex", children: headerGroup.headers.map(header => {
@@ -355,10 +355,12 @@ const Table = (_a) => {
355
355
  width: header.getSize(),
356
356
  minWidth: header.column.columnDef.minSize,
357
357
  maxWidth: header.column.columnDef.maxSize,
358
- textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
358
+ textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
359
359
  }, className: "relative", children: [header.isPlaceholder ? null : (jsxRuntime.jsxs("div", { className: `${header.column.getCanSort() ? "cursor-pointer select-none flex" : ""} items-center gap-2 py-2 overflow-hidden pr-3`,
360
360
  onClick: header.column.getToggleSortingHandler(), children: [jsxRuntime.jsxs("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap", children: [reactTable.flexRender(header.column.columnDef.header, header.getContext()), ((_c = (_b = header.column.columnDef) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c.subHeader) ? (jsxRuntime.jsx(reactComponents.Text, { size: "small", subtle: true, children: (_e = (_d = header.column.columnDef) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.subHeader })) : null] }), header.column.getCanSort() ? (jsxRuntime.jsx(reactTableBaseComponents.SortIndicator, { sortingState: header.column.getIsSorted() })) : null] })), header.column.getCanResize() ? (jsxRuntime.jsx(reactTableBaseComponents.ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null] }, header.id));
361
- }) }, headerGroup.id))) }), hasResults ? (jsxRuntime.jsx(reactTableBaseComponents.Tbody, { className: "text-sm font-normal", children: getVirtualItems().map((virtualRow, index) => {
361
+ }) }, headerGroup.id))) }), hasResults ? (jsxRuntime.jsx(reactTableBaseComponents.Tbody, { className: "text-sm font-normal", style: {
362
+ height: `${getTotalSize()}px`,
363
+ }, children: getVirtualItems().map((virtualRow, index) => {
362
364
  const row = props.getRowModel().rows[virtualRow.index];
363
365
  if (!row) {
364
366
  return null;
@@ -381,11 +383,11 @@ const Table = (_a) => {
381
383
  width: cell.column.getSize(),
382
384
  minWidth: cell.column.columnDef.minSize,
383
385
  maxWidth: cell.column.columnDef.maxSize,
384
- textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
386
+ textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
385
387
  }, children: jsxRuntime.jsx("div", { className: "grid h-full items-center", children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
386
388
  }) }, row.id));
387
389
  }
388
- }) })) : (jsxRuntime.jsx("tbody", { children: jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsxRuntime.jsx(reactComponents.EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxRuntime.jsxs("div", { className: "flex items-center p-2", children: [jsxRuntime.jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
390
+ }) })) : (jsxRuntime.jsx("tbody", { className: "min-h-[400px]", children: jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsxRuntime.jsx(reactComponents.EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxRuntime.jsxs("div", { className: "flex items-center p-2", children: [jsxRuntime.jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
389
391
  count: props.getRowModel().rows.length,
390
392
  total: ((_c = (_b = props.pagination) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.count) || 0,
391
393
  }) }), props.pagination.isLoading ? (jsxRuntime.jsx("span", { className: "ml-2", children: jsxRuntime.jsx(reactComponents.Spinner, { size: "small" }) })) : null, props.footerRightActions && jsxRuntime.jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] }))] }));
@@ -743,7 +745,7 @@ const useTable = (_a) => {
743
745
  * columns,
744
746
  * });
745
747
  */
746
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
748
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
747
749
  const [rowSelection, setRowSelection] = React.useState({});
748
750
  React.useEffect(() => {
749
751
  const initialSelection = {};
@@ -784,8 +786,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
784
786
  const selectionTableProps = React.useMemo(() => ({
785
787
  onRowSelectionChange: setRowSelection,
786
788
  getRowId: row => row.id,
787
- enableRowSelection: true,
788
- }), []);
789
+ enableRowSelection,
790
+ }), [enableRowSelection]);
789
791
  return React.useMemo(() => ({
790
792
  toggleRowSelectionState,
791
793
  selectionColumn,
package/index.esm.js CHANGED
@@ -320,8 +320,8 @@ const Table = (_a) => {
320
320
  rowHeight,
321
321
  });
322
322
  const hasResults = props.getRowModel().rows.length > 0;
323
- return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "min-h[500px] h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxs(TableRoot, { style: {
324
- height: getTotalSize() > 0 ? getTotalSize() : "100%",
323
+ return (jsxs(Card, { className: `flex flex-col overflow-hidden ${props.className || ""}`, dataTestId: props.dataTestId, children: [(props.headerLeftActions || props.headerRightActions) && (jsxs("div", { className: "z-default flex justify-between gap-2 p-2", children: [jsx("div", { className: "flex", children: props.headerLeftActions }), jsx("div", { className: "flex", children: props.headerRightActions })] })), jsx("div", { className: "h-full overflow-x-auto overflow-y-scroll border-b border-t border-gray-300", ref: tableContainerRef, onScroll: e => fetchMoreOnBottomReached(e.target), children: jsxs(TableRoot, { style: {
324
+ height: hasResults ? "auto" : "100%",
325
325
  width: "100%",
326
326
  position: "relative",
327
327
  }, children: [jsx(Thead, { className: "z-default", children: props.getHeaderGroups().map(headerGroup => (jsx(Tr, { className: "flex", children: headerGroup.headers.map(header => {
@@ -330,10 +330,12 @@ const Table = (_a) => {
330
330
  width: header.getSize(),
331
331
  minWidth: header.column.columnDef.minSize,
332
332
  maxWidth: header.column.columnDef.maxSize,
333
- textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
333
+ textAlign: ((_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
334
334
  }, className: "relative", children: [header.isPlaceholder ? null : (jsxs("div", { className: `${header.column.getCanSort() ? "cursor-pointer select-none flex" : ""} items-center gap-2 py-2 overflow-hidden pr-3`,
335
335
  onClick: header.column.getToggleSortingHandler(), children: [jsxs("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap", children: [flexRender(header.column.columnDef.header, header.getContext()), ((_c = (_b = header.column.columnDef) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c.subHeader) ? (jsx(Text, { size: "small", subtle: true, children: (_e = (_d = header.column.columnDef) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.subHeader })) : null] }), header.column.getCanSort() ? (jsx(SortIndicator, { sortingState: header.column.getIsSorted() })) : null] })), header.column.getCanResize() ? (jsx(ResizeHandle, { isResizing: header.column.getIsResizing(), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler() })) : null] }, header.id));
336
- }) }, headerGroup.id))) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", children: getVirtualItems().map((virtualRow, index) => {
336
+ }) }, headerGroup.id))) }), hasResults ? (jsx(Tbody, { className: "text-sm font-normal", style: {
337
+ height: `${getTotalSize()}px`,
338
+ }, children: getVirtualItems().map((virtualRow, index) => {
337
339
  const row = props.getRowModel().rows[virtualRow.index];
338
340
  if (!row) {
339
341
  return null;
@@ -356,11 +358,11 @@ const Table = (_a) => {
356
358
  width: cell.column.getSize(),
357
359
  minWidth: cell.column.columnDef.minSize,
358
360
  maxWidth: cell.column.columnDef.maxSize,
359
- textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left"
361
+ textAlign: ((_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.alignment) || "left",
360
362
  }, children: jsx("div", { className: "grid h-full items-center", children: flexRender(cell.column.columnDef.cell, cell.getContext()) }) }));
361
363
  }) }, row.id));
362
364
  }
363
- }) })) : (jsx("tbody", { children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsx(Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
365
+ }) })) : (jsx("tbody", { className: "min-h-[400px]", children: jsx("tr", { children: jsx("td", { className: "b-0", children: (props === null || props === void 0 ? void 0 : props.loading) ? (jsx(Spinner, { centering: "centered", containerClassName: "absolute inset-0" })) : (props === null || props === void 0 ? void 0 : props.noDataMessage) ? (props.noDataMessage) : (jsx(EmptyState, { image: "SEARCH_DOCUMENT", description: t("table.noResults"), className: "absolute inset-0" })) }) }) }))] }) }), props.hideFooter ? null : (jsxs("div", { className: "flex items-center p-2", children: [jsx("div", { className: "whitespace-nowrap text-xs font-medium text-neutral-600", children: t("table.pagination.full", {
364
366
  count: props.getRowModel().rows.length,
365
367
  total: ((_c = (_b = props.pagination) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.count) || 0,
366
368
  }) }), props.pagination.isLoading ? (jsx("span", { className: "ml-2", children: jsx(Spinner, { size: "small" }) })) : null, props.footerRightActions && jsx("div", { className: "flex flex-1 justify-end", children: props.footerRightActions })] }))] }));
@@ -718,7 +720,7 @@ const useTable = (_a) => {
718
720
  * columns,
719
721
  * });
720
722
  */
721
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
723
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
722
724
  const [rowSelection, setRowSelection] = useState({});
723
725
  useEffect(() => {
724
726
  const initialSelection = {};
@@ -759,8 +761,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
759
761
  const selectionTableProps = useMemo(() => ({
760
762
  onRowSelectionChange: setRowSelection,
761
763
  getRowId: row => row.id,
762
- enableRowSelection: true,
763
- }), []);
764
+ enableRowSelection,
765
+ }), [enableRowSelection]);
764
766
  return useMemo(() => ({
765
767
  toggleRowSelectionState,
766
768
  selectionColumn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "0.0.207",
3
+ "version": "0.0.210",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,6 +1,6 @@
1
1
  import { ColumnDef, RowSelectionState } from "@tanstack/react-table";
2
2
  import { Dispatch, SetStateAction } from "react";
3
- type selectableTableData = {
3
+ export type selectableTableData = {
4
4
  id: string;
5
5
  } & object;
6
6
  export interface TableSelectionReturn<TData extends selectableTableData> {
@@ -21,7 +21,7 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
21
21
  selectionTableProps: {
22
22
  onRowSelectionChange: Dispatch<SetStateAction<RowSelectionState>>;
23
23
  getRowId: (row: TData) => TData["id"];
24
- enableRowSelection: true;
24
+ enableRowSelection: boolean;
25
25
  };
26
26
  /**
27
27
  * A function to update the row selection state.
@@ -39,8 +39,22 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
39
39
  toggleRowSelectionState: (id: TData["id"]) => void;
40
40
  }
41
41
  export interface TableSelectionProps<TData extends selectableTableData> {
42
+ /**
43
+ * The data that is displayed in the table.
44
+ * This must have an `id` field, to enable selection.
45
+ * The same data should be passed to the `data` prop of the `useTable` Hook.
46
+ */
42
47
  data: TData[];
48
+ /**
49
+ * An array of ids of the rows that should be selected by default.
50
+ * This is useful when you want to preselect rows, for example when editing an existing entity.
51
+ */
43
52
  defaultSelectedIds?: TData["id"][];
53
+ /**
54
+ * Whether or not to enable row selection.
55
+ * If set to `false`, the selection column will still be displayed, but the checkboxes will be disabled.
56
+ */
57
+ enableRowSelection?: boolean;
44
58
  }
45
59
  /**
46
60
  * `useTableSelection` is a custom hook that provides functionality for row selection in a table.
@@ -69,5 +83,4 @@ export interface TableSelectionProps<TData extends selectableTableData> {
69
83
  * columns,
70
84
  * });
71
85
  */
72
- export declare const useTableSelection: <TData extends selectableTableData>({ data, defaultSelectedIds, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
73
- export {};
86
+ export declare const useTableSelection: <TData extends selectableTableData>({ data, defaultSelectedIds, enableRowSelection, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
@@ -0,0 +1,11 @@
1
+ import { TableSelectionProps, selectableTableData } from "./useTableSelection";
2
+ export interface UseTableSelectionDemoComponentProps<TData extends selectableTableData> extends TableSelectionProps<TData> {
3
+ }
4
+ /**
5
+ * The `useTableSelection` Hook provides functionality for row selection in a table.
6
+ *
7
+ * It returns an object containing methods and values related to row selection.
8
+ *
9
+ * It Also returns a `selectionColumn` object that can be used as a column definition in a table.
10
+ */
11
+ export declare const UseTableSelectionDemoComponent: <TData extends selectableTableData>(props: UseTableSelectionDemoComponentProps<TData>) => JSX.Element;