@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
90 lines • 4.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var BaseControl_1 = require("../_Common/BaseControl/BaseControl");
var theming_1 = require("../../../Common/theming");
var react_textarea_autosize_1 = require("react-textarea-autosize");
var styles_1 = require("./styles");
var classnames = require("classnames");
var BaseTextArea = (function (_super) {
tslib_1.__extends(BaseTextArea, _super);
function BaseTextArea() {
return _super !== null && _super.apply(this, arguments) || this;
}
BaseTextArea.prototype.render = function () {
var _a;
var _b = this.props, className = _b.className, value = _b.value, onChange = _b.onChange, name = _b.name, tabIndex = _b.tabIndex, placeholder = _b.placeholder, readonly = _b.readonly, maxChar = _b.maxChar, maxCharMsg = _b.maxCharMsg, maxCharMsgShowNumber = _b.maxCharMsgShowNumber, disabled = _b.disabled;
var shouldDisplayMaxCharMsg = maxCharMsgShowNumber
? (value === null || value === void 0 ? void 0 : value.length) > maxCharMsgShowNumber
: true;
var templateMsg = maxCharMsg &&
maxCharMsg
.replace('{{numberOfChar}}', ((_a = value === null || value === void 0 ? void 0 : value.length) === null || _a === void 0 ? void 0 : _a.toString()) || '0')
.replace('{{maxChar}}', (maxChar === null || maxChar === void 0 ? void 0 : maxChar.toString()) || '');
var dataAttributs = {};
if (this.props.dataFor) {
dataAttributs['data-tip'] = 'tooltip';
dataAttributs['data-for'] = this.props.dataFor;
}
return (React.createElement(React.Fragment, null,
React.createElement(react_textarea_autosize_1.default, tslib_1.__assign({ disabled: disabled, value: value, readOnly: readonly, name: name, placeholder: placeholder, tabIndex: tabIndex, className: classnames(className, 'up-text', {
'up-text-error': (value === null || value === void 0 ? void 0 : value.length) > maxChar,
}), onChange: function (e) { return onChange(e, e.target.value); } }, dataAttributs)),
maxChar && shouldDisplayMaxCharMsg && (React.createElement("div", { className: classnames(className, 'up-text-max-characters') },
React.createElement("span", { className: classnames(className, 'up-text-max-characters-msg') }, templateMsg)))));
};
return BaseTextArea;
}(React.Component));
var UpText = (function (_super) {
tslib_1.__extends(UpText, _super);
function UpText(p, c) {
var _this = _super.call(this, p, c) || this;
_this.onChange = function (event, value) {
event.persist();
var _a = _this.props, forceMaxChar = _a.forceMaxChar, maxChar = _a.maxChar;
var _value = event.target.value;
if (forceMaxChar &&
maxChar &&
_value &&
_value.length > maxChar) {
_value = _value.substr(0, maxChar);
}
event.target.value = _value;
_this.handleChangeEvent(event, _value);
};
_this.getValue = _this.getValue.bind(_this);
_this.state = {
value: p.value,
};
return _this;
}
UpText.prototype.showError = function () {
return this.props.showError !== undefined
? this.props.showError === true
: this.hasError;
};
UpText.prototype.showSuccess = function () {
return this.props.showSuccess;
};
UpText.prototype.getValue = function (event) {
return event != null && event.target != null
? event.target.value
: event;
};
UpText.prototype.renderControl = function () {
var _a = this.props, onChange = _a.onChange, className = _a.className, tooltip = _a.tooltip, value = _a.value, others = tslib_1.__rest(_a, ["onChange", "className", "tooltip", "value"]);
return (React.createElement(BaseTextArea, tslib_1.__assign({ className: classnames(styles_1.getStyles(this.props), className), value: this.currentValue, onChange: this.onChange }, others)));
};
UpText.defaultProps = {
width: 'fill',
showError: true,
theme: theming_1.default,
readonly: false,
maxCharMsg: 'Vous avez saisi {{numberOfChar}} sur un nombre maximal de {{maxChar}}',
forceMaxChar: false,
};
return UpText;
}(BaseControl_1.BaseControlComponent));
exports.default = UpText;
//# sourceMappingURL=UpText.js.map