1 import React, {PropTypes} from 'react';
3 const Header = React.createClass({
5 formatter: PropTypes.object,
6 prefixCls: PropTypes.string,
7 gregorianTimepickerLocale: PropTypes.object,
8 locale: PropTypes.object,
9 disabledDate: PropTypes.func,
10 placeholder: PropTypes.string,
11 value: PropTypes.object,
12 hourOptions: PropTypes.array,
13 minuteOptions: PropTypes.array,
14 secondOptions: PropTypes.array,
15 onChange: PropTypes.func,
16 onClear: PropTypes.func,
17 showClear: PropTypes.bool,
21 const value = this.props.value;
23 str: value && this.props.formatter.format(value) || '',
28 componentWillReceiveProps(nextProps) {
29 const value = this.formatValue(nextProps.value);
31 str: value && nextProps.formatter.format(value) || '',
36 onInputChange(event) {
37 const str = event.target.value;
42 const {formatter, gregorianTimepickerLocale, hourOptions, minuteOptions, secondOptions, onChange} = this.props;
45 const originalValue = this.props.value;
47 value = formatter.parse(str, {
48 locale: gregorianTimepickerLocale,
51 value = this.formatValue(value);
61 hourOptions.indexOf(value.fields[4]) < 0 ||
62 minuteOptions.indexOf(value.fields[5]) < 0 ||
63 secondOptions.indexOf(value.fields[6]) < 0
71 if (originalValue && value) {
73 originalValue.fields[4] !== value.fields[4] ||
74 originalValue.fields[5] !== value.fields[5] ||
75 originalValue.fields[6] !== value.fields[6]
79 } else if (originalValue !== value) {
98 this.setState({str: ''});
103 const { locale, prefixCls, showClear } = this.props;
107 return <a className={`${prefixCls}-clear-btn`} role="button" title={locale.clear} onMouseDown={this.onClear} />;
111 const { prefixCls, placeholder } = this.props;
112 const { invalid, str } = this.state;
113 const invalidClass = invalid ? `${prefixCls}-input-invalid` : '';
114 return <input className={`${prefixCls}-input ${invalidClass}`} value={str} placeholder={placeholder} onChange={this.onInputChange} />;
118 const newValue = this.props.value.clone();
122 newValue.fields[4] = value.fields[4];
123 newValue.fields[5] = value.fields[5];
124 newValue.fields[6] = value.fields[6];
129 const { prefixCls } = this.props;
131 <div className={`${prefixCls}-input-wrap`}>
133 {this.getClearButton()}
139 export default Header;