-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdataTypes.ts
62 lines (50 loc) · 2.37 KB
/
dataTypes.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
import type { IPagingFilter } from "@frui.ts/data";
import type { ReactNode } from "react";
import type React from "react";
export type PropertyKey<TItem> = keyof TItem & (string | number);
export interface KeyRenderProps {
key: React.Key;
}
export interface ColumnRenderProps<TItem, TContext, TProperty extends PropertyKey<TItem>> {
column: ColumnDefinition<TItem, TContext, TProperty>;
context: TContext;
}
export interface ValueRenderProps<TItem, TContext, TProperty extends PropertyKey<TItem>>
extends ColumnRenderProps<TItem, TContext, TProperty> {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
value?: TItem[TProperty] | any; // if we remove any, TS is not able to infer type when multiple columns definitions are defined next to each other :-(
item: TItem;
}
export interface ColumnDefinition<TItem, TContext = any, TProperty extends PropertyKey<TItem> = PropertyKey<TItem>> {
title?: ReactNode;
titleFactory?: (context: TContext) => ReactNode;
property?: TProperty;
sortable?: boolean;
// you can use either headerClassName and pass CSS class, or provide headerFormatter to override the whole node
headerClassName?: string;
headerFormatter?: (props: ColumnRenderProps<TItem, TContext, TProperty> & KeyRenderProps) => ReactNode;
// you can either use valueFormatter to format the value displayed, or cellFormatter to override the whole node
valueFormatter?: (props: ValueRenderProps<TItem, TContext, TProperty>) => ReactNode;
cellClassName?: string;
cellFormatter?: (props: ValueRenderProps<TItem, TContext, TProperty> & KeyRenderProps) => ReactNode;
cellProps?: (props: ValueRenderProps<TItem, TContext, TProperty>) => any;
}
export interface ResponsiveColumnDefinition<TItem, TContext> extends ColumnDefinition<TItem, TContext> {
responsiveTitle?: string | false;
responsiveTitleFactory?: (context: TContext) => string;
responsiveVisible?: boolean;
}
export interface PropsWithColumns<TItem, TContext> {
columns: ColumnDefinition<TItem, TContext>[];
context: TContext;
}
export interface PropsWithItems<TItem> {
items: TItem[];
itemKey: keyof TItem;
}
export interface DataTablePropsBase<TItem, TContext> extends PropsWithColumns<TItem, TContext>, PropsWithItems<TItem> {
id?: string;
pagingFilter?: IPagingFilter;
onColumnSort?: (column: ColumnDefinition<TItem, TContext>) => any;
displayHeader?: boolean;
}