]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Panel.jsx
Merge pull request #68 from csenk/focus-blur
[github/fretlink/time-picker.git] / src / Panel.jsx
index 0ed60e9427a7dfa82f93a7f83869763f0c1e2a98..1953ad497a0a69309251846e3c25980bd8b57741 100644 (file)
@@ -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,30 +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(),
-      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;
@@ -66,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, showSecond,
-      format, defaultOpenValue, clearText, onEsc, addon,
+      disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
+      format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
     } = this.props;
     const {
       value, currentSelectPanel,
@@ -120,7 +120,7 @@ const Panel = React.createClass({
           disabledMinutes={disabledMinutes}
           disabledSeconds={disabledSeconds}
           onChange={this.onChange}
-          onClear={this.onClear}
+          onClear={onClear}
           allowEmpty={allowEmpty}
         />
         <Combobox
@@ -130,6 +130,7 @@ const Panel = React.createClass({
           format={format}
           onChange={this.onChange}
           showHour={showHour}
+          showMinute={showMinute}
           showSecond={showSecond}
           hourOptions={hourOptions}
           minuteOptions={minuteOptions}
@@ -138,11 +139,12 @@ const Panel = React.createClass({
           disabledMinutes={disabledMinutes}
           disabledSeconds={disabledSeconds}
           onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
+          use12Hours={use12Hours}
         />
         {addon(this)}
       </div>
     );
-  },
-});
+  }
+}
 
 export default Panel;