Skip to content

Instantly share code, notes, and snippets.

@berdyshev
Forked from Grsmto/react-table.d.ts
Last active July 19, 2022 14:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save berdyshev/6eb6f50da30a10c5803d55a8a4fcef28 to your computer and use it in GitHub Desktop.
Save berdyshev/6eb6f50da30a10c5803d55a8a4fcef28 to your computer and use it in GitHub Desktop.
React Table v7 TS typings definition
// Type definitions for react-table 7
// Project: https://github.com/tannerlinsley/react-table#readme
// Definitions by: Grsmto <https://github.com/grsmto>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
declare module "react-table" {
export type Cell = {
render: (type: string) => any;
getCellProps: () => any;
column: Column;
row: Row;
state: any;
value: any;
};
export type Row = {
index: number;
cells: Cell[];
getRowProps: () => any;
original: any;
};
export interface HeaderColumn {
accessor: string | ((originalRow: any) => string);
Header?: string | ((props: Api) => JSX.Element | string);
Filter?: string | ((props: Api) => JSX.Element | string);
Cell?: string | ((cell: Cell) => JSX.Element | string);
id?: string | number;
minWidth?: string | number;
maxWidth?: string | number;
width?: string | number;
canSortBy?: boolean;
sortByFn?: (a: any, b: any, desc: boolean) => 0 | 1 | -1;
defaultSortDesc?: boolean;
}
export interface Column extends HeaderColumn {
id: string | number;
}
export type Page = Row[];
export interface EnhancedColumn extends Column {
render: (type: string) => any;
getHeaderProps: (userProps?: any) => any;
getSortByToggleProps: (userProps?: any) => any;
sorted: boolean;
sortedDesc: boolean;
sortedIndex: number;
}
export type HeaderGroup = {
headers: EnhancedColumn[];
getRowProps: (userProps?: any) => any;
};
export type Hooks = {
beforeRender: [];
columns: [];
headerGroups: [];
headers: [];
rows: Row[];
row: [];
renderableRows: [];
getTableProps: [];
getRowProps: [];
getHeaderRowProps: [];
getHeaderProps: [];
getCellProps: [];
};
export interface Api
extends TableProps,
UseRowsValues,
UseFiltersValues,
UsePaginationValues,
UseColumnsValues {
hooks: Hooks;
rows: Row[];
columns: EnhancedColumn[];
getTableProps: (userProps?: any) => any;
getRowProps: (userProps?: any) => any;
prepareRow: (row: Row) => any;
getSelectRowToggleProps: (userProps?: any) => any;
toggleSelectAll: (forcedState: boolean) => any;
}
export interface TableProps {
data: any[];
columns: HeaderColumn[];
state?: any;
debug?: boolean;
sortByFn?: (a: any, b: any, desc: boolean) => 0 | 1 | -1;
manualSorting?: boolean;
disableSorting?: boolean;
defaultSortDesc?: boolean;
disableMultiSort?: boolean;
}
export interface RowsProps {
subRowsKey: string;
}
export interface FiltersProps {
filterFn: () => void;
manualFilters: boolean;
disableFilters: boolean;
setFilter: () => any;
setAllFilters: () => any;
}
export interface UsePaginationValues {
nextPage: () => any;
previousPage: () => any;
setPageSize: (size: number) => any;
gotoPage: (page: number) => any;
canPreviousPage: boolean;
canNextPage: boolean;
page: Page;
pageOptions: [];
}
export interface UseRowsValues {
rows: Row[];
}
export interface UseColumnsValues {
columns: EnhancedColumn[];
headerGroups: HeaderGroup[];
headers: EnhancedColumn[];
}
export interface UseFiltersValues {
setFilter: () => any;
setAllFilters: () => any;
}
export function useTable(props: TableProps, ...plugins: any[]): Api;
export function useColumns(props: TableProps): TableProps & UseColumnsValues;
export function useRows(props: TableProps): TableProps & UseRowsValues;
export function useFilters(
props: TableProps
): TableProps & {
rows: Row[];
};
export function useSortBy(
props: TableProps
): TableProps & {
rows: Row[];
};
export function useGroupBy(props: TableProps): TableProps & { rows: Row[] };
export function usePagination(props: TableProps): UsePaginationValues;
export function useFlexLayout(props: TableProps): TableProps;
export function useExpanded(
props: TableProps
): TableProps & {
toggleExpandedByPath: () => any;
expandedDepth: [];
rows: [];
};
export function useTableState(
initialState?: any,
overriddenState?: any,
options?: {
reducer?: (oldState: any, newState: any, type: string) => any;
useState?: typeof React.useState;
}
): any;
export const actions: any;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment