Skip to content

Commit

Permalink
feat(ZNTA-68): Implemented highlighting a term in source text
Browse files Browse the repository at this point in the history
TODO: Pass the search term to the component as a prop
  • Loading branch information
efloden committed Jan 4, 2018
1 parent 8dff725 commit 155121e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions server/zanata-frontend/src/frontend/app/editor/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@
.fade.in {
opacity: 1;
}

.highlight {
background-color: yellow;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ class TransUnitSourcePanel extends React.Component {
{copyButton}
</div>
: undefined

// TODO: pass search as Prop to TransUnitSourcePanel @efloden
const search = 'Containers'
const getHighlightedText = (text, higlight) => {
// Split on higlight term and include term into parts, ignore case
const parts = text.split(new RegExp(`(${higlight})`, 'gi'))
return parts.map((part, index) =>
part.toLowerCase() === higlight.toLowerCase()
? <span key={index} className="highlight">{part}</span>
: <span key={index}>{part}</span>
)
}
const final = search ? getHighlightedText(source, search) : source
return (
<div className="TransUnit-item" key={index}>
{itemHeader}
<pre className="TransUnit-text">{source}</pre>
<pre className="TransUnit-text">{final}</pre>
</div>
)
})
Expand Down

0 comments on commit 155121e

Please sign in to comment.