@gem-mine/rmc-calendar
Version:
React Mobile Calendar Component(web and react-native)
122 lines (109 loc) • 4.3 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import * as React from 'react';
import { formatDate as _formatDate } from '../util';
var ConfirmPanel = function (_React$PureComponent) {
_inherits(ConfirmPanel, _React$PureComponent);
function ConfirmPanel() {
_classCallCheck(this, ConfirmPanel);
var _this = _possibleConstructorReturn(this, _React$PureComponent.apply(this, arguments));
_this.onOk = function () {
var _this$props = _this.props,
onOk = _this$props.onOk,
disableBtn = _this$props.disableBtn;
!disableBtn && onOk();
};
_this.onCancel = function () {
var onCancel = _this.props.onCancel;
onCancel && onCancel();
};
return _this;
}
ConfirmPanel.prototype.formatDate = function formatDate(date) {
var _props = this.props,
_props$formatStr = _props.formatStr,
formatStr = _props$formatStr === undefined ? '' : _props$formatStr,
locale = _props.locale;
return _formatDate(date, formatStr, locale);
};
ConfirmPanel.prototype.render = function render() {
var _props2 = this.props,
type = _props2.type,
locale = _props2.locale,
disableBtn = _props2.disableBtn,
renderConfirm = _props2.renderConfirm;
var _props3 = this.props,
startDateTime = _props3.startDateTime,
endDateTime = _props3.endDateTime;
if (startDateTime && endDateTime && +startDateTime > +endDateTime) {
var tmp = startDateTime;
startDateTime = endDateTime;
endDateTime = tmp;
}
var confirmConfig = null;
if (renderConfirm) {
confirmConfig = renderConfirm({ startDateTime: startDateTime, endDateTime: endDateTime, onOk: this.onOk, onCancel: this.onCancel });
if (confirmConfig.render) {
return React.createElement(
'div',
{ className: 'confirm-panel' },
confirmConfig.render()
);
}
}
var startTimeStr = startDateTime ? this.formatDate(startDateTime) : locale.noChoose;
var endTimeStr = endDateTime ? this.formatDate(endDateTime) : locale.noChoose;
var btnCls = disableBtn ? 'button button-disable' : 'button confirm';
var btnCancelCls = 'button';
if (type === 'one' || confirmConfig && confirmConfig.hideStartEnd) {
btnCls += ' button-full';
btnCancelCls += ' button-full';
}
return React.createElement(
'div',
{ className: 'confirm-panel' },
type === 'range' && (!confirmConfig || !confirmConfig.hideStartEnd) && React.createElement(
'div',
{ className: 'info' },
React.createElement(
'p',
null,
locale.start,
': ',
React.createElement(
'span',
{ className: !startDateTime ? 'grey' : '' },
startTimeStr
)
),
React.createElement(
'p',
null,
locale.end,
': ',
React.createElement(
'span',
{ className: !endDateTime ? 'grey' : '' },
endTimeStr
)
)
),
React.createElement(
'div',
{ className: btnCancelCls, onClick: this.onCancel },
locale.cancel
),
React.createElement(
'div',
{ className: btnCls, onClick: this.onOk },
locale.confirm
)
);
};
return ConfirmPanel;
}(React.PureComponent);
export default ConfirmPanel;
ConfirmPanel.defaultProps = {
formatStr: 'yyyy-MM-dd hh:mm'
};