choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
188 lines (157 loc) • 5.46 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import classNames from 'classnames';
import shallowequal from 'lodash/isEqual';
import Icon from '../icon';
import RcMention, { getMentions, Nav, toEditorState, toString } from '../rc-components/editor-mention';
import { getPrefixCls } from '../configure';
var Mention =
/*#__PURE__*/
function (_Component) {
_inherits(Mention, _Component);
var _super = _createSuper(Mention);
function Mention(props) {
var _this;
_classCallCheck(this, Mention);
_this = _super.call(this, props);
_this.onSearchChange = function (value, prefix) {
var onSearchChange = _this.props.onSearchChange;
if (onSearchChange) {
return onSearchChange(value, prefix);
}
return _this.defaultSearchChange(value);
};
_this.onFocus = function (ev) {
_this.setState({
focus: true
});
var onFocus = _this.props.onFocus;
if (onFocus) {
onFocus(ev);
}
};
_this.onBlur = function (ev) {
_this.setState({
focus: false
});
var onBlur = _this.props.onBlur;
if (onBlur) {
onBlur(ev);
}
};
_this.focus = function () {
_this.mentionEle._editor.focusEditor();
};
_this.mentionRef = function (ele) {
_this.mentionEle = ele;
};
_this.state = {
suggestions: props.suggestions,
focus: false
};
return _this;
}
_createClass(Mention, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
var suggestions = nextProps.suggestions;
var props = this.props;
if (!shallowequal(suggestions, props.suggestions)) {
this.setState({
suggestions: suggestions
});
}
}
}, {
key: "defaultSearchChange",
value: function defaultSearchChange(value) {
var searchValue = value.toLowerCase();
var suggestions = this.props.suggestions;
var filteredSuggestions = (suggestions || []).filter(function (suggestion) {
if (suggestion.type && suggestion.type === Nav) {
return suggestion.props.value ? suggestion.props.value.toLowerCase().indexOf(searchValue) !== -1 : true;
}
return suggestion.toLowerCase().indexOf(searchValue) !== -1;
});
this.setState({
suggestions: filteredSuggestions
});
}
}, {
key: "render",
value: function render() {
var _classNames;
var _this$props = this.props,
_this$props$className = _this$props.className,
className = _this$props$className === void 0 ? '' : _this$props$className,
customizePrefixCls = _this$props.prefixCls,
loading = _this$props.loading,
placement = _this$props.placement,
notFoundContent = _this$props.notFoundContent,
onChange = _this$props.onChange;
var prefixCls = getPrefixCls('mention', customizePrefixCls);
var _this$state = this.state,
suggestions = _this$state.suggestions,
focus = _this$state.focus;
var cls = classNames(className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-active"), focus), _defineProperty(_classNames, "".concat(prefixCls, "-placement-top"), placement === 'top'), _classNames));
var notFound = loading ? React.createElement(Icon, {
type: "loading"
}) : notFoundContent;
return React.createElement(RcMention, _extends({}, this.props, {
prefixCls: prefixCls,
className: cls,
ref: this.mentionRef,
onSearchChange: this.onSearchChange,
onChange: onChange,
onFocus: this.onFocus,
onBlur: this.onBlur,
suggestions: suggestions,
notFoundContent: notFound
}));
}
}]);
return Mention;
}(Component);
export { Mention as default };
Mention.displayName = 'Mention';
Mention.getMentions = getMentions;
Mention.defaultProps = {
notFoundContent: '无匹配结果,轻敲空格完成输入',
loading: false,
multiLines: false,
placement: 'bottom'
};
Mention.Nav = Nav;
Mention.toString = toString;
Mention.toContentState = toEditorState;
//# sourceMappingURL=index.js.map