import type { CSSProperties, ReactNode } from 'react'; import { errorMessage, getConfig, isPlanRequired, isScanLimit } from '../hooks/useApi'; import { LINKS } from '../content/links'; export function PageHead({ title, lede, actions, back }: { title: string; lede?: ReactNode; actions?: ReactNode; back?: { label: string; onClick: () => void }; }) { return (
{back && ( )}

{title}

{lede &&

{lede}

}
{actions &&
{actions}
}
); } export function Panel({ title, description, actions, children, footer, flush, className = '', id, as = 'section' }: { title?: ReactNode; description?: ReactNode; actions?: ReactNode; children?: ReactNode; footer?: ReactNode; flush?: boolean; className?: string; id?: string; as?: 'section' | 'div'; }) { const Tag = as; return ( {(title || actions) && (
{title &&

{title}

} {description &&

{description}

}
{actions &&
{actions}
}
)} {children !== undefined && children !== null && children !== false && (
{children}
)} {footer &&
{footer}
}
); } export type Tone = 'neutral' | 'critical' | 'caution' | 'clear' | 'info' | 'outline' | 'ink'; export function Chip({ tone = 'neutral', children, title }: { tone?: Tone; children: ReactNode; title?: string }) { return ( {children} ); } /** Article citation tag, set in the serif "regulation" voice. */ export function Cite({ children }: { children: ReactNode }) { return {children}; } /** Highlighter mark for what applies to the reader or needs attention. */ export function Mark({ children, soft }: { children: ReactNode; soft?: boolean }) { return {children}; } export function Notice({ tone = 'info', title, children, actions, role }: { tone?: 'info' | 'critical' | 'caution' | 'clear'; title?: ReactNode; children?: ReactNode; actions?: ReactNode; role?: 'alert' | 'status'; }) { return (
{title &&

{title}

} {children}
{actions &&
{actions}
}
); } export function Empty({ title, children, actions }: { title: string; children?: ReactNode; actions?: ReactNode }) { return (

{title}

{children &&

{children}

} {actions &&
{actions}
}
); } export function ErrorState({ title = 'This could not be loaded', message, error, onRetry }: { title?: string; message: string; error?: unknown; onRetry?: () => void; }) { const plan = isPlanRequired(error); return ( Try again )} >

{message} {plan && <>{' '}Compare plans}

); } /** * An error from an action. A plan limit (HTTP 402, or the month's scans used * up) is shown as information with a link to pricing, not as an alarm. */ export function ApiErrorNotice({ error, onDismiss }: { error: unknown; onDismiss?: () => void }) { const scanLimit = isScanLimit(error); const plan = isPlanRequired(error) || scanLimit; const message = typeof error === 'string' ? error : errorMessage(error); // Pro has the highest scan allowance, so there is no plan to compare with. const showPlans = isPlanRequired(error) || (scanLimit && getConfig().plan !== 'pro'); return ( Dismiss} >

{message} {showPlans && <>{' '}Compare plans}

); } export function Spinner({ label }: { label?: string }) { return ( <>