Skip to content

Commit d360dc1

Browse files
committed
Typedoc comment
1 parent 2daa315 commit d360dc1

File tree

7 files changed

+964
-34
lines changed

7 files changed

+964
-34
lines changed

src/TableAdapter.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,26 @@ const ExpandedRow = React.memo(
230230
);
231231
}
232232
);
233-
233+
/**
234+
* TableAdapter - A comprehensive wrapper around TanStack Table v8.0.0
235+
*
236+
* Provides a simplified API with extensive customization options while
237+
* leveraging TanStack Table's powerful core functionality.
238+
*
239+
* @template TData - The type of data being displayed in the table
240+
* @template TValue - The type of values in the table cells
241+
*
242+
* @example
243+
* ```tsx
244+
* <TableAdapter
245+
* data={users}
246+
* columns={[
247+
* { accessorKey: 'name', header: 'Name' },
248+
* { accessorKey: 'email', header: 'Email' },
249+
* ]}
250+
* />
251+
* ```
252+
*/
234253
export function TableAdapter<TData extends object, TValue = unknown>(
235254
props: TableAdapterProps<TData, TValue>
236255
) {

src/TableConfigContext.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ import { DEFAULT_TABLE_CLASSNAMES, mergeClassNames } from "./utils";
1313
const TableConfigContext = createContext<TableConfig | undefined>(undefined);
1414

1515
/**
16-
* Provider component for table configuration
17-
* Manages global styling defaults for all TableAdapter instances
16+
* Provider component for global table configuration
17+
*
18+
* Manages global styling defaults for all TableAdapter instances.
19+
* Wrap your application or a section of it with this provider to
20+
* establish consistent table styling across components.
21+
*
22+
* @param props.children - Child components
23+
* @param props.initialClassNames - Initial class name overrides
1824
*/
1925
export function TableConfigProvider({
2026
children,
@@ -64,9 +70,10 @@ export function TableConfigProvider({
6470
}
6571

6672
/**
67-
* Hook to use the table configuration
68-
* @returns The table configuration from context
69-
* @throws Error if used outside of a TableConfigProvider
73+
* Hook to access the table configuration context
74+
*
75+
* @returns The table configuration context
76+
* @throws Error if used outside of TableConfigProvider
7077
*/
7178
export function useTableConfig(): TableConfig {
7279
const context = useContext(TableConfigContext);

src/TableWithLoadingStates.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ import {
44
EnhancedPaginationLoadingComponent,
55
} from "./components";
66

7+
// For TableWithLoadingStates
78
/**
8-
* TableWithLoadingStates - A wrapper component that manages loading states for TableAdapter
9-
* This separates loading UI concerns from the table component itself
9+
* Wrapper component that manages loading states for TableAdapter
10+
*
11+
* This component separates loading UI concerns from the table component itself,
12+
* providing a clean way to handle initial loading and pagination loading states.
13+
*
14+
* @example
15+
* ```tsx
16+
* <TableWithLoadingStates
17+
* isInitialLoading={isLoading}
18+
* isPaginationLoading={isPaginating}
19+
* >
20+
* <TableAdapter data={data} columns={columns} />
21+
* </TableWithLoadingStates>
22+
* ```
1023
*/
1124
export function TableWithLoadingStates({
1225
isInitialLoading = false,

src/hooks.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ import {
1414
import { createControlledHandler, exportToCSV } from "./utils";
1515
import { TableAdapterProps, TableExportOptions, TableServer } from "./types";
1616

17-
// Custom hook for managed table state with controlled/uncontrolled pattern
17+
// For the custom hooks
18+
/**
19+
* Custom hook for managing table state with controlled/uncontrolled pattern
20+
*
21+
* Handles all table state (sorting, pagination, filtering, etc.) and
22+
* properly manages the controlled vs. uncontrolled state.
23+
*
24+
* @template TData - The type of data being displayed in the table
25+
* @template TValue - The type of values in the table cells
26+
*
27+
* @param props - The TableAdapter props
28+
* @returns Object containing current state values and handler functions
29+
*/
1830
export function useTableState<TData extends object, TValue = unknown>(
1931
props: TableAdapterProps<TData, TValue>
2032
) {
@@ -271,7 +283,19 @@ export function useTableState<TData extends object, TValue = unknown>(
271283
};
272284
}
273285

274-
// Custom hook for server-side data fetching
286+
/**
287+
* Custom hook for server-side data fetching
288+
*
289+
* Manages loading states, error handling, and data fetching based on
290+
* table state changes (pagination, sorting, filtering).
291+
*
292+
* @template TData - The type of data being displayed in the table
293+
*
294+
* @param table - The TanStack Table instance
295+
* @param serverOptions - Server-side options for data fetching
296+
* @param onError - Optional error handler
297+
* @returns Object containing loading state, data, and error information
298+
*/
275299
export function useServerSideData<TData extends object>(
276300
table: Table<TData>,
277301
serverOptions?: TableServer,
@@ -358,7 +382,19 @@ export function useServerSideData<TData extends object>(
358382
};
359383
}
360384

361-
// Custom hook for CSV/Excel export functionality
385+
/**
386+
* Custom hook for CSV/Excel/JSON export functionality
387+
*
388+
* Provides methods to export table data in various formats.
389+
*
390+
* @template TData - The type of data being displayed in the table
391+
* @template TValue - The type of values in the table cells
392+
*
393+
* @param data - The data to export
394+
* @param columns - The table columns
395+
* @param options - Export options (format, filename, etc.)
396+
* @returns Object containing export functions
397+
*/
362398
export function useTableExport<TData extends object, TValue = unknown>(
363399
data: TData[],
364400
columns: ColumnDef<TData, TValue>[],
@@ -433,7 +469,18 @@ export function useTableExport<TData extends object, TValue = unknown>(
433469
};
434470
}
435471

436-
// Custom hook for form integration
472+
/**
473+
* Custom hook for form integration with tables
474+
*
475+
* Enables editing table data with validation and form submission.
476+
*
477+
* @template TData - The type of data being displayed in the table
478+
*
479+
* @param initialData - The initial form data
480+
* @param onSubmit - Form submission handler
481+
* @param validationRules - Validation rules for form fields
482+
* @returns Object containing form state and handlers
483+
*/
437484
export function useTableForm<TData extends object>(
438485
initialData: TData[],
439486
onSubmit?: (data: TData[]) => void,

src/test-utils.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@ import userEvent from "@testing-library/user-event";
44
import { TableAdapter } from "./index";
55
import type { TableAdapterProps } from "./types";
66

7+
// For test utilities
78
/**
89
* Creates a test table with default test data and columns
9-
* This is useful for unit testing components that use TableAdapter
10+
*
11+
* This utility function is designed for unit testing components that use TableAdapter.
12+
* It provides helper methods to interact with and assert against the rendered table.
13+
*
14+
* @template TData - The type of data being displayed in the table
15+
*
16+
* @param props - Partial TableAdapter props to override defaults
17+
* @returns Object containing render result and helper functions
18+
*
19+
* @example
20+
* ```tsx
21+
* test('sorts table when clicking header', async () => {
22+
* const { sortByColumn, getCellContent } = createTestTable();
23+
*
24+
* await sortByColumn('Name');
25+
* expect(getCellContent(0, 1)).toBe('Test 1');
26+
* });
27+
* ```
1028
*/
1129
export function createTestTable<TData extends object>(
1230
props: Partial<TableAdapterProps<TData>> = {}

0 commit comments

Comments
 (0)