@grandlinex/react-components
Version:
67 lines (66 loc) • 2.38 kB
TypeScript
import React, { MouseEvent } from 'react';
import { FormErrorType } from '../form/FormTypes';
export type BaseRowEvent<T = any> = {
data: T;
index: number;
};
export type SimpleCellEvent<T = any> = BaseRowEvent<T> & {
value: any;
};
export type ChangeCellEvent<T = any> = SimpleCellEvent<T> & {
newValue: any;
};
export type DefaultColumTableProps<T = any> = {
headerName?: string;
flex?: number;
width?: number;
minWidth?: number;
editable?: boolean;
dataType?: 'string' | 'number' | 'boolean' | 'date' | 'object' | 'array';
cellRenderer?: (dat: SimpleCellEvent<T>) => React.ReactNode;
};
export type ColumTableProps<T = any> = DefaultColumTableProps<T> & {
field: string;
};
export type TableAction = {
name: string;
icon: React.ReactNode;
onClick: (event: MouseEvent) => void;
disabled?: boolean;
};
export type TableActionFc<T = any> = (dat: BaseRowEvent<T>) => TableAction;
export type TableProps<T = any> = {
className?: string;
rowData: T[] | null | undefined;
isSelectable?: keyof T;
fixedHeader?: boolean;
onSelectionChange?: (selected: (string | number)[]) => void;
columnDefs: ColumTableProps<T>[];
onClickRow?: (rowData: T) => void;
defaultColDef?: DefaultColumTableProps<T>;
onCellValueChanged?: (change: ChangeCellEvent<T>) => void;
extendRowRenderer?: (dat: BaseRowEvent<T>) => React.ReactNode;
rowAction?: TableActionFc<T>[];
editMode?: (row: T, setError: (err: FormErrorType | null) => void, clear: () => void) => Promise<boolean>;
};
export type TableRowProps<T = any> = {
rowData: T;
api: ITableFc<T>;
index: number;
extendRowRenderer?: (dat: BaseRowEvent<T>) => React.ReactNode;
};
export type ITableFc<T = any> = {
editMode?: (row: T, setError: (err: FormErrorType | null) => void, clear: () => void) => Promise<boolean>;
hasEditMode(): boolean;
rowSelected(index: number | string | T): boolean;
rowSelect(index: number | string | T): void;
rowUnSelect(index: number | string | T): void;
getColumDefs(add?: TableActionFc<T>[]): ColumTableProps<T>[];
};
export declare function useTableStore<T extends Record<string, any>>(props: TableProps<T>): {
data: {
rowData: T[];
};
api: ITableFc<T>;
};
export declare function getCellValue<T = any>(rot: T | any, col: ColumTableProps<T>): any;