kea-react
Version:
Componentes comunes de react
76 lines (75 loc) • 3.52 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ReactDateTime = require("react-datetime");
var React = require("react");
var Field = require("./formField");
var format = require("../format");
var text_1 = require("./text");
var hour_1 = require("./hour");
/**Selector de fecha y hora */
var DateTime = /** @class */ (function (_super) {
__extends(DateTime, _super);
function DateTime() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handleChange = function (value) {
if (!_this.props.onChange)
return;
if (!value)
_this.props.onChange(null);
if (typeof (value) == "string") {
}
else {
_this.props.onChange(value.toDate());
}
};
_this.handleHourChange = function (horas, minutos) {
if (!_this.props.onChange)
return;
var date = _this.dateValue;
if (!date) {
_this.props.onChange(null);
return;
}
else {
var newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), horas || 0, minutos || 0);
_this.props.onChange(newDate);
}
};
return _this;
}
Object.defineProperty(DateTime.prototype, "dateValue", {
get: function () {
var origValue = this.props.value;
var value = origValue == null ? null :
typeof (origValue) == "string" ? new Date(origValue) : origValue;
return value;
},
enumerable: true,
configurable: true
});
DateTime.prototype.render = function () {
var _this = this;
var value = this.dateValue;
var hours = value && value.getHours();
var minutes = value && value.getMinutes();
return (React.createElement(Field.FormField, { label: this.props.label, error: this.props.error }, React.createElement("div", { style: { display: "flex" } },
React.createElement("div", { style: { flex: "1 0 0" } }, this.props.isReadOnly ?
React.createElement(text_1.Text, { value: (this.props.value ? format.FormatDate(this.props.value) : "Sin fecha"), isReadOnly: true }) :
React.createElement(ReactDateTime, { locale: "es", value: value || undefined, onChange: this.handleChange, dateFormat: "DD/MM/YYYY", closeOnSelect: true, timeFormat: false })),
this.props.time &&
React.createElement("div", { style: { flex: "1 0 0" } },
React.createElement(hour_1.HourMinuteComponent, { min: 0, max: 24, hours: hours, minutes: minutes, onChange: function (x) { return _this.handleHourChange(x.hours, x.minutes); }, readonly: this.props.isReadOnly })))));
};
return DateTime;
}(React.PureComponent));
exports.DateTime = DateTime;