Skip to content
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

feat: introduce prop for defining control position (leading/trailing) fo RadioButton.Item #2713

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions example/src/Examples/RadioButtonItemExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const RadioButtonItemExample = () => {
const [checkedDefault, setCheckedDefault] = React.useState<boolean>(true);
const [checkedAndroid, setCheckedAndroid] = React.useState<boolean>(true);
const [checkedIOS, setCheckedIOS] = React.useState<boolean>(true);
const [checkedLeadingControl, setCheckedLeadingControl] = React.useState<
boolean
>(true);

const {
colors: { background },
} = useTheme();
Expand Down Expand Up @@ -39,6 +43,13 @@ const RadioButtonItemExample = () => {
onPress={() => setCheckedIOS(!checkedIOS)}
value="iOS"
/>
<RadioButton.Item
label="Default with leading control"
status={checkedLeadingControl ? 'checked' : 'unchecked'}
onPress={() => setCheckedLeadingControl(!checkedLeadingControl)}
value="iOS"
position="leading"
/>
</View>
);
};
Expand Down
20 changes: 18 additions & 2 deletions src/components/RadioButton/RadioButtonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export type Props = {
* Left undefined `<RadioButton />` will be used.
*/
mode?: 'android' | 'ios';
/**
* Radio button control position. Default is `leading`.
*/
position?: 'leading' | 'trailing';
};

/**
Expand Down Expand Up @@ -114,8 +118,10 @@ const RadioButtonItem = ({
accessibilityLabel,
testID,
mode,
position = 'trailing',
}: Props) => {
const radioButtonProps = { value, disabled, status, color, uncheckedColor };
const isLeading = position === 'leading';
lukewalczak marked this conversation as resolved.
Show resolved Hide resolved
let radioButton: any;

if (mode === 'android') {
Expand Down Expand Up @@ -145,10 +151,20 @@ const RadioButtonItem = ({
testID={testID}
>
<View style={[styles.container, style]} pointerEvents="none">
<Text style={[styles.label, { color: colors.text }, labelStyle]}>
{isLeading && radioButton}
<Text
style={[
styles.label,
{
color: colors.text,
textAlign: isLeading ? 'right' : 'left',
},
labelStyle,
]}
>
{label}
</Text>
{radioButton}
{!isLeading && radioButton}
</View>
</TouchableRipple>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exports[`can render the Android radio button on different platforms 1`] = `
},
Object {
"color": "#000000",
"textAlign": "left",
},
undefined,
],
Expand Down Expand Up @@ -156,6 +157,7 @@ exports[`can render the iOS radio button on different platforms 1`] = `
},
Object {
"color": "#000000",
"textAlign": "left",
},
undefined,
],
Expand Down Expand Up @@ -294,6 +296,7 @@ exports[`renders unchecked 1`] = `
},
Object {
"color": "#000000",
"textAlign": "left",
},
undefined,
],
Expand Down