Created
March 18, 2019 15:49
-
-
Save tonkec/16caaec8e6c43820e439356972fba8c0 to your computer and use it in GitHub Desktop.
test_feature_for_xircles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const KeywordHighlighter = (props) => { | |
const allowedKeywords = ["dosage", "happy", "sunny"]; // just some random words that would be highlighted | |
const filteredKeywords = allowedKeywords.filter((word) => props.value.includes(word)); | |
return ( | |
<div> | |
<textarea | |
type="text" | |
name="keyword" | |
value={props.value} | |
onChange={props.handleInputChange} | |
/> | |
<span> | |
{filteredKeywords.map((word, i) => ( | |
<span style={{backgroundColor: "red", color: "white"}} key={i}>{word}</span> | |
))} | |
</span> | |
</div> | |
) | |
} | |
class Filter extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
keyword: "" | |
}; | |
this.handleInputChange = this.handleInputChange.bind(this); | |
} | |
handleInputChange(evt) { | |
const inputKeyword = evt.target.value; | |
this.setState({ keyword: inputKeyword }); | |
} | |
render(){ | |
return( | |
<header className="header"> | |
<div className="wrapper"> | |
<form> | |
<KeywordHighlighter handleInputChange={this.handleInputChange} value={this.state.keyword} /> | |
</form> | |
</div> | |
</header> | |
) | |
} | |
} | |
export default Filter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment