X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FHeader.jsx;h=f6dd24157ae34e04fb43d66ff8e34475d4ae48c0;hb=0e4fd1626e460bd52a82de3f12f84d88f652dd7e;hp=2ef982776cbe71343e2478e79080ebe3b83debfc;hpb=bb87d05e6372596c8e8e1f2ebf657df6b9a8d826;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/Header.jsx b/src/Header.jsx index 2ef9827..f6dd241 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,17 @@ const Header = React.createClass({ allowEmpty: PropTypes.bool, defaultOpenValue: PropTypes.object, currentSelectPanel: PropTypes.string, - }, + onKeyDown: PropTypes.func, + }; - 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 +40,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 +120,21 @@ const Header = React.createClass({ this.setState({ invalid: false, }); - }, + } - onKeyDown(e) { + onKeyDown = (e) => { + const { onEsc, onKeyDown } = this.props; if (e.keyCode === 27) { - this.props.onEsc(); + onEsc(); } - }, - onClear() { + onKeyDown(e); + } + + onClear = () => { this.setState({ str: '' }); this.props.onClear(); - }, + } getClearButton() { const { prefixCls, allowEmpty } = this.props; @@ -141,11 +147,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 +167,7 @@ const Header = React.createClass({ onChange={this.onInputChange} /> ); - }, + } render() { const { prefixCls } = this.props; @@ -171,7 +177,7 @@ const Header = React.createClass({ {this.getClearButton()} ); - }, -}); + } +} export default Header;