]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Header.jsx
fix react createClass and PropTypes warning
[github/fretlink/time-picker.git] / src / Header.jsx
index 2ef982776cbe71343e2478e79080ebe3b83debfc..91e8549e14664555290a905a8b0102cddd27f808 100644 (file)
@@ -1,8 +1,9 @@
-import React, { PropTypes } from 'react';
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
 import moment from 'moment';
 
-const Header = React.createClass({
-  propTypes: {
+class Header extends Component {
+  static propTypes = {
     format: PropTypes.string,
     prefixCls: PropTypes.string,
     disabledDate: PropTypes.func,
@@ -21,15 +22,16 @@ const Header = React.createClass({
     allowEmpty: PropTypes.bool,
     defaultOpenValue: PropTypes.object,
     currentSelectPanel: PropTypes.string,
-  },
+  };
 
-  getInitialState() {
-    const { value, format } = this.props;
-    return {
+  constructor(props) {
+    super(props);
+    const { value, format } = props;
+    this.state = {
       str: value && value.format(format) || '',
       invalid: false,
     };
-  },
+  }
 
   componentWillReceiveProps(nextProps) {
     const { value, format } = nextProps;
@@ -37,9 +39,9 @@ const Header = React.createClass({
       str: value && value.format(format) || '',
       invalid: false,
     });
-  },
+  }
 
-  onInputChange(event) {
+  onInputChange = (event) => {
     const str = event.target.value;
     this.setState({
       str,
@@ -117,18 +119,18 @@ const Header = React.createClass({
     this.setState({
       invalid: false,
     });
-  },
+  }
 
-  onKeyDown(e) {
+  onKeyDown = (e) => {
     if (e.keyCode === 27) {
       this.props.onEsc();
     }
-  },
+  }
 
-  onClear() {
+  onClear = () => {
     this.setState({ str: '' });
     this.props.onClear();
-  },
+  }
 
   getClearButton() {
     const { prefixCls, allowEmpty } = this.props;
@@ -141,11 +143,11 @@ const Header = React.createClass({
       title={this.props.clearText}
       onMouseDown={this.onClear}
     />);
-  },
+  }
 
   getProtoValue() {
     return this.props.value || this.props.defaultOpenValue;
-  },
+  }
 
   getInput() {
     const { prefixCls, placeholder } = this.props;
@@ -161,7 +163,7 @@ const Header = React.createClass({
         onChange={this.onInputChange}
       />
     );
-  },
+  }
 
   render() {
     const { prefixCls } = this.props;
@@ -171,7 +173,7 @@ const Header = React.createClass({
         {this.getClearButton()}
       </div>
     );
-  },
-});
+  }
+}
 
 export default Header;