aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Header.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Header.jsx')
-rw-r--r--src/Header.jsx42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/Header.jsx b/src/Header.jsx
index 2ef9827..91e8549 100644
--- a/src/Header.jsx
+++ b/src/Header.jsx
@@ -1,8 +1,9 @@
1import React, { PropTypes } from 'react'; 1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
2import moment from 'moment'; 3import moment from 'moment';
3 4
4const Header = React.createClass({ 5class Header extends Component {
5 propTypes: { 6 static propTypes = {
6 format: PropTypes.string, 7 format: PropTypes.string,
7 prefixCls: PropTypes.string, 8 prefixCls: PropTypes.string,
8 disabledDate: PropTypes.func, 9 disabledDate: PropTypes.func,
@@ -21,15 +22,16 @@ const Header = React.createClass({
21 allowEmpty: PropTypes.bool, 22 allowEmpty: PropTypes.bool,
22 defaultOpenValue: PropTypes.object, 23 defaultOpenValue: PropTypes.object,
23 currentSelectPanel: PropTypes.string, 24 currentSelectPanel: PropTypes.string,
24 }, 25 };
25 26
26 getInitialState() { 27 constructor(props) {
27 const { value, format } = this.props; 28 super(props);
28 return { 29 const { value, format } = props;
30 this.state = {
29 str: value && value.format(format) || '', 31 str: value && value.format(format) || '',
30 invalid: false, 32 invalid: false,
31 }; 33 };
32 }, 34 }
33 35
34 componentWillReceiveProps(nextProps) { 36 componentWillReceiveProps(nextProps) {
35 const { value, format } = nextProps; 37 const { value, format } = nextProps;
@@ -37,9 +39,9 @@ const Header = React.createClass({
37 str: value && value.format(format) || '', 39 str: value && value.format(format) || '',
38 invalid: false, 40 invalid: false,
39 }); 41 });
40 }, 42 }
41 43
42 onInputChange(event) { 44 onInputChange = (event) => {
43 const str = event.target.value; 45 const str = event.target.value;
44 this.setState({ 46 this.setState({
45 str, 47 str,
@@ -117,18 +119,18 @@ const Header = React.createClass({
117 this.setState({ 119 this.setState({
118 invalid: false, 120 invalid: false,
119 }); 121 });
120 }, 122 }
121 123
122 onKeyDown(e) { 124 onKeyDown = (e) => {
123 if (e.keyCode === 27) { 125 if (e.keyCode === 27) {
124 this.props.onEsc(); 126 this.props.onEsc();
125 } 127 }
126 }, 128 }
127 129
128 onClear() { 130 onClear = () => {
129 this.setState({ str: '' }); 131 this.setState({ str: '' });
130 this.props.onClear(); 132 this.props.onClear();
131 }, 133 }
132 134
133 getClearButton() { 135 getClearButton() {
134 const { prefixCls, allowEmpty } = this.props; 136 const { prefixCls, allowEmpty } = this.props;
@@ -141,11 +143,11 @@ const Header = React.createClass({
141 title={this.props.clearText} 143 title={this.props.clearText}
142 onMouseDown={this.onClear} 144 onMouseDown={this.onClear}
143 />); 145 />);
144 }, 146 }
145 147
146 getProtoValue() { 148 getProtoValue() {
147 return this.props.value || this.props.defaultOpenValue; 149 return this.props.value || this.props.defaultOpenValue;
148 }, 150 }
149 151
150 getInput() { 152 getInput() {
151 const { prefixCls, placeholder } = this.props; 153 const { prefixCls, placeholder } = this.props;
@@ -161,7 +163,7 @@ const Header = React.createClass({
161 onChange={this.onInputChange} 163 onChange={this.onInputChange}
162 /> 164 />
163 ); 165 );
164 }, 166 }
165 167
166 render() { 168 render() {
167 const { prefixCls } = this.props; 169 const { prefixCls } = this.props;
@@ -171,7 +173,7 @@ const Header = React.createClass({
171 {this.getClearButton()} 173 {this.getClearButton()}
172 </div> 174 </div>
173 ); 175 );
174 }, 176 }
175}); 177}
176 178
177export default Header; 179export default Header;