Skip to content

Commit 369db76

Browse files
committed
feat: update docs
1 parent 0bb0470 commit 369db76

File tree

1 file changed

+118
-11
lines changed

1 file changed

+118
-11
lines changed

src/components/Table/Table.types.ts

Lines changed: 118 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,160 @@ import type {
77
ViewStyle,
88
} from 'react-native';
99

10+
/**
11+
* Represents a column in a table.
12+
* @template T The type of data in the table.
13+
*/
1014
export type Column<T = any> = {
15+
/**
16+
* The title of the column.
17+
*/
1118
title: string;
19+
/**
20+
* The key of the column.
21+
*/
1222
key: string;
23+
/**
24+
* The style for the column.
25+
*/
1326
style?: StyleProp<ViewStyle> | undefined;
27+
/**
28+
* The style for the column title.
29+
*/
1430
titleStyle?: StyleProp<TextStyle> | undefined;
31+
/**
32+
* The style for the column header.
33+
*/
1534
headerStyle?: StyleProp<ViewStyle> | undefined;
35+
/**
36+
* The data index for the column.
37+
*/
1638
dataIndex?: keyof T;
39+
/**
40+
* A function that renders the content of the column for each row.
41+
* @param item The data item for the row.
42+
* @returns The rendered React node.
43+
*/
1744
render?: (item: T) => React.ReactNode;
45+
/**
46+
* A function that renders the title of the column.
47+
* @param title The title of the column.
48+
* @param style The style for the title.
49+
* @returns The rendered React node.
50+
*/
1851
renderTitle?: (title: string, style?: any) => React.ReactNode;
1952
};
2053

54+
/**
55+
* Props for the Table component.
56+
*
57+
* @template T - The type of data in the dataSource array.
58+
*/
2159
export type TableProps<T = any> = {
60+
/**
61+
* An array of data objects to be rendered in the table.
62+
*/
2263
dataSource: T[];
64+
/**
65+
* An array of column configurations for the table.
66+
*/
2367
columns: Column<T>[];
68+
/**
69+
* The key to group the data by.
70+
*/
2471
groupBy?: keyof T;
72+
/**
73+
* The layout direction of the table.
74+
*/
2575
layout?: 'vertical' | 'horizontal';
76+
/**
77+
* A function to render the table header.
78+
*
79+
* @param columns - The array of column configurations.
80+
* @returns The React element representing the table header.
81+
*/
2682
renderHeader?: (columns: Column<T>[]) => React.ReactElement;
27-
28-
headerStyle?: StyleProp<ViewStyle> | undefined;
29-
rowStyle?: StyleProp<ViewStyle> | undefined;
83+
/**
84+
* The style for the table header.
85+
*/
86+
headerStyle?: StyleProp<ViewStyle>;
87+
/**
88+
* The style for each table row.
89+
*/
90+
rowStyle?: StyleProp<ViewStyle>;
91+
/**
92+
* The key to use as the unique identifier for each row.
93+
* It can be a key of the data object or a function that returns a string.
94+
*/
3095
rowKey?: keyof T | ((item: T) => string);
96+
/**
97+
* A function to be called when a row is pressed.
98+
*
99+
* @param record - The data object of the pressed row.
100+
* @param index - The index of the pressed row.
101+
*/
31102
onRow?: (record: T, index: number) => void;
32-
style?: StyleProp<ViewStyle> | undefined;
103+
/**
104+
* The style for the table container.
105+
*/
106+
style?: StyleProp<ViewStyle>;
107+
/**
108+
* A function to render each table row.
109+
*
110+
* @param props - The props for rendering the row.
111+
* @returns The React element representing the table row.
112+
*/
33113
renderRow?: (props: RenderRowProps<T>) => ReactElement;
114+
/**
115+
* Determines whether the table can be scrolled.
116+
*/
34117
scrollEnabled?: boolean;
35-
118+
/**
119+
* Determines whether the table header should stick to the top of the table when scrolling.
120+
*/
36121
isStickyHeader?: boolean;
37-
122+
/**
123+
* A React element representing the refresh control for the table.
124+
*/
38125
refreshControl?: React.ReactElement<RefreshControlProps>;
39-
126+
/**
127+
* Determines whether the table is currently refreshing.
128+
*/
40129
isRefreshing?: boolean;
41-
130+
/**
131+
* A function to be called when the table is refreshed.
132+
*/
42133
onRefresh?: () => void;
43-
134+
/**
135+
* Determines whether there is no data to display in the table.
136+
*/
44137
isNoData?: boolean;
45-
138+
/**
139+
* The content to display when there is no data in the table.
140+
*/
46141
noDataContent?: React.ReactElement | string;
47-
48142
};
49143

144+
/**
145+
* Props for the TableFlatList component.
146+
* Extends TableProps and Omit<FlatListProps<T>, 'data' | 'renderItem'>.
147+
* @template T - The type of data items in the FlatList.
148+
*/
50149
export type TableFlatListProps<T = any> = TableProps<T> &
51150
Omit<FlatListProps<T>, 'data' | 'renderItem'>;
52151

152+
/**
153+
* Props for rendering a row in the table.
154+
*
155+
* @template T - The type of the record.
156+
*/
53157
export type RenderRowProps<T = any> = {
54158
record: T;
55159
index: number;
56160
children: ReactElement;
57161
};
58162

163+
/**
164+
* Represents a reference to a table.
165+
*/
59166
export type TableRef = {};

0 commit comments

Comments
 (0)