22import { ExternalLink } from ' lucide-svelte' ;
33import type { ExternalLinkType , LinkIconType } from ' $lib/types/externalLinkTypes' ;
44
5- const { iconData, linkData, textData }: ExternalLinkType = $props ();
5+ const { iconData = { type: ' icon' , icon: ExternalLink }, linkData, textData }: ExternalLinkType = $props ();
6+ // Guarantee non-optional icon data for linkIcon()
7+ const safeIconData: LinkIconType = iconData ?? { type: ' icon' , icon: ExternalLink };
68
79let textLocationClass = ' ' ;
810if (textData ?.location === ' top' ) {
@@ -21,11 +23,9 @@ const linkDecoration =
2123 linkData ?.textDecoration && linkData ?.textDecoration === ' none' ? ` text-decoration-${linkData ?.textDecoration } ` : ' text-decoration-underline' ;
2224const linkClass = ` ${linkData ?.clazz || ' ' } ${textLocationClass } ${linkDecoration } ` .trim ();
2325
24- // Default icon config to satisfy typings when no iconData is provided
25- const defaultIconData: LinkIconType = { type: ' icon' , icon: ExternalLink };
2626 </script >
2727
28- {#snippet externalLink ({ iconData , linkData , textData }: ExternalLinkType )}
28+ {#snippet externalLink ({ iconData = { type: ' icon ' , icon: ExternalLink } , linkData , textData }: ExternalLinkType )}
2929 <a
3030 class ={linkClass }
3131 aria-label ={` Open ${linkData ?.ariaLabel ?? linkData ?.title ?? linkData ?.href } externally ` }
@@ -38,7 +38,7 @@ const defaultIconData: LinkIconType = { type: 'icon', icon: ExternalLink };
3838 {textData ?.text }
3939 {/if }
4040 {#if textData ?.showIcon }
41- {@render linkIcon (iconData ?? defaultIconData )}
41+ {@render linkIcon (safeIconData )}
4242 {/if }
4343 {#if textData ?.location === " bottom" || (textData ?.location === " right" && textData ?.text )}
4444 {textData ?.text }
0 commit comments