X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FPanel.jsx;h=1953ad497a0a69309251846e3c25980bd8b57741;hb=6022baedfba9ec831d9fddaf7979771a71ca7fb8;hp=fddea1c09ddbc8fa591bd0847c7db1e7f23450a0;hpb=e59f4eae17cbfd7eed19cd385ec64312ffe266c4;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/Panel.jsx b/src/Panel.jsx index fddea1c..1953ad4 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, @@ -37,28 +38,29 @@ const Panel = React.createClass({ showMinute: PropTypes.bool, showSecond: PropTypes.bool, onClear: PropTypes.func, + use12Hours: PropTypes.bool, addon: PropTypes.func, - }, + }; - getDefaultProps() { - return { - prefixCls: 'rc-time-picker-panel', - onChange: noop, - onClear: noop, - disabledHours: noop, - disabledMinutes: noop, - disabledSeconds: noop, - defaultOpenValue: moment(), - addon: noop, - }; - }, + static defaultProps = { + prefixCls: 'rc-time-picker-panel', + onChange: noop, + onClear: noop, + disabledHours: noop, + disabledMinutes: noop, + disabledSeconds: noop, + defaultOpenValue: moment(), + use12Hours: false, + addon: noop, + }; - getInitialState() { - return { - value: this.props.value, + constructor(props) { + super(props); + this.state = { + value: props.value, selectionRange: [], }; - }, + } componentWillReceiveProps(nextProps) { const value = nextProps.value; @@ -67,30 +69,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, showMinute, showSecond, - format, defaultOpenValue, clearText, onEsc, addon, + format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, } = this.props; const { value, currentSelectPanel, @@ -121,7 +120,7 @@ const Panel = React.createClass({ disabledMinutes={disabledMinutes} disabledSeconds={disabledSeconds} onChange={this.onChange} - onClear={this.onClear} + onClear={onClear} allowEmpty={allowEmpty} /> {addon(this)} ); - }, -}); + } +} export default Panel;