@@ -7,13 +7,15 @@ export function HighlightedText({
77 highlightClassName,
88 style,
99 containerElement,
10+ caseSensitive,
1011} : {
1112 text : string
1213 highlightedText : string [ ] | string
1314 highlightClassName ?: string
1415 className ?: string
1516 style ?: React . CSSProperties
1617 containerElement ?: React . ElementType
18+ caseSensitive ?: boolean
1719} ) {
1820 const parts = useMemo ( ( ) => {
1921 const highlights = Array . isArray ( highlightedText )
@@ -22,10 +24,11 @@ export function HighlightedText({
2224 if ( ! highlights . length ) return text
2325 const delimiterRegex = new RegExp (
2426 `(${ highlights . map ( ( it ) => it . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ) . join ( "|" ) } )` ,
25- "g ",
27+ caseSensitive ? "g" : "gi ",
2628 )
29+ console . log ( "Case sensitive:" , delimiterRegex , highlightedText )
2730 return text . split ( delimiterRegex ) . reduce ( ( acc , it , i ) => {
28- if ( highlights . includes ( it ) ) {
31+ if ( delimiterRegex . test ( it ) ) {
2932 acc . push (
3033 < span
3134 key = { i }
@@ -42,7 +45,7 @@ export function HighlightedText({
4245 acc . push ( it )
4346 return acc
4447 } , [ ] as React . ReactNode [ ] )
45- } , [ text , highlightClassName , highlightedText ] )
48+ } , [ text , highlightClassName , highlightedText , caseSensitive ] )
4649
4750 const ContainerElement = containerElement || "p"
4851
0 commit comments