@trackunit/react-table 0.0.209 → 0.0.211

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
@@ -745,7 +745,7 @@ const useTable = (_a) => {
745
745
  * columns,
746
746
  * });
747
747
  */
748
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
748
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
749
749
  const [rowSelection, setRowSelection] = React.useState({});
750
750
  React.useEffect(() => {
751
751
  const initialSelection = {};
@@ -786,8 +786,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
786
786
  const selectionTableProps = React.useMemo(() => ({
787
787
  onRowSelectionChange: setRowSelection,
788
788
  getRowId: row => row.id,
789
- enableRowSelection: true,
790
- }), []);
789
+ enableRowSelection,
790
+ }), [enableRowSelection]);
791
791
  return React.useMemo(() => ({
792
792
  toggleRowSelectionState,
793
793
  selectionColumn,
package/index.esm.js CHANGED
@@ -720,7 +720,7 @@ const useTable = (_a) => {
720
720
  * columns,
721
721
  * });
722
722
  */
723
- const useTableSelection = ({ data, defaultSelectedIds, }) => {
723
+ const useTableSelection = ({ data, defaultSelectedIds, enableRowSelection = true, }) => {
724
724
  const [rowSelection, setRowSelection] = useState({});
725
725
  useEffect(() => {
726
726
  const initialSelection = {};
@@ -761,8 +761,8 @@ const useTableSelection = ({ data, defaultSelectedIds, }) => {
761
761
  const selectionTableProps = useMemo(() => ({
762
762
  onRowSelectionChange: setRowSelection,
763
763
  getRowId: row => row.id,
764
- enableRowSelection: true,
765
- }), []);
764
+ enableRowSelection,
765
+ }), [enableRowSelection]);
766
766
  return useMemo(() => ({
767
767
  toggleRowSelectionState,
768
768
  selectionColumn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "0.0.209",
3
+ "version": "0.0.211",
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;