@draftbit/core 43.4.4-03ab3e.0 → 43.4.5-312b1d.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 (45) hide show
  1. package/lib/commonjs/components/RadioButton/RadioButton.js +9 -6
  2. package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
  3. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js +18 -8
  4. package/lib/commonjs/components/RadioButton/RadioButtonGroup.js.map +1 -1
  5. package/lib/commonjs/components/RadioButton/RadioButtonRow.js +14 -9
  6. package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
  7. package/lib/commonjs/components/StarRating.js +5 -4
  8. package/lib/commonjs/components/StarRating.js.map +1 -1
  9. package/lib/commonjs/components/Touchable.js +3 -16
  10. package/lib/commonjs/components/Touchable.js.map +1 -1
  11. package/lib/commonjs/hooks.js.map +1 -1
  12. package/lib/commonjs/mappings/Accordion.js.map +1 -1
  13. package/lib/commonjs/mappings/LinearGradient.js +2 -2
  14. package/lib/commonjs/mappings/LinearGradient.js.map +1 -1
  15. package/lib/commonjs/utilities.js +15 -0
  16. package/lib/commonjs/utilities.js.map +1 -1
  17. package/lib/module/components/RadioButton/RadioButton.js +8 -6
  18. package/lib/module/components/RadioButton/RadioButton.js.map +1 -1
  19. package/lib/module/components/RadioButton/RadioButtonGroup.js +17 -8
  20. package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
  21. package/lib/module/components/RadioButton/RadioButtonRow.js +15 -10
  22. package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
  23. package/lib/module/components/ResizeMode.js +2 -2
  24. package/lib/module/components/ResizeMode.js.map +1 -1
  25. package/lib/module/components/Swiper/Swiper.js.map +1 -1
  26. package/lib/module/mappings/FAB.js.map +1 -1
  27. package/lib/module/mappings/LinearGradient.js +2 -2
  28. package/lib/module/mappings/LinearGradient.js.map +1 -1
  29. package/lib/module/utilities.js +12 -0
  30. package/lib/module/utilities.js.map +1 -1
  31. package/lib/typescript/src/components/RadioButton/RadioButton.d.ts +2 -2
  32. package/lib/typescript/src/components/RadioButton/RadioButtonGroup.d.ts +1 -1
  33. package/lib/typescript/src/components/RadioButton/RadioButtonRow.d.ts +1 -1
  34. package/lib/typescript/src/utilities.d.ts +1 -0
  35. package/package.json +2 -2
  36. package/src/components/RadioButton/RadioButton.js +9 -5
  37. package/src/components/RadioButton/RadioButton.tsx +13 -10
  38. package/src/components/RadioButton/RadioButtonGroup.js +14 -8
  39. package/src/components/RadioButton/RadioButtonGroup.tsx +21 -12
  40. package/src/components/RadioButton/RadioButtonRow.js +15 -9
  41. package/src/components/RadioButton/RadioButtonRow.tsx +19 -13
  42. package/src/mappings/LinearGradient.js +2 -2
  43. package/src/mappings/LinearGradient.ts +2 -2
  44. package/src/utilities.js +15 -0
  45. package/src/utilities.ts +13 -0
@@ -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, getValueForRadioButton } 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 | number; // 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 = getValueForRadioButton(value);
83
+ const realContextValue = getValueForRadioButton(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>
@@ -67,11 +67,11 @@ export const SEED_DATA = {
67
67
  }),
68
68
  color2: createColorProp({
69
69
  label: "Color 2",
70
- defaultValue: "rgba(251, 252, 253, 1)",
70
+ defaultValue: "secondary",
71
71
  }),
72
72
  color1: createColorProp({
73
73
  label: "Color 1",
74
- defaultValue: "rgba(90, 69, 255, 1)",
74
+ defaultValue: "primary",
75
75
  }),
76
76
  },
77
77
  };
@@ -73,11 +73,11 @@ export const SEED_DATA = {
73
73
  }),
74
74
  color2: createColorProp({
75
75
  label: "Color 2",
76
- defaultValue: "rgba(251, 252, 253, 1)",
76
+ defaultValue: "secondary",
77
77
  }),
78
78
  color1: createColorProp({
79
79
  label: "Color 1",
80
- defaultValue: "rgba(90, 69, 255, 1)",
80
+ defaultValue: "primary",
81
81
  }),
82
82
  },
83
83
  };
package/src/utilities.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { StyleSheet } from "react-native";
2
+ import { isString, isNumber } from "lodash";
2
3
  export function extractStyles(style) {
3
4
  const { color, fontFamily, fontWeight, fontSize, lineHeight, letterSpacing, textTransform, textAlign, textDecorationLine, textDecorationColor, textDecorationStyle, ...viewStyles } = StyleSheet.flatten(style || {});
4
5
  const textStyles = {
@@ -40,3 +41,17 @@ export function applyStyles(baseStyles, stylesToApply) {
40
41
  }
41
42
  return flattenedStyles;
42
43
  }
44
+ export function getValueForRadioButton(value) {
45
+ if (isString(value)) {
46
+ return value;
47
+ }
48
+ else if (isNumber(value)) {
49
+ return String(value);
50
+ }
51
+ else if (value === undefined) {
52
+ return undefined;
53
+ }
54
+ else {
55
+ throw new Error(`Invalid value: ${value}`);
56
+ }
57
+ }
package/src/utilities.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { StyleSheet, StyleProp, TextStyle } from "react-native";
2
+ import { isString, isNumber } from "lodash";
2
3
 
3
4
  export function extractStyles(style: StyleProp<any>) {
4
5
  const {
@@ -63,3 +64,15 @@ export function applyStyles(
63
64
 
64
65
  return flattenedStyles;
65
66
  }
67
+
68
+ export function getValueForRadioButton(value?: string | number) {
69
+ if (isString(value)) {
70
+ return value;
71
+ } else if (isNumber(value)) {
72
+ return String(value);
73
+ } else if (value === undefined) {
74
+ return undefined;
75
+ } else {
76
+ throw new Error(`Invalid value: ${value}`);
77
+ }
78
+ }