ThakurBallary / react-native-radio-buttons-group

Simple, best and easy to use radio buttons for react native apps.
MIT License
263 stars 71 forks source link

Allow `ReactNode` as a `label` of `RadioButton` #74

Closed Haschikeks closed 6 months ago

Haschikeks commented 7 months ago

Hey,

I would be interested to see if the label prop of the RadioButton could accept a ReactNode instead of a string.

An example of what I want to achieve is shown in the screenshot, where I have some additional text with a different styling. Or even a text input. This is from a webapp. This would also allow people to use any themed Text components they might have, without having to override the labelStyle prop.

Screenshot 2024-02-27 at 14 09 58

I reckon, the code would look something like

const labelComp = (typeof label === "string" || typeof label === "number") ? <Text style={[margin, labelStyle]}>{label}</Text> : label;

This should keep it backwards compatible.

The docs then should probably state, that labelStyle is ignored if the label Prop is not a string.

A similar thing could be done for the descriptionprop.

I would be willing to contribute a PR for this.

ThakurBallary commented 7 months ago

@Haschikeks Interesting please send a PR.