import { type JSX, createContext, useContext, Show, splitProps } from 'solid-js'; import { cn } from '../utils/cn'; import { HoverCardRoot, HoverCardTrigger, HoverCardContent } from '../ui/hover-card'; // --- Context --- interface SourceContextValue { href: string; domain: string; } const SourceContext = createContext(); function useSourceContext() { const ctx = useContext(SourceContext); if (!ctx) throw new Error('Source.* must be used inside '); return ctx; } // --- Source (Root) --- export interface SourceProps { href: string; children: JSX.Element; } function Source(props: SourceProps) { const domain = () => { try { return new URL(props.href).hostname; } catch { return props.href.split('/').pop() || props.href; } }; return ( {props.children} ); } // --- SourceTrigger --- export interface SourceTriggerProps { label?: string | number; showFavicon?: boolean; class?: string; } function SourceTrigger(props: SourceTriggerProps) { const ctx = useSourceContext(); const labelToShow = () => props.label ?? ctx.domain.replace('www.', ''); return ( favicon {labelToShow()} ); } // --- SourceContent --- export interface SourceContentProps { title: string; description: string; class?: string; } function SourceContent(props: SourceContentProps) { const ctx = useSourceContext(); return (
favicon
{ctx.domain.replace('www.', '')}
{props.title}
{props.description}
); } // --- SourceList (convenience) --- function SourceList(props: { children: JSX.Element; class?: string }) { return
{props.children}
; } export { Source, SourceTrigger, SourceContent, SourceList };