chore: replace SocialLinks with preact component

This commit is contained in:
Stefan Imhoff
2023-12-15 14:40:53 +01:00
parent fd1fce8968
commit 59a3a859af
5 changed files with 45 additions and 29 deletions

View File

@@ -1,9 +1,8 @@
---
import Legal from './Legal.astro';
import RSSLink from './RSSLink.astro';
import SocialLinks from './SocialLinks.astro';
import Subnavigation from './Subnavigation.astro';
import { UpLink } from '.';
import { UpLink, SocialLinks } from '.';
---
<footer

View File

@@ -1,23 +0,0 @@
---
import { Sprite } from 'astro-icon';
import { Link } from '.';
import data from '../data/social-links.json';
---
<nav class="flex flex-1 sm:justify-center" aria-label="Social Links">
{
data.map(({ text, url, icon, props = {} }) => (
<Link
aria-label={text}
class="flex h-clickarea w-clickarea cursor-pointer items-center justify-center"
href={url}
title={text}
{...props}
>
<Sprite name={icon} class="h-icon-small w-icon-small" />
</Link>
))
}
</nav>

View File

@@ -0,0 +1,39 @@
import type { FunctionalComponent, JSX } from 'preact';
import type { SVGProps } from 'preact/compat';
import { Link } from '.';
import { Github, Instagram, Mail, TwitterX } from './icons';
import data from '../data/social-links.json';
type IconComponent = FunctionalComponent<SVGProps<SVGSVGElement>>;
type IconMap = { [key: string]: IconComponent };
const renderIcon = (iconName: string): JSX.Element => {
const iconMap: IconMap = {
mail: Mail,
twitter: TwitterX,
github: Github,
instagram: Instagram,
};
const IconComponent = iconMap[iconName];
return <IconComponent class="icon h-icon-small w-icon-small" />;
};
export const SocialLinks: FunctionalComponent = () => (
<nav class="flex flex-1 sm:justify-center" aria-label="Social Links">
{data.map((item, index) => (
<Link
aria-label={item.text}
class="flex h-clickarea w-clickarea cursor-pointer items-center justify-center"
href={item.url}
key={index}
title={item.text}
{...(item.props ? item.props : {})}
>
{renderIcon(item.icon)}
</Link>
))}
</nav>
);

View File

@@ -25,6 +25,7 @@ export * from './OrderedList';
export * from './PrimeVideoFlag';
export * from './ProjectIntro';
export * from './Pullquote';
export * from './SocialLinks';
export * from './Spotify';
export * from './Subheadline';
export * from './Subsubheadline';

View File

@@ -2,7 +2,7 @@
{
"text": "Mail",
"url": "#protected-email",
"icon": "ri:mail-line",
"icon": "mail",
"props": {
"data-domain": "stefanimhoff",
"data-name": "hey",
@@ -13,16 +13,16 @@
{
"text": "Twitter",
"url": "https://twitter.com/kogakure",
"icon": "ri:twitter-line"
"icon": "twitter"
},
{
"text": "Instagram",
"url": "https://instagram.com/kogakure",
"icon": "ri:instagram-line"
"icon": "instagram"
},
{
"text": "GitHub",
"url": "https://github.com/kogakure",
"icon": "ri:github-line"
"icon": "github"
}
]