@draftbit/core 43.4.4 → 43.4.5-958f08.1

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 (51) hide show
  1. package/lib/commonjs/components/Accordion/index.js.map +1 -1
  2. package/lib/commonjs/components/CardInline.js.map +1 -1
  3. package/lib/commonjs/components/FieldSearchBarFull.js.map +1 -1
  4. package/lib/commonjs/components/FormRow.js +5 -18
  5. package/lib/commonjs/components/FormRow.js.map +1 -1
  6. package/lib/commonjs/components/NumberInput.js +4 -13
  7. package/lib/commonjs/components/NumberInput.js.map +1 -1
  8. package/lib/commonjs/components/Picker/PickerComponent.android.js +6 -20
  9. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  10. package/lib/commonjs/components/Portal/PortalConsumer.js.map +1 -1
  11. package/lib/commonjs/components/Portal/PortalManager.js.map +1 -1
  12. package/lib/commonjs/components/RadioButton/RadioButton.js +9 -6
  13. package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
  14. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js +18 -8
  15. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js.map +1 -1
  16. package/lib/commonjs/components/RadioButton/RadioButtonRow.js +14 -9
  17. package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
  18. package/lib/commonjs/components/RadioButton/index.js.map +1 -1
  19. package/lib/commonjs/components/ResizeMode.js +1 -2
  20. package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
  21. package/lib/commonjs/components/Touchable.js +3 -16
  22. package/lib/commonjs/components/Touchable.js.map +1 -1
  23. package/lib/commonjs/mappings/RowHeadlineImageIcon.js.map +1 -1
  24. package/lib/commonjs/mappings/SafeAreaView.js.map +1 -1
  25. package/lib/commonjs/mappings/StarRating.js +2 -6
  26. package/lib/commonjs/mappings/StarRating.js.map +1 -1
  27. package/lib/commonjs/mappings/Surface.js.map +1 -1
  28. package/lib/commonjs/mappings/WebView.js.map +1 -1
  29. package/lib/commonjs/utilities.js +16 -0
  30. package/lib/commonjs/utilities.js.map +1 -1
  31. package/lib/module/components/Header.js.map +1 -1
  32. package/lib/module/components/RadioButton/RadioButton.js +8 -6
  33. package/lib/module/components/RadioButton/RadioButton.js.map +1 -1
  34. package/lib/module/components/RadioButton/RadioButtonGroup.js +17 -8
  35. package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
  36. package/lib/module/components/RadioButton/RadioButtonRow.js +15 -10
  37. package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
  38. package/lib/module/utilities.js +14 -0
  39. package/lib/module/utilities.js.map +1 -1
  40. package/lib/typescript/src/components/RadioButton/RadioButton.d.ts +1 -1
  41. package/lib/typescript/src/components/RadioButton/RadioButtonGroup.d.ts +1 -1
  42. package/lib/typescript/src/utilities.d.ts +1 -0
  43. package/package.json +2 -2
  44. package/src/components/RadioButton/RadioButton.js +9 -5
  45. package/src/components/RadioButton/RadioButton.tsx +12 -9
  46. package/src/components/RadioButton/RadioButtonGroup.js +14 -8
  47. package/src/components/RadioButton/RadioButtonGroup.tsx +21 -12
  48. package/src/components/RadioButton/RadioButtonRow.js +15 -9
  49. package/src/components/RadioButton/RadioButtonRow.tsx +19 -13
  50. package/src/utilities.js +12 -0
  51. package/src/utilities.ts +13 -0
@@ -16,3 +16,4 @@ export declare function extractStyles(style: StyleProp<any>): {
16
16
  * `const mergedStyles = StyleSheet.flatten([{ color: "red" }, { color: undefined }])`
17
17
  */
18
18
  export declare function applyStyles(baseStyles: Array<StyleProp<any>>, stylesToApply: StyleProp<any> | undefined): any;
19
+ export declare function getRealValue(value: any): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftbit/core",
3
- "version": "43.4.4",
3
+ "version": "43.4.5-958f08.1+958f0845",
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": "39c758981f54b268cc4c58202f077287c99a2e91"
83
+ "gitHead": "958f08459dc0f48d20fb89fa7b9607837796c151"
84
84
  }
@@ -1,16 +1,20 @@
1
1
  import * as React from "react";
2
2
  import Config from "../Config";
3
3
  import IconButton from "../IconButton";
4
+ import { getRealValue } from "../../utilities";
4
5
  import { useRadioButtonGroupContext } from "./context";
5
- const RadioButton = ({ Icon, disabled = false, color, value, selected, unselectedColor, onPress = () => { }, size = Config.radioButtonSize, selectedIcon = "MaterialIcons/radio-button-checked", unselectedIcon = "MaterialIcons/radio-button-unchecked", style, ...rest }) => {
6
+ const RadioButton = ({ Icon, disabled = false, color, value, selected, unselectedColor, onPress, size = Config.radioButtonSize, selectedIcon = "MaterialIcons/radio-button-checked", unselectedIcon = "MaterialIcons/radio-button-unchecked", style, ...rest }) => {
6
7
  const { value: contextValue, onValueChange } = useRadioButtonGroupContext();
8
+ const realValue = getRealValue(value);
9
+ const realContextValue = getRealValue(contextValue);
10
+ const isSelected = selected ??
11
+ (realContextValue && realValue && realContextValue === realValue);
7
12
  const handlePress = () => {
8
- onPress && onPress();
9
- if (onValueChange && value) {
10
- onValueChange(value);
13
+ if (realValue) {
14
+ onPress?.(realValue);
15
+ onValueChange?.(realValue);
11
16
  }
12
17
  };
13
- const isSelected = selected || (contextValue != null && contextValue === value);
14
18
  return (React.createElement(IconButton, { Icon: Icon, icon: isSelected ? selectedIcon : unselectedIcon, color: isSelected ? color : unselectedColor, disabled: disabled, onPress: handlePress, size: size, style: style, ...rest }));
15
19
  };
16
20
  export default RadioButton;
@@ -3,6 +3,7 @@ import { StyleProp, ViewStyle } from "react-native";
3
3
 
4
4
  import Config from "../Config";
5
5
  import IconButton from "../IconButton";
6
+ import { getRealValue } from "../../utilities";
6
7
  import { useRadioButtonGroupContext } from "./context";
7
8
 
8
9
  import type { IconSlot } from "../../interfaces/Icon";
@@ -13,7 +14,7 @@ export type RadioButtonProps = {
13
14
  color?: string;
14
15
  value?: string;
15
16
  unselectedColor?: string;
16
- onPress?: () => void;
17
+ onPress?: (value: string) => void;
17
18
  style?: StyleProp<ViewStyle>;
18
19
  size?: number;
19
20
  selectedIcon?: string;
@@ -27,7 +28,7 @@ const RadioButton: React.FC<RadioButtonProps> = ({
27
28
  value,
28
29
  selected,
29
30
  unselectedColor,
30
- onPress = () => {},
31
+ onPress,
31
32
  size = Config.radioButtonSize,
32
33
  selectedIcon = "MaterialIcons/radio-button-checked",
33
34
  unselectedIcon = "MaterialIcons/radio-button-unchecked",
@@ -36,17 +37,19 @@ const RadioButton: React.FC<RadioButtonProps> = ({
36
37
  }) => {
37
38
  const { value: contextValue, onValueChange } = useRadioButtonGroupContext();
38
39
 
39
- const handlePress = () => {
40
- onPress && onPress();
40
+ const realValue = getRealValue(value);
41
+ const realContextValue = getRealValue(contextValue);
42
+ const isSelected =
43
+ selected ??
44
+ (realContextValue && realValue && realContextValue === realValue);
41
45
 
42
- if (onValueChange && value) {
43
- onValueChange(value);
46
+ const handlePress = () => {
47
+ if (realValue) {
48
+ onPress?.(realValue);
49
+ onValueChange?.(realValue);
44
50
  }
45
51
  };
46
52
 
47
- const isSelected =
48
- selected || (contextValue != null && contextValue === value);
49
-
50
53
  return (
51
54
  <IconButton
52
55
  Icon={Icon}
@@ -1,22 +1,28 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
+ import { getRealValue } from "../../utilities";
3
4
  import { radioButtonGroupContext, Direction } from "./context";
4
5
  const { Provider } = radioButtonGroupContext;
5
- const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange = () => { }, defaultValue, style, children, ...rest }) => {
6
- const [internalValue, setInternalValue] = React.useState(value || defaultValue);
6
+ const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange, defaultValue, style, children, ...rest }) => {
7
+ const [internalValue, setInternalValue] = React.useState();
7
8
  React.useEffect(() => {
8
- if (value != null) {
9
- setInternalValue(value);
9
+ const realValue = getRealValue(value);
10
+ if (realValue) {
11
+ setInternalValue(realValue);
10
12
  }
11
13
  }, [value]);
12
14
  React.useEffect(() => {
13
- if (defaultValue != null) {
14
- setInternalValue(defaultValue);
15
+ const realDefaultValue = getRealValue(defaultValue);
16
+ if (realDefaultValue) {
17
+ setInternalValue(realDefaultValue);
15
18
  }
16
19
  }, [defaultValue]);
17
20
  const handleValueChange = (newValue) => {
18
- setInternalValue(newValue);
19
- onValueChange(newValue);
21
+ const realNewValue = getRealValue(newValue);
22
+ if (realNewValue) {
23
+ setInternalValue(newValue);
24
+ onValueChange?.(newValue);
25
+ }
20
26
  };
21
27
  const _containerStyle = [
22
28
  {
@@ -1,13 +1,14 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleProp, ViewStyle } from "react-native";
3
3
  import type { Theme } from "../../styles/DefaultTheme";
4
+ import { getRealValue } from "../../utilities";
4
5
  import { radioButtonGroupContext, Direction } from "./context";
5
6
  export interface RadioButtonGroupProps {
6
7
  direction?: Direction;
7
8
  style?: StyleProp<ViewStyle>;
8
9
  value?: string;
9
10
  onValueChange?: (value: string) => void;
10
- defaultValue?: string;
11
+ defaultValue?: string | number;
11
12
  theme: Theme;
12
13
  children: React.ReactNode;
13
14
  }
@@ -17,31 +18,39 @@ const { Provider } = radioButtonGroupContext;
17
18
  const RadioButtonGroup: React.FC<RadioButtonGroupProps> = ({
18
19
  direction = Direction.Vertical,
19
20
  value,
20
- onValueChange = () => {},
21
+ onValueChange,
21
22
  defaultValue,
22
23
  style,
23
24
  children,
24
25
  ...rest
25
26
  }) => {
26
- const [internalValue, setInternalValue] = React.useState<string | undefined>(
27
- value || defaultValue
28
- );
27
+ const [internalValue, setInternalValue] = React.useState<
28
+ string | undefined
29
+ >();
29
30
 
30
31
  React.useEffect(() => {
31
- if (value != null) {
32
- setInternalValue(value);
32
+ const realValue = getRealValue(value);
33
+
34
+ if (realValue) {
35
+ setInternalValue(realValue);
33
36
  }
34
37
  }, [value]);
35
38
 
36
39
  React.useEffect(() => {
37
- if (defaultValue != null) {
38
- setInternalValue(defaultValue);
40
+ const realDefaultValue = getRealValue(defaultValue);
41
+
42
+ if (realDefaultValue) {
43
+ setInternalValue(realDefaultValue);
39
44
  }
40
45
  }, [defaultValue]);
41
46
 
42
- const handleValueChange = (newValue: string) => {
43
- setInternalValue(newValue);
44
- onValueChange(newValue);
47
+ const handleValueChange = (newValue: any) => {
48
+ const realNewValue = getRealValue(newValue);
49
+
50
+ if (realNewValue) {
51
+ setInternalValue(newValue);
52
+ onValueChange?.(newValue);
53
+ }
45
54
  };
46
55
 
47
56
  const _containerStyle: StyleProp<ViewStyle> = [
@@ -5,7 +5,7 @@ import Text from "../Text";
5
5
  import { useRadioButtonGroupContext } from "./context";
6
6
  import { Direction as GroupDirection } from "./context";
7
7
  import Touchable from "../Touchable";
8
- import { extractStyles } from "../../utilities";
8
+ import { extractStyles, getRealValue } from "../../utilities";
9
9
  export var Direction;
10
10
  (function (Direction) {
11
11
  Direction["Row"] = "row";
@@ -22,19 +22,25 @@ const getRadioButtonAlignment = (parentDirection, direction) => {
22
22
  return "flex-end";
23
23
  }
24
24
  };
25
- const renderLabel = (value, labelStyle, textStyle) => {
26
- if (typeof value === "string") {
27
- return React.createElement(Text, { style: [labelStyle, textStyle] }, value);
25
+ const renderLabel = (label, labelStyle, textStyle) => {
26
+ if (typeof label === "string") {
27
+ return React.createElement(Text, { style: [labelStyle, textStyle] }, label);
28
28
  }
29
29
  else {
30
- return React.createElement(React.Fragment, null, value);
30
+ return React.createElement(React.Fragment, null, label);
31
31
  }
32
32
  };
33
- const RadioButtonRow = ({ Icon, label, value, color, unselectedColor, onPress = () => { }, labelContainerStyle, labelStyle, radioButtonStyle, direction = Direction.Row, selected, disabled, style, ...rest }) => {
33
+ const RadioButtonRow = ({ Icon, label, value, color, unselectedColor, onPress, labelContainerStyle, labelStyle, radioButtonStyle, direction = Direction.Row, selected, disabled, style, ...rest }) => {
34
34
  const { value: contextValue, onValueChange, direction: parentDirection, } = useRadioButtonGroupContext();
35
+ const realValue = getRealValue(value);
36
+ const realContextValue = getRealValue(contextValue);
37
+ const isSelected = selected ??
38
+ (realContextValue && realValue && realContextValue === realValue);
35
39
  const handlePress = () => {
36
- onPress(value);
37
- onValueChange && onValueChange(value);
40
+ if (realValue) {
41
+ onPress?.(realValue);
42
+ onValueChange?.(realValue);
43
+ }
38
44
  };
39
45
  const { textStyles, viewStyles } = extractStyles(style);
40
46
  return (React.createElement(Touchable, { onPress: handlePress, style: [styles.mainParent, { flexDirection: direction }, viewStyles], disabled: disabled, ...rest },
@@ -49,7 +55,7 @@ const RadioButtonRow = ({ Icon, label, value, color, unselectedColor, onPress =
49
55
  flex: 1,
50
56
  alignItems: getRadioButtonAlignment(parentDirection, direction),
51
57
  } },
52
- React.createElement(RadioButton, { Icon: Icon, selected: selected || (contextValue != null && contextValue === value), color: color, unselectedColor: unselectedColor, onPress: handlePress, style: radioButtonStyle }))));
58
+ React.createElement(RadioButton, { Icon: Icon, selected: isSelected ? true : false, value: realValue, color: color, unselectedColor: unselectedColor, style: radioButtonStyle }))));
53
59
  };
54
60
  const styles = StyleSheet.create({
55
61
  mainParent: {
@@ -13,7 +13,7 @@ import { useRadioButtonGroupContext } from "./context";
13
13
  import type { IconSlot } from "../../interfaces/Icon";
14
14
  import { Direction as GroupDirection } from "./context";
15
15
  import Touchable from "../Touchable";
16
- import { extractStyles } from "../../utilities";
16
+ import { extractStyles, getRealValue } from "../../utilities";
17
17
 
18
18
  export enum Direction {
19
19
  Row = "row",
@@ -22,7 +22,7 @@ export enum Direction {
22
22
 
23
23
  export interface RadioButtonRowProps extends Omit<RadioButtonProps, "onPress"> {
24
24
  label: string | React.ReactNode;
25
- value: string; // A string that this radio button row represents when selected
25
+ value: string; // A string (or number that will be parsed String(number)) that this radio button row represents when selected
26
26
  color?: string;
27
27
  unselectedColor?: string;
28
28
  labelContainerStyle: StyleProp<ViewStyle>;
@@ -46,14 +46,14 @@ const getRadioButtonAlignment = (
46
46
  };
47
47
 
48
48
  const renderLabel = (
49
- value: string | React.ReactNode,
49
+ label: string | React.ReactNode,
50
50
  labelStyle: StyleProp<TextStyle>,
51
51
  textStyle: StyleProp<TextStyle>
52
52
  ) => {
53
- if (typeof value === "string") {
54
- return <Text style={[labelStyle, textStyle]}>{value}</Text>;
53
+ if (typeof label === "string") {
54
+ return <Text style={[labelStyle, textStyle]}>{label}</Text>;
55
55
  } else {
56
- return <>{value}</>;
56
+ return <>{label}</>;
57
57
  }
58
58
  };
59
59
 
@@ -63,7 +63,7 @@ const RadioButtonRow: React.FC<RadioButtonRowProps & IconSlot> = ({
63
63
  value,
64
64
  color,
65
65
  unselectedColor,
66
- onPress = () => {},
66
+ onPress,
67
67
  labelContainerStyle,
68
68
  labelStyle,
69
69
  radioButtonStyle,
@@ -79,9 +79,17 @@ const RadioButtonRow: React.FC<RadioButtonRowProps & IconSlot> = ({
79
79
  direction: parentDirection,
80
80
  } = useRadioButtonGroupContext();
81
81
 
82
+ const realValue = getRealValue(value);
83
+ const realContextValue = getRealValue(contextValue);
84
+ const isSelected =
85
+ selected ??
86
+ (realContextValue && realValue && realContextValue === realValue);
87
+
82
88
  const handlePress = () => {
83
- onPress(value);
84
- onValueChange && onValueChange(value);
89
+ if (realValue) {
90
+ onPress?.(realValue);
91
+ onValueChange?.(realValue);
92
+ }
85
93
  };
86
94
 
87
95
  const { textStyles, viewStyles } = extractStyles(style);
@@ -112,12 +120,10 @@ const RadioButtonRow: React.FC<RadioButtonRowProps & IconSlot> = ({
112
120
  >
113
121
  <RadioButton
114
122
  Icon={Icon}
115
- selected={
116
- selected || (contextValue != null && contextValue === value)
117
- }
123
+ selected={isSelected ? true : false}
124
+ value={realValue}
118
125
  color={color}
119
126
  unselectedColor={unselectedColor}
120
- onPress={handlePress}
121
127
  style={radioButtonStyle}
122
128
  />
123
129
  </View>
package/src/utilities.js CHANGED
@@ -40,3 +40,15 @@ export function applyStyles(baseStyles, stylesToApply) {
40
40
  }
41
41
  return flattenedStyles;
42
42
  }
43
+ export function getRealValue(value) {
44
+ // console.log("getRealValue typeof", typeof value);
45
+ // console.log("getRealValue value", value);
46
+ switch (typeof value) {
47
+ case "string":
48
+ return value;
49
+ case "number":
50
+ return String(value);
51
+ default:
52
+ return undefined;
53
+ }
54
+ }
package/src/utilities.ts CHANGED
@@ -63,3 +63,16 @@ export function applyStyles(
63
63
 
64
64
  return flattenedStyles;
65
65
  }
66
+
67
+ export function getRealValue(value: any) {
68
+ // console.log("getRealValue typeof", typeof value);
69
+ // console.log("getRealValue value", value);
70
+ switch (typeof value) {
71
+ case "string":
72
+ return value;
73
+ case "number":
74
+ return String(value);
75
+ default:
76
+ return undefined;
77
+ }
78
+ }