0.1.0 • Published 6 years ago

rn-option-select v0.1.0

Weekly downloads
25
License
MIT
Repository
github
Last release
6 years ago

rn-option-select

npm version code style: prettier

An simple and customizable react-native select.

Features

  • Single / multiple choices
  • Customizable styles

Demos

Setup

This library is available on npm, install it with: npm install --save rn-option-select or yarn add rn-option-select.

Usage

  1. Import rn-option-select:
import { Select } from "rn-option-select";
  1. Create a select:
const options = 
[
    { title: "Title 1", value: 'title1' },
    { title: "Title 2", value: 'title2', selected: true },
    { title: "Title 3", value: 'title3' },
]

render () {
    return (
      <View>
        <Select
          onOptionPress={values => {
            console.log(values)
          }}
          optionStyle={{
            text: {
              color: '#333333',
            },
            container: {
              borderBottomWidth: 1,
              borderColor: 'rgb(191, 191, 191)',
            },
          }}
          options={options}
        />
      </View>
    )
  }

Available props

NameTypeDefaultDescription
optionsarrayREQUIREDArray of values objects more
multipleboolfalseSelect multiple values
onOptionPressfunc( ) => nullCalled when option is pressed (values as arg) more
disabledboolfalseDisable select
unselectedOptionReact.elementA circular View with a borderOverride element for unselected options
selectedOptionReact.elementA circular View with backgroundColor: 'blue'Override element for selected options
containerStyleObject{ }A Object with styles for select container
optionStyleObject{ }A Object with styles for options

Options Array

Basic example
[
    { title: "Title 1", value: 'title1' },
    { title: "Title 2", value: 'title2' },
    { title: "Title 3", value: 'title3' },
]
One option selected on render
[
    { title: "Title 1", value: 'title1', selected: true },
    { title: "Title 2", value: 'title2' },
    { title: "Title 3", value: 'title3' },
]
Title with a React.element
[
    {
        title: <View><Text>Whatever you want here</Text></View>,
        value: 'title1',
        selected: true,
    },
    {
        title: "You can pass strings or React.element",
        value: 'title2',
    },
    {
        title: <View><Text>Whatever you want here too</Text></View>,
        value: 'title3',
    },
]

onOptionPress

<Select
    ...
    onOptionPress={values => {
        this.setState({ options: values });
    }}
    ...
/>

values is an Array like options array with selected options.

Pull requests, feedbacks and suggestions are welcome!