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 && (
← {back.label}
)}
{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 (
<>
{label && {label} }
>
);
}
export function Loading({ label = 'Loading' }: { label?: string }) {
return (
{label}
);
}
export function Skel({ w = '100%', h = 14, style }: { w?: number | string; h?: number; style?: CSSProperties }) {
return ;
}
export function Meter({ value, max, label, size }: { value: number; max: number; label?: string; size?: 'lg' }) {
const pct = max > 0 ? Math.round((value / max) * 100) : 0;
return (
);
}
export function ExternalLink({ href, children, className }: { href: string; children: ReactNode; className?: string }) {
return (
{children}
(opens in a new tab)
);
}
/**
* `estimated`: no source gave a score or rating, so the level is a placeholder
* ("Medium (estimated)"), not an assessment.
*/
export function Severity({ level, estimated = false }: { level: string; estimated?: boolean }) {
const label = level ? level.charAt(0).toUpperCase() + level.slice(1) : 'Unknown';
return (
{estimated ? `${label} (estimated)` : label}
);
}
/** "medium" or "Medium (estimated)" in plain text, for exports and copied summaries. */
export function severityText(level: string, estimated?: boolean): string {
return estimated ? `${level} (estimated)` : level;
}