-
-
Save stooboo/f4e704d8dead3be4857ee13452b767ba to your computer and use it in GitHub Desktop.
React Table v7 TS typings definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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<TRowData = any> = { | |
column: Column<TRowData>; | |
getCellProps: () => any; | |
render: (type: string) => any; | |
row: Row<TRowData>; | |
state: any; | |
value: any; | |
}; | |
export type Row<TRowData = any> = { | |
cells: Array<Cell<TRowData>>; | |
depth: number; | |
getRowProps: () => any; | |
index: number; | |
original: TRowData; | |
path: string[] | |
subRows: [], | |
values: any, | |
}; | |
// tslint:disable-next-line:interface-name | |
export interface HeaderColumn<TRowData = any> { | |
id?: string | number; | |
accessor: string | ((originalRow: TRowData) => any); | |
canSortBy?: boolean; | |
defaultSortDesc?: boolean; | |
sortByFn?: (a: any, b: any, desc: boolean) => 0 | 1 | -1; | |
width?: string | number; | |
minWidth?: string | number; | |
maxWidth?: string | number; | |
Header?: string | ((props: Api<TRowData>) => JSX.Element | string); | |
Filter?: string | ((props: Api<TRowData>) => JSX.Element | string); | |
Cell?: string | ((cell: Cell<TRowData>) => JSX.Element | string); | |
} | |
// tslint:disable-next-line:interface-name | |
export interface Column<TRowData = any> extends HeaderColumn<TRowData> { | |
id: string | number; | |
} | |
export type Page<TRowData = any> = Array<Row<TRowData>>; | |
// tslint:disable-next-line:interface-name | |
export interface EnhancedColumn<TRowData = any> extends Column<TRowData> { | |
render: (type: string) => any; | |
getHeaderProps: (userProps?: any) => any; | |
getSortByToggleProps: (userProps?: any) => any; | |
sorted: boolean; | |
sortedDesc: boolean; | |
sortedIndex: number; | |
} | |
export type HeaderGroup<TRowData = any> = { | |
headers: Array<EnhancedColumn<TRowData>>; | |
getRowProps: (userProps?: any) => any; | |
}; | |
export type Hooks<TRowData = any> = { | |
beforeRender: []; | |
columns: []; | |
headerGroups: []; | |
headers: []; | |
rows: Row[]; | |
row: []; | |
renderableRows: []; | |
getTableProps: []; | |
getRowProps: []; | |
getHeaderRowProps: []; | |
getHeaderProps: []; | |
getCellProps: []; | |
}; | |
// tslint:disable-next-line:interface-name | |
export interface Api<TRowData = any> | |
extends | |
TableProps<TRowData>, | |
UseRowsValues<TRowData>, | |
UseFiltersValues, | |
UsePaginationValues<TRowData>, | |
UseColumnsValues<TRowData> { | |
hooks: Hooks<TRowData>; | |
rows: Array<Row<TRowData>>; | |
columns: Array<EnhancedColumn<TRowData>>; | |
getTableProps: (userProps?: any) => any; | |
getRowProps: (userProps?: any) => any; | |
prepareRow: (row: Row<TRowData>) => any; | |
getSelectRowToggleProps: (userProps?: any) => any; | |
toggleSelectAll: (forcedState: boolean) => any; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface TableProps<TRowData = any> { | |
data: TRowData[]; | |
columns: Array<HeaderColumn<TRowData>>; | |
state?: any; | |
debug?: boolean; | |
sortByFn?: (a: any, b: any, desc: boolean) => 0 | 1 | -1; | |
manualSorting?: boolean; | |
disableSorting?: boolean; | |
defaultSortDesc?: boolean; | |
disableMultiSort?: boolean; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface RowsProps { | |
subRowsKey: string; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface FiltersProps { | |
filterFn: () => void; | |
manualFilters: boolean; | |
disableFilters: boolean; | |
setFilter: () => any; | |
setAllFilters: () => any; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface UsePaginationValues<TRowData = any> { | |
nextPage: () => any; | |
previousPage: () => any; | |
setPageSize: (size: number) => any; | |
gotoPage: (page: number) => any; | |
canPreviousPage: boolean; | |
canNextPage: boolean; | |
page: Page; | |
pageOptions: []; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface UseRowsValues<TRowData = any> { | |
rows: Array<Row<TRowData>>; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface UseColumnsValues<TRowData = any> { | |
columns: Array<EnhancedColumn<TRowData>>; | |
headerGroups: Array<HeaderGroup<TRowData>>; | |
headers: Array<EnhancedColumn<TRowData>>; | |
} | |
// tslint:disable-next-line:interface-name | |
export interface UseFiltersValues { | |
setFilter: () => any; | |
setAllFilters: () => any; | |
} | |
export function useTable<TRowData = any>(props: TableProps<TRowData>, ...plugins: any[]) : Api<TRowData>; | |
export function useColumns<TRowData = any>(props: TableProps<TRowData>) : TableProps<TRowData> & UseColumnsValues; | |
export function useRows<TRowData = any>(props: TableProps<TRowData>) : TableProps<TRowData> & UseRowsValues; | |
export function useFilters<TRowData = any>( | |
props: TableProps<TRowData> | |
) : TableProps<TRowData> & { | |
rows: Array<Row<TRowData>>; | |
}; | |
export function useSortBy<TRowData = any>( | |
props: TableProps<TRowData> | |
) : TableProps<TRowData> & { | |
rows: Array<Row<TRowData>>; | |
}; | |
export function useGroupBy<TRowData = any>(props: TableProps<TRowData>) : TableProps<TRowData> & { rows: Array<Row<TRowData>> }; | |
export function usePagination<TRowData = any>(props: TableProps<TRowData>) : UsePaginationValues<TRowData>; | |
export function useFlexLayout<TRowData = any>(props: TableProps<TRowData>) : TableProps<TRowData>; | |
export function useExpanded<TRowData = any>( | |
props: TableProps<TRowData> | |
) : TableProps<TRowData> & { | |
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