@draftbit/core 46.10.3-93b2ea.2 → 46.10.3-b95a8c.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/Checkbox/CheckboxRow.js +6 -23
- package/lib/commonjs/components/Checkbox/context.js +1 -1
- package/lib/commonjs/index.js +0 -47
- package/lib/commonjs/mappings/NativeBase/Layout.js +107 -0
- package/lib/module/constants.js +1 -0
- package/lib/module/index.js +0 -5
- package/lib/module/mappings/NativeBase/Layout.js +100 -0
- package/lib/typescript/src/index.d.ts +0 -5
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mappings/NativeBase/Layout.d.ts +133 -0
- package/lib/typescript/src/mappings/NativeBase/Layout.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/index.js +0 -5
- package/src/index.tsx +0 -6
- package/src/mappings/NativeBase/Layout.js +116 -0
- package/src/mappings/NativeBase/Layout.ts +137 -0
- package/lib/commonjs/components/Container.js +0 -93
- package/lib/commonjs/components/Row.js +0 -73
- package/lib/commonjs/components/RowBodyIcon.js +0 -45
- package/lib/commonjs/components/RowHeadlineImageCaption.js +0 -45
- package/lib/commonjs/components/RowHeadlineImageIcon.js +0 -51
- package/lib/commonjs/components/Table/Table.js +0 -123
- package/lib/commonjs/components/Table/TableCell.js +0 -49
- package/lib/commonjs/components/Table/TableCommon.js +0 -30
- package/lib/commonjs/components/Table/TableRow.js +0 -61
- package/lib/commonjs/components/Table/index.js +0 -27
- package/lib/commonjs/mappings/Container.js +0 -37
- package/lib/commonjs/mappings/Table.js +0 -140
- package/lib/module/components/Container.js +0 -83
- package/lib/module/components/Row.js +0 -63
- package/lib/module/components/RowBodyIcon.js +0 -35
- package/lib/module/components/RowHeadlineImageCaption.js +0 -35
- package/lib/module/components/RowHeadlineImageIcon.js +0 -41
- package/lib/module/components/Table/Table.js +0 -114
- package/lib/module/components/Table/TableCell.js +0 -41
- package/lib/module/components/Table/TableCommon.js +0 -21
- package/lib/module/components/Table/TableRow.js +0 -53
- package/lib/module/components/Table/index.js +0 -3
- package/lib/module/mappings/Container.js +0 -30
- package/lib/module/mappings/Table.js +0 -133
- package/lib/typescript/src/components/Container.d.ts +0 -21
- package/lib/typescript/src/components/Container.d.ts.map +0 -1
- package/lib/typescript/src/components/Row.d.ts +0 -21
- package/lib/typescript/src/components/Row.d.ts.map +0 -1
- package/lib/typescript/src/components/RowBodyIcon.d.ts +0 -16
- package/lib/typescript/src/components/RowBodyIcon.d.ts.map +0 -1
- package/lib/typescript/src/components/RowHeadlineImageCaption.d.ts +0 -16
- package/lib/typescript/src/components/RowHeadlineImageCaption.d.ts.map +0 -1
- package/lib/typescript/src/components/RowHeadlineImageIcon.d.ts +0 -18
- package/lib/typescript/src/components/RowHeadlineImageIcon.d.ts.map +0 -1
- package/lib/typescript/src/components/Table/Table.d.ts +0 -19
- package/lib/typescript/src/components/Table/Table.d.ts.map +0 -1
- package/lib/typescript/src/components/Table/TableCell.d.ts +0 -9
- package/lib/typescript/src/components/Table/TableCell.d.ts.map +0 -1
- package/lib/typescript/src/components/Table/TableCommon.d.ts +0 -20
- package/lib/typescript/src/components/Table/TableCommon.d.ts.map +0 -1
- package/lib/typescript/src/components/Table/TableRow.d.ts +0 -14
- package/lib/typescript/src/components/Table/TableRow.d.ts.map +0 -1
- package/lib/typescript/src/components/Table/index.d.ts +0 -4
- package/lib/typescript/src/components/Table/index.d.ts.map +0 -1
- package/lib/typescript/src/mappings/Container.d.ts +0 -55
- package/lib/typescript/src/mappings/Container.d.ts.map +0 -1
- package/lib/typescript/src/mappings/Table.d.ts +0 -337
- package/lib/typescript/src/mappings/Table.d.ts.map +0 -1
- package/src/components/Container.js +0 -43
- package/src/components/Container.tsx +0 -116
- package/src/components/Row.js +0 -48
- package/src/components/Row.tsx +0 -108
- package/src/components/RowBodyIcon.js +0 -8
- package/src/components/RowBodyIcon.tsx +0 -47
- package/src/components/RowHeadlineImageCaption.js +0 -12
- package/src/components/RowHeadlineImageCaption.tsx +0 -49
- package/src/components/RowHeadlineImageIcon.js +0 -14
- package/src/components/RowHeadlineImageIcon.tsx +0 -61
- package/src/components/Table/Table.js +0 -93
- package/src/components/Table/Table.tsx +0 -176
- package/src/components/Table/TableCell.js +0 -31
- package/src/components/Table/TableCell.tsx +0 -63
- package/src/components/Table/TableCommon.js +0 -12
- package/src/components/Table/TableCommon.ts +0 -40
- package/src/components/Table/TableRow.js +0 -37
- package/src/components/Table/TableRow.tsx +0 -77
- package/src/components/Table/index.js +0 -3
- package/src/components/Table/index.tsx +0 -3
- package/src/mappings/Container.js +0 -30
- package/src/mappings/Container.ts +0 -41
- package/src/mappings/Table.js +0 -150
- package/src/mappings/Table.ts +0 -170
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { withTheme } from "../theming";
|
|
3
|
-
import Row from "./Row";
|
|
4
|
-
import Config from "./Config";
|
|
5
|
-
const RowBodyIcon = ({ Icon, title, subtitle, icon, style, theme: { colors, typography }, }) => {
|
|
6
|
-
return (React.createElement(Row, { titleTypeStyle: typography.body1, titleColor: colors.medium, subtitleTypeStyle: typography.subtitle2, subtitleColor: colors.light, title: title, subtitle: subtitle, right: () => (React.createElement(Icon, { name: icon, size: Config.rowSingleLineIconSize, color: colors.light, style: { marginLeft: 16 } })), style: style }));
|
|
7
|
-
};
|
|
8
|
-
export default withTheme(RowBodyIcon);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { withTheme } from "../theming";
|
|
3
|
-
import type { Theme } from "../styles/DefaultTheme";
|
|
4
|
-
import type { IconSlot } from "../interfaces/Icon";
|
|
5
|
-
|
|
6
|
-
import Row from "./Row";
|
|
7
|
-
import Config from "./Config";
|
|
8
|
-
import { StyleProp, ViewStyle } from "react-native";
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
title?: string;
|
|
12
|
-
subtitle?: string;
|
|
13
|
-
icon: string;
|
|
14
|
-
style?: StyleProp<ViewStyle>;
|
|
15
|
-
theme: Theme;
|
|
16
|
-
} & IconSlot;
|
|
17
|
-
|
|
18
|
-
const RowBodyIcon: React.FC<React.PropsWithChildren<Props>> = ({
|
|
19
|
-
Icon,
|
|
20
|
-
title,
|
|
21
|
-
subtitle,
|
|
22
|
-
icon,
|
|
23
|
-
style,
|
|
24
|
-
theme: { colors, typography },
|
|
25
|
-
}) => {
|
|
26
|
-
return (
|
|
27
|
-
<Row
|
|
28
|
-
titleTypeStyle={typography.body1}
|
|
29
|
-
titleColor={colors.medium}
|
|
30
|
-
subtitleTypeStyle={typography.subtitle2}
|
|
31
|
-
subtitleColor={colors.light}
|
|
32
|
-
title={title}
|
|
33
|
-
subtitle={subtitle}
|
|
34
|
-
right={() => (
|
|
35
|
-
<Icon
|
|
36
|
-
name={icon}
|
|
37
|
-
size={Config.rowSingleLineIconSize}
|
|
38
|
-
color={colors.light}
|
|
39
|
-
style={{ marginLeft: 16 }}
|
|
40
|
-
/>
|
|
41
|
-
)}
|
|
42
|
-
style={style}
|
|
43
|
-
/>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export default withTheme(RowBodyIcon);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Text } from "react-native";
|
|
3
|
-
import { withTheme } from "../theming";
|
|
4
|
-
import Row from "./Row";
|
|
5
|
-
const RowHeadlineImageCaption = ({ title, subtitle, caption, image, style, theme: { colors, typography }, }) => {
|
|
6
|
-
return (React.createElement(Row, { titleTypeStyle: typography.headline6, titleColor: colors.strong, subtitleTypeStyle: typography.body2, subtitleColor: colors.medium, title: title, subtitle: subtitle, image: image, right: () => (React.createElement(Text, { style: {
|
|
7
|
-
...typography.caption,
|
|
8
|
-
color: colors.strong,
|
|
9
|
-
marginLeft: 16,
|
|
10
|
-
} }, caption)), style: style }));
|
|
11
|
-
};
|
|
12
|
-
export default withTheme(RowHeadlineImageCaption);
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { Text, ImageSourcePropType, StyleProp, ViewStyle } from "react-native";
|
|
3
|
-
import { withTheme } from "../theming";
|
|
4
|
-
import Row from "./Row";
|
|
5
|
-
import theme from "../styles/DefaultTheme";
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
title?: string;
|
|
9
|
-
subtitle?: string;
|
|
10
|
-
caption?: string;
|
|
11
|
-
image: string | ImageSourcePropType;
|
|
12
|
-
style?: StyleProp<ViewStyle>;
|
|
13
|
-
theme: typeof theme;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const RowHeadlineImageCaption: React.FC<React.PropsWithChildren<Props>> = ({
|
|
17
|
-
title,
|
|
18
|
-
subtitle,
|
|
19
|
-
caption,
|
|
20
|
-
image,
|
|
21
|
-
style,
|
|
22
|
-
theme: { colors, typography },
|
|
23
|
-
}) => {
|
|
24
|
-
return (
|
|
25
|
-
<Row
|
|
26
|
-
titleTypeStyle={typography.headline6}
|
|
27
|
-
titleColor={colors.strong}
|
|
28
|
-
subtitleTypeStyle={typography.body2}
|
|
29
|
-
subtitleColor={colors.medium}
|
|
30
|
-
title={title}
|
|
31
|
-
subtitle={subtitle}
|
|
32
|
-
image={image}
|
|
33
|
-
right={() => (
|
|
34
|
-
<Text
|
|
35
|
-
style={{
|
|
36
|
-
...typography.caption,
|
|
37
|
-
color: colors.strong,
|
|
38
|
-
marginLeft: 16,
|
|
39
|
-
}}
|
|
40
|
-
>
|
|
41
|
-
{caption}
|
|
42
|
-
</Text>
|
|
43
|
-
)}
|
|
44
|
-
style={style}
|
|
45
|
-
/>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default withTheme(RowHeadlineImageCaption);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { withTheme } from "../theming";
|
|
3
|
-
import Row from "./Row";
|
|
4
|
-
import Config from "./Config";
|
|
5
|
-
const RowHeadlineImageIcon = ({ Icon, icon, title, image, subtitle, multilineSubtitle = false, style, theme: { colors, typography }, }) => {
|
|
6
|
-
return (React.createElement(Row, { titleTypeStyle: typography.headline6, titleColor: colors.strong, subtitleTypeStyle: typography.body2, subtitleColor: colors.medium, title: title, subtitle: subtitle, multilineSubtitle: multilineSubtitle, image: image, right: () => (React.createElement(Icon, { name: icon, size: multilineSubtitle
|
|
7
|
-
? Config.rowMultiLineIconSize
|
|
8
|
-
: Config.rowSingleLineIconSize, color: colors.light, style: {
|
|
9
|
-
marginLeft: 16,
|
|
10
|
-
alignSelf: multilineSubtitle ? "flex-start" : "center",
|
|
11
|
-
marginTop: multilineSubtitle ? 4 : 0,
|
|
12
|
-
} })), style: style }));
|
|
13
|
-
};
|
|
14
|
-
export default withTheme(RowHeadlineImageIcon);
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { withTheme } from "../theming";
|
|
3
|
-
import type { Theme } from "../styles/DefaultTheme";
|
|
4
|
-
import type { IconSlot } from "../interfaces/Icon";
|
|
5
|
-
|
|
6
|
-
import Row from "./Row";
|
|
7
|
-
import Config from "./Config";
|
|
8
|
-
import { ImageSourcePropType, StyleProp, ViewStyle } from "react-native";
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
title?: string;
|
|
12
|
-
image: string | ImageSourcePropType;
|
|
13
|
-
subtitle?: string;
|
|
14
|
-
multilineSubtitle?: boolean;
|
|
15
|
-
icon: string;
|
|
16
|
-
style?: StyleProp<ViewStyle>;
|
|
17
|
-
theme: Theme;
|
|
18
|
-
} & IconSlot;
|
|
19
|
-
|
|
20
|
-
const RowHeadlineImageIcon: React.FC<React.PropsWithChildren<Props>> = ({
|
|
21
|
-
Icon,
|
|
22
|
-
icon,
|
|
23
|
-
title,
|
|
24
|
-
image,
|
|
25
|
-
subtitle,
|
|
26
|
-
multilineSubtitle = false,
|
|
27
|
-
style,
|
|
28
|
-
theme: { colors, typography },
|
|
29
|
-
}) => {
|
|
30
|
-
return (
|
|
31
|
-
<Row
|
|
32
|
-
titleTypeStyle={typography.headline6}
|
|
33
|
-
titleColor={colors.strong}
|
|
34
|
-
subtitleTypeStyle={typography.body2}
|
|
35
|
-
subtitleColor={colors.medium}
|
|
36
|
-
title={title}
|
|
37
|
-
subtitle={subtitle}
|
|
38
|
-
multilineSubtitle={multilineSubtitle}
|
|
39
|
-
image={image}
|
|
40
|
-
right={() => (
|
|
41
|
-
<Icon
|
|
42
|
-
name={icon}
|
|
43
|
-
size={
|
|
44
|
-
multilineSubtitle
|
|
45
|
-
? Config.rowMultiLineIconSize
|
|
46
|
-
: Config.rowSingleLineIconSize
|
|
47
|
-
}
|
|
48
|
-
color={colors.light}
|
|
49
|
-
style={{
|
|
50
|
-
marginLeft: 16,
|
|
51
|
-
alignSelf: multilineSubtitle ? "flex-start" : "center",
|
|
52
|
-
marginTop: multilineSubtitle ? 4 : 0,
|
|
53
|
-
}}
|
|
54
|
-
/>
|
|
55
|
-
)}
|
|
56
|
-
style={style}
|
|
57
|
-
/>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export default withTheme(RowHeadlineImageIcon);
|
|
@@ -1,93 +0,0 @@
|
|
|
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);
|
|
@@ -1,176 +0,0 @@
|
|
|
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);
|
|
@@ -1,31 +0,0 @@
|
|
|
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;
|
|
@@ -1,63 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
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);
|