@draftbit/core 46.10.3-7db6c9.2 → 46.10.3-84bbff.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/AnimatedCircularProgress.js +12 -1
- package/lib/commonjs/components/Banner.js +23 -4
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +22 -4
- package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +127 -111
- package/lib/commonjs/components/Button.js +33 -10
- package/lib/commonjs/components/Checkbox/Checkbox.js +3 -4
- package/lib/commonjs/components/Checkbox/context.js +1 -1
- package/lib/commonjs/components/DeckSwiper/DeckSwiper.js +1 -4
- package/lib/commonjs/components/DeprecatedCardWrapper.js +15 -1
- package/lib/commonjs/components/Divider.js +14 -1
- package/lib/commonjs/components/FAB.js +18 -4
- package/lib/commonjs/components/Layout.js +40 -19
- package/lib/commonjs/components/Picker/PickerComponent.ios.js +36 -11
- package/lib/commonjs/components/Portal/Portal.js +27 -3
- package/lib/commonjs/components/Portal/PortalConsumer.js +22 -7
- package/lib/commonjs/components/Pressable.js +15 -2
- package/lib/commonjs/components/ScreenContainer.js +24 -6
- package/lib/commonjs/components/Shadow.js +15 -2
- package/lib/commonjs/components/Slider.js +21 -4
- package/lib/commonjs/components/Switch.js +19 -10
- package/lib/commonjs/components/TabView/TabView.js +13 -7
- package/lib/commonjs/components/Table/Table.js +123 -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 +60 -0
- package/lib/commonjs/components/Table/index.js +27 -0
- package/lib/commonjs/components/Text.js +50 -4
- package/lib/commonjs/components/TextField.js +76 -28
- package/lib/commonjs/components/ToggleButton.js +15 -2
- package/lib/commonjs/components/Touchable.js +15 -2
- package/lib/commonjs/constants.js +1 -1
- package/lib/commonjs/index.js +19 -7
- package/lib/commonjs/mappings/FieldSearchBarFull.js +3 -1
- package/lib/commonjs/mappings/NativeBase/Layout.js +2 -11
- package/lib/commonjs/mappings/StarRating.js +6 -2
- package/lib/commonjs/mappings/Table.js +140 -0
- package/lib/commonjs/styles/overlay.js +1 -3
- package/lib/module/components/Accordion/AccordionItem.js +25 -4
- package/lib/module/components/AnimatedCircularProgress.js +13 -1
- package/lib/module/components/AspectRatio.js +18 -1
- package/lib/module/components/AvatarEdit.js +15 -4
- package/lib/module/components/BottomSheet/BottomSheetComponent.js +124 -111
- package/lib/module/components/Checkbox/CheckboxGroup.js +16 -2
- package/lib/module/components/DeprecatedButton.js +21 -3
- package/lib/module/components/DeprecatedCardWrapper.js +18 -1
- package/lib/module/components/Picker/PickerComponent.android.js +21 -3
- package/lib/module/components/Picker/PickerComponent.ios.js +36 -11
- package/lib/module/components/Portal/PortalHost.js +45 -15
- package/lib/module/components/RadioButton/RadioButton.js +13 -1
- package/lib/module/components/RadioButton/RadioButtonGroup.js +16 -2
- package/lib/module/components/RadioButton/RadioButtonRow.js +24 -5
- package/lib/module/components/Surface.js +15 -1
- package/lib/module/components/TabView/TabView.js +17 -7
- package/lib/module/components/Table/Table.js +114 -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/components/Touchable.js +15 -2
- package/lib/module/constants.js +1 -0
- package/lib/module/hooks.js +1 -2
- package/lib/module/index.js +1 -1
- package/lib/module/mappings/NativeBase/Layout.js +3 -12
- package/lib/module/mappings/Table.js +133 -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/NativeBase/Layout.d.ts +4 -27
- package/lib/typescript/src/mappings/NativeBase/Layout.d.ts.map +1 -1
- package/lib/typescript/src/mappings/Table.d.ts +337 -0
- package/lib/typescript/src/mappings/Table.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/components/Table/Table.js +93 -0
- package/src/components/Table/Table.tsx +176 -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 +2 -1
- package/src/mappings/NativeBase/Layout.js +9 -11
- package/src/mappings/NativeBase/Layout.ts +8 -11
- package/src/mappings/Table.js +150 -0
- package/src/mappings/Table.ts +170 -0
- package/lib/commonjs/components/Container.js +0 -93
- package/lib/module/components/Container.js +0 -83
- package/lib/typescript/src/components/Container.d.ts +0 -21
- package/lib/typescript/src/components/Container.d.ts.map +0 -1
- package/src/components/Container.js +0 -43
- package/src/components/Container.tsx +0 -116
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "46.10.3-
|
|
3
|
+
"version": "46.10.3-84bbff.2+84bbff0",
|
|
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.10.3-
|
|
44
|
+
"@draftbit/types": "^46.10.3-84bbff.2+84bbff0",
|
|
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",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
]
|
|
101
101
|
]
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "84bbff016e35ef8ceae750a71028c78ee588366f"
|
|
104
104
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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, ...rest }) => {
|
|
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(() => {
|
|
37
|
+
const flattenedWithoutNestedHeaders = validChildren.map((item) => {
|
|
38
|
+
const nestedChildren = React.Children.toArray(item.props.children);
|
|
39
|
+
//Header can be nested in React.Fragment when in renderItem
|
|
40
|
+
const nestedHeaders = nestedChildren.filter((child) => isTableHeader(child.props));
|
|
41
|
+
if (nestedHeaders === null || nestedHeaders === void 0 ? void 0 : nestedHeaders.length) {
|
|
42
|
+
//New element excluding header children
|
|
43
|
+
return React.cloneElement(item, {
|
|
44
|
+
children: nestedChildren.filter((child) => !isTableHeader(child.props)),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return item;
|
|
48
|
+
});
|
|
49
|
+
return flattenedWithoutNestedHeaders.filter((item) => !isTableHeader(item.props));
|
|
50
|
+
}, [validChildren, isTableHeader]);
|
|
51
|
+
const header = React.useMemo(() => {
|
|
52
|
+
const flattenedPossibleHeaders = validChildren.map((item) => {
|
|
53
|
+
const nestedChildren = React.Children.toArray(item.props.children);
|
|
54
|
+
//Header can be nested in React.Fragment when in renderItem
|
|
55
|
+
const nestedHeaders = nestedChildren.filter((child) => isTableHeader(child.props));
|
|
56
|
+
if (nestedHeaders === null || nestedHeaders === void 0 ? void 0 : nestedHeaders.length) {
|
|
57
|
+
return nestedHeaders[0];
|
|
58
|
+
}
|
|
59
|
+
return item;
|
|
60
|
+
});
|
|
61
|
+
const allHeaders = flattenedPossibleHeaders.filter((item) => isTableHeader(item.props));
|
|
62
|
+
if (allHeaders.length) {
|
|
63
|
+
return allHeaders[0]; //Only 1 header taken
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}, [validChildren, isTableHeader]);
|
|
67
|
+
const contextValue = {
|
|
68
|
+
borderColor,
|
|
69
|
+
borderStyle,
|
|
70
|
+
borderWidth,
|
|
71
|
+
cellHorizontalPadding,
|
|
72
|
+
cellVerticalPadding,
|
|
73
|
+
};
|
|
74
|
+
const borderViewStyle = generateBorderStyles({
|
|
75
|
+
borderColor,
|
|
76
|
+
borderWidth,
|
|
77
|
+
borderStyle,
|
|
78
|
+
drawTopBorder,
|
|
79
|
+
drawBottomBorder,
|
|
80
|
+
drawStartBorder,
|
|
81
|
+
drawEndBorder,
|
|
82
|
+
});
|
|
83
|
+
return (React.createElement(TableStyleContext.Provider, { value: contextValue },
|
|
84
|
+
React.createElement(View, { style: [styles.container, borderViewStyle, style] },
|
|
85
|
+
React.createElement(React.Fragment, null, header),
|
|
86
|
+
React.createElement(ScrollView, { ...rest }, childrenWithoutHeader))));
|
|
87
|
+
};
|
|
88
|
+
const styles = StyleSheet.create({
|
|
89
|
+
container: {
|
|
90
|
+
flex: 1,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
export default withTheme(Table);
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
ScrollView,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
ScrollViewProps,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
import { Theme } from "../../styles/DefaultTheme";
|
|
11
|
+
import { withTheme } from "../../theming";
|
|
12
|
+
import {
|
|
13
|
+
generateBorderStyles,
|
|
14
|
+
TableProps,
|
|
15
|
+
TableStyleContext,
|
|
16
|
+
TableStyleProps,
|
|
17
|
+
} from "./TableCommon";
|
|
18
|
+
|
|
19
|
+
export interface Props<T> extends TableProps, ScrollViewProps {
|
|
20
|
+
data?: Array<T>;
|
|
21
|
+
keyExtractor?: (item: T, index: number) => string;
|
|
22
|
+
renderItem?: ({ item, index }: { item: T; index: number }) => JSX.Element;
|
|
23
|
+
style?: StyleProp<ViewStyle>;
|
|
24
|
+
theme: Theme;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Table = <T extends object>({
|
|
28
|
+
theme,
|
|
29
|
+
borderWidth = 1,
|
|
30
|
+
borderColor = theme.colors.divider,
|
|
31
|
+
borderStyle = "solid",
|
|
32
|
+
drawTopBorder = true,
|
|
33
|
+
drawBottomBorder = false,
|
|
34
|
+
drawStartBorder = false,
|
|
35
|
+
drawEndBorder = false,
|
|
36
|
+
cellVerticalPadding = 10,
|
|
37
|
+
cellHorizontalPadding = 10,
|
|
38
|
+
data,
|
|
39
|
+
keyExtractor,
|
|
40
|
+
renderItem,
|
|
41
|
+
children: childrenProp,
|
|
42
|
+
style,
|
|
43
|
+
...rest
|
|
44
|
+
}: React.PropsWithChildren<Props<T>>) => {
|
|
45
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
46
|
+
if ((data && !renderItem) || (renderItem && !data)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"'renderItem' and 'data' need to both be provided to render from 'data'. Either remove them entirley or include both"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (data && renderItem && childrenProp) {
|
|
53
|
+
console.warn(
|
|
54
|
+
"'children' of Table ignored due to usage of 'data' and 'renderItem'"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const isTableHeader = React.useCallback((object: any): boolean => {
|
|
59
|
+
return object.isTableHeader;
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
const isRenderItem = data && renderItem;
|
|
63
|
+
|
|
64
|
+
//Uses 'renderItem' and 'data' to create an array of children
|
|
65
|
+
const dataAsChildren = React.useMemo(() => {
|
|
66
|
+
if (!isRenderItem) return [];
|
|
67
|
+
|
|
68
|
+
return data.map((item, index) => {
|
|
69
|
+
const component = renderItem({ item, index });
|
|
70
|
+
|
|
71
|
+
if (!component) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const key = keyExtractor ? keyExtractor(item, index) : index.toString();
|
|
76
|
+
return React.cloneElement(component, {
|
|
77
|
+
key,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}, [data, renderItem, keyExtractor, isRenderItem]);
|
|
81
|
+
|
|
82
|
+
const children = isRenderItem
|
|
83
|
+
? dataAsChildren
|
|
84
|
+
: React.Children.toArray(childrenProp);
|
|
85
|
+
|
|
86
|
+
const validChildren = React.useMemo(
|
|
87
|
+
() =>
|
|
88
|
+
(children as any[]).filter((item) =>
|
|
89
|
+
React.isValidElement(item)
|
|
90
|
+
) as React.ReactElement[],
|
|
91
|
+
[children]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const childrenWithoutHeader = React.useMemo(() => {
|
|
95
|
+
const flattenedWithoutNestedHeaders = validChildren.map((item) => {
|
|
96
|
+
const nestedChildren = React.Children.toArray(
|
|
97
|
+
item.props.children
|
|
98
|
+
) as any[];
|
|
99
|
+
//Header can be nested in React.Fragment when in renderItem
|
|
100
|
+
const nestedHeaders = nestedChildren.filter((child: any) =>
|
|
101
|
+
isTableHeader(child.props)
|
|
102
|
+
);
|
|
103
|
+
if (nestedHeaders?.length) {
|
|
104
|
+
//New element excluding header children
|
|
105
|
+
return React.cloneElement(item, {
|
|
106
|
+
children: nestedChildren.filter(
|
|
107
|
+
(child: any) => !isTableHeader(child.props)
|
|
108
|
+
),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return item;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return flattenedWithoutNestedHeaders.filter(
|
|
115
|
+
(item) => !isTableHeader(item.props)
|
|
116
|
+
);
|
|
117
|
+
}, [validChildren, isTableHeader]);
|
|
118
|
+
|
|
119
|
+
const header = React.useMemo(() => {
|
|
120
|
+
const flattenedPossibleHeaders = validChildren.map((item) => {
|
|
121
|
+
const nestedChildren = React.Children.toArray(
|
|
122
|
+
item.props.children
|
|
123
|
+
) as any[];
|
|
124
|
+
//Header can be nested in React.Fragment when in renderItem
|
|
125
|
+
const nestedHeaders = nestedChildren.filter((child: any) =>
|
|
126
|
+
isTableHeader(child.props)
|
|
127
|
+
);
|
|
128
|
+
if (nestedHeaders?.length) {
|
|
129
|
+
return nestedHeaders[0];
|
|
130
|
+
}
|
|
131
|
+
return item;
|
|
132
|
+
});
|
|
133
|
+
const allHeaders = flattenedPossibleHeaders.filter((item) =>
|
|
134
|
+
isTableHeader(item.props)
|
|
135
|
+
);
|
|
136
|
+
if (allHeaders.length) {
|
|
137
|
+
return allHeaders[0]; //Only 1 header taken
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}, [validChildren, isTableHeader]);
|
|
141
|
+
|
|
142
|
+
const contextValue: TableStyleProps = {
|
|
143
|
+
borderColor,
|
|
144
|
+
borderStyle,
|
|
145
|
+
borderWidth,
|
|
146
|
+
cellHorizontalPadding,
|
|
147
|
+
cellVerticalPadding,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const borderViewStyle = generateBorderStyles({
|
|
151
|
+
borderColor,
|
|
152
|
+
borderWidth,
|
|
153
|
+
borderStyle,
|
|
154
|
+
drawTopBorder,
|
|
155
|
+
drawBottomBorder,
|
|
156
|
+
drawStartBorder,
|
|
157
|
+
drawEndBorder,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<TableStyleContext.Provider value={contextValue}>
|
|
162
|
+
<View style={[styles.container, borderViewStyle, style]}>
|
|
163
|
+
<>{header}</>
|
|
164
|
+
<ScrollView {...rest}>{childrenWithoutHeader}</ScrollView>
|
|
165
|
+
</View>
|
|
166
|
+
</TableStyleContext.Provider>
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const styles = StyleSheet.create({
|
|
171
|
+
container: {
|
|
172
|
+
flex: 1,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import { generateBorderStyles, TableStyleContext, } from "./TableCommon";
|
|
4
|
+
import { withTheme } from "../../theming";
|
|
5
|
+
const TableRow = ({ borderWidth, borderColor, borderStyle, drawTopBorder = false, drawBottomBorder = true, drawStartBorder = true, drawEndBorder = false, cellVerticalPadding, cellHorizontalPadding, isTableHeader = false, children, style, theme, }) => {
|
|
6
|
+
const parentContextValue = React.useContext(TableStyleContext);
|
|
7
|
+
//Create context to use and pass to children based on own props or fall back to parent provided context
|
|
8
|
+
const contextValue = {
|
|
9
|
+
borderColor: borderColor || parentContextValue.borderColor,
|
|
10
|
+
borderStyle: borderStyle || parentContextValue.borderStyle,
|
|
11
|
+
borderWidth: borderWidth || parentContextValue.borderWidth,
|
|
12
|
+
cellHorizontalPadding: cellHorizontalPadding || parentContextValue.cellHorizontalPadding,
|
|
13
|
+
cellVerticalPadding: cellVerticalPadding || parentContextValue.cellVerticalPadding,
|
|
14
|
+
};
|
|
15
|
+
const borderViewStyle = generateBorderStyles({
|
|
16
|
+
borderColor: contextValue.borderColor,
|
|
17
|
+
borderWidth: contextValue.borderWidth,
|
|
18
|
+
borderStyle: contextValue.borderStyle,
|
|
19
|
+
drawTopBorder,
|
|
20
|
+
drawBottomBorder,
|
|
21
|
+
drawStartBorder,
|
|
22
|
+
drawEndBorder,
|
|
23
|
+
});
|
|
24
|
+
return (React.createElement(TableStyleContext.Provider, { value: contextValue },
|
|
25
|
+
React.createElement(View, { style: [
|
|
26
|
+
borderViewStyle,
|
|
27
|
+
isTableHeader ? { backgroundColor: theme.colors.primary } : {},
|
|
28
|
+
style,
|
|
29
|
+
styles.cellsContainer,
|
|
30
|
+
] }, children)));
|
|
31
|
+
};
|
|
32
|
+
const styles = StyleSheet.create({
|
|
33
|
+
cellsContainer: {
|
|
34
|
+
flexDirection: "row",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
export default withTheme(TableRow);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleProp, ViewStyle, StyleSheet } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
generateBorderStyles,
|
|
5
|
+
TableProps,
|
|
6
|
+
TableStyleContext,
|
|
7
|
+
TableStyleProps,
|
|
8
|
+
} from "./TableCommon";
|
|
9
|
+
import { Theme } from "../../styles/DefaultTheme";
|
|
10
|
+
import { withTheme } from "../../theming";
|
|
11
|
+
|
|
12
|
+
export interface Props extends TableProps {
|
|
13
|
+
isTableHeader?: boolean;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
theme: Theme;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
|
|
19
|
+
borderWidth,
|
|
20
|
+
borderColor,
|
|
21
|
+
borderStyle,
|
|
22
|
+
drawTopBorder = false,
|
|
23
|
+
drawBottomBorder = true,
|
|
24
|
+
drawStartBorder = true,
|
|
25
|
+
drawEndBorder = false,
|
|
26
|
+
cellVerticalPadding,
|
|
27
|
+
cellHorizontalPadding,
|
|
28
|
+
isTableHeader = false,
|
|
29
|
+
children,
|
|
30
|
+
style,
|
|
31
|
+
theme,
|
|
32
|
+
}) => {
|
|
33
|
+
const parentContextValue = React.useContext(TableStyleContext);
|
|
34
|
+
|
|
35
|
+
//Create context to use and pass to children based on own props or fall back to parent provided context
|
|
36
|
+
const contextValue: TableStyleProps = {
|
|
37
|
+
borderColor: borderColor || parentContextValue.borderColor,
|
|
38
|
+
borderStyle: borderStyle || parentContextValue.borderStyle,
|
|
39
|
+
borderWidth: borderWidth || parentContextValue.borderWidth,
|
|
40
|
+
cellHorizontalPadding:
|
|
41
|
+
cellHorizontalPadding || parentContextValue.cellHorizontalPadding,
|
|
42
|
+
cellVerticalPadding:
|
|
43
|
+
cellVerticalPadding || parentContextValue.cellVerticalPadding,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const borderViewStyle = generateBorderStyles({
|
|
47
|
+
borderColor: contextValue.borderColor,
|
|
48
|
+
borderWidth: contextValue.borderWidth,
|
|
49
|
+
borderStyle: contextValue.borderStyle,
|
|
50
|
+
drawTopBorder,
|
|
51
|
+
drawBottomBorder,
|
|
52
|
+
drawStartBorder,
|
|
53
|
+
drawEndBorder,
|
|
54
|
+
});
|
|
55
|
+
return (
|
|
56
|
+
<TableStyleContext.Provider value={contextValue}>
|
|
57
|
+
<View
|
|
58
|
+
style={[
|
|
59
|
+
borderViewStyle,
|
|
60
|
+
isTableHeader ? { backgroundColor: theme.colors.primary } : {},
|
|
61
|
+
style,
|
|
62
|
+
styles.cellsContainer,
|
|
63
|
+
]}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</View>
|
|
67
|
+
</TableStyleContext.Provider>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const styles = StyleSheet.create({
|
|
72
|
+
cellsContainer: {
|
|
73
|
+
flexDirection: "row",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export default withTheme(TableRow);
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export { default as AvatarEdit } from "./components/AvatarEdit";
|
|
|
10
10
|
export { default as Card } from "./components/Card";
|
|
11
11
|
export { Checkbox, CheckboxGroup, CheckboxRow } from "./components/Checkbox";
|
|
12
12
|
export { default as CircleImage } from "./components/CircleImage";
|
|
13
|
-
export { default as Container } from "./components/Container";
|
|
14
13
|
export { default as Divider } from "./components/Divider";
|
|
15
14
|
export { default as FAB } from "./components/FAB";
|
|
16
15
|
export { default as FieldSearchBarFull } from "./components/FieldSearchBarFull";
|
|
@@ -37,6 +36,7 @@ export { TabView, TabViewItem } from "./components/TabView";
|
|
|
37
36
|
export { default as Markdown } from "./components/Markdown";
|
|
38
37
|
export { BottomSheet } from "./components/BottomSheet";
|
|
39
38
|
export { YoutubePlayer } from "./components/YoutubePlayer";
|
|
39
|
+
export { Table, TableRow, TableCell } from "./components/Table";
|
|
40
40
|
/* Deprecated: Fix or Delete! */
|
|
41
41
|
export { default as DatePicker } from "./components/DatePicker/DatePicker";
|
|
42
42
|
export { default as Picker } from "./components/Picker/Picker";
|
package/src/index.tsx
CHANGED
|
@@ -11,7 +11,6 @@ export { default as AvatarEdit } from "./components/AvatarEdit";
|
|
|
11
11
|
export { default as Card } from "./components/Card";
|
|
12
12
|
export { Checkbox, CheckboxGroup, CheckboxRow } from "./components/Checkbox";
|
|
13
13
|
export { default as CircleImage } from "./components/CircleImage";
|
|
14
|
-
export { default as Container } from "./components/Container";
|
|
15
14
|
export { default as Divider } from "./components/Divider";
|
|
16
15
|
export { default as FAB } from "./components/FAB";
|
|
17
16
|
export { default as FieldSearchBarFull } from "./components/FieldSearchBarFull";
|
|
@@ -62,6 +61,8 @@ export { BottomSheet } from "./components/BottomSheet";
|
|
|
62
61
|
|
|
63
62
|
export { YoutubePlayer } from "./components/YoutubePlayer";
|
|
64
63
|
|
|
64
|
+
export { Table, TableRow, TableCell } from "./components/Table";
|
|
65
|
+
|
|
65
66
|
/* Deprecated: Fix or Delete! */
|
|
66
67
|
export { default as DatePicker } from "./components/DatePicker/DatePicker";
|
|
67
68
|
export { default as Picker } from "./components/Picker/Picker";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { COMPONENT_TYPES,
|
|
1
|
+
import { COMPONENT_TYPES, createBoolProp, CONTAINER_COMPONENT_STYLES_SECTIONS, createStaticNumberProp, StylesPanelSections, createStaticBoolProp, } from "@draftbit/types";
|
|
2
2
|
const SHARED_SEED_DATA = {
|
|
3
3
|
category: COMPONENT_TYPES.layout,
|
|
4
4
|
packageName: "native-base",
|
|
@@ -19,6 +19,14 @@ export const SEED_DATA = [
|
|
|
19
19
|
defaultValue: 1.33,
|
|
20
20
|
}),
|
|
21
21
|
},
|
|
22
|
+
stylesPanelSections: [
|
|
23
|
+
StylesPanelSections.Background,
|
|
24
|
+
StylesPanelSections.Size,
|
|
25
|
+
StylesPanelSections.Margins,
|
|
26
|
+
StylesPanelSections.Position,
|
|
27
|
+
StylesPanelSections.Borders,
|
|
28
|
+
StylesPanelSections.Effects,
|
|
29
|
+
],
|
|
22
30
|
},
|
|
23
31
|
{
|
|
24
32
|
name: "Box",
|
|
@@ -91,16 +99,6 @@ export const SEED_DATA = [
|
|
|
91
99
|
description: "Stack aligns items vertically or horizontally based on the direction prop",
|
|
92
100
|
...SHARED_SEED_DATA,
|
|
93
101
|
props: {
|
|
94
|
-
direction: createTextEnumProp({
|
|
95
|
-
label: "Direction",
|
|
96
|
-
description: "The direction of the Stack",
|
|
97
|
-
options: ["row", "column"],
|
|
98
|
-
defaultValue: "column",
|
|
99
|
-
}),
|
|
100
|
-
reversed: createBoolProp({
|
|
101
|
-
label: "Reversed",
|
|
102
|
-
description: "Determines whether to reverse the direction of items",
|
|
103
|
-
}),
|
|
104
102
|
isDisabled: createBoolProp({
|
|
105
103
|
label: "Disabled",
|
|
106
104
|
description: "If true, the Stack will be disabled",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
COMPONENT_TYPES,
|
|
3
|
-
createTextEnumProp,
|
|
4
3
|
createBoolProp,
|
|
5
4
|
CONTAINER_COMPONENT_STYLES_SECTIONS,
|
|
6
5
|
createStaticNumberProp,
|
|
@@ -36,6 +35,14 @@ export const SEED_DATA = [
|
|
|
36
35
|
defaultValue: 1.33,
|
|
37
36
|
}),
|
|
38
37
|
},
|
|
38
|
+
stylesPanelSections: [
|
|
39
|
+
StylesPanelSections.Background,
|
|
40
|
+
StylesPanelSections.Size,
|
|
41
|
+
StylesPanelSections.Margins,
|
|
42
|
+
StylesPanelSections.Position,
|
|
43
|
+
StylesPanelSections.Borders,
|
|
44
|
+
StylesPanelSections.Effects,
|
|
45
|
+
],
|
|
39
46
|
},
|
|
40
47
|
{
|
|
41
48
|
name: "Box",
|
|
@@ -113,16 +120,6 @@ export const SEED_DATA = [
|
|
|
113
120
|
"Stack aligns items vertically or horizontally based on the direction prop",
|
|
114
121
|
...SHARED_SEED_DATA,
|
|
115
122
|
props: {
|
|
116
|
-
direction: createTextEnumProp({
|
|
117
|
-
label: "Direction",
|
|
118
|
-
description: "The direction of the Stack",
|
|
119
|
-
options: ["row", "column"],
|
|
120
|
-
defaultValue: "column",
|
|
121
|
-
}),
|
|
122
|
-
reversed: createBoolProp({
|
|
123
|
-
label: "Reversed",
|
|
124
|
-
description: "Determines whether to reverse the direction of items",
|
|
125
|
-
}),
|
|
126
123
|
isDisabled: createBoolProp({
|
|
127
124
|
label: "Disabled",
|
|
128
125
|
description: "If true, the Stack will be disabled",
|