UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

91 lines (88 loc) 3.54 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import { ReactElement } from 'react'; type TableStatePagination = { currentPage: number; entriesPerPage: number; }; declare const defaultTableStatePagination: { currentPage: number; entriesPerPage: number; }; type TableStateSelection<T> = { currentSelection: T[]; hasSelectedAll: boolean; hasSelectedSome: boolean; hasSelectedNone: boolean; }; declare const defaultTableStateSelection: { currentSelection: never[]; hasSelectedAll: boolean; hasSelectedSome: boolean; hasSelectedNone: boolean; }; type TableState = { pagination?: TableStatePagination; selection?: { /** * The mapped ids of the dataType */ currentSelection: string[]; hasSelectedAll: boolean; hasSelectedSome: boolean; hasSelectedNone: boolean; }; }; type IdentifierMapping<T> = (dataObject: T) => string; declare const isDataObjectSelected: <T>(tableState: TableState, dataObject: T, identifierMapping: IdentifierMapping<T>) => boolean; declare const pageForItem: <T>(data: T[], item: T, entriesPerPage: number, identifierMapping: IdentifierMapping<T>) => number; declare const updatePagination: (pagination: TableStatePagination, dataLength: number) => TableStatePagination; declare const addElementToTable: <T>(tableState: TableState, data: T[], dataObject: T, identifierMapping: IdentifierMapping<T>) => { pagination: { currentPage: number; entriesPerPage: number; } | undefined; selection: { hasSelectedAll: boolean; hasSelectedSome: boolean; /** * The mapped ids of the dataType */ currentSelection: string[]; hasSelectedNone: boolean; } | undefined; }; /** * data length before delete */ declare const removeFromTableSelection: <T>(tableState: TableState, deletedObjects: T[], dataLength: number, identifierMapping: IdentifierMapping<T>) => TableState; declare const changeTableSelectionSingle: <T>(tableState: TableState, dataObject: T, dataLength: number, identifierMapping: IdentifierMapping<T>) => TableState; type TableSortingType = 'ascending' | 'descending'; type TableSortingFunctionType<T> = (t1: T, t2: T) => number; type TableProps<T> = { data: T[]; /** * When using selection or pagination */ stateManagement?: [TableState, (tableState: TableState) => void]; identifierMapping: IdentifierMapping<T>; /** * Only the cell itself no boilerplate <tr> or <th> required */ header?: ReactElement[]; /** * Only the cells of the row no boilerplate <tr> or <td> required */ rowMappingToCells: (dataObject: T) => ReactElement[]; sorting?: [TableSortingFunctionType<T>, TableSortingType]; /** * Always go to the page of this element */ focusElement?: T; className?: string; }; /** * A Basic stateless reusable table * The state must be handled and saved with the updateTableState method */ declare const Table: <T>({ data, stateManagement, identifierMapping, header, rowMappingToCells, sorting, focusElement, className }: TableProps<T>) => react_jsx_runtime.JSX.Element; export { Table, type TableProps, type TableSortingFunctionType, type TableSortingType, type TableState, type TableStatePagination, type TableStateSelection, addElementToTable, changeTableSelectionSingle, defaultTableStatePagination, defaultTableStateSelection, isDataObjectSelected, pageForItem, removeFromTableSelection, updatePagination };