X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FHeader.jsx;h=91e8549e14664555290a905a8b0102cddd27f808;hb=3ab3a128deaf10300b31102b79458528227baa54;hp=2ef982776cbe71343e2478e79080ebe3b83debfc;hpb=16a18e356599ed2b9289314614739802ea5b5191;p=github%2Ffretlink%2Ftime-picker.git 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 @@ -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()} ); - }, -}); + } +} export default Header;