@gechiui/components
Version:
UI components for GeChiUI.
31 lines (25 loc) • 671 B
JavaScript
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import { escapeRegExp } from 'lodash';
/**
* GeChiUI dependencies
*/
import { createInterpolateElement } from '@gechiui/element';
const TextHighlight = _ref => {
let {
text = '',
highlight = ''
} = _ref;
const trimmedHighlightText = highlight.trim();
if (!trimmedHighlightText) {
return text;
}
const regex = new RegExp(`(${escapeRegExp(trimmedHighlightText)})`, 'gi');
return createInterpolateElement(text.replace(regex, '<mark>$&</mark>'), {
mark: createElement("mark", null)
});
};
export default TextHighlight;
//# sourceMappingURL=index.js.map