@draftbit/core 43.4.11-d2edf8.3 → 43.4.13-33318c.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/lib/commonjs/components/Accordion/AccordionGroup.js +2 -2
  2. package/lib/commonjs/components/Accordion/AccordionGroup.js.map +1 -1
  3. package/lib/commonjs/components/Accordion/AccordionItem.js +21 -5
  4. package/lib/commonjs/components/Accordion/AccordionItem.js.map +1 -1
  5. package/lib/commonjs/components/Checkbox/Checkbox.js +23 -6
  6. package/lib/commonjs/components/Checkbox/Checkbox.js.map +1 -1
  7. package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js +142 -0
  8. package/lib/commonjs/components/Checkbox/CheckboxGroupRow.js.map +1 -0
  9. package/lib/commonjs/components/Checkbox/CheckboxRow.js +55 -46
  10. package/lib/commonjs/components/Checkbox/CheckboxRow.js.map +1 -1
  11. package/lib/commonjs/components/Container.js +14 -0
  12. package/lib/commonjs/components/Container.js.map +1 -1
  13. package/lib/commonjs/components/DatePicker/DatePicker.js +2 -9
  14. package/lib/commonjs/components/DatePicker/DatePicker.js.map +1 -1
  15. package/lib/commonjs/components/Picker/PickerComponent.android.js +20 -6
  16. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  17. package/lib/commonjs/components/RadioButton/RadioButtonRow.js +1 -1
  18. package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
  19. package/lib/commonjs/components/RowBodyIcon.js.map +1 -1
  20. package/lib/commonjs/components/RowHeadlineImageIcon.js.map +1 -1
  21. package/lib/commonjs/components/TextField.js +24 -7
  22. package/lib/commonjs/components/TextField.js.map +1 -1
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/mappings/ActionSheetCancel.js.map +1 -1
  25. package/lib/commonjs/mappings/ActionSheetItem.js.map +1 -1
  26. package/lib/commonjs/mappings/CardContainer.js.map +1 -1
  27. package/lib/commonjs/mappings/Carousel.js.map +1 -1
  28. package/lib/commonjs/mappings/Checkbox.js.map +1 -1
  29. package/lib/commonjs/mappings/CheckboxRow.js +25 -6
  30. package/lib/commonjs/mappings/CheckboxRow.js.map +1 -1
  31. package/lib/commonjs/mappings/ImageBackground.js.map +1 -1
  32. package/lib/commonjs/mappings/MapMarker.js.map +1 -1
  33. package/lib/commonjs/mappings/ProgressBar.js.map +1 -1
  34. package/lib/commonjs/mappings/RowBodyIcon.js.map +1 -1
  35. package/lib/commonjs/mappings/RowHeadlineImageIcon.js.map +1 -1
  36. package/lib/commonjs/mappings/Slider.js.map +1 -1
  37. package/lib/commonjs/theming.js.map +1 -1
  38. package/lib/module/components/Accordion/AccordionGroup.js +2 -2
  39. package/lib/module/components/Accordion/AccordionGroup.js.map +1 -1
  40. package/lib/module/components/Checkbox/Checkbox.js +23 -6
  41. package/lib/module/components/Checkbox/Checkbox.js.map +1 -1
  42. package/lib/module/components/Checkbox/CheckboxGroupRow.js +120 -0
  43. package/lib/module/components/Checkbox/CheckboxGroupRow.js.map +1 -0
  44. package/lib/module/components/Checkbox/CheckboxRow.js +53 -46
  45. package/lib/module/components/Checkbox/CheckboxRow.js.map +1 -1
  46. package/lib/module/components/Container.js +14 -0
  47. package/lib/module/components/Container.js.map +1 -1
  48. package/lib/module/components/DatePicker/DatePicker.js +3 -9
  49. package/lib/module/components/DatePicker/DatePicker.js.map +1 -1
  50. package/lib/module/components/DatePicker/DatePickerComponent.web.js.map +1 -1
  51. package/lib/module/components/RadioButton/RadioButtonRow.js +1 -1
  52. package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
  53. package/lib/module/components/TextField.js +1 -0
  54. package/lib/module/components/TextField.js.map +1 -1
  55. package/lib/module/mappings/CheckboxRow.js +26 -7
  56. package/lib/module/mappings/CheckboxRow.js.map +1 -1
  57. package/lib/typescript/src/components/Checkbox/CheckboxGroupRow.d.ts +21 -0
  58. package/lib/typescript/src/components/Checkbox/CheckboxRow.d.ts +3 -7
  59. package/lib/typescript/src/mappings/CheckboxRow.d.ts +50 -9
  60. package/package.json +2 -2
  61. package/src/components/Accordion/AccordionGroup.js +1 -1
  62. package/src/components/Accordion/AccordionGroup.tsx +1 -1
  63. package/src/components/Checkbox/Checkbox.js +22 -6
  64. package/src/components/Checkbox/Checkbox.tsx +25 -6
  65. package/src/components/Checkbox/CheckboxGroupRow.js +77 -0
  66. package/src/components/Checkbox/CheckboxGroupRow.tsx +152 -0
  67. package/src/components/Checkbox/CheckboxRow.js +33 -32
  68. package/src/components/Checkbox/CheckboxRow.tsx +67 -62
  69. package/src/components/Container.js +13 -0
  70. package/src/components/Container.tsx +14 -0
  71. package/src/components/DatePicker/DatePicker.js +2 -4
  72. package/src/components/DatePicker/DatePicker.tsx +1 -14
  73. package/src/components/RadioButton/RadioButtonRow.js +1 -1
  74. package/src/components/RadioButton/RadioButtonRow.tsx +1 -1
  75. package/src/components/TextField.js +1 -0
  76. package/src/components/TextField.tsx +2 -0
  77. package/src/mappings/CheckboxRow.js +26 -7
  78. package/src/mappings/CheckboxRow.ts +28 -6
@@ -7,6 +7,18 @@ export declare const SEED_DATA: {
7
7
  };
8
8
  triggers: string[];
9
9
  props: {
10
+ fieldName: {
11
+ handlerPropName: string;
12
+ group: string;
13
+ label: string;
14
+ description: string;
15
+ formType: string;
16
+ propType: string;
17
+ defaultValue: string;
18
+ valuePropName: string;
19
+ editable: boolean;
20
+ required: boolean;
21
+ };
10
22
  label: any;
11
23
  labelStyle: {
12
24
  group: string;
@@ -29,19 +41,17 @@ export declare const SEED_DATA: {
29
41
  defaultValue: null;
30
42
  options: never[];
31
43
  };
32
- fieldName: {
33
- handlerPropName: string;
44
+ color: {
34
45
  group: string;
35
46
  label: string;
36
47
  description: string;
37
- formType: string;
38
- propType: string;
39
- defaultValue: string;
40
- valuePropName: string;
41
48
  editable: boolean;
42
49
  required: boolean;
50
+ defaultValue: null;
51
+ formType: string;
52
+ propType: string;
43
53
  };
44
- color: {
54
+ uncheckedColor: {
45
55
  group: string;
46
56
  label: string;
47
57
  description: string;
@@ -51,15 +61,46 @@ export declare const SEED_DATA: {
51
61
  formType: string;
52
62
  propType: string;
53
63
  };
54
- uncheckedColor: {
55
- group: string;
64
+ disabled: {
56
65
  label: string;
57
66
  description: string;
67
+ formType: string;
68
+ propType: string;
69
+ defaultValue: boolean;
58
70
  editable: boolean;
59
71
  required: boolean;
72
+ group: string;
73
+ };
74
+ size: {
75
+ label: string;
76
+ description: string;
77
+ formType: string;
78
+ propType: string;
79
+ group: string;
60
80
  defaultValue: null;
81
+ editable: boolean;
82
+ required: boolean;
83
+ step: number;
84
+ };
85
+ checkedIcon: {
86
+ label: string;
87
+ description: string;
61
88
  formType: string;
62
89
  propType: string;
90
+ defaultValue: string;
91
+ required: boolean;
92
+ editable: boolean;
93
+ group: string;
94
+ };
95
+ uncheckedIcon: {
96
+ label: string;
97
+ description: string;
98
+ formType: string;
99
+ propType: string;
100
+ defaultValue: string;
101
+ required: boolean;
102
+ editable: boolean;
103
+ group: string;
63
104
  };
64
105
  };
65
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftbit/core",
3
- "version": "43.4.11-d2edf8.3+d2edf814",
3
+ "version": "43.4.13-33318c.0+33318c53",
4
4
  "description": "Core (non-native) Components",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -80,5 +80,5 @@
80
80
  ]
81
81
  ]
82
82
  },
83
- "gitHead": "d2edf81446f0e84767bbea7fba1ea857ed1521ef"
83
+ "gitHead": "33318c53ed16ca1a66fd5f43269e5866bf430fbf"
84
84
  }
@@ -18,10 +18,10 @@ const AccordionGroup = ({ Icon, openColor, closedColor, caretColor, icon, iconSi
18
18
  icon ? (React.createElement(Icon, { name: icon, size: iconSize, color: labelColor, style: styles.icon })) : null,
19
19
  React.createElement(View, { style: styles.content },
20
20
  React.createElement(Text, { selectable: false, style: [
21
+ textStyles,
21
22
  {
22
23
  color: labelColor,
23
24
  },
24
- textStyles,
25
25
  ] }, label)),
26
26
  React.createElement(Icon, { name: expanded
27
27
  ? "MaterialIcons/keyboard-arrow-up"
@@ -74,10 +74,10 @@ const AccordionGroup = ({
74
74
  <Text
75
75
  selectable={false}
76
76
  style={[
77
+ textStyles,
77
78
  {
78
79
  color: labelColor,
79
80
  },
80
- textStyles,
81
81
  ]}
82
82
  >
83
83
  {label}
@@ -3,7 +3,23 @@ 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 = () => { }, onCheck, onUncheck, color, uncheckedColor, defaultValue, checkedIcon = "MaterialCommunityIcons/checkbox-marked", uncheckedIcon = "MaterialCommunityIcons/checkbox-blank-outline", size = 24, style, ...rest }) => {
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
+ console.log("Checbox prop", {
8
+ Icon,
9
+ status,
10
+ disabled,
11
+ onPress,
12
+ onCheck,
13
+ onUncheck,
14
+ color,
15
+ uncheckedColor,
16
+ defaultValue,
17
+ checkedIcon,
18
+ uncheckedIcon,
19
+ size,
20
+ style,
21
+ rest: { ...rest },
22
+ });
7
23
  const [internalValue, setInternalValue] = React.useState(status || defaultValue || false);
8
24
  React.useEffect(() => {
9
25
  if (status != null) {
@@ -25,12 +41,12 @@ const Checkbox = ({ Icon, status, disabled = false, onPress = () => { }, onCheck
25
41
  const handlePress = () => {
26
42
  const newValue = !internalValue;
27
43
  setInternalValue(newValue);
28
- onPress(newValue);
29
- if (onCheck && newValue) {
30
- onCheck();
44
+ onPress?.(newValue);
45
+ if (newValue) {
46
+ onCheck?.();
31
47
  }
32
- if (onUncheck && !newValue) {
33
- onUncheck();
48
+ if (!newValue) {
49
+ onUncheck?.();
34
50
  }
35
51
  };
36
52
  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,
@@ -44,6 +44,23 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
44
44
  style,
45
45
  ...rest
46
46
  }) => {
47
+ console.log("Checbox prop", {
48
+ Icon,
49
+ status,
50
+ disabled,
51
+ onPress,
52
+ onCheck,
53
+ onUncheck,
54
+ color,
55
+ uncheckedColor,
56
+ defaultValue,
57
+ checkedIcon,
58
+ uncheckedIcon,
59
+ size,
60
+ style,
61
+ rest: { ...rest },
62
+ });
63
+
47
64
  const [internalValue, setInternalValue] = React.useState<boolean>(
48
65
  status || defaultValue || false
49
66
  );
@@ -59,6 +76,7 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
59
76
  const previousDefaultValue = usePrevious(defaultValue) as
60
77
  | boolean
61
78
  | undefined;
79
+
62
80
  React.useEffect(() => {
63
81
  if (defaultValue !== previousDefaultValue) {
64
82
  setInternalValue(Boolean(defaultValue));
@@ -73,15 +91,16 @@ const Checkbox: React.FC<CheckboxProps & TouchableHighlightProps & IconSlot> =
73
91
 
74
92
  const handlePress = () => {
75
93
  const newValue = !internalValue;
94
+
76
95
  setInternalValue(newValue);
77
- onPress(newValue);
96
+ onPress?.(newValue);
78
97
 
79
- if (onCheck && newValue) {
80
- onCheck();
98
+ if (newValue) {
99
+ onCheck?.();
81
100
  }
82
101
 
83
- if (onUncheck && !newValue) {
84
- onUncheck();
102
+ if (!newValue) {
103
+ onUncheck?.();
85
104
  }
86
105
  };
87
106
 
@@ -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 Checkbox from "./Checkbox";
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 { extractStyles } from "../../utilities";
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 (typeof value === "string") {
27
- return React.createElement(Text, { style: [labelStyle, textStyle] }, value);
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 = ({ 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);
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
- if (!disabled) {
39
- onPress(!isChecked);
40
- onValueChange && onValueChange(value, !isChecked);
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 }, viewStyles], disabled: disabled, ...rest },
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, 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 }))));
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
- flex: 1,
66
+ display: "flex",
66
67
  ...Platform.select({
67
68
  web: {
68
69
  cursor: "pointer",