From 15e82588b5e7085fcaa8ad1072c6179fdc4319ca Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Fri, 20 Oct 2023 16:05:37 +0200 Subject: [PATCH 1/8] WIP TS migration --- .../{RadioButton.js => RadioButton.tsx} | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) rename src/components/{RadioButton.js => RadioButton.tsx} (61%) diff --git a/src/components/RadioButton.js b/src/components/RadioButton.tsx similarity index 61% rename from src/components/RadioButton.js rename to src/components/RadioButton.tsx index 726afd609588..1819975bb1cf 100644 --- a/src/components/RadioButton.js +++ b/src/components/RadioButton.tsx @@ -29,17 +29,34 @@ const defaultProps = { disabled: false, }; -function RadioButton(props) { +type RadioButtonProps = { + /** Whether radioButton is checked */ + isChecked: boolean; + + /** A function that is called when the box/label is pressed */ + onPress: () => void; + + /** Specifies the accessibility label for the radio button */ + accessibilityLabel: string; + + /** Should the input be styled for errors */ + hasError: boolean; + + /** Should the input be disabled */ + disabled: boolean; +} + +function RadioButton({accessibilityLabel, disabled = false, hasError = false, isChecked, onPress}: RadioButtonProps) { return ( - + Date: Wed, 8 Nov 2023 09:03:33 +0100 Subject: [PATCH 2/8] Optional props --- src/components/RadioButton.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index 1819975bb1cf..ee6c478408ec 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -40,13 +40,13 @@ type RadioButtonProps = { accessibilityLabel: string; /** Should the input be styled for errors */ - hasError: boolean; + hasError?: boolean; /** Should the input be disabled */ - disabled: boolean; + disabled?: boolean; } -function RadioButton({accessibilityLabel, disabled = false, hasError = false, isChecked, onPress}: RadioButtonProps) { +function RadioButton({isChecked, onPress = () => undefined, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { return ( Date: Wed, 8 Nov 2023 09:03:56 +0100 Subject: [PATCH 3/8] Drop propTypes and defaultProps --- src/components/RadioButton.tsx | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index ee6c478408ec..b2a37488fd72 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -1,34 +1,11 @@ import React from 'react'; import {View} from 'react-native'; -import PropTypes from 'prop-types'; import styles from '../styles/styles'; import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import PressableWithFeedback from './Pressable/PressableWithFeedback'; import CONST from '../CONST'; -const propTypes = { - /** Whether radioButton is checked */ - isChecked: PropTypes.bool.isRequired, - - /** A function that is called when the box/label is pressed */ - onPress: PropTypes.func.isRequired, - - /** Specifies the accessibility label for the radio button */ - accessibilityLabel: PropTypes.string.isRequired, - - /** Should the input be styled for errors */ - hasError: PropTypes.bool, - - /** Should the input be disabled */ - disabled: PropTypes.bool, -}; - -const defaultProps = { - hasError: false, - disabled: false, -}; - type RadioButtonProps = { /** Whether radioButton is checked */ isChecked: boolean; From 6324a610e6f7b6397375dca76846c7ea26b6fd33 Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Wed, 8 Nov 2023 12:36:46 +0100 Subject: [PATCH 4/8] Missing semicolon --- src/components/RadioButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index d5c3830366f8..1d9bd2907936 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -21,7 +21,7 @@ type RadioButtonProps = { /** Should the input be disabled */ disabled?: boolean; -} +}; function RadioButton({isChecked, onPress = () => undefined, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { return ( From 46f1132e29a3e97dc9615b1b2fd2bb514ef6db4e Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Wed, 8 Nov 2023 14:45:18 +0100 Subject: [PATCH 5/8] onPress should be optional --- src/components/RadioButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index 1d9bd2907936..452544b858a1 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -11,7 +11,7 @@ type RadioButtonProps = { isChecked: boolean; /** A function that is called when the box/label is pressed */ - onPress: () => void; + onPress?: () => void; /** Specifies the accessibility label for the radio button */ accessibilityLabel: string; From 838f2e27eccae8d4d50ff6802ef3c329279fdbdb Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Mon, 20 Nov 2023 19:34:43 +0100 Subject: [PATCH 6/8] Make onPress required --- src/components/RadioButton.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index 101807f4c162..f89c06356c15 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -12,7 +12,7 @@ type RadioButtonProps = { isChecked: boolean; /** A function that is called when the box/label is pressed */ - onPress?: () => void; + onPress: () => void; /** Specifies the accessibility label for the radio button */ accessibilityLabel: string; @@ -24,7 +24,7 @@ type RadioButtonProps = { disabled?: boolean; }; -function RadioButton({isChecked, onPress = () => undefined, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { +function RadioButton({isChecked, onPress, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { const theme = useTheme(); const styles = useThemeStyles(); From c2f7796d2e3094a7a0a376ae412218acc4c02b57 Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Mon, 20 Nov 2023 19:35:07 +0100 Subject: [PATCH 7/8] Restore displayName --- src/components/RadioButton.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index f89c06356c15..cb98df9afffb 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -51,4 +51,6 @@ function RadioButton({isChecked, onPress, accessibilityLabel, disabled = false, ); } +RadioButton.displayName = 'RadioButton'; + export default RadioButton; From 56a48416846cda7adb38be644ade166485c2e1ab Mon Sep 17 00:00:00 2001 From: Maciej Dobosz Date: Fri, 24 Nov 2023 13:32:31 +0100 Subject: [PATCH 8/8] Reorder props --- src/components/RadioButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/RadioButton.tsx b/src/components/RadioButton.tsx index cb98df9afffb..b5e0467d3f00 100644 --- a/src/components/RadioButton.tsx +++ b/src/components/RadioButton.tsx @@ -24,7 +24,7 @@ type RadioButtonProps = { disabled?: boolean; }; -function RadioButton({isChecked, onPress, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { +function RadioButton({isChecked, onPress, accessibilityLabel, hasError = false, disabled = false}: RadioButtonProps) { const theme = useTheme(); const styles = useThemeStyles();