@up-group-ui/react-controls
Version:
Up shared react controls
59 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var Input_1 = (0, tslib_1.__importDefault)(require("../Input"));
var _ = (0, tslib_1.__importStar)(require("lodash"));
var UpPhone = (function (_super) {
(0, tslib_1.__extends)(UpPhone, _super);
function UpPhone(p, c) {
var _this = _super.call(this, p, c) || this;
_this.phoneHandleChangeEvent = function (event, value, error) {
_this.setState({ value: value, error: error }, function () {
if (_this.props.onChange) {
_this.props.onChange(event, value, error);
}
});
};
_this.state = {};
return _this;
}
Object.defineProperty(UpPhone.prototype, "isControlled", {
get: function () {
return this.props.value !== undefined;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UpPhone.prototype, "currentValue", {
get: function () {
return this.isControlled ? this.props.value : this.state.value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UpPhone.prototype, "currentError", {
get: function () {
return this.isControlled ? this.props.error : this.state.error;
},
enumerable: false,
configurable: true
});
UpPhone.prototype.render = function () {
return ((0, jsx_runtime_1.jsx)(Input_1.default, (0, tslib_1.__assign)({}, this.props, { iconName: "phone", value: this.currentValue, onChange: this.phoneHandleChangeEvent, error: this.currentError, hasError: !_.isEmpty(this.currentError), tabIndex: this.props.tabIndex }), void 0));
};
UpPhone.defaultProps = {
showError: true,
defaultValue: '',
validation: [
{
pattern: /^(0|\+33)[1-9]([-. ]*[0-9]{2}){4}$/,
errorMessage: 'Le champ doit être un numéro de téléphone',
},
],
};
return UpPhone;
}(react_1.default.Component));
exports.default = UpPhone;
//# sourceMappingURL=UpPhone.js.map