1 | import PropTypes from 'prop-types';
|
2 | import React from 'react';
|
3 | const propTypes = {
|
4 | text: PropTypes.string,
|
5 | searchTerm: PropTypes.string
|
6 | };
|
7 |
|
8 | function AutocompleteListItem({
|
9 | text,
|
10 | searchTerm
|
11 | }) {
|
12 | if (!text || !searchTerm) return text;
|
13 | let idx = text.indexOf(searchTerm);
|
14 | if (idx === -1) idx = text.toLowerCase().indexOf(searchTerm);
|
15 | if (idx === -1 || searchTerm.length >= text.length) return text;
|
16 | return React.createElement(React.Fragment, null, text.slice(0, idx), React.createElement("strong", null, text.slice(idx, idx + searchTerm.length)), text.slice(idx + searchTerm.length));
|
17 | }
|
18 |
|
19 | AutocompleteListItem.propTypes = propTypes;
|
20 | export default AutocompleteListItem; |
\ | No newline at end of file |