Skip to content

Commit cdbedcd

Browse files
committed
wrap SimpleIcon component adapt for dark/light mode
usage: <SimpleIcon klass="w-4 h-4" src="https://cdn.simpleicons.org/x" alt="X" />
1 parent 7948222 commit cdbedcd

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

app/components/layouts/Footer.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import LogoIcon from "@/components/icons/Logo";
22
import NewsletterPopover from "@/components/ui/$NewsletterPopover";
3+
import SimpleIcon from "@/components/ui/SimpleIcon";
34
import { GITHUB_URL, TELEGRAM_GROUP_LINK, TWITTER_ID } from "@/const";
45

56
export default function Footer() {
@@ -12,9 +13,9 @@ export default function Footer() {
1213
target="_blank"
1314
rel="noopener noreferrer"
1415
>
15-
<img
16-
class="w-4 h-4"
17-
src="https://cdn.simpleicons.org/x/eee?viewbox=auto"
16+
<SimpleIcon
17+
klass="w-4 h-4"
18+
src="https://cdn.simpleicons.org/x"
1819
alt="X"
1920
/>
2021
</a>
@@ -25,18 +26,18 @@ export default function Footer() {
2526
target="_blank"
2627
rel="noopener noreferrer"
2728
>
28-
<img
29-
class="w-4 h-4"
30-
src="https://cdn.simpleicons.org/telegram/eee?viewbox=auto"
29+
<SimpleIcon
30+
klass="w-4 h-4"
31+
src="https://cdn.simpleicons.org/telegram"
3132
alt="Telegram"
3233
/>
3334
</a>
3435
</li>
3536
<li>
3637
<a href={GITHUB_URL} target="_blank" rel="noopener noreferrer">
37-
<img
38-
class="w-4 h-4"
39-
src="https://cdn.simpleicons.org/github/eee?viewbox=auto"
38+
<SimpleIcon
39+
klass="w-4 h-4"
40+
src="https://cdn.simpleicons.org/github"
4041
alt="github"
4142
/>
4243
</a>

app/components/ui/$NewsletterPopover.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState } from "hono/jsx";
2+
import SimpleIcon from "@/components/ui/SimpleIcon";
23

34
const target = "newsletter";
45

@@ -72,10 +73,10 @@ export default function NewsletterDialog() {
7273
type="button"
7374
class="hover:text-secondary"
7475
>
75-
<img
76-
class="w-4 h-4"
77-
src="https://cdn.simpleicons.org/substack/eee?viewbox=auto"
78-
alt="github"
76+
<SimpleIcon
77+
klass="w-4 h-4"
78+
src="https://cdn.simpleicons.org/substack"
79+
alt="substack"
7980
/>
8081
</button>
8182
<div

app/components/ui/SimpleIcon.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export default function SimpleIcon({
2+
src,
3+
alt,
4+
klass = "w-4 h-4",
5+
}: {
6+
src: string;
7+
alt: string;
8+
klass?: string;
9+
}) {
10+
// Remove query params or color paths if present to get clean SVG content for masking
11+
// actually, keeping query params like viewbox=auto is fine, but we should strip colors if the user passes them by mistake.
12+
// For this implementation, we assume the user (me) will pass the clean URL.
13+
14+
return (
15+
<div
16+
aria-label={alt}
17+
role="img"
18+
class={`${klass} bg-current`}
19+
style={{
20+
maskImage: `url('${src}')`,
21+
maskRepeat: "no-repeat",
22+
maskPosition: "center",
23+
maskSize: "contain",
24+
WebkitMaskImage: `url('${src}')`,
25+
WebkitMaskRepeat: "no-repeat",
26+
WebkitMaskPosition: "center",
27+
WebkitMaskSize: "contain",
28+
backgroundColor: "currentColor",
29+
}}
30+
/>
31+
);
32+
}

0 commit comments

Comments
 (0)