A high-performance inference engine for AI models
import { ChevronRight } from "lucide-react";
import { Button } from "@headlessui/react";
import type { ReactNode } from "react";
import { twMerge } from "tailwind-merge";
import { Text } from "@/components/ui/typography";
export type FamilyCardBadgeTone = "neutral" | "success";
export type FamilyCardBadge = {
label: ReactNode;
tone?: FamilyCardBadgeTone;
};
export type FamilyCardProps = {
vendorIcon: ReactNode;
familyName: ReactNode;
vendorName: ReactNode;
badges?: FamilyCardBadge[];
onClick?: () => void;
compact?: boolean;
};
// Raised off the card like the row buttons, so the badges read on the soft fill.
const RAISED =
"bg-surface-popover shadow-[0_0_0_0.5px_rgb(0_0_0/0.08),0_1px_2px_rgb(0_0_0/0.06)] dark:shadow-[inset_0_0_0_0.5px_rgb(255_255_255/0.1)]";
// Every badge is the same raised pill; success only adds a green dot and lifts the text a step.
const TONE_CLASSES: Record<FamilyCardBadgeTone, { border: string; text: string }> = {
neutral: { border: RAISED, text: "text-text-muted" },
success: { border: twMerge(RAISED, "gap-1.5 pl-2"), text: "text-text-secondary" },
};
export function FamilyBadge({ badge }: { badge: FamilyCardBadge }) {
const { label, tone = "neutral" } = badge;
const tones = TONE_CLASSES[tone];
return (
<div className={twMerge("flex items-center justify-center h-6 px-2.5 rounded-full cursor-default", tones.border)}>
{tone === "success" && <span aria-hidden className="size-1.5 shrink-0 rounded-full bg-success-strong" />}
<Text
as="span"
opticalSize={14}
className={twMerge("text-[12px] font-[450] leading-[1.3] whitespace-nowrap tabular-nums", tones.text)}
>
{label}
</Text>
</div>
);
}
export function FamilyCard({ vendorIcon, familyName, vendorName, badges, onClick, compact = false }: FamilyCardProps) {
const fallbackAria = typeof familyName === "string" ? `Open ${familyName} models` : undefined;
const heading = (
<div className="flex items-center gap-4 min-w-0 flex-1">
<span className="shrink-0 flex items-center justify-center w-4 h-4 [&>svg]:w-4 [&>svg]:h-4">{vendorIcon}</span>
<div className="flex items-baseline gap-1.5 min-w-0">
<Text as="span" size="sm" color="primary" opticalSize={14} className="truncate leading-[1.5] font-[450]">
{familyName}
</Text>
<Text as="span" size="sm" color="muted" opticalSize={14} className="truncate leading-[1.5] font-[450]">
from {vendorName}
</Text>
</div>
</div>
);
const chips = badges?.map((badge, idx) => <FamilyBadge key={idx} badge={badge} />);
const chevron = <ChevronRight size={14} className="text-text-muted shrink-0" />;
if (compact) {
return (
<Button
type="button"
onClick={onClick}
aria-label={fallbackAria}
className="w-full flex flex-col items-stretch gap-3 px-4 py-3 rounded-xl bg-surface-soft transition-colors duration-150 ease-out cursor-pointer outline-hidden data-[focus]:shadow-focus hover:bg-surface-tertiary text-left"
>
<div className="flex items-center gap-3 min-w-0">
{heading}
{chevron}
</div>
{chips && chips.length > 0 && <div className="flex items-center gap-1.5 flex-wrap">{chips}</div>}
</Button>
);
}
return (
<Button
type="button"
onClick={onClick}
aria-label={fallbackAria}
className="w-full flex items-center justify-between gap-4 h-14 pl-4 pr-3 rounded-xl bg-surface-soft transition-colors duration-150 ease-out cursor-pointer outline-hidden data-[focus]:shadow-focus hover:bg-surface-tertiary"
>
{heading}
<div className="flex items-center gap-1.5 shrink-0">
{chips}
<span className="ml-1">{chevron}</span>
</div>
</Button>
);
}