chayns-components
Version:
A set of beautiful React components for developing chayns® applications.
32 lines (31 loc) • 1.16 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import "./ResultSelection.css";
const escapeRegExp = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const ResultSelection = _ref => {
let {
text = '',
search = ''
} = _ref;
const regexp = new RegExp(escapeRegExp(search), 'gi');
const mismatches = text.split(regexp);
const matches = text.match(regexp);
const mismatchesWithId = mismatches.map((part, index) => ({
value: part,
id: index
}));
return mismatchesWithId.map((mismatch, mismatchIndex) => [/*#__PURE__*/React.createElement("span", {
key: `${mismatch.id}_missmatch`,
className: "cc__result-selection cc__result-selection--mismatch"
}, mismatch.value), matches && mismatchIndex < matches.length && /*#__PURE__*/React.createElement("span", {
key: `${mismatch.id}_match`,
className: "cc__result-selection cc__result-selection--match"
}, matches[mismatchIndex])]);
};
ResultSelection.propTypes = {
text: PropTypes.string,
search: PropTypes.string
};
ResultSelection.displayName = 'ResultSelection';
export default ResultSelection;
//# sourceMappingURL=ResultSelection.js.map