2023-02-27 06:18:16 +00:00
|
|
|
<script lang="ts">
|
2024-12-13 00:55:46 +00:00
|
|
|
import { ExternalLink } from "lucide-svelte";
|
|
|
|
|
import type {
|
|
|
|
|
ExternalLinkType,
|
|
|
|
|
LinkIconType,
|
|
|
|
|
} from "$lib/types/externalLinkTypes";
|
2024-12-09 05:26:51 +00:00
|
|
|
|
2024-12-13 00:55:46 +00:00
|
|
|
const { iconData, linkData, textData }: ExternalLinkType = $props();
|
|
|
|
|
|
|
|
|
|
let textLocationClass = "";
|
|
|
|
|
if (textData?.location === "top") {
|
|
|
|
|
textLocationClass = "text-top";
|
|
|
|
|
} else if (textData?.location === "bottom") {
|
|
|
|
|
textLocationClass = "text-bottom";
|
|
|
|
|
} else if (textData?.location === "left") {
|
|
|
|
|
textLocationClass = "text-left";
|
|
|
|
|
} else if (textData?.location === "right") {
|
|
|
|
|
textLocationClass = "text-right";
|
2024-12-04 17:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-13 00:55:46 +00:00
|
|
|
const linkDecoration =
|
|
|
|
|
linkData?.textDecoration && linkData?.textDecoration === "none"
|
|
|
|
|
? `text-decoration-${linkData?.textDecoration}`
|
|
|
|
|
: "text-decoration-underline";
|
|
|
|
|
const linkClass =
|
|
|
|
|
`${linkData?.clazz} ${textLocationClass} ${linkDecoration}`.trim();
|
2023-02-27 06:18:16 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-12-13 00:55:46 +00:00
|
|
|
{#snippet externalLink({ iconData, linkData, textData }: ExternalLinkType)}
|
|
|
|
|
<a
|
|
|
|
|
class={linkClass}
|
|
|
|
|
aria-label={`Open ${linkData?.ariaLabel ?? linkData?.title ?? linkData?.href} externally`}
|
|
|
|
|
title={linkData?.title ?? `Open ${linkData?.ariaLabel} externally`}
|
|
|
|
|
href={linkData.href}
|
|
|
|
|
rel={linkData?.rel ?? "noreferrer"}
|
|
|
|
|
target={linkData?.target ?? "_blank"}
|
|
|
|
|
>
|
|
|
|
|
{#if textData?.location === "top" || (textData?.location === "left" && textData?.text)}
|
|
|
|
|
<span class="link-text">{textData?.text}</span>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if textData?.showIcon}
|
|
|
|
|
{@render linkIcon?.(iconData ?? {})}
|
2024-12-09 05:26:51 +00:00
|
|
|
{/if}
|
2024-12-13 00:55:46 +00:00
|
|
|
{#if textData?.location === "bottom" || (textData?.location === "right" && textData?.text)}
|
|
|
|
|
<span class="link-text">{textData?.text}</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</a>
|
|
|
|
|
{/snippet}
|
|
|
|
|
|
|
|
|
|
{#snippet linkIcon({ type, icon, iconClass }: LinkIconType)}
|
|
|
|
|
{#if type === "svg" && icon}
|
|
|
|
|
<svg
|
|
|
|
|
style="width: 2.5rem; height: 2.5rem;"
|
|
|
|
|
class={iconClass ?? ""}
|
|
|
|
|
role="img"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
{@render icon?.()}
|
|
|
|
|
</svg>
|
|
|
|
|
{:else if type === "icon" && icon}
|
|
|
|
|
{@const Icon = icon}
|
|
|
|
|
<Icon />
|
|
|
|
|
{:else}
|
|
|
|
|
{@const Icon = ExternalLink}
|
|
|
|
|
<Icon />
|
2023-02-27 06:18:16 +00:00
|
|
|
{/if}
|
2024-12-13 00:55:46 +00:00
|
|
|
{/snippet}
|
|
|
|
|
|
|
|
|
|
{@render externalLink({ iconData, linkData, textData })}
|
2023-02-27 06:18:16 +00:00
|
|
|
|
|
|
|
|
<style lang="postcss">
|
2024-05-15 00:33:39 +00:00
|
|
|
a {
|
2024-12-13 00:55:46 +00:00
|
|
|
display: grid;
|
|
|
|
|
place-items: center;
|
2024-05-15 00:33:39 +00:00
|
|
|
padding: 0;
|
|
|
|
|
font-size: var(--bodyTextSize);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-13 00:55:46 +00:00
|
|
|
.text-top {
|
|
|
|
|
padding-bottom: 0.3rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text-bottom {
|
|
|
|
|
padding-top: 0.3rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text-left,
|
|
|
|
|
.text-right {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text-decoration-none {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.text-decoration-underline {
|
|
|
|
|
text-decoration: underline;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 06:18:16 +00:00
|
|
|
.show-icon {
|
2024-12-13 00:55:46 +00:00
|
|
|
/* display: inline-flex;
|
2023-04-17 19:02:41 +00:00
|
|
|
align-items: center;
|
2024-12-13 00:55:46 +00:00
|
|
|
gap: 0.5rem; */
|
2023-02-27 06:18:16 +00:00
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
color: var(--shellYellow);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-13 00:55:46 +00:00
|
|
|
</style>
|