0.2.3 • Published 5 years ago

@mobly/react-mobile-picker v0.2.3

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

React Mobile Picker

Travis npm GitHub license

This is a forked package of the original (which seems no longer maintained). Updated react, cleaned up code and fixed passive event listener error for touchmove.

TODO

  • Add tests
  • Update webpack and config

React Mobile Picker is a super simple component with no restriction, which means you can use it in any way you want.

screen-capture

Preview

qr

Scan this Qr in you mobile.

Or visit (in mobile or mobile simulator): http://adcentury.github.io/react-mobile-picker

Install

npm install @mobly/react-mobile-picker --save

Usage

ES6

import Picker from '@mobly/react-mobile-picker';

CommonJS

var Picker = require('@mobly/react-mobile-picker');

Props

Property nameTypeDefaultDescription
optionGroupsObjectN/AKey-value pairs as {name1: options1, name2: options2}. options is an array of all options for this name.
valueGroupsObjectN/ASelected value pairs as {name1: value1, name2: value2}.
onChange(name, value)FunctionN/ACallback called when user pick a new value.
onClick(name, value)FunctionN/ACallback called when user click on selected value.
itemHeightNumber36Height of each item (that is each option). In px.
heightNumber216Height of the picker. In px.

Getting Started

By design, React Mobile Picker is a Controlled Component, which means the selected value of the rendered element will always reflect the valueGroups. Every time you want to change the selected item, just modify valueGroups values.

Here is an example of how to integrate React Mobile Picker:

import React, {Component} from 'react';
import Picker from '@mobly/react-mobile-picker';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      valueGroups: {
        title: 'Mr.',
        firstName: 'Micheal',
        secondName: 'Jordan'
      },
      optionGroups: {
        title: ['Mr.', 'Mrs.', 'Ms.', 'Dr.'],
        firstName: ['John', 'Micheal', 'Elizabeth'],
        secondName: ['Lennon', 'Jackson', 'Jordan', 'Legend', 'Taylor']
      }
    };
  }

  // Update the value in response to user picking event
  handleChange = (name, value) => {
    this.setState(({valueGroups}) => ({
      valueGroups: {
        ...valueGroups,
        [name]: value
      }
    }));
  };

  render() {
    const {optionGroups, valueGroups} = this.state;

    return (
      <Picker
        optionGroups={optionGroups}
        valueGroups={valueGroups}
        onChange={this.handleChange} />
    );
  }
}

More Examples

git clone this repo
npm install
npm start
point your browser to http://localhost:8080

License

MIT.