0.1.2 • Published 5 years ago

react-native-radio-btn v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

React Native Radio Button

Fork of: react-native-flexi-radio-button

Example Expo Snack

Installation

npm i react-native-radio-btn

or

yarn add react-native-radio-btn

Usage

import {RadioGroup, RadioButton} from 'react-native-radio-btn'

state = {
   radioItems: [
     {
       id: 1,
       label: 'Item 1',
       selected: false,
     },
     {
       id: 2,
       label: 'Item 2',
       selected: false,
     },
     {
       id: 3,
       label: 'Item 3',
       selected: false,
     },
   ],
 };

 onSelect(index, value) {
   console.log(`Selected index: ${index} , value: ${value}`);
 }

render(){
  return(
    <View style={styles.container}>

    <RadioGroup onSelect={(index, value) => this.onSelect(index, value)}>
        {this.state.radioItems.map((item, index) => {
          return (
            <RadioButton
              key={index}
              value={item.label}
              displayText={item.label}
              displayTextColor="#000"
              displayTextActiveColor="#fff"
              prefixColor="rgba(0, 0, 0, 0.4)"
              prefixActiveColor="rgba(0, 0, 0, 0.4)"
              prefixWithNumbers
            />
          );
        })}
      </RadioGroup>

    </View>
  )
}

Configuration

Radio Group:
PropertyTypeDefaultDescription
sizenumber20Size of the radio button
thicknessnumber1width of radio button border
colorstring'#007AFF'color of radio button
activeColorstringnullcolor of radio button when selected
highlightColorstringnullbackground of radio button after selected
selectedIndexnumbernulldefault selected index of radio group, can be changed to new value or to null for clear selection
styleobjectnullCustom styles to be applied if supplied
onSelectfunction(index, value)nullfunction to be invoked when radio button is selected
Radio Button:
PropertyTypeDefaultDescription
valueanynullvalue will be passed on callback onSelect as second argument
styleobjectnullStyles to be applied on 'RadioButton' component
colorstringsame as 'RadioGroup' componentcolor of radio dot
disabledboolfalseIf true, disable all interactions for this component.
displayTextColorstring'#000'color of label text
displayTextActiveColorstring'#fff'color of label text when selected
prefixColorstring'#000'color of prefixes
prefixActiveColorstring'#fff'color of prefixes when selected
prefixWithAlphabetbooleanfalseprefixes label with alphabets (a,b,...z)
prefixWithNumbersbooleanfalseprefixes label with numbers (1,2...n)