X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FPanel.jsx;h=65832eabaabade0a522b5926d5f1c158a1ce6468;hb=3ab3a128deaf10300b31102b79458528227baa54;hp=f5cf7bc6c1184b20646222a7b0db0a286cf2f9fb;hpb=c6a1a235f9ff6de74cae402c7359b25fa655a537;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/Panel.jsx b/src/Panel.jsx index f5cf7bc..65832ea 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,32 @@ 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, + }; - 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, + }; - getInitialState() { - return { - value: this.props.value, + constructor(props) { + super(props); + this.state = { + value: props.value, selectionRange: [], }; - }, + } componentWillReceiveProps(nextProps) { const value = nextProps.value; @@ -64,26 +69,22 @@ 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 }); - }, + } 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, } = this.props; const { value, currentSelectPanel, @@ -97,7 +98,7 @@ const Panel = React.createClass({ const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); return ( -
+
+ {addon(this)}
); - }, -}); + } +} export default Panel;