import React from 'react'; import { Box, sx } from '@hanzo/ui' import { cn } from './utils'; // Inline external link arrow icon const ArrowIcon = ({ className, style }: { readonly className?: string; readonly style?: React.CSSProperties }) => ( ); // Strip UTM params for privacy (standalone, no config dependency) function stripUtmParams(url: string): string { try { const urlObj = new URL(url); for (const param of [ 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content' ]) { urlObj.searchParams.delete(param); } return urlObj.toString(); } catch { return url; } } import { Skeleton } from './skeleton'; type LinkVariant = 'primary' | 'secondary' | 'subtle' | 'underlaid' | 'menu' | 'navigation' | 'plain'; export interface LinkProps extends Omit, 'href'> { readonly href?: string; readonly loading?: boolean; readonly external?: boolean; readonly iconColor?: string; readonly noIcon?: boolean; readonly disabled?: boolean; readonly variant?: LinkVariant; readonly asChild?: boolean; // Next.js-specific props accepted for compatibility (ignored by base ) readonly shallow?: boolean; readonly prefetch?: boolean; readonly scroll?: boolean; // Legacy Chakra style-prop shims readonly fontWeight?: string | number; readonly whiteSpace?: string; readonly wordBreak?: string; readonly textStyle?: string; readonly ml?: number | string | Record; readonly mr?: number | string; readonly display?: string; readonly alignItems?: string; readonly flexShrink?: number; readonly minW?: number | string; readonly justifyContent?: string; readonly position?: string; } const VARIANT_CLASSES: Record = { primary: cn( 'text-[var(--color-link-primary)]', 'hover:no-underline hover:text-[var(--color-link-primary-hover)]', 'data-[hover]:no-underline data-[hover]:text-[var(--color-link-primary-hover)]', ), secondary: cn( 'text-[var(--color-link-secondary)]', 'hover:no-underline hover:text-[var(--color-hover)]', 'data-[hover]:no-underline data-[hover]:text-[var(--color-hover)]', ), subtle: cn( 'text-[var(--color-link-subtle)]', 'hover:text-[var(--color-link-subtle-hover)] hover:underline hover:decoration-[var(--color-link-subtle-hover)]', 'data-[hover]:text-[var(--color-link-subtle-hover)] data-[hover]:underline data-[hover]:decoration-[var(--color-link-subtle-hover)]', ), underlaid: cn( 'text-[var(--color-link-primary)] bg-[var(--color-link-underlaid-bg)]', 'px-2 py-1.5 rounded-md text-sm', 'hover:text-[var(--color-link-primary-hover)] hover:no-underline', 'data-[hover]:text-[var(--color-link-primary-hover)] data-[hover]:no-underline', ), menu: cn( 'text-[var(--color-link-menu)]', 'hover:text-[var(--color-hover)] hover:no-underline', 'data-[hover]:text-[var(--color-hover)] data-[hover]:no-underline', ), navigation: cn( 'text-[var(--color-link-nav-fg)] bg-transparent', 'hover:text-[var(--color-link-nav-fg-hover)] hover:no-underline', 'data-[hover]:text-[var(--color-link-nav-fg-hover)] data-[hover]:no-underline', 'data-[selected]:text-[var(--color-link-nav-fg-selected)] data-[selected]:bg-[var(--color-link-nav-bg-selected)]', 'data-[active]:text-[var(--color-link-nav-fg-active)]', ), plain: cn( 'text-inherit', 'hover:no-underline', 'data-[hover]:no-underline', ), }; const BASE_CLASSES = 'inline-flex items-center gap-0 cursor-pointer data-[disabled]:cursor-not-allowed'; export const LinkExternalIcon = ({ color }: { color?: string }) => ( tag. Framework-specific routing // (e.g. Next.js Link) should be provided by the consuming app's wrapper. if (href) { return ( } asChild> { children } ); } return ( } asChild> } > { children } ); }, ); export const LinkBox = React.forwardRef>( function LinkBox(props, ref) { const { className, ...rest } = props; return ( ); }, ); export const LinkOverlay = React.forwardRef( function LinkOverlay(props, ref) { const { children, external, loading, href, noIcon, iconColor, variant = 'primary', className, disabled, asChild: _asChild2, shallow: _shallow2, prefetch: _prefetch2, scroll: _scroll2, fontWeight: _fw2, whiteSpace: _ws2, wordBreak: _wb2, textStyle: _ts2, ml: _ml2, mr: _mr2, display: _d2, alignItems: _ai2, flexShrink: _fs2, minW: _mw2, justifyContent: _jc2, position: _p2, ...rest } = props; const overlayClasses = cn( BASE_CLASSES, VARIANT_CLASSES[variant], // Static positioning with a ::before pseudo-element that covers the LinkBox 'static', 'before:absolute before:inset-0 before:z-0 before:content-[""]', className, ); if (external) { const processedHref = typeof href === 'string' ? stripUtmParams(href) : href; return ( { (children || (!noIcon && href)) && ( { children } { !noIcon && href && } ) } ); } const content = children ? ( { children } ) : null; if (href) { return ( { content } ); } return ( } className={ overlayClasses } { ...rest as React.HTMLAttributes } > { content } ); }, );