-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
77 lines (68 loc) · 1.55 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* External dependencies
*/
import classnames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { isEmpty, omit } from 'lodash';
import { localize } from 'i18n-calypso';
/**
* Internal dependencies
*/
import FormSelect from 'calypso/components/forms/form-select';
/**
* Style dependencies
*/
import './style.scss';
export class FormCountrySelect extends Component {
static propTypes = {
countriesList: PropTypes.array.isRequired,
className: PropTypes.string,
disabled: PropTypes.bool,
onChange: PropTypes.func,
translate: PropTypes.func.isRequired,
};
getOptions() {
const { countriesList, translate } = this.props;
if ( isEmpty( countriesList ) ) {
return [
{
key: '',
label: translate( 'Loading…' ),
},
];
}
return countriesList.map( ( { code, name }, idx ) => ( {
key: idx,
label: name,
code,
disabled: ! code,
} ) );
}
render() {
const options = this.getOptions();
return (
<FormSelect
{ ...omit( this.props, [
'className',
'countriesList',
'translate',
'moment',
'numberFormat',
] ) }
className={ classnames( this.props.className, 'form-country-select' ) }
onChange={ this.props.onChange }
disabled={ this.props.disabled }
>
{ options.map( function ( option ) {
return (
<option key={ option.key } value={ option.code } disabled={ option.disabled }>
{ option.label }
</option>
);
} ) }
</FormSelect>
);
}
}
export default localize( FormCountrySelect );