es-grid-template
Version:
es-grid-template
319 lines (318 loc) • 11.7 kB
TypeScript
import type { Key, ReactElement, ReactNode } from "react";
import type React from "react";
import type { IOperator } from "./hooks";
import type { TypeFilter, TableProps as RcTableProps, TableColumnType as RcColumnType, EditType, TablePaginationConfig } from "rc-master-ui";
import type { FilterOperator, TableRowSelection } from "rc-master-ui/es/table/interface";
import type { ToolbarItem as RcToolbarItem } from "rc-master-ui/es/toolbar";
import type { ItemType } from "rc-master-ui/es/menu/interface";
import type { FieldNames, FilterFunc } from "rc-select/es/Select";
import type { ColorPickerProps } from "antd";
import type { FixedType } from "rc-base-table/lib/interface";
export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
export type AnyObject = Record<PropertyKey, any>;
export type SelectMode = 'checkbox' | 'radio' | undefined;
export type ITextAlign = 'center' | 'left' | 'right';
export type Frozen = 'left' | 'right' | 'Left' | 'Right';
export type ToolbarItem = Omit<RcToolbarItem, 'position' | 'align'> & {
position?: 'Top' | 'Bottom';
align?: ITextAlign;
onClick?: (args: any) => void;
};
export type ContextMenuItem = ItemType;
export type ITemplateColumn = {
value: any;
column: any;
rowData: any;
field: number | string;
index: number;
};
export type ColumnSelectTable = {
field: string;
dataIndex?: string;
type?: IColumnType;
headerText?: string;
fixedType?: 'left' | 'right' | undefined;
width?: number | undefined;
minWidth?: number;
maxWidth?: number;
visible?: boolean;
textAlign?: ITextAlign;
headerTextAlign?: ITextAlign;
template?: (props: ITemplateColumn) => ReactNode | ReactElement;
headerTemplate?: any;
ellipsis?: boolean | undefined;
format?: IFormat;
tooltipDescription?: string | ((rowData: any) => string | ReactNode);
showTooltip?: boolean;
showTooltipHeader?: boolean;
};
export type IEditSelectSettings = {
fieldKey?: string;
options: any[] | ((rowData: any, field: string) => any[]);
/** get value form other field **/
fieldValue?: string;
/** get label form other field **/
fieldLabel?: string;
inputKey?: string;
filterKey?: string[];
selectMode?: SelectMode;
getPasteValue?: (value: any) => Record<string, any> | null;
validateOption?: (rowData: any, field: string) => any[];
defaultOptions?: any[];
defaultValue?: (value: any, rowData: any) => {
value: any;
label: string;
[key: string]: string;
} | null;
formatOptionLabel?: (option: any) => ReactNode | ReactElement;
loadOptions?: (search: string, callback: (newOptions: any[]) => void) => void;
isMulti?: boolean;
closeMenuOnSelect?: boolean;
menuWidth?: number;
menuHeight?: number;
columns?: ColumnSelectTable[];
toolbarItems?: ToolbarItem[];
toolbarClick?: (props: ToolbarClick) => void;
toolbarHeight?: number;
hideSelectedOptions?: boolean;
showItems?: number;
isLengthSelected?: boolean;
fieldNames?: FieldNames;
filterOption?: boolean | FilterFunc<any>;
};
export type ToolbarClick = {
item: any;
column: any;
};
export type LoadOptionsArgs = {
rowData?: any;
};
export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title' | 'format' | 'commandItems'> & {
field?: string;
key?: any;
type?: IColumnType;
/** @deprecated This function is deprecated and should use `onChange` instead */
haveSum?: boolean;
isSummary?: boolean;
summaryTemplate?: (data: number, key: string) => ReactElement | ReactNode;
maxWidth?: string | number;
format?: IFormat | ((rowData: any) => IFormat);
allowFiltering?: boolean;
allowSorter?: boolean;
operator?: FilterOperator;
hideOperator?: boolean;
placeholder?: string;
showInColumnChoose?: boolean;
typeFilter?: TypeFilter;
source?: any[];
showFilterSearch?: boolean;
headerText?: string;
visible?: boolean;
headerTooltip?: boolean | string | (() => ReactNode | ReactElement);
columnGroupText?: string;
textAlign?: ITextAlign;
headerTextAlign?: ITextAlign;
template?: ReactNode | ReactElement | ((args: ColumnTemplate<RecordType>) => ReactNode | ReactElement);
showTooltip?: boolean;
tooltipDescription?: ReactNode | ReactElement | ((value: any, record: RecordType, index: number) => ReactNode | ReactElement);
headerTemplate?: React.ReactNode | React.ReactElement | ((column: ColumnTable<RecordType>) => React.ReactNode | React.ReactElement);
commandItems?: CommandItem[];
children?: ColumnTable<RecordType>[];
editType?: EditType | ((rowData?: RecordType) => EditType);
disable?: boolean | ((rowData: any) => boolean);
editEnable?: boolean | ((rowData: any) => boolean);
isClearable?: boolean;
maxDate?: any;
minDate?: any;
maxTime?: any;
minTime?: any;
max?: number;
min?: number;
editSelectSettings?: IEditSelectSettings;
fixedType?: FixedType;
};
export type ColumnTemplate<RecordType> = {
value: any;
rowData: RecordType;
index: number;
field: string;
};
export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary' | 'pagination'> {
editAble?: boolean;
groupAble?: boolean;
groupColumns?: string[];
groupSetting?: IGroupSetting;
onChooseColumns?: (props: IOnChooseColumns) => void;
pagination?: false | PaginationConfig;
showCustomTooltip?: boolean;
sortMultiple?: boolean;
dataSource: RecordType[];
columns: ColumnsTable<RecordType>;
height?: number;
format?: IFormat;
t?: any;
lang?: string;
contextMenuItems?: ContextMenuItem[];
showDefaultContext?: boolean;
contextMenuHidden?: string[] | ((args?: Omit<ContextInfo<RecordType>, 'item' | 'event'>) => string[]);
contextMenuOpen?: (args: Omit<ContextInfo<RecordType>, 'item'>) => void;
contextMenuClick?: (args: ContextInfo<RecordType>) => void;
recordDoubleClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
toolbarItems?: ToolbarItem[];
showColumnChoose?: boolean;
showAdvanceFilter?: boolean;
onFilter?: (query: {
field: string;
key: string;
operator: IOperator;
predicate: 'and' | 'or';
value: any;
}[]) => void;
onSorter?: (args: {
column: ColumnTable<RecordType>;
columnKey: string;
field: string;
direction: 'Ascending' | 'Descending' | null;
}) => void;
selectionSettings?: SelectionSettings;
rowKey?: string | keyof RecordType | GetRowKey<RecordType>;
rowSelection?: RowSelection<RecordType>;
rowSelected?: (args: {
type: string;
rowData: RecordType;
selected: RecordType | RecordType[];
}) => void;
dataSourceFilter?: SourceFilter[];
onFilterClick?: (column: ColumnTable<RecordType>, callback: (key: string, data: any) => void) => void;
loading?: boolean;
allowResizing?: boolean;
showToolbar?: boolean;
onDataChange?: (data: RecordType[]) => void;
defaultValue?: AnyObject | (() => AnyObject);
summary?: boolean | ((data: readonly RecordType[]) => React.ReactNode);
showEmptyText?: boolean;
commandSettings?: CommandSettings;
onCellPaste?: ICellPasteModel<RecordType>;
onCellChange?: (args: CellChangeArgs<RecordType>, handleCallback: (rowData: any, index: any, value?: any) => void) => void;
onCellClick?: (args: ICellClick, callback?: any) => void;
rowEditable?: (rowData: RecordType) => boolean;
validate?: any;
onBlur?: (data: RecordType[]) => void;
onExpandClick?: (args: {
expandedKeys: string[];
key: string;
rowData: any;
}) => void;
}
export type PaginationConfig = TablePaginationConfig & {
currentPage?: number;
};
export type ICellClick = {
index: number;
indexCol?: number;
rowId: string | number;
type: 'Editing' | 'Default';
field: string;
cellValue: any;
rowData: any;
};
export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType>;
export interface CommandItem {
id: string;
type?: string;
visible?: boolean | ((record: any) => boolean);
title: string;
color?: 'blue' | 'purple' | 'cyan' | 'green' | 'magenta' | 'pink' | 'red' | 'orange' | 'yellow' | 'volcano' | 'geekblue' | 'lime' | 'gold';
tooltip?: string;
icon?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
template?: ReactNode | ReactElement | ((record: any) => ReactNode | ReactElement);
client?: boolean;
confirmDialog?: boolean;
}
export type IGroupSetting = {
client?: boolean;
onGroup?: (props: IOnGroup) => void;
hiddenColumnGroup?: boolean;
showGroupIcon?: boolean;
unClearableLevel?: 1 | 2 | 3 | undefined;
};
type IOnGroup = {
columnGrouped: string[];
columns: ColumnsTable;
flattenColumns: ColumnsTable;
};
export type IOnChooseColumns = {
columns: ColumnsTable;
showColumns: ColumnsTable;
flattenColumns: ColumnsTable;
};
export type CellChangeArgs<T> = {
type: 'onPaste' | 'onChange' | 'onCellPaste';
value: any;
option: AnyObject;
rowData: T;
rowsData: T[];
indexRow: number;
rowId?: string;
field: string | undefined;
indexCol: any;
sumValue?: any[];
};
export type IOnPastedProps = {
data: any[];
pastedColumns: string[];
pasteData: any[];
type: 'onPaste' | 'onChange' | 'onCellPaste';
};
export interface ICellPasteModel<RecordType = AnyObject> {
onPasted?: (args: IOnPastedProps, handleCallback: (callbackData: any[]) => void) => void;
dataChange?: (data: RecordType[]) => void;
getCallbackData?: (props: any) => void;
maxRowsPaste?: number;
}
export type SourceFilter = {
key: string;
data: any[];
loadOptions?: (search: string, callback: (newOptions: any[]) => void) => void;
};
export type RowSelection<RecordType> = Omit<TableRowSelection<RecordType>, 'type' | 'columnWidth' | 'hideSelectAll' | 'defaultSelectedRowKeys'>;
export type SelectionSettings = Omit<TableRowSelection, 'type' | 'onChange' | 'onSelect' | 'onSelectAll' | 'onSelectNone' | 'onSelectMultiple'> & {
mode?: 'checkbox' | 'radio';
type?: 'single' | 'multiple';
checkboxOnly?: boolean;
};
export type RecordDoubleClickEventArgs<RecordType> = {
rowData: RecordType;
rowIndex: number | undefined;
e: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
};
export type ContextInfo<RecordType> = {
rowInfo: {
rowData: RecordType | null;
};
event: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
item: ItemType;
};
export type IFormat = {
thousandSeparator?: string;
decimalSeparator?: string;
decimalScale?: number | undefined;
allowNegative?: boolean;
prefix?: string | undefined;
suffix?: string | undefined;
fixedDecimalScale?: boolean;
dateFormat?: string;
datetimeFormat?: string;
timeFormat?: string;
weekFormat?: string;
monthFormat?: string;
yearFormat?: string;
};
export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
export type Presets = Required<ColorPickerProps>['presets'][number];
export type CommandSettings = {
client?: boolean;
confirmDialog?: boolean;
};
export {};