({
label,
matchedIndex,
userInput,
textColor,
highlightColor = Colors.AccentYellow,
})
| 18 | } |
| 19 | |
| 20 | export const PrepareLabel: React.FC<PrepareLabelProps> = ({ |
| 21 | label, |
| 22 | matchedIndex, |
| 23 | userInput, |
| 24 | textColor, |
| 25 | highlightColor = Colors.AccentYellow, |
| 26 | }) => { |
| 27 | if ( |
| 28 | matchedIndex === undefined || |
| 29 | matchedIndex < 0 || |
| 30 | matchedIndex >= label.length || |
| 31 | userInput.length === 0 |
| 32 | ) { |
| 33 | return <Text color={textColor}>{label}</Text>; |
| 34 | } |
| 35 | |
| 36 | const start = label.slice(0, matchedIndex); |
| 37 | const match = label.slice(matchedIndex, matchedIndex + userInput.length); |
| 38 | const end = label.slice(matchedIndex + userInput.length); |
| 39 | |
| 40 | return ( |
| 41 | <Text> |
| 42 | <Text color={textColor}>{start}</Text> |
| 43 | <Text color="black" bold backgroundColor={highlightColor}> |
| 44 | {match} |
| 45 | </Text> |
| 46 | <Text color={textColor}>{end}</Text> |
| 47 | </Text> |
| 48 | ); |
| 49 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected