Skip to content

Commit 8f20379

Browse files
authored
Feat/radio button customize styling (#1092)
* prettier format * style prop only applies to the radiobutton, not the container * Added containerStyle prop, allowing to style the container
1 parent 4b0c22f commit 8f20379

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

src/components/radioButton/RadioButton.tsx

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,64 @@ import {RadioGroupContextProps} from './RadioGroupContext';
2323
const DEFAULT_SIZE = 24;
2424
const DEFAULT_COLOR = Colors.blue30;
2525

26-
export type RadioButtonProps = RadioGroupContextProps & ViewProps & {
27-
/**
28-
* The identifier value of the radio button. must be different than other RadioButtons in the same group
29-
*/
30-
value?: string | number | boolean;
31-
/**
32-
* When using RadioButton without a RadioGroup, use this prop to toggle selection
33-
*/
34-
selected?: boolean;
35-
/**
36-
* Invoked when pressing the button
37-
*/
38-
onPress?: (selected: boolean) => void;
39-
/**
40-
* Whether the radio button should be disabled
41-
*/
42-
disabled?: boolean;
43-
/**
44-
* The color of the radio button
45-
*/
46-
color?: string;
47-
/**
48-
* The size of the radio button, affect both width & height
49-
*/
50-
size?: number;
51-
/**
52-
* The radio button border radius
53-
*/
54-
borderRadius?: number;
55-
/**
56-
* A label for the radio button description
57-
*/
58-
label?: string;
59-
/**
60-
* Label style
61-
*/
62-
labelStyle?: TextStyle;
63-
/**
64-
* Icon image source
65-
*/
66-
iconSource?: ImageSourcePropType;
67-
/**
68-
* Icon image style
69-
*/
70-
iconStyle?: ImageStyle;
71-
/**
72-
* Should the icon be on the right side of the label
73-
*/
74-
iconOnRight?: boolean;
75-
/**
26+
export type RadioButtonProps = RadioGroupContextProps &
27+
ViewProps & {
28+
/**
29+
* The identifier value of the radio button. must be different than other RadioButtons in the same group
30+
*/
31+
value?: string | number | boolean;
32+
/**
33+
* When using RadioButton without a RadioGroup, use this prop to toggle selection
34+
*/
35+
selected?: boolean;
36+
/**
37+
* Invoked when pressing the button
38+
*/
39+
onPress?: (selected: boolean) => void;
40+
/**
41+
* Whether the radio button should be disabled
42+
*/
43+
disabled?: boolean;
44+
/**
45+
* The color of the radio button
46+
*/
47+
color?: string;
48+
/**
49+
* The size of the radio button, affect both width & height
50+
*/
51+
size?: number;
52+
/**
53+
* The radio button border radius
54+
*/
55+
borderRadius?: number;
56+
/**
57+
* A label for the radio button description
58+
*/
59+
label?: string;
60+
/**
61+
* Label style
62+
*/
63+
labelStyle?: TextStyle;
64+
/**
65+
* Icon image source
66+
*/
67+
iconSource?: ImageSourcePropType;
68+
/**
69+
* Icon image style
70+
*/
71+
iconStyle?: ImageStyle;
72+
/**
73+
* Should the icon be on the right side of the label
74+
*/
75+
iconOnRight?: boolean;
76+
/**
7677
* Should the content be rendered right to the button
7778
*/
7879
contentOnRight?: boolean;
80+
/**
81+
* Additional styling for the container
82+
*/
83+
containerStyle?: StyleProp<ViewStyle>;
7984
};
8085
export type RadioButtonPropTypes = RadioButtonProps; //TODO: remove after ComponentPropTypes deprecation;
8186

@@ -224,7 +229,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
224229
renderIcon() {
225230
const {iconSource, iconStyle} = this.props;
226231
const style = [this.styles.image, iconStyle];
227-
return iconSource && <Image style={style} source={iconSource}/>;
232+
return iconSource && <Image style={style} source={iconSource} />;
228233
}
229234

230235
renderButton() {
@@ -244,7 +249,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
244249
}
245250

246251
render() {
247-
const {onPress, onValueChange, contentOnRight, ...others} = this.props;
252+
const {onPress, onValueChange, contentOnRight, style, containerStyle, ...others} = this.props;
248253
const Container = onPress || onValueChange ? TouchableOpacity : View;
249254

250255
return (
@@ -253,6 +258,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
253258
row
254259
centerV
255260
activeOpacity={1}
261+
style={containerStyle}
256262
{...others}
257263
onPress={this.onPress}
258264
{...this.getAccessibilityProps()}

0 commit comments

Comments
 (0)