3.0.3 • Published 4 years ago

react-multiple-selector v3.0.3

Weekly downloads
117
License
-
Repository
github
Last release
4 years ago

react-multiple-selector

This package built on react-select to select cities, countries, regions, ..etc.

Installation and usage

NPM

You can install it using npm

npm install react-multiple-selector

then use it in your app like this:

import React, { useState } from 'react';
import ReactSelect from 'react-multiple-selector';

function App() {
  const [inputValue, setValue] = useState("");

  function onChange(value, callback) {
    if(!value) return callback([]);
    return new Promise((resolve, reject) => {
      const url = `https://api.test.com`;
      return fetch(url).then(async response => {
        if (response.ok) {
          const data = await response.json();
          const modifiedData = data.map(i => ({key: i._id, ...i}));
          callback(modifiedData);
        } else {
          reject(new Error('error'))
        }
      }, error => {
        reject(new Error(error.message))
      })
    })
  }

  return (
    <div className="App">
        <ReactSelect
          maxSelectedItems={5}
          onInputChange={(e) => {
            setValue(e);
            return e;
          }}
          debounceTime={2000}
          loadOptions={onChange}
          inputValue={inputValue}
          onChange={(a, b) => {
            console.log("from Parent: ", a, b);
          }}
          customType="Country"
        />
    </div>
  );
}

export default App;

Props

PropTypeUsageNote
maxSelectedItemsNumberThe maximum number of countries you can select.you can select any number of cities/regions/zipcode under those countries, but you can't add another country.
onInputChangeFunctionfires when you change the input value.(inputValue) => { return inputValue;}
inputValueStringThe input value you enteredyou can manage it using state
onChangeFunctionFires when the value of cities changed(currentSelectedCities, lastAction) => {}
loadOptionsFunctionFires to load options to select(value, callback) => ...
labelOptionStringLabel Option to show in options list or when selecteddefault = 'name'
valueOptionStringUnique value option to selectdefault = '_id'
typeOptionStringProperty to set maximum selected items on itdefault = 'type'
customTypeStringPrevious Property value to apply the maximum on itdefault = 'country'
debounceTimeNumberDebounce time applied to onChange function so the function doesn't fire before your last keyboard click and this timedefault = 300
valueArrayList of default values{}, {}, ...
placeholderStringPlaceholder for searchingdefault = 'Search...'
3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago