-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,
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;
str: value && value.format(format) || '',
invalid: false,
});
- },
+ }
- onInputChange(event) {
+ onInputChange = (event) => {
const str = event.target.value;
this.setState({
str,
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;
title={this.props.clearText}
onMouseDown={this.onClear}
/>);
- },
+ }
getProtoValue() {
return this.props.value || this.props.defaultOpenValue;
- },
+ }
getInput() {
const { prefixCls, placeholder } = this.props;
onChange={this.onInputChange}
/>
);
- },
+ }
render() {
const { prefixCls } = this.props;
{this.getClearButton()}
</div>
);
- },
-});
+ }
+}
export default Header;