forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
year_dropdown.js
72 lines (59 loc) · 2.03 KB
/
year_dropdown.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
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
'use strict';
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _createReactClass = require('create-react-class');
var _createReactClass2 = _interopRequireDefault(_createReactClass);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _year_dropdown_options = require('./year_dropdown_options');
var _year_dropdown_options2 = _interopRequireDefault(_year_dropdown_options);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var YearDropdown = (0, _createReactClass2.default)({
displayName: 'YearDropdown',
propTypes: {
onChange: _propTypes2.default.func.isRequired,
year: _propTypes2.default.number.isRequired
},
getInitialState: function getInitialState() {
return {
dropdownVisible: false
};
},
renderReadView: function renderReadView() {
return _react2.default.createElement(
'div',
{ className: 'react-datepicker__year-read-view', onClick: this.toggleDropdown },
_react2.default.createElement(
'span',
{ className: 'react-datepicker__year-read-view--selected-year' },
this.props.year
),
_react2.default.createElement('span', { className: 'react-datepicker__year-read-view--down-arrow' })
);
},
renderDropdown: function renderDropdown() {
return _react2.default.createElement(_year_dropdown_options2.default, {
ref: 'options',
year: this.props.year,
onChange: this.onChange,
onCancel: this.toggleDropdown });
},
onChange: function onChange(year) {
this.toggleDropdown();
if (year === this.props.year) return;
this.props.onChange(year);
},
toggleDropdown: function toggleDropdown() {
this.setState({
dropdownVisible: !this.state.dropdownVisible
});
},
render: function render() {
return _react2.default.createElement(
'div',
null,
this.state.dropdownVisible ? this.renderDropdown() : this.renderReadView()
);
}
});
module.exports = YearDropdown;