react-select-country-list
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "react-select-country-list", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Maps ISO 3166-1-alpha-2 codes to English country names and match react-select options props", | ||
@@ -5,0 +5,0 @@ "main": "country-list.js", |
@@ -1,3 +0,5 @@ | ||
# country-list | ||
# react-select-country-list | ||
This package take [country-list](https://github.com/fannarsh/country-list) as reference, and make it more friendly to react-select | ||
Maps ISO 3166-1-alpha-2 codes to English country names and match react-select options props. | ||
@@ -11,9 +13,37 @@ | ||
``` js | ||
var countries = require('country-list')(); | ||
```js | ||
import React, { Component } from 'react'; | ||
import Select from 'react-select' | ||
import countryList from 'react-select-country-list' | ||
console.log(countries.getValue('IS')); // Iceland | ||
console.log(countries.getLabel('Iceland')); // IS | ||
class CountrySelector extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.options = countryList().getData() | ||
this.state = { | ||
options: this.options, | ||
value: null, | ||
} | ||
} | ||
changeHandler = value => { | ||
this.setState({ value }) | ||
} | ||
render() { | ||
return ( | ||
<Select | ||
options={this.state.options} | ||
value={this.state.value} | ||
onChange={this.changeHandler} | ||
/> | ||
) | ||
} | ||
} | ||
``` | ||
## Methods | ||
@@ -24,3 +54,3 @@ | ||
``` js | ||
var countries = require('country-list')(); | ||
import countryList from 'react-select-country-list'; | ||
``` | ||
@@ -61,38 +91,4 @@ All input is case-insensitive. | ||
### react-select | ||
```js | ||
import React, { Component } from 'react'; | ||
import Select from 'react-select' | ||
import countryList from 'react-select-country-list' | ||
class CountrySelector extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.options = countryList().getData() | ||
this.state = { | ||
options: this.options, | ||
value: null, | ||
} | ||
} | ||
changeHandler = value => { | ||
this.setState({ value }) | ||
} | ||
render() { | ||
return ( | ||
<Select | ||
options={this.state.options} | ||
value={this.state.value} | ||
onChange={this.changeHandler} | ||
/> | ||
) | ||
} | ||
} | ||
``` | ||
### Use with | ||
@@ -99,0 +95,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18721
102