@trackunit/react-table 1.21.21 → 1.21.23

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
@@ -1400,9 +1400,47 @@ const computeMergedPinning = (initialPinning, columnConfigPinning) => {
1400
1400
  /**
1401
1401
  * Hook for managing and controlling a table's state and behavior.
1402
1402
  *
1403
+ * Wraps `@tanstack/react-table` with built-in state management for column visibility,
1404
+ * ordering, sorting, sizing, and pinning. Reads `meta.hiddenByDefault` and `meta.pinned`
1405
+ * from column definitions so the table is correctly configured from a single source of truth.
1406
+ *
1407
+ * **When to use:**
1408
+ * - Use `useTable` whenever you render a `<Table>` component — it is the standard way to
1409
+ * initialise and manage table state in this codebase.
1410
+ * - Use `useTableSelection` on top of `useTable` when you need row selection checkboxes.
1411
+ * - Do **not** call `useReactTable` directly — `useTable` adds required column-state
1412
+ * orchestration that the raw hook does not provide.
1413
+ *
1403
1414
  * @template TData - The type representing the data model associated with the table.
1404
1415
  * @param {TableOptionsProps<TData>} props - The props object containing configuration options.
1405
- * @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
1416
+ * @returns {object} An object containing the React Table instance and associated state management functions.
1417
+ * @example
1418
+ * ```tsx
1419
+ * import { createColumnHelper } from "@tanstack/react-table";
1420
+ * import { Table, useTable } from "@trackunit/react-table";
1421
+ *
1422
+ * const columnHelper = createColumnHelper<Asset>();
1423
+ *
1424
+ * const columns = [
1425
+ * columnHelper.accessor("name", { header: "Name" }),
1426
+ * columnHelper.accessor("brand", { header: "Brand" }),
1427
+ * columnHelper.accessor("hours", {
1428
+ * header: "Hours",
1429
+ * meta: { hiddenByDefault: true },
1430
+ * }),
1431
+ * ];
1432
+ *
1433
+ * const AssetsTable = ({ data }: { data: Asset[] }) => {
1434
+ * const { table } = useTable({
1435
+ * data,
1436
+ * columns,
1437
+ * initialState: { sorting: [{ id: "name", desc: false }] },
1438
+ * onTableStateChange: state => saveTablePreferences(state),
1439
+ * });
1440
+ *
1441
+ * return <Table table={table} />;
1442
+ * };
1443
+ * ```
1406
1444
  */
1407
1445
  const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
1408
1446
  const stableColumns = react.useMemo(() => JSON.stringify(columns), [columns]);
package/index.esm.js CHANGED
@@ -1399,9 +1399,47 @@ const computeMergedPinning = (initialPinning, columnConfigPinning) => {
1399
1399
  /**
1400
1400
  * Hook for managing and controlling a table's state and behavior.
1401
1401
  *
1402
+ * Wraps `@tanstack/react-table` with built-in state management for column visibility,
1403
+ * ordering, sorting, sizing, and pinning. Reads `meta.hiddenByDefault` and `meta.pinned`
1404
+ * from column definitions so the table is correctly configured from a single source of truth.
1405
+ *
1406
+ * **When to use:**
1407
+ * - Use `useTable` whenever you render a `<Table>` component — it is the standard way to
1408
+ * initialise and manage table state in this codebase.
1409
+ * - Use `useTableSelection` on top of `useTable` when you need row selection checkboxes.
1410
+ * - Do **not** call `useReactTable` directly — `useTable` adds required column-state
1411
+ * orchestration that the raw hook does not provide.
1412
+ *
1402
1413
  * @template TData - The type representing the data model associated with the table.
1403
1414
  * @param {TableOptionsProps<TData>} props - The props object containing configuration options.
1404
- * @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
1415
+ * @returns {object} An object containing the React Table instance and associated state management functions.
1416
+ * @example
1417
+ * ```tsx
1418
+ * import { createColumnHelper } from "@tanstack/react-table";
1419
+ * import { Table, useTable } from "@trackunit/react-table";
1420
+ *
1421
+ * const columnHelper = createColumnHelper<Asset>();
1422
+ *
1423
+ * const columns = [
1424
+ * columnHelper.accessor("name", { header: "Name" }),
1425
+ * columnHelper.accessor("brand", { header: "Brand" }),
1426
+ * columnHelper.accessor("hours", {
1427
+ * header: "Hours",
1428
+ * meta: { hiddenByDefault: true },
1429
+ * }),
1430
+ * ];
1431
+ *
1432
+ * const AssetsTable = ({ data }: { data: Asset[] }) => {
1433
+ * const { table } = useTable({
1434
+ * data,
1435
+ * columns,
1436
+ * initialState: { sorting: [{ id: "name", desc: false }] },
1437
+ * onTableStateChange: state => saveTablePreferences(state),
1438
+ * });
1439
+ *
1440
+ * return <Table table={table} />;
1441
+ * };
1442
+ * ```
1405
1443
  */
1406
1444
  const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
1407
1445
  const stableColumns = useMemo(() => JSON.stringify(columns), [columns]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "1.21.21",
3
+ "version": "1.21.23",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,14 +11,14 @@
11
11
  "react-dnd": "16.0.1",
12
12
  "react-dnd-html5-backend": "16.0.1",
13
13
  "tailwind-merge": "^2.0.0",
14
- "@trackunit/react-components": "1.22.17",
15
- "@trackunit/shared-utils": "1.13.111",
16
- "@trackunit/css-class-variance-utilities": "1.11.111",
17
- "@trackunit/ui-icons": "1.11.107",
18
- "@trackunit/react-table-base-components": "1.21.21",
19
- "@trackunit/react-form-components": "1.22.21",
20
- "@trackunit/i18n-library-translation": "1.18.17",
21
- "@trackunit/iris-app-runtime-core-api": "1.14.25"
14
+ "@trackunit/react-components": "1.22.19",
15
+ "@trackunit/shared-utils": "1.13.113",
16
+ "@trackunit/css-class-variance-utilities": "1.11.113",
17
+ "@trackunit/ui-icons": "1.11.109",
18
+ "@trackunit/react-table-base-components": "1.21.23",
19
+ "@trackunit/react-form-components": "1.22.23",
20
+ "@trackunit/i18n-library-translation": "1.18.19",
21
+ "@trackunit/iris-app-runtime-core-api": "1.14.27"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@tanstack/react-router": "^1.114.29",
package/src/useTable.d.ts CHANGED
@@ -5,9 +5,47 @@ export interface TableOptionsProps<TData extends object> extends Omit<TableOptio
5
5
  /**
6
6
  * Hook for managing and controlling a table's state and behavior.
7
7
  *
8
+ * Wraps `@tanstack/react-table` with built-in state management for column visibility,
9
+ * ordering, sorting, sizing, and pinning. Reads `meta.hiddenByDefault` and `meta.pinned`
10
+ * from column definitions so the table is correctly configured from a single source of truth.
11
+ *
12
+ * **When to use:**
13
+ * - Use `useTable` whenever you render a `<Table>` component — it is the standard way to
14
+ * initialise and manage table state in this codebase.
15
+ * - Use `useTableSelection` on top of `useTable` when you need row selection checkboxes.
16
+ * - Do **not** call `useReactTable` directly — `useTable` adds required column-state
17
+ * orchestration that the raw hook does not provide.
18
+ *
8
19
  * @template TData - The type representing the data model associated with the table.
9
20
  * @param {TableOptionsProps<TData>} props - The props object containing configuration options.
10
- * @returns {TableOptionsProps<TData>} An object containing the React Table instance and associated state management functions.
21
+ * @returns {object} An object containing the React Table instance and associated state management functions.
22
+ * @example
23
+ * ```tsx
24
+ * import { createColumnHelper } from "@tanstack/react-table";
25
+ * import { Table, useTable } from "@trackunit/react-table";
26
+ *
27
+ * const columnHelper = createColumnHelper<Asset>();
28
+ *
29
+ * const columns = [
30
+ * columnHelper.accessor("name", { header: "Name" }),
31
+ * columnHelper.accessor("brand", { header: "Brand" }),
32
+ * columnHelper.accessor("hours", {
33
+ * header: "Hours",
34
+ * meta: { hiddenByDefault: true },
35
+ * }),
36
+ * ];
37
+ *
38
+ * const AssetsTable = ({ data }: { data: Asset[] }) => {
39
+ * const { table } = useTable({
40
+ * data,
41
+ * columns,
42
+ * initialState: { sorting: [{ id: "name", desc: false }] },
43
+ * onTableStateChange: state => saveTablePreferences(state),
44
+ * });
45
+ *
46
+ * return <Table table={table} />;
47
+ * };
48
+ * ```
11
49
  */
12
50
  export declare const useTable: <TData extends object>({ onTableStateChange, initialState, columns, ...reactTableProps }: TableOptionsProps<TData>) => {
13
51
  table: import("@tanstack/react-table").Table<TData>;