rn-highlighter
Version:
rn-highlighter is a simple and effective way to highlight text in React Native applications.
32 lines (31 loc) • 774 B
JavaScript
import React from 'react';
import { Text } from 'react-native';
import { jsx as _jsx } from "react/jsx-runtime";
export const Highlighter = ({
text,
highlight,
highlightStyle = {
backgroundColor: 'yellow'
},
textStyle = {}
}) => {
if (!highlight) {
return /*#__PURE__*/_jsx(Text, {
style: textStyle,
children: text
});
}
const regex = new RegExp(`(${highlight})`, 'gi');
const parts = text.split(regex);
return /*#__PURE__*/_jsx(Text, {
style: textStyle,
children: parts.map((part, index) => regex.test(part) ? /*#__PURE__*/_jsx(Text, {
style: highlightStyle,
children: part
}, index) : /*#__PURE__*/_jsx(Text, {
children: part
}, index))
});
};
//# sourceMappingURL=index.js.map
;