X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FTimePicker.jsx;h=01bab2c5b5185e33ba0431ac200da40c441725ab;hb=ed8496061a1535fb82503d9723a6014a85ee7625;hp=ad4e834a60277cdc8d0795efd6e142a23461fc37;hpb=71bd9bc11f2ca6068f7977ff3511b2798f73d0c6;p=github%2Ffretlink%2Ftime-picker.git
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index ad4e834..01bab2c 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -1,10 +1,8 @@
-import React, {PropTypes} from 'react';
+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 defaultGregorianCalendarLocale from 'gregorian-calendar/lib/locale/en_US';
+import Panel from './Panel';
+import placements from './placements';
+import moment from 'moment';
function noop() {
}
@@ -16,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,13 +26,13 @@ const Picker = React.createClass({
placement: PropTypes.any,
transitionName: PropTypes.string,
getPopupContainer: PropTypes.func,
- gregorianCalendarLocale: PropTypes.object,
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,
@@ -41,19 +40,21 @@ const Picker = React.createClass({
onChange: PropTypes.func,
onOpen: PropTypes.func,
onClose: PropTypes.func,
+ addon: PropTypes.func,
},
- mixins: [CommonMixin],
-
getDefaultProps() {
return {
+ clearText: 'clear',
+ prefixCls: 'rc-time-picker',
defaultOpen: false,
style: {},
className: '',
- gregorianCalendarLocale: defaultGregorianCalendarLocale,
align: {},
+ defaultOpenValue: moment(),
allowEmpty: true,
showHour: true,
+ showMinute: true,
showSecond: true,
disabledHours: noop,
disabledMinutes: noop,
@@ -63,6 +64,7 @@ const Picker = React.createClass({
onChange: noop,
onOpen: noop,
onClose: noop,
+ addon: noop,
};
},
@@ -77,13 +79,13 @@ const Picker = React.createClass({
componentWillReceiveProps(nextProps) {
const { value, open } = nextProps;
- if (value !== undefined) {
+ if ('value' in nextProps) {
this.setState({
value,
});
}
if (open !== undefined) {
- this.setState({open});
+ this.setState({ open });
}
},
@@ -102,7 +104,7 @@ const Picker = React.createClass({
onEsc() {
this.setOpen(false);
- this.refs.picker.focus();
+ this.focus();
},
onKeyDown(e) {
@@ -120,71 +122,52 @@ 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;
- }
- if (!this.normalFormatter) {
- this.normalFormatter = getFormatter('HH:mm:ss', locale);
+ getFormat() {
+ const { format, showHour, showMinute, showSecond } = this.props;
+ if (format) {
+ return format;
}
- return this.normalFormatter;
+ return [
+ showHour ? 'HH' : '',
+ showMinute ? 'mm' : '',
+ showSecond ? 'ss' : '',
+ ].filter(item => !!item).join(':');
},
getPanelElement() {
- const { prefixCls, defaultValue, locale, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, gregorianCalendarLocale, value } = this.props;
- let calendarLocale;
- if (value) {
- calendarLocale = value.locale;
- } else if (defaultValue) {
- calendarLocale = defaultValue.locale;
- } else {
- calendarLocale = gregorianCalendarLocale;
- }
+ const {
+ prefixCls, placeholder, disabledHours,
+ disabledMinutes, disabledSeconds, hideDisabledOptions,
+ allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
+ addon,
+ } = this.props;
return (
);
},
setOpen(open, callback) {
- const {onOpen, onClose} = this.props;
+ const { onOpen, onClose } = this.props;
if (this.state.open !== open) {
this.setState({
open,
@@ -200,11 +183,19 @@ const Picker = React.createClass({
}
},
+ focus() {
+ this.refs.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,
+ } = this.props;
const { open, value } = this.state;
let popupClassName;
- if (!showHour || !showSecond) {
+ if (!showHour || !showMinute || !showSecond) {
popupClassName = `${prefixCls}-panel-narrow`;
}
return (
@@ -223,11 +214,13 @@ const Picker = React.createClass({
onPopupVisibleChange={this.onVisibleChange}
>
-
+