use-table-tools
Version:
react hook for building powerful table components
76 lines • 2.64 kB
TypeScript
import { ChangeEvent } from 'react';
export declare type ColumnProps = {
title: string;
sortKey: string;
locked?: boolean;
[key: string]: any;
};
export declare type SelectAllCheckboxStates = 'all' | 'none' | 'some';
export declare type SortProps = {
direction: 'asc' | 'desc';
fieldKey: string;
};
export declare type TableToolsProps = {
totalItems: number;
columns: ColumnProps[];
clientSortBy?: SortProps;
checkedItems?: string[];
layout?: {
[key: number]: string[];
} | string[];
};
export interface TableToolsState {
currentLayout: string[];
visibleColumns: ColumnProps[];
totalItems: number;
columns: ColumnProps[];
checkedItems: string[];
selectAllCheckboxState: SelectAllCheckboxStates;
currentSort: SortProps;
lastChecked: {
id: string;
value: string;
} | null;
}
export interface TableToolsReturnProps extends TableToolsState {
switchColumns: (from: string, to: string) => void;
switchCurrentLayout: (currentLayout: string[]) => void;
offsetColumns: (obj?: {
includeVisible: boolean;
}) => ColumnProps[];
onSelection: (items: string[]) => void;
deselectAll: () => void;
selectAll: (checkedItems: string[]) => void;
checkboxToggle: (evt: ChangeEvent<HTMLInputElement>) => void;
checkboxShiftToggle: (evt: ChangeEvent<HTMLInputElement>) => void;
checkboxState: (id: string) => boolean;
clientSortMethod: (a: object, b: object) => number;
changeSortDirection: (direction: SortProps['direction']) => void;
toggleSortDirection: () => void;
toggleSortByKey: (fieldKey: string) => void;
sortData: (sortProps: SortProps) => void;
activeSort: (sortProps: SortProps) => boolean;
activeSortKey: (key: string) => boolean;
getCheckboxProps: any;
}
export declare const actionTypes: {
updateState: string;
switchColumns: string;
switchCurrentLayout: string;
deselectAll: string;
selectAll: string;
checkboxToggle: string;
checkboxShiftToggle: string;
changeSortDirection: string;
toggleSortDirection: string;
toggleSortByKey: string;
sortData: string;
};
export declare type Action = {
type: string;
payload?: any;
};
export declare type ReducerProps<S, A> = (prevState: S, action: A) => S;
export declare const tableToolsReducer: ReducerProps<TableToolsState, Action>;
export declare const useTableTools: ({ layout, totalItems, clientSortBy, columns, checkedItems, }: TableToolsProps, reducer?: ReducerProps<TableToolsState, Action>) => TableToolsReturnProps;
//# sourceMappingURL=tableTools.d.ts.map