2015-11-16 23:11:41 +08:00
|
|
|
import React from 'react';
|
|
|
|
import DateTimeFormat from 'gregorian-calendar-format';
|
|
|
|
import TimePicker from 'rc-time-picker/lib/TimePicker';
|
|
|
|
|
|
|
|
// import defaultLocale from './locale';
|
|
|
|
import TimePickerLocale from 'rc-time-picker/lib/locale/zh_CN';
|
|
|
|
|
2015-11-17 18:11:46 +08:00
|
|
|
const AntTimepicker = React.createClass({
|
2015-11-16 23:11:41 +08:00
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
format: 'HH:mm:ss',
|
|
|
|
placeholder: '请选择时间',
|
|
|
|
onChange() {}, // onChange 可用于 Validator
|
|
|
|
locale: {},
|
|
|
|
align: {
|
2015-11-18 12:14:26 +08:00
|
|
|
offset: [0, -1],
|
2015-11-16 23:11:41 +08:00
|
|
|
},
|
|
|
|
open: false,
|
|
|
|
disabled: false,
|
|
|
|
hourOptions: undefined,
|
|
|
|
minuteOptions: undefined,
|
|
|
|
secondOptions: undefined,
|
2015-11-18 12:14:26 +08:00
|
|
|
size: '',
|
|
|
|
placement: 'bottomLeft',
|
|
|
|
transitionName: 'slide-up',
|
2015-11-16 23:11:41 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-11-18 12:14:26 +08:00
|
|
|
/**
|
|
|
|
* 获得输入框的 className
|
|
|
|
*/
|
|
|
|
getSizeClass() {
|
|
|
|
let sizeClass = '';
|
|
|
|
if (this.props.size === 'large') {
|
|
|
|
sizeClass = ' ant-input-lg';
|
|
|
|
} else if (this.props.size === 'small') {
|
|
|
|
sizeClass = ' ant-input-sm';
|
|
|
|
}
|
|
|
|
return sizeClass;
|
|
|
|
},
|
2015-11-16 23:11:41 +08:00
|
|
|
|
2015-11-18 12:14:26 +08:00
|
|
|
/**
|
|
|
|
* 获得输入框的默认值
|
|
|
|
*/
|
|
|
|
getDefaultValue(formatter) {
|
|
|
|
const defaultValue = this.props.defaultValue;
|
2015-11-16 23:11:41 +08:00
|
|
|
if (defaultValue) {
|
2015-11-18 12:14:26 +08:00
|
|
|
return formatter.parse(defaultValue, {
|
2015-11-16 23:11:41 +08:00
|
|
|
locale: defaultValue.locale,
|
|
|
|
obeyCount: true,
|
|
|
|
});
|
|
|
|
}
|
2015-11-18 12:14:26 +08:00
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { format, placeholder, align, disabled, hourOptions, minuteOptions, secondOptions, placement, transitionName } = this.props;
|
|
|
|
const prefixCls = 'ant-timepicker';
|
|
|
|
const formatter = new DateTimeFormat(format);
|
2015-11-16 23:11:41 +08:00
|
|
|
|
|
|
|
return (
|
2015-11-18 12:14:26 +08:00
|
|
|
<TimePicker
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
locale={TimePickerLocale}
|
|
|
|
formatter={formatter}
|
|
|
|
hourOptions={hourOptions}
|
|
|
|
minuteOptions={minuteOptions}
|
|
|
|
secondOptions={secondOptions}
|
|
|
|
disabled={disabled}
|
|
|
|
align={align}
|
|
|
|
placeholder={placeholder}
|
|
|
|
inputClassName={`ant-input ${this.getSizeClass()}`}
|
|
|
|
defaultValue={this.getDefaultValue(formatter)}
|
|
|
|
placement={placement}
|
|
|
|
transitionName={transitionName}
|
|
|
|
/>
|
2015-11-16 23:11:41 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-11-17 18:11:46 +08:00
|
|
|
export default AntTimepicker;
|