1.0.4 • Published 8 years ago

react-native-option-select v1.0.4

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

React Native Option Select

A simple DropDown menu for React Native App!

Introduction

React Native Option Select is simple, customizable and easy to use dropdown in React Native with a material outlook and plays well with the flex layout of the rest of the application.

Installation

npm i react-native-option-select --save

Usage

Require it inside your Javascript files. Also supporting components using object-deconstructing. Select Option OptionList.

<OptionList /> is to be used to append the options. This has to be placed as a last component so that it take the highest Z-Index.

Example

import React, {
  Component,
  AppRegistry,
  Text,
  View,
} from 'react-native';

import DropDown, {
  Select,
  Option,
  OptionList,
} from 'react-native-option-select';

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      canada: ''
    };
  }

  _getOptionList() {
    return this.refs['OPTIONLIST'];
  }

  
  _canada(province) {

  this.setState({
      ...this.state,
      canada: province
    });
  }

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
          <Select
            width={250}
            optionListRef={this._getOptionList.bind(this)}
            defaultValue="Select a Province in Canada ..."
            onSelect={this._canada.bind(this)}>
            <Option value = {{id : "alberta"}}>Alberta</Option>
            <Option>British Columbia</Option>
            <Option>Manitoba</Option>
            <Option>New Brunswick</Option>
            <Option>Newfoundland and Labrador</Option>
            <Option>Northwest Territories</Option>
            <Option>Nova Scotia</Option>
            <Option>Nunavut</Option>
            <Option>Ontario</Option>
            <Option>Prince Edward Island</Option>
            <Option>Quebec</Option>
            <Option>Saskatchewan</Option>
            <Option>Yukon</Option>
          </Select>

          <Text>Selected Canada's province: {this.state.canada}</Text>
          
          <OptionList ref="OPTIONLIST"/>
      </View>
    );
  }
}

AppRegistry.registerComponent('App', () => App);

Configuration

Select:
PropertyTypeDefaultDescriptionMandatory
widthnumber400Width of the selectionNo
onSelectfunction(text, value)nullfunction to be invoked when option is selectedYes
heightnumber50Height of the selectionNo
optionListReffunctionrequiredReference to <OptionList /> to display the selection menuYes
styleobjectnullCustom styles to be applied to the select container element if suppliedNo
styleOptionobjectnullCustom styles to be applied to the option element displayed on select if suppliedNo
styleTextobjectnullCustom styles to be applied to the text of the option element displayed on select if suppliedNo
defaultValuestringfirst optionThe value to be displayed if none of the options are selected.Yes
Option:
PropertyTypeDefaultDescriptionMandatory
valueanynullvalue will be passed on callback onSelect as second argumentYes
styleobjectnullStyles to be applied on 'Option' componentNo
styleTextobjectnullStyles to be applied on text inside of 'Option'No
OptionList:
PropertyTypeDefaultDescriptionMandatory
overlayStylesobjectnullStyles to be applied on 'overlay' backdropNo
useSelectHeightobjectnullIf set to true, then each option element will take height equal to the height of the select element on the opening of the dropdownNo

Demo

IOS and Android:

To be attached

Contributions

Please feel free to contribute. (✿◠‿◠)