Skip to content

V7/ radio button content on right #2473

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

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/components/radioButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export type RadioButtonProps = RadioGroupContextProps &
* Should the icon be on the right side of the label
*/
iconOnRight?: boolean;
/**
* @deprecated The content is on right by default, for content on left use 'contentOnLeft'
*/
contentOnRight?: boolean;
/**
* Should the content be rendered left to the button
*/
Expand Down Expand Up @@ -131,17 +127,12 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
}
}

get isContentOnLeft() {
const {contentOnLeft, contentOnRight} = this.props;
return contentOnLeft || contentOnRight;
}

animate() {
const {selected} = this.props;
const {opacityAnimationValue, scaleAnimationValue} = this.state;
const animationTime = 150;
const animationDelay = 60;

if (selected) {
Animated.parallel([
Animated.timing(opacityAnimationValue, {
Expand Down Expand Up @@ -227,10 +218,17 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
}

renderLabel() {
const {label, labelStyle, testID} = this.props;
const {label, labelStyle, contentOnLeft, testID} = this.props;
return (
label && (
<Text flexS marginL-10={!this.isContentOnLeft} marginR-10={this.isContentOnLeft} $textDefault style={labelStyle} testID={`${testID}.label`}>
<Text
flexS
marginL-10={!contentOnLeft}
marginR-10={contentOnLeft}
$textDefault
style={labelStyle}
testID={`${testID}.label`}
>
{label}
</Text>
)
Expand Down Expand Up @@ -260,7 +258,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
}

render() {
const {onPress, onValueChange, containerStyle, ...others} = this.props;
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
const Container = onPress || onValueChange ? TouchableOpacity : View;

return (
Expand All @@ -274,10 +272,10 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
onPress={this.onPress}
{...this.getAccessibilityProps()}
>
{!this.isContentOnLeft && this.renderButton()}
{!contentOnLeft && this.renderButton()}
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
{this.props.iconOnRight ? this.renderIcon() : this.renderLabel()}
{this.isContentOnLeft && this.renderButton()}
{contentOnLeft && this.renderButton()}
</Container>
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/components/radioButton/radioButton.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
"description": "Should the icon be on the right side of the label",
"default": "false"
},
{
"name": "contentOnRight",
"type": "boolean",
"description": "Deprecated. The content is on right by default, for content on left use 'contentOnLeft'",
"deprecated": true
},
{"name": "contentOnLeft", "type": "boolean", "description": "Should the content be rendered left to the button"},
{"name": "containerStyle", "type": "ViewStyle", "description": "Additional styling for the container"}
],
Expand Down