SumProof / web /src /components /ui.tsx
Wizzas's picture
Upload source code (part 2)
0c52aa7 verified
Raw History Blame Contribute Delete
5.52 kB
import { ChevronRight } from "lucide-react";
import Link from "next/link";
export function Card({
title,
icon,
action,
children,
className = "",
bodyClassName = "",
}: {
title?: React.ReactNode;
icon?: React.ReactNode;
action?: React.ReactNode;
children: React.ReactNode;
className?: string;
bodyClassName?: string;
}) {
return (
<section className={`min-w-0 rounded-xl border border-line bg-surface-solid p-4 shadow-card sm:p-5 ${className}`}>
{(title || action) && (
<div className="mb-3.5 flex items-center gap-2.5">
{icon && <span className="text-accent">{icon}</span>}
{title && <h2 className="text-[16px] font-semibold text-ink">{title}</h2>}
{action && <div className="ml-auto flex items-center gap-2">{action}</div>}
</div>
)}
<div className={bodyClassName}>{children}</div>
</section>
);
}
/** Plain page header: breadcrumb, title with status pills, one-line description. */
export function Banner({
crumbs,
title,
pills,
meta,
right,
children,
}: {
crumbs: { label: string; href?: string }[];
title: React.ReactNode;
pills?: React.ReactNode;
meta?: React.ReactNode;
right?: React.ReactNode;
children?: React.ReactNode;
}) {
return (
<div className="mb-6">
<nav aria-label="Breadcrumb" className="mb-1.5 flex flex-wrap items-center gap-1.5 text-[13px] text-muted">
{crumbs.map((c, i) => (
<span key={i} className="flex items-center gap-1.5">
{i > 0 && <ChevronRight size={14} className="text-muted/60" />}
{c.href ? (
<Link href={c.href} className="hover:text-accent">
{c.label}
</Link>
) : (
<span>{c.label}</span>
)}
</span>
))}
</nav>
<div className="flex flex-wrap items-center gap-x-4 gap-y-3">
<h1 className="text-[24px] font-semibold tracking-tight text-ink [text-wrap:balance] sm:text-[28px]">{title}</h1>
{pills && <div className="flex flex-wrap items-center gap-2">{pills}</div>}
{right && <div className="ml-auto flex flex-wrap items-center gap-2">{right}</div>}
</div>
{meta && <div className="mt-1 text-[14px] text-muted">{meta}</div>}
{children}
</div>
);
}
const PILL_TONES = {
dark: "bg-accent-soft text-accent-deep",
light: "bg-surface-solid text-ink border border-line",
good: "bg-good-soft text-good",
warn: "bg-warn-soft text-warn",
info: "bg-info-soft text-info",
accent: "accent-fill text-white",
} as const;
export function Pill({ tone = "light", children, className = "" }: { tone?: keyof typeof PILL_TONES; children: React.ReactNode; className?: string }) {
return (
<span className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-[12.5px] font-medium whitespace-nowrap ${PILL_TONES[tone]} ${className}`}>
{children}
</span>
);
}
export function Stat({ label, before, after, note }: { label: string; before: string; after: string; note?: string }) {
return (
<div className="rounded-xl border border-line bg-surface-solid p-4 shadow-card">
<p className="text-[13px] font-medium text-muted">{label}</p>
<p className="tabular mt-2 flex items-baseline gap-2 text-ink">
<span className="text-[17px] text-muted line-through decoration-1">{before}</span>
<span className="text-[13px] text-muted">→</span>
<span className="text-[30px] leading-none font-semibold text-accent">{after}</span>
</p>
{note && <p className="mt-2 text-[12.5px] text-muted">{note}</p>}
</div>
);
}
export function Segmented<T extends string>({
options,
value,
onChange,
label,
}: {
options: { value: T; label: string }[];
value: T;
onChange: (v: T) => void;
label: string;
}) {
return (
<div role="radiogroup" aria-label={label} className="inline-flex flex-wrap rounded-lg border border-line bg-sunken p-1">
{options.map((o) => (
<button
key={o.value}
type="button"
role="radio"
aria-checked={value === o.value}
onClick={() => onChange(o.value)}
className={`rounded-md px-3 py-1.5 text-[13px] font-medium transition-colors ${
value === o.value ? "bg-accent text-white" : "text-muted hover:text-ink"
}`}
>
{o.label}
</button>
))}
</div>
);
}
export function Button({
children,
onClick,
tone = "light",
href,
disabled,
className = "",
}: {
children: React.ReactNode;
onClick?: () => void;
tone?: "dark" | "light" | "accent";
href?: string;
disabled?: boolean;
className?: string;
}) {
const styles = {
dark: "bg-nav text-white hover:bg-ink",
light: "bg-surface-solid text-ink border border-line hover:border-accent",
accent: "bg-accent text-white hover:bg-accent-deep",
}[tone];
const cls = `inline-flex items-center justify-center gap-2 rounded-lg px-4 py-2.5 text-[14px] font-medium shadow-card transition disabled:opacity-50 ${styles} ${className}`;
if (href) {
return (
<Link href={href} className={cls}>
{children}
</Link>
);
}
return (
<button type="button" onClick={onClick} disabled={disabled} className={cls}>
{children}
</button>
);
}