@draftbit/core 46.9.1-200936.2 → 46.9.1-258aa2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/CircleImage.js +1 -15
- package/lib/commonjs/components/Container.js +15 -4
- package/lib/commonjs/components/Table/Table.js +91 -0
- package/lib/commonjs/components/Table/TableCell.js +49 -0
- package/lib/commonjs/components/Table/TableCommon.js +30 -0
- package/lib/commonjs/components/Table/TableRow.js +61 -0
- package/lib/commonjs/components/Table/index.js +27 -0
- package/lib/commonjs/index.js +19 -7
- package/lib/commonjs/mappings/ActionSheet.js +1 -1
- package/lib/commonjs/mappings/ActionSheetCancel.js +1 -1
- package/lib/commonjs/mappings/ActionSheetItem.js +1 -1
- package/lib/commonjs/mappings/MapCallout.js +1 -1
- package/lib/commonjs/mappings/MapMarker.js +1 -1
- package/lib/commonjs/mappings/Table.js +135 -0
- package/lib/module/components/Table/Table.js +83 -0
- package/lib/module/components/Table/TableCell.js +41 -0
- package/lib/module/components/Table/TableCommon.js +21 -0
- package/lib/module/components/Table/TableRow.js +53 -0
- package/lib/module/components/Table/index.js +3 -0
- package/lib/module/constants.js +0 -1
- package/lib/module/index.js +4 -2
- package/lib/module/mappings/ActionSheet.js +1 -1
- package/lib/module/mappings/ActionSheetCancel.js +1 -1
- package/lib/module/mappings/ActionSheetItem.js +1 -1
- package/lib/module/mappings/MapCallout.js +2 -2
- package/lib/module/mappings/MapMarker.js +2 -2
- package/lib/module/mappings/Table.js +128 -0
- package/lib/typescript/src/components/Table/Table.d.ts +19 -0
- package/lib/typescript/src/components/Table/Table.d.ts.map +1 -0
- package/lib/typescript/src/components/Table/TableCell.d.ts +9 -0
- package/lib/typescript/src/components/Table/TableCell.d.ts.map +1 -0
- package/lib/typescript/src/components/Table/TableCommon.d.ts +20 -0
- package/lib/typescript/src/components/Table/TableCommon.d.ts.map +1 -0
- package/lib/typescript/src/components/Table/TableRow.d.ts +14 -0
- package/lib/typescript/src/components/Table/TableRow.d.ts.map +1 -0
- package/lib/typescript/src/components/Table/index.d.ts +4 -0
- package/lib/typescript/src/components/Table/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mappings/ActionSheet.d.ts.map +1 -1
- package/lib/typescript/src/mappings/ActionSheetCancel.d.ts.map +1 -1
- package/lib/typescript/src/mappings/ActionSheetItem.d.ts.map +1 -1
- package/lib/typescript/src/mappings/MapCallout.d.ts.map +1 -1
- package/lib/typescript/src/mappings/MapMarker.d.ts.map +1 -1
- package/lib/typescript/src/mappings/Table.d.ts +327 -0
- package/lib/typescript/src/mappings/Table.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/components/Table/Table.js +64 -0
- package/src/components/Table/Table.tsx +136 -0
- package/src/components/Table/TableCell.js +31 -0
- package/src/components/Table/TableCell.tsx +63 -0
- package/src/components/Table/TableCommon.js +12 -0
- package/src/components/Table/TableCommon.ts +40 -0
- package/src/components/Table/TableRow.js +37 -0
- package/src/components/Table/TableRow.tsx +77 -0
- package/src/components/Table/index.js +3 -0
- package/src/components/Table/index.tsx +3 -0
- package/src/index.js +1 -1
- package/src/index.tsx +1 -1
- package/src/mappings/ActionSheet.js +4 -1
- package/src/mappings/ActionSheet.ts +4 -1
- package/src/mappings/ActionSheetCancel.js +4 -1
- package/src/mappings/ActionSheetCancel.ts +4 -1
- package/src/mappings/ActionSheetItem.js +4 -1
- package/src/mappings/ActionSheetItem.ts +4 -1
- package/src/mappings/MapCallout.js +6 -2
- package/src/mappings/MapCallout.ts +6 -2
- package/src/mappings/MapMarker.js +6 -2
- package/src/mappings/MapMarker.ts +6 -2
- package/src/mappings/Table.js +145 -0
- package/src/mappings/Table.ts +164 -0
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +0 -89
- package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +0 -464
- package/lib/commonjs/components/BottomSheet/index.js +0 -13
- package/lib/commonjs/mappings/BottomSheet.js +0 -75
- package/lib/module/components/BottomSheet/BottomSheet.js +0 -81
- package/lib/module/components/BottomSheet/BottomSheetComponent.js +0 -470
- package/lib/module/components/BottomSheet/index.js +0 -1
- package/lib/module/mappings/BottomSheet.js +0 -68
- package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +0 -20
- package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts.map +0 -1
- package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts +0 -170
- package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts.map +0 -1
- package/lib/typescript/src/components/BottomSheet/index.d.ts +0 -2
- package/lib/typescript/src/components/BottomSheet/index.d.ts.map +0 -1
- package/lib/typescript/src/mappings/BottomSheet.d.ts +0 -120
- package/lib/typescript/src/mappings/BottomSheet.d.ts.map +0 -1
- package/src/components/BottomSheet/BottomSheet.js +0 -57
- package/src/components/BottomSheet/BottomSheet.tsx +0 -121
- package/src/components/BottomSheet/BottomSheetComponent.js +0 -437
- package/src/components/BottomSheet/BottomSheetComponent.tsx +0 -895
- package/src/components/BottomSheet/index.js +0 -1
- package/src/components/BottomSheet/index.ts +0 -1
- package/src/mappings/BottomSheet.js +0 -64
- package/src/mappings/BottomSheet.ts +0 -78
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
export declare const SEED_DATA: ({
|
|
2
|
+
name: string;
|
|
3
|
+
tag: string;
|
|
4
|
+
description: string;
|
|
5
|
+
category: string;
|
|
6
|
+
stylesPanelSections: string[];
|
|
7
|
+
layout: {
|
|
8
|
+
flex: number;
|
|
9
|
+
flexDirection?: undefined;
|
|
10
|
+
};
|
|
11
|
+
props: {
|
|
12
|
+
borderWidth: {
|
|
13
|
+
defaultValue: number;
|
|
14
|
+
label: string;
|
|
15
|
+
description: string;
|
|
16
|
+
formType: string;
|
|
17
|
+
propType: string;
|
|
18
|
+
group: string;
|
|
19
|
+
editable: boolean;
|
|
20
|
+
required: boolean;
|
|
21
|
+
step: number;
|
|
22
|
+
};
|
|
23
|
+
borderColor: {
|
|
24
|
+
defaultValue: string;
|
|
25
|
+
group: string;
|
|
26
|
+
label: string;
|
|
27
|
+
description: string;
|
|
28
|
+
editable: boolean;
|
|
29
|
+
required: boolean;
|
|
30
|
+
formType: string;
|
|
31
|
+
propType: string;
|
|
32
|
+
};
|
|
33
|
+
borderStyle: {
|
|
34
|
+
defaultValue: string;
|
|
35
|
+
group: string;
|
|
36
|
+
label: string;
|
|
37
|
+
description: string;
|
|
38
|
+
editable: boolean;
|
|
39
|
+
required: boolean;
|
|
40
|
+
formType: string;
|
|
41
|
+
propType: string;
|
|
42
|
+
options: never[];
|
|
43
|
+
};
|
|
44
|
+
drawTopBorder: {
|
|
45
|
+
defaultValue: boolean;
|
|
46
|
+
label: string;
|
|
47
|
+
description: string;
|
|
48
|
+
formType: string;
|
|
49
|
+
propType: string;
|
|
50
|
+
editable: boolean;
|
|
51
|
+
required: boolean;
|
|
52
|
+
group: string;
|
|
53
|
+
};
|
|
54
|
+
cellVerticalPadding: {
|
|
55
|
+
defaultValue: number;
|
|
56
|
+
label: string;
|
|
57
|
+
description: string;
|
|
58
|
+
formType: string;
|
|
59
|
+
propType: string;
|
|
60
|
+
group: string;
|
|
61
|
+
editable: boolean;
|
|
62
|
+
required: boolean;
|
|
63
|
+
step: number;
|
|
64
|
+
};
|
|
65
|
+
cellHorizontalPadding: {
|
|
66
|
+
defaultValue: number;
|
|
67
|
+
label: string;
|
|
68
|
+
description: string;
|
|
69
|
+
formType: string;
|
|
70
|
+
propType: string;
|
|
71
|
+
group: string;
|
|
72
|
+
editable: boolean;
|
|
73
|
+
required: boolean;
|
|
74
|
+
step: number;
|
|
75
|
+
};
|
|
76
|
+
drawBottomBorder: {
|
|
77
|
+
label: string;
|
|
78
|
+
description: string;
|
|
79
|
+
formType: string;
|
|
80
|
+
propType: string;
|
|
81
|
+
defaultValue: boolean;
|
|
82
|
+
editable: boolean;
|
|
83
|
+
required: boolean;
|
|
84
|
+
group: string;
|
|
85
|
+
};
|
|
86
|
+
drawStartBorder: {
|
|
87
|
+
label: string;
|
|
88
|
+
description: string;
|
|
89
|
+
formType: string;
|
|
90
|
+
propType: string;
|
|
91
|
+
defaultValue: boolean;
|
|
92
|
+
editable: boolean;
|
|
93
|
+
required: boolean;
|
|
94
|
+
group: string;
|
|
95
|
+
};
|
|
96
|
+
drawEndBorder: {
|
|
97
|
+
label: string;
|
|
98
|
+
description: string;
|
|
99
|
+
formType: string;
|
|
100
|
+
propType: string;
|
|
101
|
+
defaultValue: boolean;
|
|
102
|
+
editable: boolean;
|
|
103
|
+
required: boolean;
|
|
104
|
+
group: string;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
} | {
|
|
108
|
+
name: string;
|
|
109
|
+
tag: string;
|
|
110
|
+
description: string;
|
|
111
|
+
category: string;
|
|
112
|
+
stylesPanelSections: string[];
|
|
113
|
+
props: {
|
|
114
|
+
drawStartBorder: {
|
|
115
|
+
defaultValue: boolean;
|
|
116
|
+
label: string;
|
|
117
|
+
description: string;
|
|
118
|
+
formType: string;
|
|
119
|
+
propType: string;
|
|
120
|
+
editable: boolean;
|
|
121
|
+
required: boolean;
|
|
122
|
+
group: string;
|
|
123
|
+
};
|
|
124
|
+
drawBottomBorder: {
|
|
125
|
+
defaultValue: boolean;
|
|
126
|
+
label: string;
|
|
127
|
+
description: string;
|
|
128
|
+
formType: string;
|
|
129
|
+
propType: string;
|
|
130
|
+
editable: boolean;
|
|
131
|
+
required: boolean;
|
|
132
|
+
group: string;
|
|
133
|
+
};
|
|
134
|
+
isTableHeader: {
|
|
135
|
+
label: string;
|
|
136
|
+
description: string;
|
|
137
|
+
formType: string;
|
|
138
|
+
propType: string;
|
|
139
|
+
defaultValue: boolean;
|
|
140
|
+
editable: boolean;
|
|
141
|
+
required: boolean;
|
|
142
|
+
group: string;
|
|
143
|
+
};
|
|
144
|
+
borderWidth: {
|
|
145
|
+
label: string;
|
|
146
|
+
description: string;
|
|
147
|
+
formType: string;
|
|
148
|
+
propType: string;
|
|
149
|
+
group: string;
|
|
150
|
+
defaultValue: null;
|
|
151
|
+
editable: boolean;
|
|
152
|
+
required: boolean;
|
|
153
|
+
step: number;
|
|
154
|
+
};
|
|
155
|
+
borderColor: {
|
|
156
|
+
group: string;
|
|
157
|
+
label: string;
|
|
158
|
+
description: string;
|
|
159
|
+
editable: boolean;
|
|
160
|
+
required: boolean;
|
|
161
|
+
defaultValue: null;
|
|
162
|
+
formType: string;
|
|
163
|
+
propType: string;
|
|
164
|
+
};
|
|
165
|
+
borderStyle: {
|
|
166
|
+
group: string;
|
|
167
|
+
label: string;
|
|
168
|
+
description: string;
|
|
169
|
+
editable: boolean;
|
|
170
|
+
required: boolean;
|
|
171
|
+
formType: string;
|
|
172
|
+
propType: string;
|
|
173
|
+
defaultValue: null;
|
|
174
|
+
options: never[];
|
|
175
|
+
};
|
|
176
|
+
drawTopBorder: {
|
|
177
|
+
label: string;
|
|
178
|
+
description: string;
|
|
179
|
+
formType: string;
|
|
180
|
+
propType: string;
|
|
181
|
+
defaultValue: boolean;
|
|
182
|
+
editable: boolean;
|
|
183
|
+
required: boolean;
|
|
184
|
+
group: string;
|
|
185
|
+
};
|
|
186
|
+
drawEndBorder: {
|
|
187
|
+
label: string;
|
|
188
|
+
description: string;
|
|
189
|
+
formType: string;
|
|
190
|
+
propType: string;
|
|
191
|
+
defaultValue: boolean;
|
|
192
|
+
editable: boolean;
|
|
193
|
+
required: boolean;
|
|
194
|
+
group: string;
|
|
195
|
+
};
|
|
196
|
+
cellVerticalPadding: {
|
|
197
|
+
label: string;
|
|
198
|
+
description: string;
|
|
199
|
+
formType: string;
|
|
200
|
+
propType: string;
|
|
201
|
+
group: string;
|
|
202
|
+
defaultValue: null;
|
|
203
|
+
editable: boolean;
|
|
204
|
+
required: boolean;
|
|
205
|
+
step: number;
|
|
206
|
+
};
|
|
207
|
+
cellHorizontalPadding: {
|
|
208
|
+
label: string;
|
|
209
|
+
description: string;
|
|
210
|
+
formType: string;
|
|
211
|
+
propType: string;
|
|
212
|
+
group: string;
|
|
213
|
+
defaultValue: null;
|
|
214
|
+
editable: boolean;
|
|
215
|
+
required: boolean;
|
|
216
|
+
step: number;
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
layout?: undefined;
|
|
220
|
+
} | {
|
|
221
|
+
name: string;
|
|
222
|
+
tag: string;
|
|
223
|
+
description: string;
|
|
224
|
+
category: string;
|
|
225
|
+
stylesPanelSections: string[];
|
|
226
|
+
layout: {
|
|
227
|
+
flex: number;
|
|
228
|
+
flexDirection: string;
|
|
229
|
+
};
|
|
230
|
+
props: {
|
|
231
|
+
drawEndBorder: {
|
|
232
|
+
defaultValue: boolean;
|
|
233
|
+
label: string;
|
|
234
|
+
description: string;
|
|
235
|
+
formType: string;
|
|
236
|
+
propType: string;
|
|
237
|
+
editable: boolean;
|
|
238
|
+
required: boolean;
|
|
239
|
+
group: string;
|
|
240
|
+
};
|
|
241
|
+
borderWidth: {
|
|
242
|
+
label: string;
|
|
243
|
+
description: string;
|
|
244
|
+
formType: string;
|
|
245
|
+
propType: string;
|
|
246
|
+
group: string;
|
|
247
|
+
defaultValue: null;
|
|
248
|
+
editable: boolean;
|
|
249
|
+
required: boolean;
|
|
250
|
+
step: number;
|
|
251
|
+
};
|
|
252
|
+
borderColor: {
|
|
253
|
+
group: string;
|
|
254
|
+
label: string;
|
|
255
|
+
description: string;
|
|
256
|
+
editable: boolean;
|
|
257
|
+
required: boolean;
|
|
258
|
+
defaultValue: null;
|
|
259
|
+
formType: string;
|
|
260
|
+
propType: string;
|
|
261
|
+
};
|
|
262
|
+
borderStyle: {
|
|
263
|
+
group: string;
|
|
264
|
+
label: string;
|
|
265
|
+
description: string;
|
|
266
|
+
editable: boolean;
|
|
267
|
+
required: boolean;
|
|
268
|
+
formType: string;
|
|
269
|
+
propType: string;
|
|
270
|
+
defaultValue: null;
|
|
271
|
+
options: never[];
|
|
272
|
+
};
|
|
273
|
+
drawTopBorder: {
|
|
274
|
+
label: string;
|
|
275
|
+
description: string;
|
|
276
|
+
formType: string;
|
|
277
|
+
propType: string;
|
|
278
|
+
defaultValue: boolean;
|
|
279
|
+
editable: boolean;
|
|
280
|
+
required: boolean;
|
|
281
|
+
group: string;
|
|
282
|
+
};
|
|
283
|
+
drawBottomBorder: {
|
|
284
|
+
label: string;
|
|
285
|
+
description: string;
|
|
286
|
+
formType: string;
|
|
287
|
+
propType: string;
|
|
288
|
+
defaultValue: boolean;
|
|
289
|
+
editable: boolean;
|
|
290
|
+
required: boolean;
|
|
291
|
+
group: string;
|
|
292
|
+
};
|
|
293
|
+
drawStartBorder: {
|
|
294
|
+
label: string;
|
|
295
|
+
description: string;
|
|
296
|
+
formType: string;
|
|
297
|
+
propType: string;
|
|
298
|
+
defaultValue: boolean;
|
|
299
|
+
editable: boolean;
|
|
300
|
+
required: boolean;
|
|
301
|
+
group: string;
|
|
302
|
+
};
|
|
303
|
+
cellVerticalPadding: {
|
|
304
|
+
label: string;
|
|
305
|
+
description: string;
|
|
306
|
+
formType: string;
|
|
307
|
+
propType: string;
|
|
308
|
+
group: string;
|
|
309
|
+
defaultValue: null;
|
|
310
|
+
editable: boolean;
|
|
311
|
+
required: boolean;
|
|
312
|
+
step: number;
|
|
313
|
+
};
|
|
314
|
+
cellHorizontalPadding: {
|
|
315
|
+
label: string;
|
|
316
|
+
description: string;
|
|
317
|
+
formType: string;
|
|
318
|
+
propType: string;
|
|
319
|
+
group: string;
|
|
320
|
+
defaultValue: null;
|
|
321
|
+
editable: boolean;
|
|
322
|
+
required: boolean;
|
|
323
|
+
step: number;
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
})[];
|
|
327
|
+
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/mappings/Table.ts"],"names":[],"mappings":"AAsEA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6FrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "46.9.1-
|
|
3
|
+
"version": "46.9.1-258aa2.2+258aa22",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@date-io/date-fns": "^1.3.13",
|
|
43
43
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
44
|
-
"@draftbit/types": "^46.9.1-
|
|
44
|
+
"@draftbit/types": "^46.9.1-258aa2.2+258aa22",
|
|
45
45
|
"@material-ui/core": "^4.11.0",
|
|
46
46
|
"@material-ui/pickers": "^3.2.10",
|
|
47
47
|
"@react-native-community/slider": "4.2.3",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
]
|
|
97
97
|
]
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "258aa2278e6c2b74dba1cd565f04cd5b024aa2ca"
|
|
100
100
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ScrollView, View, StyleSheet, } from "react-native";
|
|
3
|
+
import { withTheme } from "../../theming";
|
|
4
|
+
import { generateBorderStyles, TableStyleContext, } from "./TableCommon";
|
|
5
|
+
const Table = ({ theme, borderWidth = 1, borderColor = theme.colors.divider, borderStyle = "solid", drawTopBorder = true, drawBottomBorder = false, drawStartBorder = false, drawEndBorder = false, cellVerticalPadding = 10, cellHorizontalPadding = 10, data, keyExtractor, renderItem, children: childrenProp, style, }) => {
|
|
6
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
7
|
+
if ((data && !renderItem) || (renderItem && !data)) {
|
|
8
|
+
throw new Error("'renderItem' and 'data' need to both be provided to render from 'data'. Either remove them entirley or include both");
|
|
9
|
+
}
|
|
10
|
+
if (data && renderItem && childrenProp) {
|
|
11
|
+
console.warn("'children' of Table ignored due to usage of 'data' and 'renderItem'");
|
|
12
|
+
}
|
|
13
|
+
const isTableHeader = React.useCallback((object) => {
|
|
14
|
+
return object.isTableHeader;
|
|
15
|
+
}, []);
|
|
16
|
+
const isRenderItem = data && renderItem;
|
|
17
|
+
//Uses 'renderItem' and 'data' to create an array of children
|
|
18
|
+
const dataAsChildren = React.useMemo(() => {
|
|
19
|
+
if (!isRenderItem)
|
|
20
|
+
return [];
|
|
21
|
+
return data.map((item, index) => {
|
|
22
|
+
const component = renderItem({ item, index });
|
|
23
|
+
if (!component) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const key = keyExtractor ? keyExtractor(item, index) : index.toString();
|
|
27
|
+
return React.cloneElement(component, {
|
|
28
|
+
key,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}, [data, renderItem, keyExtractor, isRenderItem]);
|
|
32
|
+
const children = isRenderItem
|
|
33
|
+
? dataAsChildren
|
|
34
|
+
: React.Children.toArray(childrenProp);
|
|
35
|
+
const validChildren = React.useMemo(() => children.filter((item) => React.isValidElement(item)), [children]);
|
|
36
|
+
const childrenWithoutHeader = React.useMemo(() => validChildren.filter((item) => !isTableHeader(item.props)), [validChildren, isTableHeader]);
|
|
37
|
+
const headers = React.useMemo(() => validChildren.filter((item) => isTableHeader(item.props)), [validChildren, isTableHeader]);
|
|
38
|
+
const contextValue = {
|
|
39
|
+
borderColor,
|
|
40
|
+
borderStyle,
|
|
41
|
+
borderWidth,
|
|
42
|
+
cellHorizontalPadding,
|
|
43
|
+
cellVerticalPadding,
|
|
44
|
+
};
|
|
45
|
+
const borderViewStyle = generateBorderStyles({
|
|
46
|
+
borderColor,
|
|
47
|
+
borderWidth,
|
|
48
|
+
borderStyle,
|
|
49
|
+
drawTopBorder,
|
|
50
|
+
drawBottomBorder,
|
|
51
|
+
drawStartBorder,
|
|
52
|
+
drawEndBorder,
|
|
53
|
+
});
|
|
54
|
+
return (React.createElement(TableStyleContext.Provider, { value: contextValue },
|
|
55
|
+
React.createElement(View, { style: [styles.container, borderViewStyle, style] },
|
|
56
|
+
React.createElement(React.Fragment, null, headers),
|
|
57
|
+
React.createElement(ScrollView, null, childrenWithoutHeader))));
|
|
58
|
+
};
|
|
59
|
+
const styles = StyleSheet.create({
|
|
60
|
+
container: {
|
|
61
|
+
flex: 1,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
export default withTheme(Table);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
ScrollView,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import { Theme } from "../../styles/DefaultTheme";
|
|
10
|
+
import { withTheme } from "../../theming";
|
|
11
|
+
import {
|
|
12
|
+
generateBorderStyles,
|
|
13
|
+
TableProps,
|
|
14
|
+
TableStyleContext,
|
|
15
|
+
TableStyleProps,
|
|
16
|
+
} from "./TableCommon";
|
|
17
|
+
|
|
18
|
+
export interface Props<T> extends TableProps {
|
|
19
|
+
data?: Array<T>;
|
|
20
|
+
keyExtractor?: (item: T, index: number) => string;
|
|
21
|
+
renderItem?: ({ item, index }: { item: T; index: number }) => JSX.Element;
|
|
22
|
+
style?: StyleProp<ViewStyle>;
|
|
23
|
+
theme: Theme;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const Table = <T extends object>({
|
|
27
|
+
theme,
|
|
28
|
+
borderWidth = 1,
|
|
29
|
+
borderColor = theme.colors.divider,
|
|
30
|
+
borderStyle = "solid",
|
|
31
|
+
drawTopBorder = true,
|
|
32
|
+
drawBottomBorder = false,
|
|
33
|
+
drawStartBorder = false,
|
|
34
|
+
drawEndBorder = false,
|
|
35
|
+
cellVerticalPadding = 10,
|
|
36
|
+
cellHorizontalPadding = 10,
|
|
37
|
+
data,
|
|
38
|
+
keyExtractor,
|
|
39
|
+
renderItem,
|
|
40
|
+
children: childrenProp,
|
|
41
|
+
style,
|
|
42
|
+
}: React.PropsWithChildren<Props<T>>) => {
|
|
43
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
44
|
+
if ((data && !renderItem) || (renderItem && !data)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"'renderItem' and 'data' need to both be provided to render from 'data'. Either remove them entirley or include both"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (data && renderItem && childrenProp) {
|
|
51
|
+
console.warn(
|
|
52
|
+
"'children' of Table ignored due to usage of 'data' and 'renderItem'"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isTableHeader = React.useCallback((object: any): boolean => {
|
|
57
|
+
return object.isTableHeader;
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
const isRenderItem = data && renderItem;
|
|
61
|
+
|
|
62
|
+
//Uses 'renderItem' and 'data' to create an array of children
|
|
63
|
+
const dataAsChildren = React.useMemo(() => {
|
|
64
|
+
if (!isRenderItem) return [];
|
|
65
|
+
|
|
66
|
+
return data.map((item, index) => {
|
|
67
|
+
const component = renderItem({ item, index });
|
|
68
|
+
|
|
69
|
+
if (!component) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const key = keyExtractor ? keyExtractor(item, index) : index.toString();
|
|
74
|
+
return React.cloneElement(component, {
|
|
75
|
+
key,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}, [data, renderItem, keyExtractor, isRenderItem]);
|
|
79
|
+
|
|
80
|
+
const children = isRenderItem
|
|
81
|
+
? dataAsChildren
|
|
82
|
+
: React.Children.toArray(childrenProp);
|
|
83
|
+
|
|
84
|
+
const validChildren = React.useMemo(
|
|
85
|
+
() =>
|
|
86
|
+
(children as any[]).filter((item) =>
|
|
87
|
+
React.isValidElement(item)
|
|
88
|
+
) as React.ReactElement[],
|
|
89
|
+
[children]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const childrenWithoutHeader = React.useMemo(
|
|
93
|
+
() => validChildren.filter((item) => !isTableHeader(item.props)),
|
|
94
|
+
[validChildren, isTableHeader]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const headers = React.useMemo(
|
|
98
|
+
() => validChildren.filter((item) => isTableHeader(item.props)),
|
|
99
|
+
[validChildren, isTableHeader]
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const contextValue: TableStyleProps = {
|
|
103
|
+
borderColor,
|
|
104
|
+
borderStyle,
|
|
105
|
+
borderWidth,
|
|
106
|
+
cellHorizontalPadding,
|
|
107
|
+
cellVerticalPadding,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const borderViewStyle = generateBorderStyles({
|
|
111
|
+
borderColor,
|
|
112
|
+
borderWidth,
|
|
113
|
+
borderStyle,
|
|
114
|
+
drawTopBorder,
|
|
115
|
+
drawBottomBorder,
|
|
116
|
+
drawStartBorder,
|
|
117
|
+
drawEndBorder,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<TableStyleContext.Provider value={contextValue}>
|
|
122
|
+
<View style={[styles.container, borderViewStyle, style]}>
|
|
123
|
+
<>{headers}</>
|
|
124
|
+
<ScrollView>{childrenWithoutHeader}</ScrollView>
|
|
125
|
+
</View>
|
|
126
|
+
</TableStyleContext.Provider>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const styles = StyleSheet.create({
|
|
131
|
+
container: {
|
|
132
|
+
flex: 1,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export default withTheme(Table);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import { generateBorderStyles, TableStyleContext, } from "./TableCommon";
|
|
4
|
+
const TableCell = ({ borderWidth, borderColor, borderStyle, drawTopBorder = false, drawBottomBorder = false, drawStartBorder = false, drawEndBorder = true, cellVerticalPadding, cellHorizontalPadding, children, style, }) => {
|
|
5
|
+
const parentContextValue = React.useContext(TableStyleContext);
|
|
6
|
+
const borderViewStyle = generateBorderStyles({
|
|
7
|
+
borderColor: borderColor || parentContextValue.borderColor,
|
|
8
|
+
borderWidth: borderWidth || parentContextValue.borderWidth,
|
|
9
|
+
borderStyle: borderStyle || parentContextValue.borderStyle,
|
|
10
|
+
drawTopBorder,
|
|
11
|
+
drawBottomBorder,
|
|
12
|
+
drawStartBorder,
|
|
13
|
+
drawEndBorder,
|
|
14
|
+
});
|
|
15
|
+
return (React.createElement(View, { style: [
|
|
16
|
+
styles.cellContainer,
|
|
17
|
+
borderViewStyle,
|
|
18
|
+
{
|
|
19
|
+
paddingVertical: cellVerticalPadding || parentContextValue.cellVerticalPadding,
|
|
20
|
+
paddingHorizontal: cellHorizontalPadding || parentContextValue.cellHorizontalPadding,
|
|
21
|
+
},
|
|
22
|
+
style,
|
|
23
|
+
] }, children));
|
|
24
|
+
};
|
|
25
|
+
const styles = StyleSheet.create({
|
|
26
|
+
cellContainer: {
|
|
27
|
+
flex: 1,
|
|
28
|
+
flexDirection: "row",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
export default TableCell;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleProp, ViewStyle, StyleSheet } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
generateBorderStyles,
|
|
5
|
+
TableProps,
|
|
6
|
+
TableStyleContext,
|
|
7
|
+
} from "./TableCommon";
|
|
8
|
+
|
|
9
|
+
export interface Props extends TableProps {
|
|
10
|
+
style?: StyleProp<ViewStyle>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
|
|
14
|
+
borderWidth,
|
|
15
|
+
borderColor,
|
|
16
|
+
borderStyle,
|
|
17
|
+
drawTopBorder = false,
|
|
18
|
+
drawBottomBorder = false,
|
|
19
|
+
drawStartBorder = false,
|
|
20
|
+
drawEndBorder = true,
|
|
21
|
+
cellVerticalPadding,
|
|
22
|
+
cellHorizontalPadding,
|
|
23
|
+
children,
|
|
24
|
+
style,
|
|
25
|
+
}) => {
|
|
26
|
+
const parentContextValue = React.useContext(TableStyleContext);
|
|
27
|
+
|
|
28
|
+
const borderViewStyle = generateBorderStyles({
|
|
29
|
+
borderColor: borderColor || parentContextValue.borderColor,
|
|
30
|
+
borderWidth: borderWidth || parentContextValue.borderWidth,
|
|
31
|
+
borderStyle: borderStyle || parentContextValue.borderStyle,
|
|
32
|
+
drawTopBorder,
|
|
33
|
+
drawBottomBorder,
|
|
34
|
+
drawStartBorder,
|
|
35
|
+
drawEndBorder,
|
|
36
|
+
});
|
|
37
|
+
return (
|
|
38
|
+
<View
|
|
39
|
+
style={[
|
|
40
|
+
styles.cellContainer,
|
|
41
|
+
borderViewStyle,
|
|
42
|
+
{
|
|
43
|
+
paddingVertical:
|
|
44
|
+
cellVerticalPadding || parentContextValue.cellVerticalPadding,
|
|
45
|
+
paddingHorizontal:
|
|
46
|
+
cellHorizontalPadding || parentContextValue.cellHorizontalPadding,
|
|
47
|
+
},
|
|
48
|
+
style,
|
|
49
|
+
]}
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const styles = StyleSheet.create({
|
|
57
|
+
cellContainer: {
|
|
58
|
+
flex: 1,
|
|
59
|
+
flexDirection: "row",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default TableCell;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export const TableStyleContext = React.createContext({});
|
|
3
|
+
export function generateBorderStyles({ borderColor, borderWidth, borderStyle, drawTopBorder, drawBottomBorder, drawStartBorder, drawEndBorder, }) {
|
|
4
|
+
return {
|
|
5
|
+
borderColor,
|
|
6
|
+
borderStyle,
|
|
7
|
+
borderTopWidth: drawTopBorder ? borderWidth : 0,
|
|
8
|
+
borderBottomWidth: drawBottomBorder ? borderWidth : 0,
|
|
9
|
+
borderStartWidth: drawStartBorder ? borderWidth : 0,
|
|
10
|
+
borderEndWidth: drawEndBorder ? borderWidth : 0,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ViewStyle } from "react-native";
|
|
3
|
+
|
|
4
|
+
type BorderStyle = "solid" | "dotted" | "dashed";
|
|
5
|
+
|
|
6
|
+
export const TableStyleContext = React.createContext<TableStyleProps>({});
|
|
7
|
+
|
|
8
|
+
export interface TableStyleProps {
|
|
9
|
+
borderWidth?: number;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
borderStyle?: BorderStyle;
|
|
12
|
+
cellVerticalPadding?: number;
|
|
13
|
+
cellHorizontalPadding?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TableProps extends TableStyleProps {
|
|
17
|
+
drawTopBorder?: boolean;
|
|
18
|
+
drawBottomBorder?: boolean;
|
|
19
|
+
drawStartBorder?: boolean;
|
|
20
|
+
drawEndBorder?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function generateBorderStyles({
|
|
24
|
+
borderColor,
|
|
25
|
+
borderWidth,
|
|
26
|
+
borderStyle,
|
|
27
|
+
drawTopBorder,
|
|
28
|
+
drawBottomBorder,
|
|
29
|
+
drawStartBorder,
|
|
30
|
+
drawEndBorder,
|
|
31
|
+
}: TableProps): ViewStyle {
|
|
32
|
+
return {
|
|
33
|
+
borderColor,
|
|
34
|
+
borderStyle,
|
|
35
|
+
borderTopWidth: drawTopBorder ? borderWidth : 0,
|
|
36
|
+
borderBottomWidth: drawBottomBorder ? borderWidth : 0,
|
|
37
|
+
borderStartWidth: drawStartBorder ? borderWidth : 0,
|
|
38
|
+
borderEndWidth: drawEndBorder ? borderWidth : 0,
|
|
39
|
+
};
|
|
40
|
+
}
|