Skip to content

Instantly share code, notes, and snippets.

@tonkec
Created March 18, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonkec/16caaec8e6c43820e439356972fba8c0 to your computer and use it in GitHub Desktop.
Save tonkec/16caaec8e6c43820e439356972fba8c0 to your computer and use it in GitHub Desktop.
test_feature_for_xircles
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