X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FTimePicker.jsx;h=70653331185a61a7738d3383157806a45a4128e9;hb=4e020febdf6201ab5f10a0e49be81c6ff32daaeb;hp=86faa714e09af9a9ab1b64cfcd127987db3f4106;hpb=04de55f8a50f58575ccda435ba62edfca1d4a5e4;p=github%2Ffretlink%2Ftime-picker.git
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index 86faa71..7065333 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -1,9 +1,8 @@
import React, { PropTypes } from 'react';
import Trigger from 'rc-trigger';
-import Panel from './module/Panel';
-import placements from './util/placements';
-import CommonMixin from './mixin/CommonMixin';
-import { getFormatter } from './util/index';
+import Panel from './Panel';
+import placements from './placements';
+import moment from 'moment';
function noop() {
}
@@ -15,8 +14,9 @@ function refFn(field, component) {
const Picker = React.createClass({
propTypes: {
prefixCls: PropTypes.string,
- locale: PropTypes.object,
+ clearText: PropTypes.string,
value: PropTypes.object,
+ defaultOpenValue: PropTypes.object,
disabled: PropTypes.bool,
allowEmpty: PropTypes.bool,
defaultValue: PropTypes.object,
@@ -27,11 +27,12 @@ const Picker = React.createClass({
transitionName: PropTypes.string,
getPopupContainer: PropTypes.func,
placeholder: PropTypes.string,
- formatter: PropTypes.any,
+ format: PropTypes.string,
showHour: PropTypes.bool,
+ showMinute: PropTypes.bool,
+ showSecond: PropTypes.bool,
style: PropTypes.object,
className: PropTypes.string,
- showSecond: PropTypes.bool,
disabledHours: PropTypes.func,
disabledMinutes: PropTypes.func,
disabledSeconds: PropTypes.func,
@@ -39,19 +40,24 @@ const Picker = React.createClass({
onChange: PropTypes.func,
onOpen: PropTypes.func,
onClose: PropTypes.func,
+ addon: PropTypes.func,
+ name: PropTypes.string,
+ autoComplete: PropTypes.string,
+ use12Hours: PropTypes.bool,
},
- mixins: [CommonMixin],
-
getDefaultProps() {
return {
+ clearText: 'clear',
prefixCls: 'rc-time-picker',
defaultOpen: false,
style: {},
className: '',
align: {},
+ defaultOpenValue: moment(),
allowEmpty: true,
showHour: true,
+ showMinute: true,
showSecond: true,
disabledHours: noop,
disabledMinutes: noop,
@@ -61,10 +67,13 @@ const Picker = React.createClass({
onChange: noop,
onOpen: noop,
onClose: noop,
+ addon: noop,
+ use12Hours: false,
};
},
getInitialState() {
+ this.saveInputRef = refFn.bind(this, 'picker');
this.savePanelRef = refFn.bind(this, 'panelInstance');
const { defaultOpen, defaultValue, open = defaultOpen, value = defaultValue } = this.props;
return {
@@ -100,7 +109,7 @@ const Picker = React.createClass({
onEsc() {
this.setOpen(false);
- this.refs.picker.focus();
+ this.focus();
},
onKeyDown(e) {
@@ -118,87 +127,89 @@ const Picker = React.createClass({
this.props.onChange(value);
},
- getFormatter() {
- const formatter = this.props.formatter;
- const locale = this.props.locale;
- if (formatter) {
- if (formatter === this.lastFormatter) {
- return this.normalFormatter;
- }
- this.normalFormatter = getFormatter(formatter, locale);
- this.lastFormatter = formatter;
- return this.normalFormatter;
- }
- if (!this.props.showSecond) {
- if (!this.notShowSecondFormatter) {
- this.notShowSecondFormatter = getFormatter('HH:mm', locale);
- }
- return this.notShowSecondFormatter;
- }
- if (!this.props.showHour) {
- if (!this.notShowHourFormatter) {
- this.notShowHourFormatter = getFormatter('mm:ss', locale);
- }
- return this.notShowHourFormatter;
+ getFormat() {
+ const { format, showHour, showMinute, showSecond, use12Hours } = this.props;
+ if (format) {
+ return format;
}
- if (!this.normalFormatter) {
- this.normalFormatter = getFormatter('HH:mm:ss', locale);
+
+ if (use12Hours) {
+ const fmtString = ([
+ showHour ? 'h' : '',
+ showMinute ? 'mm' : '',
+ showSecond ? 'ss' : '',
+ ].filter(item => !!item).join(':'));
+
+ return fmtString.concat(' a');
}
- return this.normalFormatter;
+
+ return [
+ showHour ? 'HH' : '',
+ showMinute ? 'mm' : '',
+ showSecond ? 'ss' : '',
+ ].filter(item => !!item).join(':');
},
getPanelElement() {
const {
- prefixCls, defaultValue, locale, placeholder, disabledHours,
+ prefixCls, placeholder, disabledHours,
disabledMinutes, disabledSeconds, hideDisabledOptions,
- allowEmpty, showHour, showSecond,
+ allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
+ addon, use12Hours,
} = this.props;
return (
);
},
- setOpen(open, callback) {
+ setOpen(open) {
const { onOpen, onClose } = this.props;
if (this.state.open !== open) {
- this.setState({
- open,
- }, callback);
- const event = {
- open,
- };
+ if (!('open' in this.props)) {
+ this.setState({ open });
+ }
if (open) {
- onOpen(event);
+ onOpen({ open });
} else {
- onClose(event);
+ onClose({ open });
}
}
},
+ focus() {
+ this.picker.focus();
+ },
+
render() {
- const { prefixCls, placeholder, placement, align, disabled, transitionName, style, className, showHour, showSecond, getPopupContainer } = this.props;
+ const {
+ prefixCls, placeholder, placement, align,
+ disabled, transitionName, style, className, showHour,
+ showMinute, showSecond, getPopupContainer, name, autoComplete,
+ } = this.props;
const { open, value } = this.state;
let popupClassName;
- if (!showHour || !showSecond) {
+ if (!showHour || !showMinute || !showSecond) {
popupClassName = `${prefixCls}-panel-narrow`;
}
return (
@@ -219,10 +230,14 @@ const Picker = React.createClass({