-
-
Notifications
You must be signed in to change notification settings - Fork 240
/
types.ts
73 lines (65 loc) · 1.94 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { ComponentChild } from 'preact';
import Row from './row';
import { SortConfig } from './view/plugin/sort/sort';
import { JSXInternal } from 'preact/src/jsx';
import { Plugin } from './plugin';
export type ProtoExtends<T, U> = U & Omit<T, keyof U>;
export type OneDArray<T> = T[];
export type TwoDArray<T> = T[][];
/**
* Table cell types
*/
export type TCell = number | string | boolean | ComponentChild | HTMLElement;
// Array of Arrays
export type TDataArrayRow = OneDArray<TCell>;
export type TDataArray = OneDArray<TDataArrayRow>;
// Array of Objects
export type TDataObjectRow = { [key: string]: TCell };
export type TDataObject = OneDArray<TDataObjectRow>;
// (Array of Arrays) and (Array of Objects)
export type TData = TDataArray | TDataObject;
// Table header cell type
export interface TColumn {
id?: string;
// default data for all columns
data?: ((row: TDataArrayRow | TDataObjectRow) => TCell) | TCell;
// column label
name?: string | ComponentChild;
plugin?: Plugin<any>;
// column width
width?: string;
minWidth?: string;
sort?: SortConfig;
columns?: OneDArray<TColumn>;
fixedHeader?: boolean;
resizable?: boolean;
hidden?: boolean;
formatter?: (cell: TCell, row: Row, column: TColumn) => ComponentChild;
// HTML attributes to be added to all cells and header of this column
attributes?:
| ((
// this is null when `attributes` is called for a th
cell: TCell | null,
row: Row | null,
column: TColumn,
) => JSXInternal.HTMLAttributes<HTMLTableCellElement>)
| JSXInternal.HTMLAttributes<HTMLTableCellElement>;
}
// Comparator function for the sorting plugin
export type Comparator<T> = (a: T, b: T) => number;
export interface TColumnSort {
index: number;
// 1 ascending, -1 descending
direction?: 1 | -1;
}
// container status
export enum Status {
Init,
Loading,
Loaded,
Rendered,
Error,
}
export type CSSDeclaration = {
[key: string]: string | number;
};