Skip to content

Commit

Permalink
Added dynamic highlighting using <b> tag in Swipe Away box (speeches)
Browse files Browse the repository at this point in the history
Currently magic numbers for the RegExp at code line 276, but it works.  Sourced from @rehat101 at facebook/react#3386
  • Loading branch information
djD-REK committed Aug 9, 2019
1 parent 0696b81 commit bc6271f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const texts = {
"#7700FE": "Malas"
};
const initialSpeeches = [
"Yes! <b>You can do it!</b> <br /> <b>¡Puedes hacerlo!</b>",
"Yes, we say <br /> <b>Pingüinos son bellos</b> <br /> in penguin!"
"Yes! You can do it! ¡Puedes hacerlo!",
"Yes, we say Pingüinos son bellos in penguin!"
];

const CorrectWord = ({ color }) => {
Expand Down Expand Up @@ -272,6 +272,13 @@ const Speech = ({ speech, speeches, setSpeeches, i, text }) => {
clamp: false
});

const highlightRegExp = new RegExp(
/you|can|do|it|puedes|hacerlo|pingüinos|son|bellos/,
"gi"
);
const delineator = " ";
const parts = text.split(delineator);

return (
<motion.div
className="speechContainer"
Expand All @@ -296,7 +303,11 @@ const Speech = ({ speech, speeches, setSpeeches, i, text }) => {
}
}}
>
{text}
<div>
{parts.map(part =>
part.match(highlightRegExp) ? <b>{part + " "}</b> : part + " "
)}
</div>
<motion.div
className="speechBubble"
aria-label="speechBubble"
Expand Down

0 comments on commit bc6271f

Please sign in to comment.