martials.no/src/components/links/ExternalLink.astro

29 lines
762 B
Plaintext
Raw Normal View History

2024-09-25 22:20:47 +02:00
---
import type { LinkProps } from "@/types/props"
import type { PajamasIcon } from "@/types/icons"
import ExternalLinkTextOnly from "./ExternalLinkTextOnly.astro"
import ExternalLinkIconLeft from "./ExternalLinkIconLeft.astro"
interface Props extends LinkProps {
iconLeft?: PajamasIcon
iconLeftAriaLabel?: string
2024-09-25 22:20:47 +02:00
}
const { iconLeft, iconLeftAriaLabel, ...props } = Astro.props
if (iconLeft && !iconLeftAriaLabel) {
throw new Error("ExternalLink: iconLeftAriaLabel is required when iconLeft is provided")
}
2024-09-25 22:20:47 +02:00
---
{ iconLeft && iconLeftAriaLabel
?
<ExternalLinkIconLeft iconLeft={iconLeft} iconLeftAriaLabel={iconLeftAriaLabel} {...props}>
2024-09-25 22:20:47 +02:00
<slot />
</ExternalLinkIconLeft>
:
<ExternalLinkTextOnly {...props}>
<slot />
</ExternalLinkTextOnly>
}