@trackunit/react-table 0.0.209 → 0.0.210-alpha-2c211422d9.0

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
@@ -405,9 +405,9 @@ const cvaColumnFilterGrabbable = cssClassVarianceUtilities.cvaMerge(["flex", "it
405
405
  /**
406
406
  * ColumnFilter component for managing visibility and order of table columns.
407
407
  *
408
- * @template T - The type representing the data model associated with the columns.
409
- * @template V - The type representing the value of columns.
410
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
408
+ * @template TColumnFilter - The type representing the data model associated with the columns.
409
+ * @template TColumnFilterValue - The type representing the value of columns.
410
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
411
411
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
412
412
  */
413
413
  const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
@@ -558,12 +558,12 @@ const CompactIcon = () => {
558
558
  /**
559
559
  * Sorting component for managing table column sorting.
560
560
  *
561
- * @template T - The type representing the data model associated with the columns.
562
- * @template V - The type representing the value of columns.
563
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
561
+ * @template TSorting - The type representing the data model associated with the columns.
562
+ * @template TSortingValue - The type representing the value of columns.
563
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
564
564
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
565
565
  */
566
- const Sorting = ({ columns }) => {
566
+ const Sorting = ({ columns, }) => {
567
567
  var _a, _b;
568
568
  const [t] = useTranslation();
569
569
  const sortableColumns = columns.filter(column => column.getCanSort());
@@ -601,7 +601,7 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
601
601
  const nextPage = React.useCallback(() => {
602
602
  if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
603
603
  setVariables({
604
- after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
604
+ after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
605
605
  first: props.pageSize,
606
606
  });
607
607
  }
@@ -609,7 +609,7 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
609
609
  const previousPage = React.useCallback(() => {
610
610
  if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
611
611
  setVariables({
612
- before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
612
+ before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
613
613
  last: props.pageSize,
614
614
  });
615
615
  }
@@ -624,8 +624,9 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
624
624
  if (props.onReset) {
625
625
  props.onReset();
626
626
  }
627
+ // eslint-disable-next-line react-hooks/exhaustive-deps
627
628
  }, [props.onReset, props.pageSize]);
628
- const pagination = React.useMemo(() => {
629
+ return React.useMemo(() => {
629
630
  return {
630
631
  variables,
631
632
  table: {
@@ -639,7 +640,6 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
639
640
  },
640
641
  };
641
642
  }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
642
- return pagination;
643
643
  };
644
644
 
645
645
  /**
@@ -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
@@ -380,9 +380,9 @@ const cvaColumnFilterGrabbable = cvaMerge(["flex", "items-center", "justify-cent
380
380
  /**
381
381
  * ColumnFilter component for managing visibility and order of table columns.
382
382
  *
383
- * @template T - The type representing the data model associated with the columns.
384
- * @template V - The type representing the value of columns.
385
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
383
+ * @template TColumnFilter - The type representing the data model associated with the columns.
384
+ * @template TColumnFilterValue - The type representing the value of columns.
385
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
386
386
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
387
387
  */
388
388
  const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
@@ -533,12 +533,12 @@ const CompactIcon = () => {
533
533
  /**
534
534
  * Sorting component for managing table column sorting.
535
535
  *
536
- * @template T - The type representing the data model associated with the columns.
537
- * @template V - The type representing the value of columns.
538
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
536
+ * @template TSorting - The type representing the data model associated with the columns.
537
+ * @template TSortingValue - The type representing the value of columns.
538
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
539
539
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
540
540
  */
541
- const Sorting = ({ columns }) => {
541
+ const Sorting = ({ columns, }) => {
542
542
  var _a, _b;
543
543
  const [t] = useTranslation();
544
544
  const sortableColumns = columns.filter(column => column.getCanSort());
@@ -576,7 +576,7 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
576
576
  const nextPage = useCallback(() => {
577
577
  if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
578
578
  setVariables({
579
- after: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor,
579
+ after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
580
580
  first: props.pageSize,
581
581
  });
582
582
  }
@@ -584,7 +584,7 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
584
584
  const previousPage = useCallback(() => {
585
585
  if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
586
586
  setVariables({
587
- before: (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor) === null ? undefined : pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor,
587
+ before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
588
588
  last: props.pageSize,
589
589
  });
590
590
  }
@@ -599,8 +599,9 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
599
599
  if (props.onReset) {
600
600
  props.onReset();
601
601
  }
602
+ // eslint-disable-next-line react-hooks/exhaustive-deps
602
603
  }, [props.onReset, props.pageSize]);
603
- const pagination = useMemo(() => {
604
+ return useMemo(() => {
604
605
  return {
605
606
  variables,
606
607
  table: {
@@ -614,7 +615,6 @@ const useRelayPagination = (props = { pageSize: 50 }) => {
614
615
  },
615
616
  };
616
617
  }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
617
- return pagination;
618
618
  };
619
619
 
620
620
  /**
@@ -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.210-alpha-2c211422d9.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Column, ColumnOrderState, Updater } from "@tanstack/react-table";
3
- export interface IColumnFilterProps<T extends object, V> {
4
- columns: Column<T, V>[];
3
+ export interface ColumnFilterProps<TColumnFilter extends object, TColumnFilterValue> {
4
+ columns: Column<TColumnFilter, TColumnFilterValue>[];
5
5
  defaultColumnOrder: ColumnOrderState;
6
6
  columnOrder?: ColumnOrderState;
7
7
  className?: string;
@@ -11,14 +11,14 @@ export interface IColumnFilterProps<T extends object, V> {
11
11
  /**
12
12
  * ColumnFilter component for managing visibility and order of table columns.
13
13
  *
14
- * @template T - The type representing the data model associated with the columns.
15
- * @template V - The type representing the value of columns.
16
- * @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
14
+ * @template TColumnFilter - The type representing the data model associated with the columns.
15
+ * @template TColumnFilterValue - The type representing the value of columns.
16
+ * @param {ColumnFilterProps<TColumnFilter, TColumnFilterValue>} props - The props object containing necessary properties.
17
17
  * @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
18
18
  */
19
- export declare const ColumnFilter: <T extends Object, V>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: IColumnFilterProps<T, V>) => JSX.Element | null;
20
- export interface ColumnFiltersDragAndDropProps<T extends object, V> {
21
- columns: Column<T, V>[];
19
+ export declare const ColumnFilter: <TColumnFilter extends Object, TColumnFilterValue>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: ColumnFilterProps<TColumnFilter, TColumnFilterValue>) => JSX.Element | null;
20
+ export interface ColumnFiltersDragAndDropProps<TColumnFiltersDragAndDrop extends object, TColumnFiltersDragAndDropValue> {
21
+ columns: Column<TColumnFiltersDragAndDrop, TColumnFiltersDragAndDropValue>[];
22
22
  setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
23
23
  onUserEvent?: (event: "Column Reordering" | "Column Filter", payload: Record<string, unknown>) => void;
24
24
  }
@@ -1,15 +1,15 @@
1
1
  /// <reference types="react" />
2
2
  import { Column } from "@tanstack/react-table";
3
- interface SortingProps<T extends object, V> {
4
- columns: Column<T, V>[];
3
+ interface SortingProps<TSorting extends object, TSortingValue> {
4
+ columns: Column<TSorting, TSortingValue>[];
5
5
  }
6
6
  /**
7
7
  * Sorting component for managing table column sorting.
8
8
  *
9
- * @template T - The type representing the data model associated with the columns.
10
- * @template V - The type representing the value of columns.
11
- * @param {SortingProps<T, V>} props - The props object containing sorting properties.
9
+ * @template TSorting - The type representing the data model associated with the columns.
10
+ * @template TSortingValue - The type representing the value of columns.
11
+ * @param {SortingProps<TSorting, TSortingValue>} props - The props object containing sorting properties.
12
12
  * @returns {JSX.Element | null} A React JSX element representing the Sorting component or null if there are no sortable columns.
13
13
  */
14
- export declare const Sorting: <T extends Object, V>({ columns }: SortingProps<T, V>) => JSX.Element | null;
14
+ export declare const Sorting: <TSorting extends Object, TSortingValue>({ columns, }: SortingProps<TSorting, TSortingValue>) => JSX.Element | null;
15
15
  export {};
@@ -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;