-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS migration] Migrate RadioButton to Typescript #31050
Merged
stitesExpensify
merged 13 commits into
Expensify:main
from
software-mansion-labs:ts-migration/RadioButton
Nov 27, 2023
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
15e8258
WIP TS migration
MaciejSWM d9e6d23
Optional props
MaciejSWM 46eb799
Drop propTypes and defaultProps
MaciejSWM c7c5cf1
Merge branch 'main' into ts-migration/RadioButton
MaciejSWM 6324a61
Missing semicolon
MaciejSWM 46f1132
onPress should be optional
MaciejSWM 873e587
Merge branch 'main' into ts-migration/RadioButton
MaciejSWM 66284aa
Merge branch 'main' into ts-migration/RadioButton
MaciejSWM 838f2e2
Make onPress required
MaciejSWM c2f7796
Restore displayName
MaciejSWM 6d1a971
Merge branch 'main' into ts-migration/RadioButton
MaciejSWM 56a4841
Reorder props
MaciejSWM 56f326a
Merge branch 'main' into ts-migration/RadioButton
MaciejSWM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import useTheme from '@styles/themes/useTheme'; | ||
|
@@ -8,42 +7,38 @@ import Icon from './Icon'; | |
import * as Expensicons from './Icon/Expensicons'; | ||
import PressableWithFeedback from './Pressable/PressableWithFeedback'; | ||
|
||
const propTypes = { | ||
type RadioButtonProps = { | ||
/** Whether radioButton is checked */ | ||
isChecked: PropTypes.bool.isRequired, | ||
isChecked: boolean; | ||
|
||
/** A function that is called when the box/label is pressed */ | ||
onPress: PropTypes.func.isRequired, | ||
onPress: () => void; | ||
|
||
/** Specifies the accessibility label for the radio button */ | ||
accessibilityLabel: PropTypes.string.isRequired, | ||
accessibilityLabel: string; | ||
|
||
/** Should the input be styled for errors */ | ||
hasError: PropTypes.bool, | ||
hasError?: boolean; | ||
|
||
/** Should the input be disabled */ | ||
disabled: PropTypes.bool, | ||
disabled?: boolean; | ||
}; | ||
|
||
const defaultProps = { | ||
hasError: false, | ||
disabled: false, | ||
}; | ||
|
||
function RadioButton(props) { | ||
function RadioButton({isChecked, onPress, accessibilityLabel, disabled = false, hasError = false}: RadioButtonProps) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
|
||
return ( | ||
<PressableWithFeedback | ||
disabled={props.disabled} | ||
onPress={props.onPress} | ||
disabled={disabled} | ||
onPress={onPress} | ||
hoverDimmingValue={1} | ||
pressDimmingValue={1} | ||
accessibilityLabel={props.accessibilityLabel} | ||
accessibilityLabel={accessibilityLabel} | ||
role={CONST.ACCESSIBILITY_ROLE.RADIO} | ||
> | ||
<View style={[styles.radioButtonContainer, props.hasError && styles.borderColorDanger, props.disabled && styles.cursorDisabled]}> | ||
{props.isChecked && ( | ||
<View style={[styles.radioButtonContainer, hasError && styles.borderColorDanger, disabled && styles.cursorDisabled]}> | ||
{isChecked && ( | ||
<Icon | ||
src={Expensicons.Checkmark} | ||
fill={theme.checkBox} | ||
|
@@ -56,8 +51,6 @@ function RadioButton(props) { | |
); | ||
} | ||
|
||
RadioButton.propTypes = propTypes; | ||
RadioButton.defaultProps = defaultProps; | ||
RadioButton.displayName = 'RadioButton'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the RadioButton.displayName = 'RadioButton'; |
||
export default RadioButton; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Unnecessary reordering of properties compared to the type declaration (
hasError
could be beforedisabled
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!