UNPKG

kea-react

Version:

Componentes comunes de react

73 lines (72 loc) 3.07 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; }; Object.defineProperty(exports, "__esModule", { value: true }); var text_1 = require("./text"); var React = require("react"); var Field = require("./formField"); function parseValue(val) { var phoneRegex = /((?:\d|-|\s|\t|,)+)\s*(?:ext\.\s+(.*))?/; if (phoneRegex.test(val)) { var result = phoneRegex.exec(val); return { phone: result[1], ext: result[2] }; } else { return { phone: val, ext: "" }; } } function valueToString(value) { return value.ext ? value.phone + " ext. " + value.ext : value.phone; } var Phone = /** @class */ (function (_super) { __extends(Phone, _super); function Phone() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handlePhoneChange = function (value) { if (_this.props.onChange) { _this.props.onChange(valueToString(__assign({}, _this.parsedValue, { phone: value }))); } }; _this.handleExtChange = function (value) { if (_this.props.onChange) { _this.props.onChange(valueToString(__assign({}, _this.parsedValue, { ext: value }))); } }; return _this; } Object.defineProperty(Phone.prototype, "parsedValue", { get: function () { return parseValue(this.props.value || ""); }, enumerable: true, configurable: true }); Phone.prototype.render = function () { var parse = this.parsedValue; return (React.createElement(Field.FormField, { label: this.props.label, error: this.props.error }, React.createElement("div", { style: { display: "flex" } }, React.createElement("div", { style: { flex: "3 0 0" } }, React.createElement(text_1.Text, { value: parse.phone, onChange: this.handlePhoneChange, placeholder: "teléfono" })), !this.props.hideExtension && React.createElement("div", { style: { flex: "1 0 0" } }, React.createElement(text_1.Text, { value: parse.ext, onChange: this.handleExtChange, placeholder: "ext." }))))); }; return Phone; }(React.PureComponent)); exports.Phone = Phone;