aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Panel.jsx
diff options
context:
space:
mode:
authorafc163 <afc163@gmail.com>2017-04-14 17:13:04 +0800
committerafc163 <afc163@gmail.com>2017-04-14 17:13:04 +0800
commit3ab3a128deaf10300b31102b79458528227baa54 (patch)
treec179b1ccfe954b1df0e2c9a238f604a0e1ba1534 /src/Panel.jsx
parent16a18e356599ed2b9289314614739802ea5b5191 (diff)
downloadtime-picker-3ab3a128deaf10300b31102b79458528227baa54.tar.gz
time-picker-3ab3a128deaf10300b31102b79458528227baa54.tar.zst
time-picker-3ab3a128deaf10300b31102b79458528227baa54.zip
fix react createClass and PropTypes warningfix-react-15.5-warning
Diffstat (limited to 'src/Panel.jsx')
-rw-r--r--src/Panel.jsx68
1 files changed, 30 insertions, 38 deletions
diff --git a/src/Panel.jsx b/src/Panel.jsx
index df128ff..65832ea 100644
--- a/src/Panel.jsx
+++ b/src/Panel.jsx
@@ -1,4 +1,5 @@
1import React, { PropTypes } from 'react'; 1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
2import Header from './Header'; 3import Header from './Header';
3import Combobox from './Combobox'; 4import Combobox from './Combobox';
4import moment from 'moment'; 5import moment from 'moment';
@@ -17,8 +18,8 @@ function generateOptions(length, disabledOptions, hideDisabledOptions) {
17 return arr; 18 return arr;
18} 19}
19 20
20const Panel = React.createClass({ 21class Panel extends Component {
21 propTypes: { 22 static propTypes = {
22 clearText: PropTypes.string, 23 clearText: PropTypes.string,
23 prefixCls: PropTypes.string, 24 prefixCls: PropTypes.string,
24 className: PropTypes.string, 25 className: PropTypes.string,
@@ -39,28 +40,27 @@ const Panel = React.createClass({
39 onClear: PropTypes.func, 40 onClear: PropTypes.func,
40 use12Hours: PropTypes.bool, 41 use12Hours: PropTypes.bool,
41 addon: PropTypes.func, 42 addon: PropTypes.func,
42 }, 43 };
43 44
44 getDefaultProps() { 45 static defaultProps = {
45 return { 46 prefixCls: 'rc-time-picker-panel',
46 prefixCls: 'rc-time-picker-panel', 47 onChange: noop,
47 onChange: noop, 48 onClear: noop,
48 onClear: noop, 49 disabledHours: noop,
49 disabledHours: noop, 50 disabledMinutes: noop,
50 disabledMinutes: noop, 51 disabledSeconds: noop,
51 disabledSeconds: noop, 52 defaultOpenValue: moment(),
52 defaultOpenValue: moment(), 53 use12Hours: false,
53 use12Hours: false, 54 addon: noop,
54 addon: noop, 55 };
55 };
56 },
57 56
58 getInitialState() { 57 constructor(props) {
59 return { 58 super(props);
60 value: this.props.value, 59 this.state = {
60 value: props.value,
61 selectionRange: [], 61 selectionRange: [],
62 }; 62 };
63 }, 63 }
64 64
65 componentWillReceiveProps(nextProps) { 65 componentWillReceiveProps(nextProps) {
66 const value = nextProps.value; 66 const value = nextProps.value;
@@ -69,30 +69,22 @@ const Panel = React.createClass({
69 value, 69 value,
70 }); 70 });
71 } 71 }
72 }, 72 }
73 73
74 onChange(newValue) { 74 onChange = (newValue) => {
75 this.setState({ value: newValue }); 75 this.setState({ value: newValue });
76 this.props.onChange(newValue); 76 this.props.onChange(newValue);
77 }, 77 }
78
79 onClear() {
80 this.props.onClear();
81 },
82 78
83 onCurrentSelectPanelChange(currentSelectPanel) { 79 onCurrentSelectPanelChange = (currentSelectPanel) => {
84 this.setState({ currentSelectPanel }); 80 this.setState({ currentSelectPanel });
85 }, 81 }
86
87 close() {
88 this.props.onEsc();
89 },
90 82
91 render() { 83 render() {
92 const { 84 const {
93 prefixCls, className, placeholder, disabledHours, disabledMinutes, 85 prefixCls, className, placeholder, disabledHours, disabledMinutes,
94 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, 86 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
95 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, 87 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
96 } = this.props; 88 } = this.props;
97 const { 89 const {
98 value, currentSelectPanel, 90 value, currentSelectPanel,
@@ -123,7 +115,7 @@ const Panel = React.createClass({
123 disabledMinutes={disabledMinutes} 115 disabledMinutes={disabledMinutes}
124 disabledSeconds={disabledSeconds} 116 disabledSeconds={disabledSeconds}
125 onChange={this.onChange} 117 onChange={this.onChange}
126 onClear={this.onClear} 118 onClear={onClear}
127 allowEmpty={allowEmpty} 119 allowEmpty={allowEmpty}
128 /> 120 />
129 <Combobox 121 <Combobox
@@ -147,7 +139,7 @@ const Panel = React.createClass({
147 {addon(this)} 139 {addon(this)}
148 </div> 140 </div>
149 ); 141 );
150 }, 142 }
151}); 143}
152 144
153export default Panel; 145export default Panel;