forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonth_dropdown.jsx
63 lines (54 loc) · 1.52 KB
/
month_dropdown.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
import React from 'react'
import moment from 'moment'
import range from 'lodash/range'
var MonthDropdown = React.createClass({
displayName: 'MonthDropdown',
propTypes: {
dropdownMode: React.PropTypes.oneOf(['scroll', 'select']).isRequired,
locale: React.PropTypes.string,
month: React.PropTypes.number.isRequired,
onChange: React.PropTypes.func.isRequired
},
getInitialState () {
return {
dropdownVisible: false
}
},
renderSelectOptions () {
const localeData = moment.localeData(this.props.locale)
return range(0, 12).map((M, i) => (
<option key={i} value={i}>{localeData.months(moment({M}))}</option>
))
},
renderSelectMode () {
return (
<select value={this.props.month} className="react-datepicker__month-select" onChange={e => this.onChange(e.target.value)}>
{this.renderSelectOptions()}
</select>
)
},
onChange (month) {
if (month !== this.props.month) {
this.props.onChange(month)
}
},
render () {
let renderedDropdown
switch (this.props.dropdownMode) {
// TODO: implement scroll mode
// case 'scroll':
// renderedDropdown = this.renderScrollMode()
// break
case 'select':
renderedDropdown = this.renderSelectMode()
break
}
return (
<div
className={`react-datepicker__month-dropdown-container react-datepicker__month-dropdown-container--${this.props.dropdownMode}`}>
{renderedDropdown}
</div>
)
}
})
module.exports = MonthDropdown