|
1 | 1 | --- |
2 | | -type Props = { |
3 | | - title: string; |
4 | | - link: string; |
5 | | - icon: string; |
| 2 | +import type { HTMLAttributes } from 'astro/types'; |
| 3 | +
|
| 4 | +type Props = HTMLAttributes<'a'> & { |
| 5 | + title?: string | null; |
| 6 | + link?: string | null; |
| 7 | + icon?: string | null; |
6 | 8 | }; |
7 | 9 |
|
8 | | -const { title, link, icon } = Astro.props; |
| 10 | +const { title, link, icon, ...rest } = Astro.props; |
| 11 | +const safeTitle = title ?? ""; |
| 12 | +const safeLink = link ?? "#"; |
| 13 | +const safeIcon = icon ?? ""; |
9 | 14 | --- |
10 | 15 |
|
11 | | -<a href={link} target="_blank" aria-label={`Go to ${title}`}> |
12 | | - <span class="sr-only">{title}</span> |
13 | | - {icon === "TbBrandX" && ( |
| 16 | +<a href={safeLink} target="_blank" aria-label={`Go to ${safeTitle}`} {...rest}> |
| 17 | + <span class="sr-only">{safeTitle}</span> |
| 18 | + {safeIcon === "TbBrandX" && ( |
14 | 19 | <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
15 | 20 | <path d="M4 4l11.733 16h4.267l-11.733 -16z"></path> |
16 | 21 | <path d="M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772"></path> |
17 | 22 | </svg> |
18 | 23 | )} |
19 | | - {icon === "TbBook2" && ( |
| 24 | + {safeIcon === "TbBook2" && ( |
20 | 25 | <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
21 | 26 | <path d="M19 4v16h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12z"></path> |
22 | 27 | <path d="M19 16h-12a2 2 0 0 0 -2 2"></path> |
23 | 28 | <path d="M9 8h6"></path> |
24 | 29 | </svg> |
25 | 30 | )} |
26 | | - {icon === "TbBrandGithub" && ( |
| 31 | + {safeIcon === "TbBrandGithub" && ( |
27 | 32 | <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
28 | 33 | <path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path> |
29 | 34 | </svg> |
|
0 commit comments