Skip to content

Commit 70bc271

Browse files
committed
fix: made Highlighter functionality available across sections
1 parent fd2c389 commit 70bc271

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

src/components/About.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
import { ArrowUpRight } from "lucide-react"
22
import BlurFade, { BLUR_FADE_DELAY } from "@/components/ui/BlurFade";
3-
4-
function Highlight(text: string, color = "yellow") {
5-
var colorClassName: string = "bg-opacity-50 px-1 rounded ";
6-
if (color === "yellow") {
7-
colorClassName = colorClassName + "bg-[#ffff77]"
8-
}
9-
if (color === "cyan") {
10-
colorClassName = colorClassName + "bg-cyan-300 dark:bg-cyan-500/30"
11-
}
12-
if (color === "pink") {
13-
colorClassName = colorClassName + "bg-[#ff77e4]"
14-
}
15-
if (color === "slate-blue") {
16-
colorClassName = colorClassName + "bg-[#7777ff]"
17-
}
18-
if (color === "red") {
19-
colorClassName = colorClassName + "bg-[#ff7777]"
20-
}
21-
return (
22-
<span className={colorClassName}>{text}</span>
23-
)
24-
}
3+
import Highlight from "@/lib/highlighter";
254

265
const About = () => {
276
return (

src/lib/highlighter.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { cn } from "@/lib/utils";
2+
3+
/**
4+
* Highlights the given text with the highlighter of specified color.
5+
*
6+
* @param text - the text to be highlighted
7+
* @param color - the color of the highlighter [cyan,pink,violet-web,slate-blue,red,yellow,lemon,laser-lemon]
8+
* @returns Returns a `span` element with the highlighted text of specified color.
9+
*
10+
*/
11+
export default function Highlight(text: string, color = "yellow") {
12+
let colorClass: string;
13+
14+
if (color === "cyan") {
15+
colorClass = "bg-cyan-300 dark:bg-cyan-500/30";
16+
}
17+
else if (color === "pink" || color === "violet-web") {
18+
colorClass = "bg-[#ff77e4]";
19+
}
20+
else if (color === "slate-blue") {
21+
colorClass = "bg-[#7777ff]";
22+
}
23+
else if (color === "red") {
24+
colorClass = "bg-[#ff7777]";
25+
}
26+
else {
27+
// This covers "yellow", "lemon", "laser-lemon", and the default case
28+
colorClass = "bg-[#ffff77]";
29+
}
30+
31+
return (
32+
<span className={cn("bg-opacity-50 px-1 rounded", colorClass)}>{text}</span>
33+
)
34+
}

0 commit comments

Comments
 (0)