Skip to content

Commit

Permalink
Add basic typings.
Browse files Browse the repository at this point in the history
  • Loading branch information
astegmaier committed Feb 26, 2018
1 parent b904822 commit 3cc7706
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"test:watch": "watch 'npm run test' ./test ./src"
},
"devDependencies": {
"@types/react": "^16.0.38",
"babel-cli": "^6.6.4",
"babel-core": "^6.7.4",
"babel-eslint": "^6.0.2",
Expand Down Expand Up @@ -68,5 +69,6 @@
"files": [
"lib"
],
"main": "lib/index.js"
"main": "lib/index.js",
"types": "types/react-datasheet.d.ts"
}
43 changes: 43 additions & 0 deletions types/react-datasheet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {PureComponent, Component} from "react";

declare namespace ReactDataSheet {
export interface Cell {
readOnly?: boolean;
key?: string | undefined;
className?: string | undefined;
component?: Component<any, any>;
forceComponent?: boolean;
colSpan?: number;
rowSpan?: number;
}

export interface DataSheetProps<T extends Cell> {
data: T[][];
className?: string;
valueRenderer: (cell: T) => string | number | void;
dataRenderer?: (cell: T) => string | number | void;
onChange?: (cell: T, row: number, col: number, newValue: string) => any;
onContextMenu?: (event: MouseEvent, cell: T, i : number, j: number) => any;
onCellsChanged?: (arrayOfChanges: {cell: T, row: number, col: number, newValue: string}[]) => void;
}

export interface CellReference {
row: number;
col: number;
}

export interface DataSheetState {
start?: CellReference;
end?: CellReference;
selecting?: boolean;
forceEdit?: boolean;
editing?: CellReference;
clear?: CellReference;
}
}

declare class ReactDataSheet<T extends ReactDataSheet.Cell> extends PureComponent<ReactDataSheet.DataSheetProps<T>, ReactDataSheet.DataSheetState> {
getSelectedCells(data: T[][], start: ReactDataSheet.CellReference, end: ReactDataSheet.CellReference): {cell: T, row: number, col: number};
}

export default ReactDataSheet;
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# yarn lockfile v1


"@types/react@^16.0.38":
version "16.0.38"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.0.38.tgz#76617433ea10274505f60bb86eddfdd0476ffdc2"

abab@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
Expand Down

0 comments on commit 3cc7706

Please sign in to comment.