react-konva-grid
Version:
Canvas grid to render large set of tabular data with virtualization.
90 lines (89 loc) • 2.57 kB
TypeScript
import React from "react";
import { Stage } from "react-konva/lib/ReactKonvaCore";
export interface IProps {
width: number;
height: number;
columnCount: number;
rowCount: number;
rowHeight: TItemSize;
columnWidth: TItemSize;
children: RenderComponent;
scrollbarSize: number;
estimatedColumnWidth?: number;
estimatedRowHeight?: number;
onScroll: ({ scrollLeft, scrollTop }: TScrollCoords) => void;
showScrollbar: boolean;
selectionBackgroundColor: string;
selectionBorderColor: string;
selections: IArea[];
mergedCells: IArea[];
frozenRows: number;
frozenColumns: number;
itemRenderer: (props: IChildrenProps) => React.ReactNode;
onViewChange: (view: IView) => void;
}
export declare type TScrollCoords = {
scrollTop: number;
scrollLeft: number;
};
export declare type TForceUpdate = {
shouldForceUpdate: boolean;
};
export declare type RenderComponent = React.FC<IChildrenProps>;
export interface IPosition {
x: number;
y: number;
width: number;
height: number;
}
export interface IChildrenProps extends IPosition, ICell {
key: string;
}
export declare type TItemSize = (index?: number) => number;
export interface IArea {
top: number;
bottom: number;
left: number;
right: number;
}
export interface ICell {
rowIndex: number;
columnIndex: number;
}
export interface IView {
rowStartIndex: number;
rowStopIndex: number;
columnStartIndex: number;
columnStopIndex: number;
}
export interface IInstanceProps {
columnMetadataMap: TCellMetaDataMap;
rowMetadataMap: TCellMetaDataMap;
lastMeasuredColumnIndex: number;
lastMeasuredRowIndex: number;
estimatedRowHeight: number;
estimatedColumnWidth: number;
}
export declare type TCellMetaDataMap = Record<number, TCellMetaData>;
export declare type TCellMetaData = {
offset: number;
size: number;
};
export interface IRef {
scrollTo: (scrollPosition: TScrollCoords) => void;
stage: typeof Stage;
resetAfterIndices: (coords: ICell) => void;
getScrollPosition: () => TScrollCoords;
isMergedCell: (coords: ICell) => boolean;
getCellBounds: (coords: ICell) => IArea;
getCellCoordsFromOffsets: (x: number, y: number) => ICell;
getCellOffsetFromCoords: (coords: ICell) => IPosition;
}
export declare type TGridRef = React.MutableRefObject<IRef>;
export declare type MergedCellMap = Map<string, IArea>;
/**
* Grid component using React Konva
* @param props
*/
declare const Grid: React.FC<IProps>;
export default Grid;