amotify
Version:
UI Component for React,NextJS,esbuild
157 lines (156 loc) • 6.02 kB
TypeScript
import { ReactElement, StyleProps } from '../../@declares';
import React from 'react';
import Input from '../Input';
declare namespace DataGrid {
type customTableHTMLAttributes<T> = Omit<React.TableHTMLAttributes<T>, 'border'>;
type Table = StyleProps.BasicElement & customTableHTMLAttributes<HTMLTableElement>;
type TableHead = StyleProps.BasicElement & customTableHTMLAttributes<HTMLTableSectionElement>;
type TableBody = StyleProps.BasicElement & customTableHTMLAttributes<HTMLTableSectionElement>;
type TR = StyleProps.BasicElement & React.HTMLAttributes<HTMLTableRowElement>;
type TableCell = StyleProps.BasicElement & React.ThHTMLAttributes<HTMLTableCellElement>;
type RowID = string | number;
type KeyType = string | number;
type DataType = string | number | boolean;
/**
* -1: descending
* 0: disabled
* 1: ascending
*/
type SortType = -1 | 0 | 1;
type Checkable = boolean | 'left' | 'right';
type Tones = 'border' | 'border.vertical' | 'border.horizontal' | false;
type CellInfo = {
rowIdx: number;
colIdx: number;
topIdx: number;
leftIdx: number;
rightIdx: number;
bottomIdx: number;
isHeader: boolean;
isBody: boolean;
isFooter: boolean;
};
type Cell = TableCell & {
isTH?: boolean;
label?: ReactElement;
};
namespace Cell {
type Header<K extends KeyType = KeyType> = Cell & {
key: K;
columnIdx?: number;
/**
* default 0
*/
sortable?: SortType;
defSort?: boolean;
filterable?: boolean;
checkable?: Checkable;
/**
* if true, ( sortable/defSort/filterable ) will be ignored.
*/
draggable?: boolean;
isHidden?: boolean;
onLabelRender?(value: K): ReactElement;
};
type Body<T = DataType> = Cell & {
data: T;
sortKey?: string | number;
onLabelRender?(value: T): ReactElement;
};
type Footer<T = DataType> = Cell & {
data: T;
onLabelRender?(value: T): ReactElement;
};
}
type Header<K extends KeyType = KeyType> = Cell.Header<K>[];
type RowMeta = {
row_id?: RowID;
/**
* for checker
*/
isSelected?: boolean;
isFilterMatched?: boolean;
isVisible?: boolean;
onCheckerDisabled?(): ReactElement;
onDraggerDisabled?(): ReactElement;
draggerIndex?: number;
onRowClick?(event: React.MouseEvent<HTMLTableRowElement, MouseEvent>): void;
};
type Row<K extends KeyType = KeyType, T = DataType> = RowMeta & Partial<Record<K, Cell.Body<T> | KeyType | boolean | Function>>;
type StrictRow<K extends KeyType = KeyType, T = DataType> = RowMeta & Partial<Record<K, Cell.Body<T>>>;
type Body<K extends KeyType = KeyType> = Row<K>[];
type StrictBody<K extends KeyType = KeyType> = StrictRow<K>[];
type Footer<K extends KeyType = KeyType, T = DataType> = Partial<Record<K, Cell.Footer<T> | RowID>>;
type Input<K extends KeyType = KeyType> = {
tone?: Tones;
datagridID?: string;
/**
* default 100
*/
maxRows?: number;
colLength?: number;
/**
* If true, the header will not be rendered.
*/
headerless?: boolean;
header: Header<K>;
body: Body<K> | StrictBody<K>;
footer?: Footer<K>;
defaultSearchKey?: string;
rowStyles?: StyleProps.StyleProps;
cellStyles?: StyleProps.StyleProps & {
onHeader?: StyleProps.StyleProps;
onBody?: StyleProps.StyleProps;
onFooter?: StyleProps.StyleProps;
onTop?: StyleProps.StyleProps;
onBottom?: StyleProps.StyleProps;
onLeft?: StyleProps.StyleProps;
onRight?: StyleProps.StyleProps;
};
cellClassName?: string;
onCellStyles?(props: CellInfo, def: StyleProps.StyleProps): StyleProps.StyleProps;
className?: string;
onNoRecordsRender?(): ReactElement;
onRowClick?(row: Row, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>): void;
onCellClick?(opt: CellInfo, event: React.MouseEvent<HTMLTableCellElement, MouseEvent>): void;
onSorted?(col: number, sort: SortType): void;
onSelected?(rows: StrictRow<K>[]): void;
onDragged?(rows: StrictRow<K>[]): void;
} & StyleProps.States;
type Component = <K extends KeyType = KeyType>(props: DataGrid.Input<K>) => React.JSX.Element;
type FNs = {
toSafetyBody<K extends KeyType = KeyType>(body: Body<K>): StrictBody<K>;
getBodyRows<K extends KeyType = KeyType>(datagridID: string): StrictBody<K>;
reset(datagridID: string): void;
refreshBody(datagridID: string): void;
reservedKeys: string[];
Table: React.FC<Table>;
Head: React.FC<TableHead>;
Body: React.FC<TableBody>;
Row: React.FC<TR>;
Cell: React.FC<TableCell & {
isTH?: boolean;
}>;
TH: React.FC<TableCell>;
TD: React.FC<TableCell>;
RightIndicator: Cell.Body;
SearchInput: React.FC<Input.TextField.Input & {
datagridID: string;
}>;
Info: React.FC<{
datagridID: string;
totalCount?: number;
}>;
Paging: React.FC<Omit<Input.TextField.Input, 'options'> & {
datagridID: string;
}>;
RowCount: React.FC<Omit<Input.TextField.Input, 'options'> & {
datagridID: string;
options: number[];
}>;
};
type Methods = Component & FNs;
}
export declare const onDefaultCellStyles: (args: DataGrid.CellInfo, prev: StyleProps.StyleProps) => StyleProps.StyleProps;
declare const DataGrid: DataGrid.Methods;
export { DataGrid, DataGrid as default };