import type { ReactNode } from "react";
// The card language every screen shares (first drawn for Environments):
// compact cards in an auto-fill grid that never stretch across a wide window,
// an icon tile, a small-caps eyebrow, chips for facts, the control in the
// card's corner. Plus the ring gauge used wherever a share of something is
// shown.
const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
/** Cards side by side, each at least `min` px wide; they wrap, never stretch thin. */
export function CardGrid({ min = 280, children, className }: { min?: number; children: ReactNode; className?: string }) {
return (
<div className={cx("grid gap-2.5", className)} style={{ gridTemplateColumns: `repeat(auto-fill, minmax(min(${min}px, 100%), 1fr))` }}>
{children}
</div>
);
}
export function Card({ children, className, accent, dashed, as: As = "article" }: { children: ReactNode; className?: string; accent?: boolean; dashed?: boolean; as?: "article" | "section" | "div" }) {
return (
<As className={cx("grid min-w-0 content-start gap-2.5 rounded-md border bg-surface px-3.5 py-3", accent ? "border-wine/50" : "border-hairline", dashed && "border-dashed bg-transparent", className)}>{children}</As>
);
}
export function Eyebrow({ children, className }: { children: ReactNode; className?: string }) {
return <span className={cx("font-mono text-[10px] uppercase tracking-[0.06em] text-fg-dim", className)}>{children}</span>;
}
/** A section's heading: title, a count, something on the right. */
export function Section({ title, count, aside, children }: { title: ReactNode; count?: ReactNode; aside?: ReactNode; children: ReactNode }) {
return (
<section className="grid min-w-0 gap-2.5">
<h5 className="m-0 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1 text-[13px] font-semibold">
<span className="flex items-baseline gap-2">
{title}
{count != null && <span className="tnum text-[11.5px] font-normal text-fg-dim">{count}</span>}
</span>
{aside && <span className="text-[11.5px] font-normal text-fg-dim">{aside}</span>}
</h5>
{children}
</section>
);
}
/** One fact about a card ("CPU only", "3 hosts"). */
export function Facts({ children, className }: { children: ReactNode; className?: string }) {
return <div className={cx("tnum flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11.5px] text-fg-dim", className)}>{children}</div>;
}
export type IconName = "home" | "gauge" | "nodes" | "box" | "grid" | "list" | "users" | "wallet" | "gear" | "log" | "cpu" | "memory" | "disk" | "bolt" | "plug" | "moon" | "terminal" | "plus" | "shield" | "workers" | "tag";
const PATHS: Record<IconName, string> = {
home: "M2.5 7.5 8 3l5.5 4.5V13a.5.5 0 0 1-.5.5H9.5v-3.5h-3V13.5H3a.5.5 0 0 1-.5-.5z",
gauge: "M2.5 11a5.5 5.5 0 1 1 11 0M8 11l2.5-3.5",
nodes: "M3 3.5h4v3H3zM9 9.5h4v3H9zM5 6.5v2.5a1 1 0 0 0 1 1h3",
box: "M2.5 5 8 2.5 13.5 5v6L8 13.5 2.5 11zM2.5 5 8 7.5 13.5 5M8 7.5v6",
grid: "M2.5 2.5h4.5v4.5H2.5zM9 2.5h4.5v4.5H9zM2.5 9h4.5v4.5H2.5zM9 9h4.5v4.5H9z",
list: "M5.5 4h8M5.5 8h8M5.5 12h8M2.5 4h.01M2.5 8h.01M2.5 12h.01",
users: "M6 7.5a2.25 2.25 0 1 0 0-4.5 2.25 2.25 0 0 0 0 4.5zM1.5 13c.4-2.2 2.2-3.5 4.5-3.5s4.1 1.3 4.5 3.5M10.5 3.2a2.25 2.25 0 0 1 0 4.1M12 9.8c1.3.5 2.2 1.6 2.5 3.2",
wallet: "M2.5 4.5h10a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1h-10zM2.5 4.5V3.5a1 1 0 0 1 1-1H11M10.5 8.5h.01",
gear: "M8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM8 1.8v1.7M8 12.5v1.7M2.6 4.9l1.5.9M11.9 10.2l1.5.9M2.6 11.1l1.5-.9M11.9 5.8l1.5-.9",
log: "M3.5 2.5h9v11h-9zM5.5 5.5h5M5.5 8h5M5.5 10.5h3",
cpu: "M5 5h6v6H5zM6.5 2.5V5M9.5 2.5V5M6.5 11v2.5M9.5 11v2.5M2.5 6.5H5M2.5 9.5H5M11 6.5h2.5M11 9.5h2.5",
memory: "M2 5h12v6H2zM4.5 7v2M7 7v2M9.5 7v2M12 7v2M4 11v2M12 11v2",
disk: "M2.5 4.5c0-1 2.5-2 5.5-2s5.5 1 5.5 2-2.5 2-5.5 2-5.5-1-5.5-2zM2.5 4.5v7c0 1 2.5 2 5.5 2s5.5-1 5.5-2v-7M2.5 8c0 1 2.5 2 5.5 2s5.5-1 5.5-2",
bolt: "M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z",
plug: "M5.5 2v3.5M10.5 2v3.5M3.5 5.5h9v2a4.5 4.5 0 0 1-9 0zM8 12v2.5",
moon: "M13 9.5A5.5 5.5 0 0 1 6.5 3a5.5 5.5 0 1 0 6.5 6.5z",
terminal: "M2 3h12v10H2zM4.5 6l2 2-2 2M8 10h3",
plus: "M8 3v10M3 8h10",
shield: "M8 1.8 13 4v4c0 3-2.1 5.2-5 6.2C5.1 13.2 3 11 3 8V4z",
workers: "M2.5 12.5v-2a1 1 0 0 1 1-1h9a1 1 0 0 1 1 1v2M5 9.5V6.5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3M7 5.5v-2h2v2",
tag: "M2.5 2.5h5l6 6-5 5-6-6zM5.5 5.5h.01",
};
export function Icon({ name, className }: { name: IconName; className?: string }) {
return (
<svg viewBox="0 0 16 16" className={cx("h-4 w-4 flex-none", className)} fill="none" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d={PATHS[name]} />
</svg>
);
}
type TileTone = "wine" | "neutral" | "live" | "warn";
const TILE: Record<TileTone, string> = {
wine: "bg-wine/10 text-wine-bright",
neutral: "bg-raised text-fg-dim",
live: "bg-live/15 text-live",
warn: "bg-warn/15 text-warn",
};
/** The square at a card's top-left: an icon, or a letter. */
export function Tile({ icon, letter, tone = "wine" }: { icon?: IconName; letter?: string; tone?: TileTone }) {
return (
<span aria-hidden="true" className={cx("grid h-9 w-9 flex-none place-items-center rounded-md text-[15px] font-semibold", TILE[tone])}>
{icon ? <Icon name={icon} className="h-[18px] w-[18px]" /> : (letter ?? "").trim().charAt(0).toUpperCase()}
</span>
);
}
/** A card's head: tile, eyebrow over a name, and the control in the corner. */
export function CardHead({ tile, eyebrow, title, sub, corner }: { tile: ReactNode; eyebrow?: ReactNode; title: ReactNode; sub?: ReactNode; corner?: ReactNode }) {
return (
<div className="flex items-start gap-2.5">
{tile}
<div className="grid min-w-0 flex-1 gap-px">
{eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
<b className="truncate text-[13.5px] font-semibold">{title}</b>
{sub && <span className="truncate text-[11.5px] text-fg-dim">{sub}</span>}
</div>
{corner}
</div>
);
}
export interface RingPart {
/** Share of the whole ring, 0..100. */
pct: number;
/** A Tailwind `stroke-*` class. */
className: string;
}
/** A ring split into consecutive parts, clockwise from the top; what is not
* covered shows the track. `children` sit in the middle. */
export function Ring({ parts, size = 112, stroke = 10, label, children }: { parts: RingPart[]; size?: number; stroke?: number; label: string; children?: ReactNode }) {
const r = (size - stroke) / 2;
const c = 2 * Math.PI * r;
let at = 0;
return (
<div className="relative flex-none" style={{ width: size, height: size }} role="img" aria-label={label}>
<svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className="-rotate-90">
<circle cx={size / 2} cy={size / 2} r={r} fill="none" strokeWidth={stroke} className="stroke-raised" />
{parts.map((p, i) => {
const pct = Math.max(0, Math.min(100 - at, p.pct));
const len = (pct / 100) * c;
const el = len > 0.01 && (
<circle key={i} cx={size / 2} cy={size / 2} r={r} fill="none" strokeWidth={stroke} className={cx(p.className, "transition-[stroke-dasharray,stroke-dashoffset] duration-500")} strokeDasharray={`${len} ${c - len}`} strokeDashoffset={-(at / 100) * c} />
);
at += pct;
return el;
})}
</svg>
{children && <div className="absolute inset-0 grid place-items-center text-center">{children}</div>}
</div>
);
}
/** A dot and a label, for a ring's or a bar's parts. */
export function Key({ className, children }: { className: string; children: ReactNode }) {
return (
<span className="flex items-center gap-1.5">
<i className={cx("inline-block h-2 w-2 flex-none rounded-full", className)} aria-hidden="true" />
{children}
</span>
);
}
/** A thin bar of consecutive parts (a split, a usage). */
export function Bar({ parts, label, className }: { parts: { pct: number; className: string }[]; label?: string; className?: string }) {
return (
<div className={cx("flex h-1.5 gap-px overflow-hidden rounded-full bg-raised", className)} role={label ? "img" : undefined} aria-label={label}>
{parts.map((p, i) => (
<i key={i} className={cx("block h-full transition-[width] duration-500", p.className)} style={{ width: `${Math.max(0, Math.min(100, p.pct))}%` }} />
))}
</div>
);
}
/** Something that is not here yet, said for the owner; the reference a
* developer needs is small print. */
export function ComingSoon({ icon, title, children, reference }: { icon: IconName; title: string; children: ReactNode; reference?: string }) {
return (
<Card dashed>
<CardHead tile={<Tile icon={icon} tone="neutral" />} eyebrow="Coming soon" title={title} />
<p className="m-0 text-[12px] leading-snug text-fg-dim">{children}</p>
{reference && <span className="font-mono text-[10px] text-fg-dim/70">{reference}</span>}
</Card>
);
}