1 import React, { PropTypes } from 'react';
2 import Trigger from 'rc-trigger';
3 import Panel from './Panel';
4 import placements from './placements';
5 import moment from 'moment';
10 function refFn(field, component) {
11 this[field] = component;
14 const Picker = React.createClass({
16 prefixCls: PropTypes.string,
17 clearText: PropTypes.string,
18 value: PropTypes.object,
19 defaultOpenValue: PropTypes.object,
20 disabled: PropTypes.bool,
21 allowEmpty: PropTypes.bool,
22 defaultValue: PropTypes.object,
24 defaultOpen: PropTypes.bool,
25 align: PropTypes.object,
26 placement: PropTypes.any,
27 transitionName: PropTypes.string,
28 getPopupContainer: PropTypes.func,
29 placeholder: PropTypes.string,
30 format: PropTypes.string,
31 showHour: PropTypes.bool,
32 showMinute: PropTypes.bool,
33 showSecond: PropTypes.bool,
34 style: PropTypes.object,
35 className: PropTypes.string,
36 disabledHours: PropTypes.func,
37 disabledMinutes: PropTypes.func,
38 disabledSeconds: PropTypes.func,
39 hideDisabledOptions: PropTypes.bool,
40 onChange: PropTypes.func,
41 onOpen: PropTypes.func,
42 onClose: PropTypes.func,
43 addon: PropTypes.func,
44 name: PropTypes.string,
45 autoComplete: PropTypes.string,
51 prefixCls: 'rc-time-picker',
56 defaultOpenValue: moment(),
62 disabledMinutes: noop,
63 disabledSeconds: noop,
64 hideDisabledOptions: false,
65 placement: 'bottomLeft',
74 this.saveInputRef = refFn.bind(this, 'picker');
75 this.savePanelRef = refFn.bind(this, 'panelInstance');
76 const { defaultOpen, defaultValue, open = defaultOpen, value = defaultValue } = this.props;
83 componentWillReceiveProps(nextProps) {
84 const { value, open } = nextProps;
85 if ('value' in nextProps) {
90 if (open !== undefined) {
91 this.setState({ open });
95 onPanelChange(value) {
104 onVisibleChange(open) {
114 if (e.keyCode === 40) {
120 if (!('value' in this.props)) {
125 this.props.onChange(value);
129 const { format, showHour, showMinute, showSecond } = this.props;
134 showHour ? 'HH' : '',
135 showMinute ? 'mm' : '',
136 showSecond ? 'ss' : '',
137 ].filter(item => !!item).join(':');
142 prefixCls, placeholder, disabledHours,
143 disabledMinutes, disabledSeconds, hideDisabledOptions,
144 allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
149 clearText={clearText}
150 prefixCls={`${prefixCls}-panel`}
151 ref={this.savePanelRef}
152 value={this.state.value}
153 onChange={this.onPanelChange}
154 onClear={this.onPanelClear}
155 defaultOpenValue={defaultOpenValue}
157 showMinute={showMinute}
158 showSecond={showSecond}
160 allowEmpty={allowEmpty}
161 format={this.getFormat()}
162 placeholder={placeholder}
163 disabledHours={disabledHours}
164 disabledMinutes={disabledMinutes}
165 disabledSeconds={disabledSeconds}
166 hideDisabledOptions={hideDisabledOptions}
173 const { onOpen, onClose } = this.props;
174 if (this.state.open !== open) {
175 if (!('open' in this.props)) {
176 this.setState({ open });
192 prefixCls, placeholder, placement, align,
193 disabled, transitionName, style, className, showHour,
194 showMinute, showSecond, getPopupContainer, name, autoComplete,
196 const { open, value } = this.state;
198 if (!showHour || !showMinute || !showSecond) {
199 popupClassName = `${prefixCls}-panel-narrow`;
203 prefixCls={`${prefixCls}-panel`}
204 popupClassName={popupClassName}
205 popup={this.getPanelElement()}
207 builtinPlacements={placements}
208 popupPlacement={placement}
209 action={disabled ? [] : ['click']}
211 getPopupContainer={getPopupContainer}
212 popupTransitionName={transitionName}
214 onPopupVisibleChange={this.onVisibleChange}
216 <span className={`${prefixCls} ${className}`} style={style}>
218 className={`${prefixCls}-input`}
219 ref={this.saveInputRef}
221 placeholder={placeholder}
224 onKeyDown={this.onKeyDown}
225 disabled={disabled} value={value && value.format(this.getFormat()) || ''}
226 autoComplete={autoComplete}
228 <span className={`${prefixCls}-icon`}/>
235 export default Picker;