@draftbit/core 46.9.0 → 46.9.1-0cc3ba.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.
Files changed (70) hide show
  1. package/lib/commonjs/components/Container.js +15 -4
  2. package/lib/commonjs/components/Table/Table.js +108 -0
  3. package/lib/commonjs/components/Table/TableCell.js +49 -0
  4. package/lib/commonjs/components/Table/TableCommon.js +30 -0
  5. package/lib/commonjs/components/Table/TableRow.js +61 -0
  6. package/lib/commonjs/components/Table/index.js +27 -0
  7. package/lib/commonjs/hooks.js +1 -2
  8. package/lib/commonjs/index.js +19 -0
  9. package/lib/commonjs/mappings/ActionSheet.js +1 -1
  10. package/lib/commonjs/mappings/ActionSheetCancel.js +1 -1
  11. package/lib/commonjs/mappings/ActionSheetItem.js +1 -1
  12. package/lib/commonjs/mappings/MapCallout.js +1 -1
  13. package/lib/commonjs/mappings/MapMarker.js +1 -1
  14. package/lib/commonjs/mappings/Table.js +135 -0
  15. package/lib/module/components/Table/Table.js +100 -0
  16. package/lib/module/components/Table/TableCell.js +41 -0
  17. package/lib/module/components/Table/TableCommon.js +21 -0
  18. package/lib/module/components/Table/TableRow.js +53 -0
  19. package/lib/module/components/Table/index.js +3 -0
  20. package/lib/module/index.js +1 -0
  21. package/lib/module/mappings/ActionSheet.js +1 -1
  22. package/lib/module/mappings/ActionSheetCancel.js +1 -1
  23. package/lib/module/mappings/ActionSheetItem.js +1 -1
  24. package/lib/module/mappings/MapCallout.js +2 -2
  25. package/lib/module/mappings/MapMarker.js +2 -2
  26. package/lib/module/mappings/Table.js +128 -0
  27. package/lib/typescript/src/components/Table/Table.d.ts +19 -0
  28. package/lib/typescript/src/components/Table/Table.d.ts.map +1 -0
  29. package/lib/typescript/src/components/Table/TableCell.d.ts +9 -0
  30. package/lib/typescript/src/components/Table/TableCell.d.ts.map +1 -0
  31. package/lib/typescript/src/components/Table/TableCommon.d.ts +20 -0
  32. package/lib/typescript/src/components/Table/TableCommon.d.ts.map +1 -0
  33. package/lib/typescript/src/components/Table/TableRow.d.ts +14 -0
  34. package/lib/typescript/src/components/Table/TableRow.d.ts.map +1 -0
  35. package/lib/typescript/src/components/Table/index.d.ts +4 -0
  36. package/lib/typescript/src/components/Table/index.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +1 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/lib/typescript/src/mappings/ActionSheet.d.ts.map +1 -1
  40. package/lib/typescript/src/mappings/ActionSheetCancel.d.ts.map +1 -1
  41. package/lib/typescript/src/mappings/ActionSheetItem.d.ts.map +1 -1
  42. package/lib/typescript/src/mappings/MapCallout.d.ts.map +1 -1
  43. package/lib/typescript/src/mappings/MapMarker.d.ts.map +1 -1
  44. package/lib/typescript/src/mappings/Table.d.ts +327 -0
  45. package/lib/typescript/src/mappings/Table.d.ts.map +1 -0
  46. package/package.json +3 -3
  47. package/src/components/Table/Table.js +82 -0
  48. package/src/components/Table/Table.tsx +152 -0
  49. package/src/components/Table/TableCell.js +31 -0
  50. package/src/components/Table/TableCell.tsx +63 -0
  51. package/src/components/Table/TableCommon.js +12 -0
  52. package/src/components/Table/TableCommon.ts +40 -0
  53. package/src/components/Table/TableRow.js +37 -0
  54. package/src/components/Table/TableRow.tsx +77 -0
  55. package/src/components/Table/index.js +3 -0
  56. package/src/components/Table/index.tsx +3 -0
  57. package/src/index.js +1 -0
  58. package/src/index.tsx +2 -0
  59. package/src/mappings/ActionSheet.js +4 -1
  60. package/src/mappings/ActionSheet.ts +4 -1
  61. package/src/mappings/ActionSheetCancel.js +4 -1
  62. package/src/mappings/ActionSheetCancel.ts +4 -1
  63. package/src/mappings/ActionSheetItem.js +4 -1
  64. package/src/mappings/ActionSheetItem.ts +4 -1
  65. package/src/mappings/MapCallout.js +6 -2
  66. package/src/mappings/MapCallout.ts +6 -2
  67. package/src/mappings/MapMarker.js +6 -2
  68. package/src/mappings/MapMarker.ts +6 -2
  69. package/src/mappings/Table.js +145 -0
  70. package/src/mappings/Table.ts +164 -0
@@ -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.0",
3
+ "version": "46.9.1-0cc3ba.2+0cc3ba5",
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.0",
44
+ "@draftbit/types": "^46.9.1-0cc3ba.2+0cc3ba5",
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": "5e1d8597a03893593a88d41fb202bdb94bb28bc3"
99
+ "gitHead": "0cc3ba52d63daba146b52c76da42d5207d8906ac"
100
100
  }
@@ -0,0 +1,82 @@
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) => {
37
+ var _a, _b;
38
+ return !isTableHeader(item.props) &&
39
+ //Check first child props, Row can be inside React.Fragment when using renderItem
40
+ (!((_b = (_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.length) ||
41
+ !isTableHeader(item.props.children[0].props));
42
+ }), [validChildren, isTableHeader]);
43
+ const header = React.useMemo(() => {
44
+ const allHeaders = validChildren.filter((item) => {
45
+ var _a, _b;
46
+ return isTableHeader(item.props) ||
47
+ //Check first child props, Row can be inside React.Fragment when using renderItem
48
+ (((_b = (_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.length) &&
49
+ isTableHeader(item.props.children[0].props));
50
+ });
51
+ if (allHeaders.length) {
52
+ return allHeaders[0]; //Only 1 header taken
53
+ }
54
+ return null;
55
+ }, [validChildren, isTableHeader]);
56
+ const contextValue = {
57
+ borderColor,
58
+ borderStyle,
59
+ borderWidth,
60
+ cellHorizontalPadding,
61
+ cellVerticalPadding,
62
+ };
63
+ const borderViewStyle = generateBorderStyles({
64
+ borderColor,
65
+ borderWidth,
66
+ borderStyle,
67
+ drawTopBorder,
68
+ drawBottomBorder,
69
+ drawStartBorder,
70
+ drawEndBorder,
71
+ });
72
+ return (React.createElement(TableStyleContext.Provider, { value: contextValue },
73
+ React.createElement(View, { style: [styles.container, borderViewStyle, style] },
74
+ React.createElement(React.Fragment, null, header),
75
+ React.createElement(ScrollView, null, childrenWithoutHeader))));
76
+ };
77
+ const styles = StyleSheet.create({
78
+ container: {
79
+ flex: 1,
80
+ },
81
+ });
82
+ export default withTheme(Table);
@@ -0,0 +1,152 @@
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
+ () =>
94
+ validChildren.filter(
95
+ (item) =>
96
+ !isTableHeader(item.props) &&
97
+ //Check first child props, Row can be inside React.Fragment when using renderItem
98
+ (!item?.props?.children?.length ||
99
+ !isTableHeader(item.props.children[0].props))
100
+ ),
101
+ [validChildren, isTableHeader]
102
+ );
103
+
104
+ const header = React.useMemo(() => {
105
+ const allHeaders = validChildren.filter(
106
+ (item) =>
107
+ isTableHeader(item.props) ||
108
+ //Check first child props, Row can be inside React.Fragment when using renderItem
109
+ (item?.props?.children?.length &&
110
+ isTableHeader(item.props.children[0].props))
111
+ );
112
+ if (allHeaders.length) {
113
+ return allHeaders[0]; //Only 1 header taken
114
+ }
115
+ return null;
116
+ }, [validChildren, isTableHeader]);
117
+
118
+ const contextValue: TableStyleProps = {
119
+ borderColor,
120
+ borderStyle,
121
+ borderWidth,
122
+ cellHorizontalPadding,
123
+ cellVerticalPadding,
124
+ };
125
+
126
+ const borderViewStyle = generateBorderStyles({
127
+ borderColor,
128
+ borderWidth,
129
+ borderStyle,
130
+ drawTopBorder,
131
+ drawBottomBorder,
132
+ drawStartBorder,
133
+ drawEndBorder,
134
+ });
135
+
136
+ return (
137
+ <TableStyleContext.Provider value={contextValue}>
138
+ <View style={[styles.container, borderViewStyle, style]}>
139
+ <>{header}</>
140
+ <ScrollView>{childrenWithoutHeader}</ScrollView>
141
+ </View>
142
+ </TableStyleContext.Provider>
143
+ );
144
+ };
145
+
146
+ const styles = StyleSheet.create({
147
+ container: {
148
+ flex: 1,
149
+ },
150
+ });
151
+
152
+ 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
+ }