1.1.0 • Published 8 years ago

rn-search-option-bar v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

RN-Search-Option-Bar

  • npm install rn-search-option-bar --save

Example One

How it works

  • The first option shows as selected by default
  • The buttonStyle backgroundColor will be applied to the selected option
  • Unselected options are transparent background
  • Unselected option's text gets the button's backgroundColor as it's color
import React from 'react';

import { StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  searchOptionBar:{
     height: 50,
     backgroundColor: colors.pageBackground,
     borderBottomColor: 'black',
     borderBottomWidth: StyleSheet.hairlineWidth
   },
   searchOptionButton: {
     width: 80,
     height: 30,
     borderRadius: 12,
     borderWidth: StyleSheet.hairlineWidth,
     borderColor: 'blue',
     backgroundColor: 'blue'
   },
   buttonText:{
     color:'white',
     fontSize:14
   }
 })


import SearchOptionBar from 'rn-search-option-bar';

class SearchOptionBarExample extends React.Component {
  render(){
    return(
      <SearchOptionBar
        onPress={ (opt) => console.log(opt) }
        options={ peopleSearchCategories }
        containerStyle={ styles.searchOptionBar }
        buttonStyle={ styles.searchOptionButton }
        textStyle={ styles.buttonText }
      />    
    )
  };

}

Props

PropTypeDescriptionRequired
optionsArray of StringsThe options listed in the buttonsYES
onPressfunctionthe function called when the button is pressed, called with the string as the argumentYES
buttonStyleobjectstyles applied to the buttonsYES must include backgroundColor
containerStyleobjectstyles applied to the containerYES
textStyleobjectstyles for the text, color will only be applied to the selected option, unselected will default to the backgroundColor of the buttonYES must include color
showsHorizontalScrollIndicatorbooleanshow the scroll indicatorno