X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FPanel.jsx;h=8a6c872e7e73784aeeace67fe3d4bca09384b57b;hb=0e4fd1626e460bd52a82de3f12f84d88f652dd7e;hp=9066b033bd4c1a1d68800fa542d2cdf06217cc76;hpb=9c01af6e34f7d63843bacfcffb8c7ad45d6866cf;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/Panel.jsx b/src/Panel.jsx index 9066b03..8a6c872 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -1,4 +1,5 @@ -import React, { PropTypes } from 'react'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import Header from './Header'; import Combobox from './Combobox'; import moment from 'moment'; @@ -17,8 +18,8 @@ function generateOptions(length, disabledOptions, hideDisabledOptions) { return arr; } -const Panel = React.createClass({ - propTypes: { +class Panel extends Component { + static propTypes = { clearText: PropTypes.string, prefixCls: PropTypes.string, className: PropTypes.string, @@ -34,28 +35,34 @@ const Panel = React.createClass({ onEsc: PropTypes.func, allowEmpty: PropTypes.bool, showHour: PropTypes.bool, + showMinute: PropTypes.bool, showSecond: PropTypes.bool, onClear: PropTypes.func, - }, + use12Hours: PropTypes.bool, + addon: PropTypes.func, + onKeyDown: PropTypes.func, + }; - getDefaultProps() { - return { - prefixCls: 'rc-time-picker-panel', - onChange: noop, - onClear: noop, - disabledHours: noop, - disabledMinutes: noop, - disabledSeconds: noop, - defaultOpenValue: moment(), - }; - }, + static defaultProps = { + prefixCls: 'rc-time-picker-panel', + onChange: noop, + onClear: noop, + disabledHours: noop, + disabledMinutes: noop, + disabledSeconds: noop, + defaultOpenValue: moment(), + use12Hours: false, + addon: noop, + onKeyDown: noop, + }; - getInitialState() { - return { - value: this.props.value, + constructor(props) { + super(props); + this.state = { + value: props.value, selectionRange: [], }; - }, + } componentWillReceiveProps(nextProps) { const value = nextProps.value; @@ -64,26 +71,27 @@ const Panel = React.createClass({ value, }); } - }, + } - onChange(newValue) { + onChange = (newValue) => { this.setState({ value: newValue }); this.props.onChange(newValue); - }, - - onClear() { - this.props.onClear(); - }, + } - onCurrentSelectPanelChange(currentSelectPanel) { + onCurrentSelectPanelChange = (currentSelectPanel) => { this.setState({ currentSelectPanel }); - }, + } + + // https://github.com/ant-design/ant-design/issues/5829 + close() { + this.props.onEsc(); + } render() { const { prefixCls, className, placeholder, disabledHours, disabledMinutes, - disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, - format, defaultOpenValue, clearText, onEsc, + disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, + format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, onKeyDown, } = this.props; const { value, currentSelectPanel, @@ -114,8 +122,9 @@ const Panel = React.createClass({ disabledMinutes={disabledMinutes} disabledSeconds={disabledSeconds} onChange={this.onChange} - onClear={this.onClear} + onClear={onClear} allowEmpty={allowEmpty} + onKeyDown={onKeyDown} /> + {addon(this)} ); - }, -}); + } +} export default Panel;