sws-frontend
Version:
sws frontend project
67 lines • 4.21 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 __());
};
})();
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 react_bootstrap_1 = require("react-bootstrap");
//import * as ReactQuill from 'react-quill';
var react_mentions_1 = require("react-mentions");
require("./mentionfield.scss");
var MentionField = (function (_super) {
__extends(MentionField, _super);
function MentionField(p) {
var _this = _super.call(this, p) || this;
_this.onChange = _this.onChange.bind(_this);
_this.state = {
typing: false
};
return _this;
}
MentionField.prototype.onChange = function (e) {
//console.log(e);
this.props.onChange(e);
};
MentionField.prototype.displayTransform = function (id, display, type) {
return ' ' + type + ' | ' + id.split(":")[0] + ' ';
};
MentionField.prototype.renderSuggestion = function (suggestion, search, highlightedDisplay) {
return (React.createElement("div", { className: "user" }, highlightedDisplay));
};
MentionField.prototype.filterParams = function (query, type, mentions) {
var regex = new RegExp(query, "i");
return mentions.filter(function (f) { return f.type == type && (f.display || f.id).search(regex) > -1; });
};
MentionField.prototype.render = function () {
var _this = this;
var _a = this.props, withMention = _a.withMention, mentions = _a.mentions, disabled = _a.disabled, onChange = _a.onChange, mentionsTypes = _a.mentionsTypes, markup = _a.markup, className = _a.className, style = _a.style, displayTransform = _a.displayTransform, renderSuggestion = _a.renderSuggestion, fCProps = __rest(_a, ["withMention", "mentions", "disabled", "onChange", "mentionsTypes", "markup", "className", "style", "displayTransform", "renderSuggestion"]);
var typing = this.state.typing;
return (withMention ?
React.createElement("div", { className: "mention-field form-control type-" + (fCProps.type || 'text') + (typing ? ' typing' : '') + ' ' + className, style: style },
React.createElement(react_mentions_1.MentionsInput, { disabled: disabled, className: "mention-input", value: fCProps.value ? fCProps.value : '', onChange: this.onChange, markup: markup, displayTransform: (displayTransform && displayTransform) || this.displayTransform, singleLine: true, onFocus: function (e) { return _this.setState({ typing: true }); }, onBlur: function (e) { return _this.setState({ typing: false }); } }, mentionsTypes.map(function (m, mi) {
return (React.createElement(react_mentions_1.Mention, { key: mi, className: "mention-mention", trigger: "$", data: function (query) { return _this.filterParams(query, m, mentions); }, renderSuggestion: (renderSuggestion && renderSuggestion) || _this.renderSuggestion, type: m }));
})))
:
React.createElement(react_bootstrap_1.FormControl, { componentClass: fCProps.componentClass, type: fCProps.type, value: fCProps.value, bsSize: fCProps.bsSize, bsClass: fCProps.bsClass, className: className, style: style, disabled: disabled, onChange: this.onChange }));
};
return MentionField;
}(React.Component));
;
exports.default = MentionField;
//# sourceMappingURL=mentionfield.js.map