Files
react/components/table/table-types.ts
witt 4062d7b5a8 refactor(table): redesign interfaces to improve the experience in TypeScript (#569)
* refactor(table): redesign interfaces to improve the experience in TypeScript

* docs: upgrade to new type exports

* style: fix lint warnings
2021-08-13 17:11:24 +08:00

33 lines
885 B
TypeScript

import React from 'react'
export type TableDataItemBase = Record<string, any>
export type TableColumnRender<Item extends TableDataItemBase> = (
value: Item[keyof Item],
rowData: Item,
rowIndex: number,
) => JSX.Element | void
export type TableAbstractColumn<TableDataItem> = {
prop: keyof TableDataItem
label: React.ReactNode | string
className: string
width?: number
renderHandler: TableColumnRender<TableDataItem>
}
export type TableOnRowClick<TableDataItem> = (
rowData: TableDataItem,
rowIndex: number,
) => void
export type TableOnCellClick<TableDataItem> = (
cellValue: TableDataItem[keyof TableDataItem],
rowIndex: number,
colunmIndex: number,
) => void
export type TableOnChange<TableDataItem> = (data: Array<TableDataItem>) => void
export type TableRowClassNameHandler<TableDataItem> = (
rowData: TableDataItem,
rowIndex: number,
) => string