-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (36 loc) · 900 Bytes
/
index.js
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
'use strict'
const ce = require('react').createElement
const countries = require('@paylike/countries')
module.exports = render
function render(props) {
const classes = []
classes.push(props.className ? props.className : 'country-select')
if (props.value === null || props.value === '') classes.push('initial')
return ce(
'select',
{
value: props.value,
required: props.required,
className: classes.join(' '),
onChange: function (e) {
props.onChange && props.onChange(e.target.value)
},
},
props.initial && ce('option', {value: ''}, props.initial),
(typeof props.filter === 'function'
? countries.filter(props.filter)
: Array.isArray(props.exclude)
? countries.filter(({ code }) => !props.exclude.includes(code))
: countries
).map((c) =>
ce(
'option',
{
key: c.code,
value: c.name,
},
c.name
)
)
)
}