@draftbit/core 43.4.11-ca8fc3.1 → 43.4.12
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/Accordion/AccordionItem.js +5 -21
- package/lib/commonjs/components/Accordion/AccordionItem.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 +55 -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/FAB.js +5 -19
- package/lib/commonjs/components/FAB.js.map +1 -1
- package/lib/commonjs/components/NumberInput.js +15 -17
- package/lib/commonjs/components/NumberInput.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/TextField.js +8 -5
- package/lib/commonjs/components/TextField.js.map +1 -1
- package/lib/commonjs/mappings/CheckboxRow.js +25 -6
- package/lib/commonjs/mappings/CheckboxRow.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 +53 -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/NumberInput.js +15 -17
- package/lib/module/components/NumberInput.js.map +1 -1
- package/lib/module/components/Picker/PickerComponent.ios.js +29 -10
- package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -1
- package/lib/module/components/Picker/PickerTypes.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/TextField.js +8 -5
- package/lib/module/components/TextField.js.map +1 -1
- package/lib/module/components/Touchable.web.js.map +1 -1
- package/lib/module/components/Typography.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 +67 -62
- package/src/components/DatePicker/DatePicker.js +2 -4
- package/src/components/DatePicker/DatePicker.tsx +1 -14
- package/src/components/NumberInput.js +13 -14
- package/src/components/NumberInput.tsx +16 -31
- package/src/components/RadioButton/RadioButtonRow.js +1 -1
- package/src/components/RadioButton/RadioButtonRow.tsx +1 -1
- package/src/components/TextField.js +5 -4
- package/src/components/TextField.tsx +6 -5
- package/src/mappings/CheckboxRow.js +26 -7
- package/src/mappings/CheckboxRow.ts +28 -6
|
@@ -3,7 +3,7 @@ import { View, StyleSheet, } from "react-native";
|
|
|
3
3
|
import { useTheme } from "../../theming";
|
|
4
4
|
import Touchable from "../Touchable";
|
|
5
5
|
import { usePrevious } from "../../hooks";
|
|
6
|
-
const Checkbox = ({ Icon, status, disabled = false, onPress
|
|
6
|
+
const Checkbox = ({ Icon, status, disabled = false, onPress, onCheck, onUncheck, color, uncheckedColor, defaultValue, checkedIcon = "MaterialCommunityIcons/checkbox-marked", uncheckedIcon = "MaterialCommunityIcons/checkbox-blank-outline", size = 24, style, ...rest }) => {
|
|
7
7
|
const [internalValue, setInternalValue] = React.useState(status || defaultValue || false);
|
|
8
8
|
React.useEffect(() => {
|
|
9
9
|
if (status != null) {
|
|
@@ -25,12 +25,12 @@ const Checkbox = ({ Icon, status, disabled = false, onPress = () => { }, onCheck
|
|
|
25
25
|
const handlePress = () => {
|
|
26
26
|
const newValue = !internalValue;
|
|
27
27
|
setInternalValue(newValue);
|
|
28
|
-
onPress(newValue);
|
|
29
|
-
if (
|
|
30
|
-
onCheck();
|
|
28
|
+
onPress?.(newValue);
|
|
29
|
+
if (newValue) {
|
|
30
|
+
onCheck?.();
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
33
|
-
onUncheck();
|
|
32
|
+
if (!newValue) {
|
|
33
|
+
onUncheck?.();
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
return (React.createElement(Touchable, { ...rest, onPress: handlePress, disabled: disabled, accessibilityState: { disabled }, accessibilityRole: "button", accessibilityLiveRegion: "polite", style: [styles.container, style, { width: size, height: size }] },
|
|
@@ -32,7 +32,7 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
32
32
|
Icon,
|
|
33
33
|
status,
|
|
34
34
|
disabled = false,
|
|
35
|
-
onPress
|
|
35
|
+
onPress,
|
|
36
36
|
onCheck,
|
|
37
37
|
onUncheck,
|
|
38
38
|
color,
|
|
@@ -59,6 +59,7 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
59
59
|
const previousDefaultValue = usePrevious(defaultValue) as
|
|
60
60
|
| boolean
|
|
61
61
|
| undefined;
|
|
62
|
+
|
|
62
63
|
React.useEffect(() => {
|
|
63
64
|
if (defaultValue !== previousDefaultValue) {
|
|
64
65
|
setInternalValue(Boolean(defaultValue));
|
|
@@ -73,15 +74,16 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
|
|
|
73
74
|
|
|
74
75
|
const handlePress = () => {
|
|
75
76
|
const newValue = !internalValue;
|
|
77
|
+
|
|
76
78
|
setInternalValue(newValue);
|
|
77
|
-
onPress(newValue);
|
|
79
|
+
onPress?.(newValue);
|
|
78
80
|
|
|
79
|
-
if (
|
|
80
|
-
onCheck();
|
|
81
|
+
if (newValue) {
|
|
82
|
+
onCheck?.();
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
if (
|
|
84
|
-
onUncheck();
|
|
85
|
+
if (!newValue) {
|
|
86
|
+
onUncheck?.();
|
|
85
87
|
}
|
|
86
88
|
};
|
|
87
89
|
|
|
@@ -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, onPress: handlePress, 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,21 @@ 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
|
+
onPress={handlePress}
|
|
127
|
+
color={color}
|
|
128
|
+
uncheckedColor={uncheckedColor}
|
|
129
|
+
checkedIcon={checkedIcon}
|
|
130
|
+
uncheckedIcon={uncheckedIcon}
|
|
131
|
+
size={size}
|
|
132
|
+
/>
|
|
128
133
|
</Touchable>
|
|
129
134
|
);
|
|
130
135
|
};
|
|
@@ -136,7 +141,7 @@ const styles = StyleSheet.create({
|
|
|
136
141
|
paddingStart: 20,
|
|
137
142
|
minHeight: 50,
|
|
138
143
|
paddingEnd: 20,
|
|
139
|
-
|
|
144
|
+
display: "flex",
|
|
140
145
|
...Platform.select({
|
|
141
146
|
web: {
|
|
142
147
|
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
|
}}
|