diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..69f3551 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,184 @@ +import { Dispatch, SetStateAction, ReactNode } from 'react'; + +declare module 'react-table' { + export interface Cell { + render: (type: string) => any; + getCellProps: () => any; + column: Column; + row: Row; + state: any; + value: any; + } + + export interface Row { + index: number; + cells: Cell[]; + getRowProps: () => any; + original: any; + } + + export interface HeaderColumn { + /** + * This string/function is used to build the data model for your column. + */ + accessor: A | ((originalRow: D) => string); + Header?: string | ((props: TableInstance) => ReactNode); + Filter?: string | ((props: TableInstance) => ReactNode); + Cell?: string | ((cell: Cell) => ReactNode); + + /** + * This is the unique ID for the column. It is used by reference in things like sorting, grouping, filtering etc. + */ + 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 interface Hooks { + beforeRender: []; + columns: []; + headerGroups: []; + headers: []; + rows: Row[]; + row: []; + renderableRows: []; + getTableProps: []; + getRowProps: []; + getHeaderRowProps: []; + getHeaderProps: []; + getCellProps: []; + } + + export interface TableInstance + extends TableOptions, + 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 TableOptions { + data: D[]; + columns: HeaderColumn[]; + state?: [any, Dispatch>]; + 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: TableOptions, ...plugins: any[]): TableInstance; + + export function useColumns(props: TableOptions): TableOptions & UseColumnsValues; + + export function useRows(props: TableOptions): TableOptions & UseRowsValues; + + export function useFilters( + props: TableOptions, + ): TableOptions & { + rows: Row[]; + }; + + export function useSortBy( + props: TableOptions, + ): TableOptions & { + rows: Row[]; + }; + + export function useGroupBy(props: TableOptions): TableOptions & { rows: Row[] }; + + export function usePagination(props: TableOptions): UsePaginationValues; + + export function useFlexLayout(props: TableOptions): TableOptions; + + export function useExpanded( + props: TableOptions, + ): TableOptions & { + toggleExpandedByPath: () => any; + expandedDepth: []; + rows: []; + }; + + export function useTableState( + initialState?: any, + overriddenState?: any, + options?: { + reducer?: (oldState: any, newState: any, type: string) => any; + useState?: [any, Dispatch>]; + }, + ): any; + + export const actions: any; +} \ No newline at end of file diff --git a/package.json b/package.json index e18d7d8..bb561d5 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "main": "dist/index.js", "module": "dist/index.es.js", "jsnext:main": "dist/index.es.js", + "types": "index.d.ts", "scripts": { "commit": "git add . && git-cz", "test": "is-ci 'test:ci' 'test:dev'", @@ -32,6 +33,7 @@ "files": [ "CHANGELOG.md", "src/**/*.js", + "index.d.ts", "dist", "LICENCE", "package.json",