@draftbit/core 43.4.11-d2edf8.3 → 43.4.11
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/Accordion/AccordionGroup.js +2 -2
- package/lib/commonjs/components/Accordion/AccordionGroup.js.map +1 -1
- package/lib/commonjs/components/Checkbox/Checkbox.js +6 -6
- package/lib/commonjs/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js +142 -0
- package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js.map +1 -0
- package/lib/commonjs/components/Checkbox/CheckboxRow.js +54 -46
- package/lib/commonjs/components/Checkbox/CheckboxRow.js.map +1 -1
- package/lib/commonjs/components/DatePicker/DatePicker.js +2 -9
- package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/commonjs/components/Divider.js +13 -3
- package/lib/commonjs/components/Divider.js.map +1 -1
- package/lib/commonjs/components/RadioButton/RadioButtonRow.js +1 -1
- package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
- package/lib/commonjs/components/RowBodyIcon.js.map +1 -1
- package/lib/commonjs/components/RowHeadlineImageIcon.js.map +1 -1
- package/lib/commonjs/mappings/CardContainer.js.map +1 -1
- package/lib/commonjs/mappings/Carousel.js.map +1 -1
- package/lib/commonjs/mappings/CheckboxRow.js +25 -6
- package/lib/commonjs/mappings/CheckboxRow.js.map +1 -1
- package/lib/commonjs/mappings/ImageBackground.js.map +1 -1
- package/lib/commonjs/mappings/ProgressBar.js.map +1 -1
- package/lib/commonjs/mappings/RowHeadlineImageIcon.js.map +1 -1
- package/lib/commonjs/mappings/Slider.js.map +1 -1
- package/lib/commonjs/theming.js.map +1 -1
- package/lib/module/components/Accordion/AccordionGroup.js +2 -2
- package/lib/module/components/Accordion/AccordionGroup.js.map +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +6 -6
- package/lib/module/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/module/components/Checkbox/CheckboxGroupRow.js +120 -0
- package/lib/module/components/Checkbox/CheckboxGroupRow.js.map +1 -0
- package/lib/module/components/Checkbox/CheckboxRow.js +52 -46
- package/lib/module/components/Checkbox/CheckboxRow.js.map +1 -1
- package/lib/module/components/DatePicker/DatePicker.js +3 -9
- package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButtonRow.js +1 -1
- package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
- package/lib/module/components/RadioButton/index.js.map +1 -1
- package/lib/module/mappings/CardContainerRating.js.map +1 -1
- package/lib/module/mappings/CheckboxRow.js +26 -7
- package/lib/module/mappings/CheckboxRow.js.map +1 -1
- package/lib/typescript/src/components/Checkbox/CheckboxGroupRow.d.ts +21 -0
- package/lib/typescript/src/components/Checkbox/CheckboxRow.d.ts +3 -7
- package/lib/typescript/src/mappings/CheckboxRow.d.ts +50 -9
- package/package.json +2 -2
- package/src/components/Accordion/AccordionGroup.js +1 -1
- package/src/components/Accordion/AccordionGroup.tsx +1 -1
- package/src/components/Checkbox/Checkbox.js +6 -6
- package/src/components/Checkbox/Checkbox.tsx +8 -6
- package/src/components/Checkbox/CheckboxGroupRow.js +77 -0
- package/src/components/Checkbox/CheckboxGroupRow.tsx +152 -0
- package/src/components/Checkbox/CheckboxRow.js +33 -32
- package/src/components/Checkbox/CheckboxRow.tsx +66 -62
- package/src/components/DatePicker/DatePicker.js +2 -4
- package/src/components/DatePicker/DatePicker.tsx +1 -14
- package/src/components/RadioButton/RadioButtonRow.js +1 -1
- package/src/components/RadioButton/RadioButtonRow.tsx +1 -1
- package/src/mappings/CheckboxRow.js +26 -7
- package/src/mappings/CheckboxRow.ts +28 -6
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet, View, Platform, } from "react-native";
|
|
3
|
+
import Checkbox from "./Checkbox";
|
|
4
|
+
import Text from "../Text";
|
|
5
|
+
import { useCheckboxGroupContext } from "./context";
|
|
6
|
+
import { Direction as GroupDirection } from "./context";
|
|
7
|
+
import Touchable from "../Touchable";
|
|
8
|
+
import { extractStyles } from "../../utilities";
|
|
9
|
+
export var Direction;
|
|
10
|
+
(function (Direction) {
|
|
11
|
+
Direction["Row"] = "row";
|
|
12
|
+
Direction["RowReverse"] = "row-reverse";
|
|
13
|
+
})(Direction || (Direction = {}));
|
|
14
|
+
const getCheckboxAlignment = (parentDirection, direction) => {
|
|
15
|
+
if (parentDirection === GroupDirection.Horizontal) {
|
|
16
|
+
return direction === Direction.Row ? "flex-start" : "flex-end";
|
|
17
|
+
}
|
|
18
|
+
else if (direction === Direction.RowReverse) {
|
|
19
|
+
return "flex-start";
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return "flex-end";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const renderLabel = (value, labelStyle, textStyle) => {
|
|
26
|
+
if (typeof value === "string") {
|
|
27
|
+
return React.createElement(Text, { style: [labelStyle, textStyle] }, value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return React.createElement(React.Fragment, null, value);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const CheckboxGroupRow = ({ Icon, label = "Label", status, value, onPress, labelContainerStyle, labelStyle, checkboxStyle, direction = Direction.Row, disabled, style, color, uncheckedColor, ...rest }) => {
|
|
34
|
+
const { values: selectedValues, onValueChange, direction: parentDirection, } = useCheckboxGroupContext();
|
|
35
|
+
const values = Array.isArray(selectedValues) ? selectedValues : [];
|
|
36
|
+
const isChecked = status || values.includes(value);
|
|
37
|
+
const handlePress = () => {
|
|
38
|
+
if (!disabled) {
|
|
39
|
+
onPress?.(!isChecked);
|
|
40
|
+
onValueChange?.(value, !isChecked);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const { textStyles, viewStyles } = extractStyles(style);
|
|
44
|
+
return (React.createElement(Touchable, { onPress: handlePress, style: [styles.mainParent, { flexDirection: direction }, viewStyles], disabled: disabled, ...rest },
|
|
45
|
+
React.createElement(View, { style: [
|
|
46
|
+
styles.label,
|
|
47
|
+
{
|
|
48
|
+
alignItems: direction === Direction.Row ? "flex-start" : "flex-end",
|
|
49
|
+
},
|
|
50
|
+
labelContainerStyle,
|
|
51
|
+
] }, renderLabel(label, labelStyle, textStyles)),
|
|
52
|
+
React.createElement(View, { style: {
|
|
53
|
+
flex: 1,
|
|
54
|
+
alignItems: getCheckboxAlignment(parentDirection, direction),
|
|
55
|
+
} },
|
|
56
|
+
React.createElement(Checkbox, { Icon: Icon, status: isChecked, onPress: handlePress, style: checkboxStyle, disabled: disabled, color: color, uncheckedColor: uncheckedColor }))));
|
|
57
|
+
};
|
|
58
|
+
const styles = StyleSheet.create({
|
|
59
|
+
mainParent: {
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
justifyContent: "space-around",
|
|
62
|
+
paddingStart: 20,
|
|
63
|
+
minHeight: 50,
|
|
64
|
+
paddingEnd: 20,
|
|
65
|
+
display: "flex",
|
|
66
|
+
...Platform.select({
|
|
67
|
+
web: {
|
|
68
|
+
cursor: "pointer",
|
|
69
|
+
userSelect: "none",
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
label: {
|
|
74
|
+
flex: 3,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
export default CheckboxGroupRow;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
StyleProp,
|
|
4
|
+
ViewStyle,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
TextStyle,
|
|
7
|
+
View,
|
|
8
|
+
Platform,
|
|
9
|
+
} from "react-native";
|
|
10
|
+
import Checkbox, { CheckboxProps } from "./Checkbox";
|
|
11
|
+
import Text from "../Text";
|
|
12
|
+
import { useCheckboxGroupContext } from "./context";
|
|
13
|
+
import type { IconSlot } from "../../interfaces/Icon";
|
|
14
|
+
import { Direction as GroupDirection } from "./context";
|
|
15
|
+
import Touchable from "../Touchable";
|
|
16
|
+
import { extractStyles } from "../../utilities";
|
|
17
|
+
|
|
18
|
+
export enum Direction {
|
|
19
|
+
Row = "row",
|
|
20
|
+
RowReverse = "row-reverse",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CheckboxGroupRowProps extends Omit<CheckboxProps, "onPress"> {
|
|
24
|
+
label: string | React.ReactNode;
|
|
25
|
+
value: string; // A string that this checkbox represents
|
|
26
|
+
labelContainerStyle: StyleProp<ViewStyle>;
|
|
27
|
+
checkboxStyle?: StyleProp<ViewStyle>;
|
|
28
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
29
|
+
onPress?: (value: boolean) => void;
|
|
30
|
+
direction?: Direction;
|
|
31
|
+
color: string;
|
|
32
|
+
unselectedColor: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const getCheckboxAlignment = (
|
|
36
|
+
parentDirection: GroupDirection | undefined,
|
|
37
|
+
direction: Direction
|
|
38
|
+
) => {
|
|
39
|
+
if (parentDirection === GroupDirection.Horizontal) {
|
|
40
|
+
return direction === Direction.Row ? "flex-start" : "flex-end";
|
|
41
|
+
} else if (direction === Direction.RowReverse) {
|
|
42
|
+
return "flex-start";
|
|
43
|
+
} else {
|
|
44
|
+
return "flex-end";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const renderLabel = (
|
|
49
|
+
value: string | React.ReactNode,
|
|
50
|
+
labelStyle: StyleProp<TextStyle>,
|
|
51
|
+
textStyle: StyleProp<TextStyle>
|
|
52
|
+
) => {
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
return <Text style={[labelStyle, textStyle]}>{value}</Text>;
|
|
55
|
+
} else {
|
|
56
|
+
return <>{value}</>;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const CheckboxGroupRow: React.FC<CheckboxGroupRowProps & IconSlot> = ({
|
|
61
|
+
Icon,
|
|
62
|
+
label = "Label",
|
|
63
|
+
status,
|
|
64
|
+
value,
|
|
65
|
+
onPress,
|
|
66
|
+
labelContainerStyle,
|
|
67
|
+
labelStyle,
|
|
68
|
+
checkboxStyle,
|
|
69
|
+
direction = Direction.Row,
|
|
70
|
+
disabled,
|
|
71
|
+
style,
|
|
72
|
+
color,
|
|
73
|
+
uncheckedColor,
|
|
74
|
+
...rest
|
|
75
|
+
}) => {
|
|
76
|
+
const {
|
|
77
|
+
values: selectedValues,
|
|
78
|
+
onValueChange,
|
|
79
|
+
direction: parentDirection,
|
|
80
|
+
} = useCheckboxGroupContext();
|
|
81
|
+
|
|
82
|
+
const values = Array.isArray(selectedValues) ? selectedValues : [];
|
|
83
|
+
const isChecked = status || values.includes(value);
|
|
84
|
+
|
|
85
|
+
const handlePress = () => {
|
|
86
|
+
if (!disabled) {
|
|
87
|
+
onPress?.(!isChecked);
|
|
88
|
+
onValueChange?.(value, !isChecked);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const { textStyles, viewStyles } = extractStyles(style);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Touchable
|
|
96
|
+
onPress={handlePress}
|
|
97
|
+
style={[styles.mainParent, { flexDirection: direction }, viewStyles]}
|
|
98
|
+
disabled={disabled}
|
|
99
|
+
{...rest}
|
|
100
|
+
>
|
|
101
|
+
<View
|
|
102
|
+
style={[
|
|
103
|
+
styles.label,
|
|
104
|
+
{
|
|
105
|
+
alignItems: direction === Direction.Row ? "flex-start" : "flex-end",
|
|
106
|
+
},
|
|
107
|
+
labelContainerStyle,
|
|
108
|
+
]}
|
|
109
|
+
>
|
|
110
|
+
{renderLabel(label, labelStyle, textStyles)}
|
|
111
|
+
</View>
|
|
112
|
+
<View
|
|
113
|
+
style={{
|
|
114
|
+
flex: 1,
|
|
115
|
+
alignItems: getCheckboxAlignment(parentDirection, direction),
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<Checkbox
|
|
119
|
+
Icon={Icon}
|
|
120
|
+
status={isChecked}
|
|
121
|
+
onPress={handlePress}
|
|
122
|
+
style={checkboxStyle}
|
|
123
|
+
disabled={disabled}
|
|
124
|
+
color={color}
|
|
125
|
+
uncheckedColor={uncheckedColor}
|
|
126
|
+
/>
|
|
127
|
+
</View>
|
|
128
|
+
</Touchable>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const styles = StyleSheet.create({
|
|
133
|
+
mainParent: {
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
justifyContent: "space-around",
|
|
136
|
+
paddingStart: 20,
|
|
137
|
+
minHeight: 50,
|
|
138
|
+
paddingEnd: 20,
|
|
139
|
+
display: "flex",
|
|
140
|
+
...Platform.select({
|
|
141
|
+
web: {
|
|
142
|
+
cursor: "pointer",
|
|
143
|
+
userSelect: "none",
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
},
|
|
147
|
+
label: {
|
|
148
|
+
flex: 3,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export default CheckboxGroupRow;
|
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { StyleSheet, View, Platform, } from "react-native";
|
|
3
|
-
import
|
|
3
|
+
import { isString } from "lodash";
|
|
4
|
+
import { extractStyles } from "../../utilities";
|
|
5
|
+
import { usePrevious } from "../../hooks";
|
|
4
6
|
import Text from "../Text";
|
|
5
|
-
import { useCheckboxGroupContext } from "./context";
|
|
6
|
-
import { Direction as GroupDirection } from "./context";
|
|
7
7
|
import Touchable from "../Touchable";
|
|
8
|
-
import
|
|
8
|
+
import Checkbox from "./Checkbox";
|
|
9
9
|
export var Direction;
|
|
10
10
|
(function (Direction) {
|
|
11
11
|
Direction["Row"] = "row";
|
|
12
12
|
Direction["RowReverse"] = "row-reverse";
|
|
13
13
|
})(Direction || (Direction = {}));
|
|
14
|
-
const getCheckboxAlignment = (parentDirection, direction) => {
|
|
15
|
-
if (parentDirection === GroupDirection.Horizontal) {
|
|
16
|
-
return direction === Direction.Row ? "flex-start" : "flex-end";
|
|
17
|
-
}
|
|
18
|
-
else if (direction === Direction.RowReverse) {
|
|
19
|
-
return "flex-start";
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return "flex-end";
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
14
|
const renderLabel = (value, labelStyle, textStyle) => {
|
|
26
|
-
if (
|
|
27
|
-
return React.createElement(Text, { style: [
|
|
15
|
+
if (isString(value)) {
|
|
16
|
+
return React.createElement(Text, { style: [textStyle, labelStyle] }, value);
|
|
28
17
|
}
|
|
29
18
|
else {
|
|
30
19
|
return React.createElement(React.Fragment, null, value);
|
|
31
20
|
}
|
|
32
21
|
};
|
|
33
|
-
const CheckboxRow = ({
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
const CheckboxRow = ({ label = "Label", labelStyle, labelContainerStyle, checkboxStyle, direction = Direction.Row, Icon, status, disabled = false, onPress, onCheck, onUncheck, color, uncheckedColor, defaultValue, checkedIcon, uncheckedIcon, size, style, ...rest }) => {
|
|
23
|
+
const [internalValue, setInternalValue] = React.useState(status || defaultValue || false);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (status != null) {
|
|
26
|
+
setInternalValue(status);
|
|
27
|
+
}
|
|
28
|
+
}, [status]);
|
|
29
|
+
// This special logic is to handle weird APIs like Airtable that return
|
|
30
|
+
// true or undefined for a boolean
|
|
31
|
+
const previousDefaultValue = usePrevious(defaultValue);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (defaultValue !== previousDefaultValue) {
|
|
34
|
+
setInternalValue(Boolean(defaultValue));
|
|
35
|
+
}
|
|
36
|
+
}, [defaultValue, previousDefaultValue]);
|
|
37
37
|
const handlePress = () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const newValue = !internalValue;
|
|
39
|
+
setInternalValue(newValue);
|
|
40
|
+
onPress?.(newValue);
|
|
41
|
+
if (newValue) {
|
|
42
|
+
onCheck?.();
|
|
43
|
+
}
|
|
44
|
+
if (!newValue) {
|
|
45
|
+
onUncheck?.();
|
|
41
46
|
}
|
|
42
47
|
};
|
|
43
48
|
const { textStyles, viewStyles } = extractStyles(style);
|
|
44
|
-
return (React.createElement(Touchable, { onPress: handlePress, style: [styles.mainParent, { flexDirection: direction }
|
|
49
|
+
return (React.createElement(Touchable, { onPress: handlePress, style: [viewStyles, styles.mainParent, { flexDirection: direction }], disabled: disabled, ...rest },
|
|
45
50
|
React.createElement(View, { style: [
|
|
46
51
|
styles.label,
|
|
47
52
|
{
|
|
48
53
|
alignItems: direction === Direction.Row ? "flex-start" : "flex-end",
|
|
49
54
|
},
|
|
50
55
|
labelContainerStyle,
|
|
51
|
-
] }, renderLabel(label,
|
|
52
|
-
React.createElement(
|
|
53
|
-
flex: 1,
|
|
54
|
-
alignItems: getCheckboxAlignment(parentDirection, direction),
|
|
55
|
-
} },
|
|
56
|
-
React.createElement(Checkbox, { Icon: Icon, status: isChecked, onPress: handlePress, style: checkboxStyle, disabled: disabled, color: color, uncheckedColor: uncheckedColor }))));
|
|
56
|
+
] }, renderLabel(label, textStyles, labelStyle)),
|
|
57
|
+
React.createElement(Checkbox, { Icon: Icon, status: internalValue, style: checkboxStyle, disabled: disabled, color: color, uncheckedColor: uncheckedColor, checkedIcon: checkedIcon, uncheckedIcon: uncheckedIcon, size: size })));
|
|
57
58
|
};
|
|
58
59
|
const styles = StyleSheet.create({
|
|
59
60
|
mainParent: {
|
|
@@ -62,7 +63,7 @@ const styles = StyleSheet.create({
|
|
|
62
63
|
paddingStart: 20,
|
|
63
64
|
minHeight: 50,
|
|
64
65
|
paddingEnd: 20,
|
|
65
|
-
|
|
66
|
+
display: "flex",
|
|
66
67
|
...Platform.select({
|
|
67
68
|
web: {
|
|
68
69
|
cursor: "pointer",
|
|
@@ -7,85 +7,93 @@ import {
|
|
|
7
7
|
View,
|
|
8
8
|
Platform,
|
|
9
9
|
} from "react-native";
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import { useCheckboxGroupContext } from "./context";
|
|
10
|
+
import { isString } from "lodash";
|
|
11
|
+
|
|
13
12
|
import type { IconSlot } from "../../interfaces/Icon";
|
|
14
|
-
import { Direction as GroupDirection } from "./context";
|
|
15
|
-
import Touchable from "../Touchable";
|
|
16
13
|
import { extractStyles } from "../../utilities";
|
|
14
|
+
import { usePrevious } from "../../hooks";
|
|
15
|
+
import Text from "../Text";
|
|
16
|
+
import Touchable from "../Touchable";
|
|
17
|
+
import Checkbox, { CheckboxProps } from "./Checkbox";
|
|
17
18
|
|
|
18
19
|
export enum Direction {
|
|
19
20
|
Row = "row",
|
|
20
21
|
RowReverse = "row-reverse",
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export interface CheckboxRowProps extends
|
|
24
|
+
export interface CheckboxRowProps extends CheckboxProps {
|
|
24
25
|
label: string | React.ReactNode;
|
|
25
|
-
|
|
26
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
26
27
|
labelContainerStyle: StyleProp<ViewStyle>;
|
|
27
28
|
checkboxStyle?: StyleProp<ViewStyle>;
|
|
28
|
-
labelStyle?: StyleProp<TextStyle>;
|
|
29
|
-
onPress?: (value: boolean) => void;
|
|
30
29
|
direction?: Direction;
|
|
31
|
-
color: string;
|
|
32
|
-
unselectedColor: string;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
const getCheckboxAlignment = (
|
|
36
|
-
parentDirection: GroupDirection | undefined,
|
|
37
|
-
direction: Direction
|
|
38
|
-
) => {
|
|
39
|
-
if (parentDirection === GroupDirection.Horizontal) {
|
|
40
|
-
return direction === Direction.Row ? "flex-start" : "flex-end";
|
|
41
|
-
} else if (direction === Direction.RowReverse) {
|
|
42
|
-
return "flex-start";
|
|
43
|
-
} else {
|
|
44
|
-
return "flex-end";
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
32
|
const renderLabel = (
|
|
49
33
|
value: string | React.ReactNode,
|
|
50
34
|
labelStyle: StyleProp<TextStyle>,
|
|
51
35
|
textStyle: StyleProp<TextStyle>
|
|
52
36
|
) => {
|
|
53
|
-
if (
|
|
54
|
-
return <Text style={[
|
|
37
|
+
if (isString(value)) {
|
|
38
|
+
return <Text style={[textStyle, labelStyle]}>{value}</Text>;
|
|
55
39
|
} else {
|
|
56
40
|
return <>{value}</>;
|
|
57
41
|
}
|
|
58
42
|
};
|
|
59
43
|
|
|
60
44
|
const CheckboxRow: React.FC<CheckboxRowProps & IconSlot> = ({
|
|
61
|
-
Icon,
|
|
62
45
|
label = "Label",
|
|
63
|
-
status,
|
|
64
|
-
value,
|
|
65
|
-
onPress = () => {},
|
|
66
|
-
labelContainerStyle,
|
|
67
46
|
labelStyle,
|
|
47
|
+
labelContainerStyle,
|
|
68
48
|
checkboxStyle,
|
|
69
49
|
direction = Direction.Row,
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
Icon,
|
|
51
|
+
status,
|
|
52
|
+
disabled = false,
|
|
53
|
+
onPress,
|
|
54
|
+
onCheck,
|
|
55
|
+
onUncheck,
|
|
72
56
|
color,
|
|
73
57
|
uncheckedColor,
|
|
58
|
+
defaultValue,
|
|
59
|
+
checkedIcon,
|
|
60
|
+
uncheckedIcon,
|
|
61
|
+
size,
|
|
62
|
+
style,
|
|
74
63
|
...rest
|
|
75
64
|
}) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
direction: parentDirection,
|
|
80
|
-
} = useCheckboxGroupContext();
|
|
65
|
+
const [internalValue, setInternalValue] = React.useState<boolean>(
|
|
66
|
+
status || defaultValue || false
|
|
67
|
+
);
|
|
81
68
|
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (status != null) {
|
|
71
|
+
setInternalValue(status);
|
|
72
|
+
}
|
|
73
|
+
}, [status]);
|
|
74
|
+
|
|
75
|
+
// This special logic is to handle weird APIs like Airtable that return
|
|
76
|
+
// true or undefined for a boolean
|
|
77
|
+
const previousDefaultValue = usePrevious(defaultValue) as boolean | undefined;
|
|
78
|
+
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (defaultValue !== previousDefaultValue) {
|
|
81
|
+
setInternalValue(Boolean(defaultValue));
|
|
82
|
+
}
|
|
83
|
+
}, [defaultValue, previousDefaultValue]);
|
|
84
84
|
|
|
85
85
|
const handlePress = () => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const newValue = !internalValue;
|
|
87
|
+
|
|
88
|
+
setInternalValue(newValue);
|
|
89
|
+
onPress?.(newValue);
|
|
90
|
+
|
|
91
|
+
if (newValue) {
|
|
92
|
+
onCheck?.();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!newValue) {
|
|
96
|
+
onUncheck?.();
|
|
89
97
|
}
|
|
90
98
|
};
|
|
91
99
|
|
|
@@ -94,7 +102,7 @@ const CheckboxRow: React.FC<CheckboxRowProps & IconSlot> = ({
|
|
|
94
102
|
return (
|
|
95
103
|
<Touchable
|
|
96
104
|
onPress={handlePress}
|
|
97
|
-
style={[styles.mainParent, { flexDirection: direction }
|
|
105
|
+
style={[viewStyles, styles.mainParent, { flexDirection: direction }]}
|
|
98
106
|
disabled={disabled}
|
|
99
107
|
{...rest}
|
|
100
108
|
>
|
|
@@ -107,24 +115,20 @@ const CheckboxRow: React.FC<CheckboxRowProps & IconSlot> = ({
|
|
|
107
115
|
labelContainerStyle,
|
|
108
116
|
]}
|
|
109
117
|
>
|
|
110
|
-
{renderLabel(label,
|
|
111
|
-
</View>
|
|
112
|
-
<View
|
|
113
|
-
style={{
|
|
114
|
-
flex: 1,
|
|
115
|
-
alignItems: getCheckboxAlignment(parentDirection, direction),
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
<Checkbox
|
|
119
|
-
Icon={Icon}
|
|
120
|
-
status={isChecked}
|
|
121
|
-
onPress={handlePress}
|
|
122
|
-
style={checkboxStyle}
|
|
123
|
-
disabled={disabled}
|
|
124
|
-
color={color}
|
|
125
|
-
uncheckedColor={uncheckedColor}
|
|
126
|
-
/>
|
|
118
|
+
{renderLabel(label, textStyles, labelStyle)}
|
|
127
119
|
</View>
|
|
120
|
+
|
|
121
|
+
<Checkbox
|
|
122
|
+
Icon={Icon}
|
|
123
|
+
status={internalValue}
|
|
124
|
+
style={checkboxStyle}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
color={color}
|
|
127
|
+
uncheckedColor={uncheckedColor}
|
|
128
|
+
checkedIcon={checkedIcon}
|
|
129
|
+
uncheckedIcon={uncheckedIcon}
|
|
130
|
+
size={size}
|
|
131
|
+
/>
|
|
128
132
|
</Touchable>
|
|
129
133
|
);
|
|
130
134
|
};
|
|
@@ -136,7 +140,7 @@ const styles = StyleSheet.create({
|
|
|
136
140
|
paddingStart: 20,
|
|
137
141
|
minHeight: 50,
|
|
138
142
|
paddingEnd: 20,
|
|
139
|
-
|
|
143
|
+
display: "flex",
|
|
140
144
|
...Platform.select({
|
|
141
145
|
web: {
|
|
142
146
|
cursor: "pointer",
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { View, Animated, Text, StyleSheet,
|
|
2
|
+
import { View, Animated, Text, StyleSheet, I18nManager, TextInput as NativeTextInput, } from "react-native";
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
4
|
import dateFormat from "dateformat";
|
|
5
5
|
import { withTheme } from "../../theming";
|
|
6
6
|
import Portal from "../Portal/Portal";
|
|
7
|
-
import Button from "../DeprecatedButton";
|
|
8
7
|
import Touchable from "../Touchable";
|
|
9
8
|
import DateTimePicker from "./DatePickerComponent";
|
|
10
9
|
const AnimatedText = Animated.createAnimatedComponent(Text);
|
|
@@ -325,9 +324,8 @@ const DatePicker = ({ Icon, style, theme: { colors, typography, roundness, disab
|
|
|
325
324
|
paddingRight: insets.right,
|
|
326
325
|
},
|
|
327
326
|
] },
|
|
328
|
-
Platform.OS === "ios" && (React.createElement(Button, { Icon: Icon, type: "text", onPress: toggleVisibility, style: styles.closeButton }, "Close")),
|
|
329
327
|
React.createElement(DateTimePicker, { value: getValidDate(), mode: mode, isVisible: pickerVisible, toggleVisibility: toggleVisibility, onChange: (_event, data) => {
|
|
330
|
-
|
|
328
|
+
toggleVisibility();
|
|
331
329
|
setValue(data);
|
|
332
330
|
onDateChange(data);
|
|
333
331
|
} })))))));
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
StyleProp,
|
|
8
8
|
ViewStyle,
|
|
9
9
|
TextStyle,
|
|
10
|
-
Platform,
|
|
11
10
|
TextInputProps,
|
|
12
11
|
ImageStyle,
|
|
13
12
|
I18nManager,
|
|
@@ -19,7 +18,6 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
|
19
18
|
import dateFormat from "dateformat";
|
|
20
19
|
import { withTheme } from "../../theming";
|
|
21
20
|
import Portal from "../Portal/Portal";
|
|
22
|
-
import Button from "../DeprecatedButton";
|
|
23
21
|
import Touchable from "../Touchable";
|
|
24
22
|
import DateTimePicker from "./DatePickerComponent";
|
|
25
23
|
|
|
@@ -496,24 +494,13 @@ const DatePicker: React.FC<Props> = ({
|
|
|
496
494
|
},
|
|
497
495
|
]}
|
|
498
496
|
>
|
|
499
|
-
{Platform.OS === "ios" && (
|
|
500
|
-
<Button
|
|
501
|
-
Icon={Icon}
|
|
502
|
-
type="text"
|
|
503
|
-
onPress={toggleVisibility}
|
|
504
|
-
style={styles.closeButton}
|
|
505
|
-
>
|
|
506
|
-
Close
|
|
507
|
-
</Button>
|
|
508
|
-
)}
|
|
509
|
-
|
|
510
497
|
<DateTimePicker
|
|
511
498
|
value={getValidDate()}
|
|
512
499
|
mode={mode}
|
|
513
500
|
isVisible={pickerVisible}
|
|
514
501
|
toggleVisibility={toggleVisibility}
|
|
515
502
|
onChange={(_event: any, data: any) => {
|
|
516
|
-
|
|
503
|
+
toggleVisibility();
|
|
517
504
|
setValue(data);
|
|
518
505
|
onDateChange(data);
|
|
519
506
|
}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTextProp, createTextStyle, createRowDirectionProp, createFieldNameProp, COMPONENT_TYPES, Triggers, createColorProp, } from "@draftbit/types";
|
|
1
|
+
import { createBoolProp, createTextProp, createTextStyle, createRowDirectionProp, createFieldNameProp, createIconProp, createStaticNumberProp, COMPONENT_TYPES, Triggers, createColorProp, } from "@draftbit/types";
|
|
2
2
|
export const SEED_DATA = {
|
|
3
3
|
name: "Checkbox Row",
|
|
4
4
|
tag: "CheckboxRow",
|
|
@@ -6,8 +6,13 @@ export const SEED_DATA = {
|
|
|
6
6
|
layout: {
|
|
7
7
|
minHeight: 50,
|
|
8
8
|
},
|
|
9
|
-
triggers: [Triggers.OnPress],
|
|
9
|
+
triggers: [Triggers.OnPress, Triggers.OnCheck, Triggers.OnUncheck],
|
|
10
10
|
props: {
|
|
11
|
+
fieldName: createFieldNameProp({
|
|
12
|
+
defaultValue: "checkboxRowValue",
|
|
13
|
+
valuePropName: "value",
|
|
14
|
+
handlerPropName: "onPress",
|
|
15
|
+
}),
|
|
11
16
|
label: createTextProp({
|
|
12
17
|
label: "Label",
|
|
13
18
|
description: "Label to show with the checkbox",
|
|
@@ -21,11 +26,6 @@ export const SEED_DATA = {
|
|
|
21
26
|
editable: false,
|
|
22
27
|
}),
|
|
23
28
|
direction: createRowDirectionProp(),
|
|
24
|
-
fieldName: createFieldNameProp({
|
|
25
|
-
defaultValue: "checkboxRowValue",
|
|
26
|
-
valuePropName: "value",
|
|
27
|
-
handlerPropName: "onPress",
|
|
28
|
-
}),
|
|
29
29
|
color: createColorProp({
|
|
30
30
|
description: "Color for the button (used when the checkbox is checked)",
|
|
31
31
|
}),
|
|
@@ -33,5 +33,24 @@ export const SEED_DATA = {
|
|
|
33
33
|
label: "Unselected Color",
|
|
34
34
|
description: "Color for the button when the checkbox is unchecked",
|
|
35
35
|
}),
|
|
36
|
+
disabled: createBoolProp({
|
|
37
|
+
label: "Disabled",
|
|
38
|
+
description: "Whether the checkbox is disabled",
|
|
39
|
+
}),
|
|
40
|
+
size: createStaticNumberProp({
|
|
41
|
+
label: "Size",
|
|
42
|
+
description: "Specifies the size of the icon",
|
|
43
|
+
defaultValue: null,
|
|
44
|
+
}),
|
|
45
|
+
checkedIcon: createIconProp({
|
|
46
|
+
label: "Checked Icon",
|
|
47
|
+
description: 'Icon to show when the checkbox status is "checked"',
|
|
48
|
+
defaultValue: null,
|
|
49
|
+
}),
|
|
50
|
+
uncheckedIcon: createIconProp({
|
|
51
|
+
label: "Unchecked Icon",
|
|
52
|
+
description: 'Icon to show when the checkbox status is "unchecked"',
|
|
53
|
+
defaultValue: null,
|
|
54
|
+
}),
|
|
36
55
|
},
|
|
37
56
|
};
|