@@ -7,13 +7,15 @@ export function HighlightedText({
7
7
highlightClassName,
8
8
style,
9
9
containerElement,
10
+ caseSensitive,
10
11
} : {
11
12
text : string
12
13
highlightedText : string [ ] | string
13
14
highlightClassName ?: string
14
15
className ?: string
15
16
style ?: React . CSSProperties
16
17
containerElement ?: React . ElementType
18
+ caseSensitive ?: boolean
17
19
} ) {
18
20
const parts = useMemo ( ( ) => {
19
21
const highlights = Array . isArray ( highlightedText )
@@ -22,10 +24,11 @@ export function HighlightedText({
22
24
if ( ! highlights . length ) return text
23
25
const delimiterRegex = new RegExp (
24
26
`(${ highlights . map ( ( it ) => it . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ) . join ( "|" ) } )` ,
25
- "g ",
27
+ caseSensitive ? "g" : "gi ",
26
28
)
29
+ console . log ( "Case sensitive:" , delimiterRegex , highlightedText )
27
30
return text . split ( delimiterRegex ) . reduce ( ( acc , it , i ) => {
28
- if ( highlights . includes ( it ) ) {
31
+ if ( delimiterRegex . test ( it ) ) {
29
32
acc . push (
30
33
< span
31
34
key = { i }
@@ -42,7 +45,7 @@ export function HighlightedText({
42
45
acc . push ( it )
43
46
return acc
44
47
} , [ ] as React . ReactNode [ ] )
45
- } , [ text , highlightClassName , highlightedText ] )
48
+ } , [ text , highlightClassName , highlightedText , caseSensitive ] )
46
49
47
50
const ContainerElement = containerElement || "p"
48
51
0 commit comments