| 1 |
import { getHighlightSegments } from "../search"; |
| 2 |
|
| 3 |
interface HighlightedTextProps { |
| 4 |
content: string; |
| 5 |
searchTerm: string; |
| 6 |
highlightColor: string; |
| 7 |
} |
| 8 |
|
| 9 |
export function HighlightedText({ |
| 10 |
content, |
| 11 |
searchTerm, |
| 12 |
highlightColor, |
| 13 |
}: HighlightedTextProps) { |
| 14 |
const segments = getHighlightSegments(content, searchTerm); |
| 15 |
|
| 16 |
return ( |
| 17 |
<> |
| 18 |
{segments.map((segment, index) => |
| 19 |
segment.highlighted ? ( |
| 20 |
<mark |
| 21 |
key={index} |
| 22 |
style={{ |
| 23 |
backgroundColor: highlightColor, |
| 24 |
borderRadius: "2px", |
| 25 |
}} |
| 26 |
> |
| 27 |
{segment.text} |
| 28 |
</mark> |
| 29 |
) : ( |
| 30 |
segment.text |
| 31 |
) |
| 32 |
)} |
| 33 |
</> |
| 34 |
); |
| 35 |
} |
| 36 |
|