@draftbit/core 43.4.4 → 43.4.5-ccf125.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.
- package/lib/commonjs/components/Accordion/AccordionItem.js +21 -5
- package/lib/commonjs/components/Accordion/AccordionItem.js.map +1 -1
- package/lib/commonjs/components/CardInline.js.map +1 -1
- package/lib/commonjs/components/DatePicker/DatePickerComponent.js.map +1 -1
- package/lib/commonjs/components/FieldSearchBarFull.js.map +1 -1
- package/lib/commonjs/components/FormRow.js +5 -18
- package/lib/commonjs/components/FormRow.js.map +1 -1
- package/lib/commonjs/components/NumberInput.js +4 -13
- package/lib/commonjs/components/NumberInput.js.map +1 -1
- package/lib/commonjs/components/Picker/PickerComponent.android.js +6 -20
- package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
- package/lib/commonjs/components/Portal/PortalManager.js.map +1 -1
- package/lib/commonjs/components/RadioButton/RadioButton.js +9 -6
- package/lib/commonjs/components/RadioButton/RadioButton.js.map +1 -1
- package/lib/commonjs/components/RadioButton/RadioButtonGroup.js +18 -8
- package/lib/commonjs/components/RadioButton/RadioButtonGroup.js.map +1 -1
- package/lib/commonjs/components/RadioButton/RadioButtonRow.js +14 -9
- package/lib/commonjs/components/RadioButton/RadioButtonRow.js.map +1 -1
- package/lib/commonjs/components/RadioButton/index.js.map +1 -1
- package/lib/commonjs/components/ResizeMode.js +1 -2
- package/lib/commonjs/components/Swiper/Swiper.js.map +1 -1
- package/lib/commonjs/components/Touchable.js +3 -16
- package/lib/commonjs/components/Touchable.js.map +1 -1
- package/lib/commonjs/mappings/SafeAreaView.js.map +1 -1
- package/lib/commonjs/mappings/StarRating.js +2 -6
- package/lib/commonjs/mappings/StarRating.js.map +1 -1
- package/lib/commonjs/mappings/Surface.js.map +1 -1
- package/lib/commonjs/mappings/WebView.js.map +1 -1
- package/lib/commonjs/utilities.js +16 -0
- package/lib/commonjs/utilities.js.map +1 -1
- package/lib/module/components/DatePicker/DatePickerComponentType.js.map +1 -1
- package/lib/module/components/Header.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButton.js +8 -6
- package/lib/module/components/RadioButton/RadioButton.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButtonGroup.js +17 -8
- package/lib/module/components/RadioButton/RadioButtonGroup.js.map +1 -1
- package/lib/module/components/RadioButton/RadioButtonRow.js +15 -10
- package/lib/module/components/RadioButton/RadioButtonRow.js.map +1 -1
- package/lib/module/mappings/ImageBackground.js.map +1 -1
- package/lib/module/mappings/KeyboardAvoidingView.js.map +1 -1
- package/lib/module/utilities.js +14 -0
- package/lib/module/utilities.js.map +1 -1
- package/lib/typescript/src/components/RadioButton/RadioButton.d.ts +1 -1
- package/lib/typescript/src/components/RadioButton/RadioButtonGroup.d.ts +1 -1
- package/lib/typescript/src/utilities.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/RadioButton/RadioButton.js +9 -5
- package/src/components/RadioButton/RadioButton.tsx +12 -9
- package/src/components/RadioButton/RadioButtonGroup.js +14 -8
- package/src/components/RadioButton/RadioButtonGroup.tsx +21 -12
- package/src/components/RadioButton/RadioButtonRow.js +15 -9
- package/src/components/RadioButton/RadioButtonRow.tsx +19 -13
- package/src/utilities.js +12 -0
- package/src/utilities.ts +13 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["KeyboardAvoidingView.
|
|
1
|
+
{"version":3,"sources":["KeyboardAvoidingView.js"],"names":["COMPONENT_TYPES","FORM_TYPES","PROP_TYPES","GROUPS","SEED_DATA","name","tag","description","category","layout","props","enabled","label","editable","required","defaultValue","formType","boolean","propType","BOOLEAN","group","basic","behavior","options","flatArray","STRING","keyboardVerticalOffset","number","NUMBER"],"mappings":"AAAA,SAASA,eAAT,EAA0BC,UAA1B,EAAsCC,UAAtC,EAAkDC,MAAlD,QAAiE,iBAAjE;AACA,OAAO,MAAMC,SAAS,GAAG;AACrBC,EAAAA,IAAI,EAAE,wBADe;AAErBC,EAAAA,GA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ALc,CAAlB","sourcesContent":["import { COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, GROUPS, } from \"@draftbit/types\";\nexport const SEED_DATA = {\n name: \"Keyboard Avoiding View\",\n tag: \"KeyboardAvoidingView\",\n description: \"View that moves out of the way of the virtual keyboard. \",\n category: COMPONENT_TYPES.layout,\n props: {\n enabled: {\n label: \"Enable\",\n description: \"Enable the keyboard avoiding view\",\n editable: true,\n required: true,\n defaultValue: true,\n formType: FORM_TYPES.boolean,\n propType: PROP_TYPES.BOOLEAN,\n group: GROUPS.basic,\n },\n behavior: {\n label: \"Resizing Behavior\",\n description: \"The behavior for how the keyboard resizing interacts with the rest of the screen. (Default: padding).\",\n editable: true,\n required: true,\n defaultValue: \"padding\",\n options: [\"padding\", \"position\", \"height\"],\n formType: FORM_TYPES.flatArray,\n propType: PROP_TYPES.STRING,\n group: GROUPS.basic,\n },\n keyboardVerticalOffset: {\n label: \"Keyboard Vertical Offset\",\n description: \"The distance between the bottom of the view and the keyboard\",\n editable: true,\n required: false,\n defaultValue: 0,\n formType: FORM_TYPES.number,\n propType: PROP_TYPES.NUMBER,\n group: GROUPS.basic,\n },\n },\n};\n"]}
|
package/lib/module/utilities.js
CHANGED
|
@@ -60,4 +60,18 @@ export function applyStyles(baseStyles, stylesToApply) {
|
|
|
60
60
|
|
|
61
61
|
return flattenedStyles;
|
|
62
62
|
}
|
|
63
|
+
export function getRealValue(value) {
|
|
64
|
+
// console.log("getRealValue typeof", typeof value);
|
|
65
|
+
// console.log("getRealValue value", value);
|
|
66
|
+
switch (typeof value) {
|
|
67
|
+
case "string":
|
|
68
|
+
return value;
|
|
69
|
+
|
|
70
|
+
case "number":
|
|
71
|
+
return String(value);
|
|
72
|
+
|
|
73
|
+
default:
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
63
77
|
//# sourceMappingURL=utilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["utilities.ts"],"names":["StyleSheet","extractStyles","style","color","fontFamily","fontWeight","fontSize","lineHeight","letterSpacing","textTransform","textAlign","textDecorationLine","textDecorationColor","textDecorationStyle","viewStyles","flatten","textStyles","applyStyles","baseStyles","stylesToApply","flattenedStyles","key","value","Object","entries"],"mappings":"AAAA,SAASA,UAAT,QAAiD,cAAjD;AAEA,OAAO,SAASC,aAAT,CAAuBC,KAAvB,EAA8C;AACnD,QAAM;AACJC,IAAAA,KADI;AAEJC,IAAAA,UAFI;AAGJC,IAAAA,UAHI;AAIJC,IAAAA,QAJI;AAKJC,IAAAA,UALI;AAMJC,IAAAA,aANI;AAOJC,IAAAA,aAPI;AAQJC,IAAAA,SARI;AASJC,IAAAA,kBATI;AAUJC,IAAAA,mBAVI;AAWJC,IAAAA,mBAXI;AAYJ,OAAGC;AAZC,MAaFd,UAAU,CAACe,OAAX,CAAmBb,KAAK,IAAI,EAA5B,CAbJ;AAeA,QAAMc,UAAqB,GAAG;AAC5Bb,IAAAA,KAD4B;AAE5BC,IAAAA,UAF4B;AAG5BC,IAAAA,UAH4B;AAI5BC,IAAAA,QAJ4B;AAK5BC,IAAAA,UAL4B;AAM5BC,IAAAA,aAN4B;AAO5BC,IAAAA,aAP4B;AAQ5BC,IAAAA,SAR4B;AAS5BC,IAAAA,kBAT4B;AAU5BC,IAAAA,mBAV4B;AAW5BC,IAAAA;AAX4B,GAA9B;AAcA,SAAO;AAAEC,IAAAA,UAAF;AAAcE,IAAAA;AAAd,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,WAAT,CACLC,UADK,EAELC,aAFK,EAGL;AACA,MAAI,CAACA,aAAL,EAAoB;AAClB;AACD;;AAED,QAAMC,eAAe,GAAGpB,UAAU,CAACe,OAAX,CAAmBG,UAAnB,CAAxB;;AAEA,OAAK,MAAM,CAACG,GAAD,EAAMC,KAAN,CAAX,IAA2BC,MAAM,CAACC,OAAP,CAAeL,aAAf,CAA3B,EAA0D;AACxD,QAAIG,KAAK,IAAI,IAAb,EAAmB;AACjBF,MAAAA,eAAe,CAACC,GAAD,CAAf,GAAuBC,KAAvB;AACD;AACF;;AAED,SAAOF,eAAP;AACD","sourcesContent":["import { StyleSheet, StyleProp, TextStyle } from \"react-native\";\n\nexport function extractStyles(style: StyleProp<any>) {\n const {\n color,\n fontFamily,\n fontWeight,\n fontSize,\n lineHeight,\n letterSpacing,\n textTransform,\n textAlign,\n textDecorationLine,\n textDecorationColor,\n textDecorationStyle,\n ...viewStyles\n } = StyleSheet.flatten(style || {});\n\n const textStyles: TextStyle = {\n color,\n fontFamily,\n fontWeight,\n fontSize,\n lineHeight,\n letterSpacing,\n textTransform,\n textAlign,\n textDecorationLine,\n textDecorationColor,\n textDecorationStyle,\n };\n\n return { viewStyles, textStyles };\n}\n\n/**\n * Merges a style object on top of another style object. In React Native,\n * keys with undefined values in a style object will still override styles\n * that appear earlier in a sequence. This avoids that problem.\n *\n * This lets us avoid the `...(something ? { something } : {})` pattern.\n * There doesn't seem to be a better way to do this. These all seem to not\n * work (i.e. they all result in `{ color: undefined }`:\n * `const mergedStyles = [{ color: \"red\" }, { color: undefined }]`\n * `const mergedStyles = StyleSheet.compose({ color: \"red\" }, { color: undefined })`\n * `const mergedStyles = StyleSheet.flatten([{ color: \"red\" }, { color: undefined }])`\n */\nexport function applyStyles(\n baseStyles: Array<StyleProp<any>>,\n stylesToApply: StyleProp<any> | undefined\n) {\n if (!stylesToApply) {\n return;\n }\n\n const flattenedStyles = StyleSheet.flatten(baseStyles);\n\n for (const [key, value] of Object.entries(stylesToApply)) {\n if (value != null) {\n flattenedStyles[key] = value;\n }\n }\n\n return flattenedStyles;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["utilities.ts"],"names":["StyleSheet","extractStyles","style","color","fontFamily","fontWeight","fontSize","lineHeight","letterSpacing","textTransform","textAlign","textDecorationLine","textDecorationColor","textDecorationStyle","viewStyles","flatten","textStyles","applyStyles","baseStyles","stylesToApply","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eAAP;AACD;AAED,OAAO,SAASK,YAAT,CAAsBH,KAAtB,EAAkC;AACvC;AACA;AACA,UAAQ,OAAOA,KAAf;AACE,SAAK,QAAL;AACE,aAAOA,KAAP;;AACF,SAAK,QAAL;AACE,aAAOI,MAAM,CAACJ,KAAD,CAAb;;AACF;AACE,aAAOK,SAAP;AANJ;AAQD","sourcesContent":["import { StyleSheet, StyleProp, TextStyle } from \"react-native\";\n\nexport function extractStyles(style: StyleProp<any>) {\n const {\n color,\n fontFamily,\n fontWeight,\n fontSize,\n lineHeight,\n letterSpacing,\n textTransform,\n textAlign,\n textDecorationLine,\n textDecorationColor,\n textDecorationStyle,\n ...viewStyles\n } = StyleSheet.flatten(style || {});\n\n const textStyles: TextStyle = {\n color,\n fontFamily,\n fontWeight,\n fontSize,\n lineHeight,\n letterSpacing,\n textTransform,\n textAlign,\n textDecorationLine,\n textDecorationColor,\n textDecorationStyle,\n };\n\n return { viewStyles, textStyles };\n}\n\n/**\n * Merges a style object on top of another style object. In React Native,\n * keys with undefined values in a style object will still override styles\n * that appear earlier in a sequence. This avoids that problem.\n *\n * This lets us avoid the `...(something ? { something } : {})` pattern.\n * There doesn't seem to be a better way to do this. These all seem to not\n * work (i.e. they all result in `{ color: undefined }`:\n * `const mergedStyles = [{ color: \"red\" }, { color: undefined }]`\n * `const mergedStyles = StyleSheet.compose({ color: \"red\" }, { color: undefined })`\n * `const mergedStyles = StyleSheet.flatten([{ color: \"red\" }, { color: undefined }])`\n */\nexport function applyStyles(\n baseStyles: Array<StyleProp<any>>,\n stylesToApply: StyleProp<any> | undefined\n) {\n if (!stylesToApply) {\n return;\n }\n\n const flattenedStyles = StyleSheet.flatten(baseStyles);\n\n for (const [key, value] of Object.entries(stylesToApply)) {\n if (value != null) {\n flattenedStyles[key] = value;\n }\n }\n\n return flattenedStyles;\n}\n\nexport function getRealValue(value: any) {\n // console.log(\"getRealValue typeof\", typeof value);\n // console.log(\"getRealValue value\", value);\n switch (typeof value) {\n case \"string\":\n return value;\n case \"number\":\n return String(value);\n default:\n return undefined;\n }\n}\n"]}
|
|
@@ -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.
|
|
3
|
+
"version": "43.4.5-ccf125.1+ccf12583",
|
|
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": "
|
|
83
|
+
"gitHead": "ccf12583c8865a81ca50d7e0cd9e2057560f089b"
|
|
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
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
onValueChange(
|
|
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
|
|
40
|
-
|
|
40
|
+
const realValue = getRealValue(value);
|
|
41
|
+
const realContextValue = getRealValue(contextValue);
|
|
42
|
+
const isSelected =
|
|
43
|
+
selected ??
|
|
44
|
+
(realContextValue && realValue && realContextValue === realValue);
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
6
|
-
const [internalValue, setInternalValue] = React.useState(
|
|
6
|
+
const RadioButtonGroup = ({ direction = Direction.Vertical, value, onValueChange, defaultValue, style, children, ...rest }) => {
|
|
7
|
+
const [internalValue, setInternalValue] = React.useState();
|
|
7
8
|
React.useEffect(() => {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const realValue = getRealValue(value);
|
|
10
|
+
if (realValue) {
|
|
11
|
+
setInternalValue(realValue);
|
|
10
12
|
}
|
|
11
13
|
}, [value]);
|
|
12
14
|
React.useEffect(() => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const realDefaultValue = getRealValue(defaultValue);
|
|
16
|
+
if (realDefaultValue) {
|
|
17
|
+
setInternalValue(realDefaultValue);
|
|
15
18
|
}
|
|
16
19
|
}, [defaultValue]);
|
|
17
20
|
const handleValueChange = (newValue) => {
|
|
18
|
-
|
|
19
|
-
|
|
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<
|
|
27
|
-
|
|
28
|
-
);
|
|
27
|
+
const [internalValue, setInternalValue] = React.useState<
|
|
28
|
+
string | undefined
|
|
29
|
+
>();
|
|
29
30
|
|
|
30
31
|
React.useEffect(() => {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const realValue = getRealValue(value);
|
|
33
|
+
|
|
34
|
+
if (realValue) {
|
|
35
|
+
setInternalValue(realValue);
|
|
33
36
|
}
|
|
34
37
|
}, [value]);
|
|
35
38
|
|
|
36
39
|
React.useEffect(() => {
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const realDefaultValue = getRealValue(defaultValue);
|
|
41
|
+
|
|
42
|
+
if (realDefaultValue) {
|
|
43
|
+
setInternalValue(realDefaultValue);
|
|
39
44
|
}
|
|
40
45
|
}, [defaultValue]);
|
|
41
46
|
|
|
42
|
-
const handleValueChange = (newValue:
|
|
43
|
-
|
|
44
|
-
|
|
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 = (
|
|
26
|
-
if (typeof
|
|
27
|
-
return React.createElement(Text, { style: [labelStyle, textStyle] },
|
|
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,
|
|
30
|
+
return React.createElement(React.Fragment, null, label);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
const RadioButtonRow = ({ Icon, label, value, color, unselectedColor, onPress
|
|
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
|
-
|
|
37
|
-
|
|
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:
|
|
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
|
-
|
|
49
|
+
label: string | React.ReactNode,
|
|
50
50
|
labelStyle: StyleProp<TextStyle>,
|
|
51
51
|
textStyle: StyleProp<TextStyle>
|
|
52
52
|
) => {
|
|
53
|
-
if (typeof
|
|
54
|
-
return <Text style={[labelStyle, textStyle]}>{
|
|
53
|
+
if (typeof label === "string") {
|
|
54
|
+
return <Text style={[labelStyle, textStyle]}>{label}</Text>;
|
|
55
55
|
} else {
|
|
56
|
-
return <>{
|
|
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
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
+
}
|