UNPKG

kea-react

Version:

Componentes comunes de react

120 lines (119 loc) 6.29 kB
"use strict"; 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 __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var Field = require("./formField"); var NumberInput = require("react-number-input"); var async_1 = require("../async"); var fastInput_1 = require("./fastInput"); var format_1 = require("../format"); var cargando_1 = require("../cargando"); var slowInput_1 = require("./slowInput"); var TextIcon = /** @class */ (function (_super) { __extends(TextIcon, _super); function TextIcon() { return _super !== null && _super.apply(this, arguments) || this; } TextIcon.prototype.render = function () { //Quitamos los props que no le pertenecen al FastInput //ver https://github.com/facebook/react/issues/7266 var _a = this.props, addon = _a.addon, error = _a.error, isReadOnly = _a.isReadOnly, value = _a.value, label = _a.label, disableFastInput = _a.disableFastInput, props = __rest(_a, ["addon", "error", "isReadOnly", "value", "label", "disableFastInput"]); var input = disableFastInput ? React.createElement(slowInput_1.SlowInput, __assign({}, props, { className: "form-control", value: value || "", disabled: isReadOnly })) : React.createElement(fastInput_1.FastInput, __assign({}, props, { className: "form-control", value: value || "", disabled: isReadOnly, type: props.type || "text" })); return (addon ? React.createElement("div", { className: "input-group" }, React.createElement("span", { className: "input-group-addon" }, addon), input) : input); }; return TextIcon; }(React.PureComponent)); var TextInput = /** @class */ (function (_super) { __extends(TextInput, _super); function TextInput() { return _super !== null && _super.apply(this, arguments) || this; } TextInput.prototype.render = function () { return (React.createElement(Field.FormField, { label: this.props.label, error: this.props.error }, React.createElement(TextIcon, __assign({}, this.props)))); }; return TextInput; }(React.PureComponent)); /**Un campo de texto */ var Text = /** @class */ (function (_super) { __extends(Text, _super); function Text() { return _super !== null && _super.apply(this, arguments) || this; } Text.prototype.render = function () { var _this = this; return (async_1.async(this.props.value, function (x) { return React.createElement(TextInput, __assign({}, __assign({}, _this.props, { type: "text", value: (x || "") }))); }, { cargando: React.createElement(TextInput, { isReadOnly: this.props.isReadOnly, onChange: this.props.onChange, value: "", placeholder: "Cargando...", multiline: this.props.multiline, type: "text", addon: React.createElement(cargando_1.Spinner, null), disableFastInput: true }) })); }; return Text; }(React.PureComponent)); exports.Text = Text; /**Un campo numérico */ var Number = /** @class */ (function (_super) { __extends(Number, _super); function Number() { return _super !== null && _super.apply(this, arguments) || this; } Number.prototype.render = function () { var format = this.props.format == "decimal" ? "0,0[.]00" : this.props.format == "int" ? "0" : this.props.format == "currency" ? "$0,0.00" : this.props.format == "percentage" ? "0%" : this.props.format == "int-2-digit" ? "00" : this.props.format == undefined ? "0,0[.][00]" : this.props.format; var text = this.props.format == "currency" ? format_1.FormatCurrency(this.props.value) : (this.props.value + ""); var textProps = __assign({}, this.props, { value: text, onChange: undefined, isReadOnly: true }); var readOnly = React.createElement(Text, __assign({}, textProps)); var editor = React.createElement(Field.FormField, { label: this.props.label, error: this.props.error }, React.createElement(NumberInput.default, { className: "form-control", value: this.props.value, onChange: this.props.onChange, format: format, placeholder: this.props.placeholder, min: this.props.min, max: this.props.max })); return this.props.isReadOnly ? readOnly : editor; }; return Number; }(React.PureComponent)); exports.Number = Number; /**Un campo de contraseña */ var Password = /** @class */ (function (_super) { __extends(Password, _super); function Password() { return _super !== null && _super.apply(this, arguments) || this; } Password.prototype.render = function () { return (React.createElement(TextInput, { type: "password", error: this.props.error, isReadOnly: this.props.isReadOnly, label: this.props.label, onChange: this.props.onChange, value: this.props.value, addon: this.props.addon })); }; return Password; }(React.PureComponent)); exports.Password = Password;