File tree Expand file tree Collapse file tree 2 files changed +30
-21
lines changed
Expand file tree Collapse file tree 2 files changed +30
-21
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ const ValueBase = styled.div`
111111 font-size: ${ FontSizes . copy } ;
112112 padding: ${ Spacings . m } ${ Spacings . l } ;
113113`
114+
114115const TextWrapper = styled ( ValueBase ) `
115116 position: relative;
116117 flex: 1;
Original file line number Diff line number Diff line change 1+ import { styled } from 'styled-components'
2+
13interface highlighterProps {
24 term : string
35 children : string
46}
57
8+ const Text = styled . p `
9+ margin: 0;
10+ padding: 0;
11+ white-space: pre-wrap;
12+ word-break: break-word;
13+ `
14+
615const Highlighter : React . FC < highlighterProps > = ( { term, children } ) => {
716 if ( ! term ) {
8- return < > { children } </ >
17+ return < Text > { children } </ Text >
918 }
1019 const regex = new RegExp ( `(${ term } )` , 'gi' )
1120 const parts = children . split ( regex )
1221
1322 return (
1423 < >
15- < div > test</ div >
16- { parts . map ( ( part : string , index : number ) =>
17- regex . test ( part ) ? (
18- < span
19- key = { index }
20- style = { {
21- margin : 0 ,
22- backgroundColor : 'rgb(84 198 247)' ,
23- padding : 0 ,
24- whiteSpace : 'pre-wrap' ,
25- wordBreak : 'break-word' ,
26- fontWeight : 'bold' ,
27- } }
28- >
29- { part }
30- </ span >
31- ) : (
32- part
33- )
34- ) }
24+ < Text >
25+ < >
26+ { parts . map ( ( part : string , index : number ) =>
27+ regex . test ( part ) ? (
28+ < span
29+ key = { index }
30+ style = { {
31+ backgroundColor : 'rgb(84 198 247)' ,
32+ fontWeight : 'bold' ,
33+ } }
34+ >
35+ { part }
36+ </ span >
37+ ) : (
38+ part
39+ )
40+ ) }
41+ </ >
42+ </ Text >
3543 </ >
3644 )
3745}
You can’t perform that action at this time.
0 commit comments