@trackunit/react-table 0.0.196 → 0.0.197

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
@@ -717,11 +717,18 @@ const useTable = (_a) => {
717
717
  * ...selectionTableState,
718
718
  * },
719
719
  * data,
720
- * columns
720
+ * columns,
721
721
  * });
722
722
  */
723
- const useTableSelection = ({ data, }) => {
723
+ const useTableSelection = ({ data, defaultSelectedIds, }) => {
724
724
  const [rowSelection, setRowSelection] = React.useState({});
725
+ React.useEffect(() => {
726
+ const initialSelection = {};
727
+ defaultSelectedIds === null || defaultSelectedIds === void 0 ? void 0 : defaultSelectedIds.forEach(id => {
728
+ initialSelection[id] = true;
729
+ });
730
+ setRowSelection(() => (Object.assign({}, initialSelection)));
731
+ }, [defaultSelectedIds]);
725
732
  const toggleRowSelectionState = React.useCallback((id) => {
726
733
  setRowSelection(prevRowSelection => (Object.assign(Object.assign({}, prevRowSelection), { [id]: !prevRowSelection[id] })));
727
734
  }, []);
package/index.esm.js CHANGED
@@ -692,11 +692,18 @@ const useTable = (_a) => {
692
692
  * ...selectionTableState,
693
693
  * },
694
694
  * data,
695
- * columns
695
+ * columns,
696
696
  * });
697
697
  */
698
- const useTableSelection = ({ data, }) => {
698
+ const useTableSelection = ({ data, defaultSelectedIds, }) => {
699
699
  const [rowSelection, setRowSelection] = useState({});
700
+ useEffect(() => {
701
+ const initialSelection = {};
702
+ defaultSelectedIds === null || defaultSelectedIds === void 0 ? void 0 : defaultSelectedIds.forEach(id => {
703
+ initialSelection[id] = true;
704
+ });
705
+ setRowSelection(() => (Object.assign({}, initialSelection)));
706
+ }, [defaultSelectedIds]);
700
707
  const toggleRowSelectionState = useCallback((id) => {
701
708
  setRowSelection(prevRowSelection => (Object.assign(Object.assign({}, prevRowSelection), { [id]: !prevRowSelection[id] })));
702
709
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "0.0.196",
3
+ "version": "0.0.197",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -40,6 +40,7 @@ export interface TableSelectionReturn<TData extends selectableTableData> {
40
40
  }
41
41
  export interface TableSelectionProps<TData extends selectableTableData> {
42
42
  data: TData[];
43
+ defaultSelectedIds?: TData["id"][];
43
44
  }
44
45
  /**
45
46
  * `useTableSelection` is a custom hook that provides functionality for row selection in a table.
@@ -65,8 +66,8 @@ export interface TableSelectionProps<TData extends selectableTableData> {
65
66
  * ...selectionTableState,
66
67
  * },
67
68
  * data,
68
- * columns
69
+ * columns,
69
70
  * });
70
71
  */
71
- export declare const useTableSelection: <TData extends selectableTableData>({ data, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
72
+ export declare const useTableSelection: <TData extends selectableTableData>({ data, defaultSelectedIds, }: TableSelectionProps<TData>) => TableSelectionReturn<TData>;
72
73
  export {};