Repository URL to install this package:
|
Version:
3.12.16 ▾
|
import { jsx as _jsx } from "react/jsx-runtime";
var TextWithHighlights = function TextWithHighlights(_ref) {
var _ref$text = _ref.text,
text = _ref$text === void 0 ? '' : _ref$text,
_ref$hightlightText = _ref.hightlightText,
hightlightText = _ref$hightlightText === void 0 ? '' : _ref$hightlightText,
_ref$hightlightBackgr = _ref.hightlightBackgroundColor,
hightlightBackgroundColor = _ref$hightlightBackgr === void 0 ? 'rgb(104 121 235 / 17%)' : _ref$hightlightBackgr;
if (!text || !hightlightText) {
return text;
}
// to handle search with "+"
var regexp = hightlightText === '+' ? new RegExp("[".concat(hightlightText, "]"), 'gi') : new RegExp(hightlightText, 'gi');
var includesSubStr = hightlightText === '+' ? regexp.test([text] || '') : regexp.test(text || '');
if (!includesSubStr) {
return text;
}
return /*#__PURE__*/_jsx("span", {
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML: {
__html: text.replace(regexp, "<span style=\"background: ".concat(hightlightBackgroundColor, ";\">$&</span>"))
}
});
};
export default TextWithHighlights;