100 lines
4.7 KiB
TypeScript
100 lines
4.7 KiB
TypeScript
// Page building blocks of the console (PEP-38): header, sections, empty states, status badges, alerts.
|
||
import Link from "next/link";
|
||
import type { ReactNode } from "react";
|
||
import { CircleAlert, CircleCheck } from "lucide-react";
|
||
import { Badge } from "@/components/ui/badge";
|
||
import { SESSION_STATUS, TASK_STATUS, TONE_BG } from "@/lib/status";
|
||
import { cn } from "@/lib/utils";
|
||
import { getT } from "@/lib/i18n";
|
||
|
||
export function PageHeader({ title, crumbs, actions, children }: { title: ReactNode; crumbs?: ReactNode; actions?: ReactNode; children?: ReactNode }) {
|
||
return (
|
||
<header className="mb-6 flex flex-col gap-1.5">
|
||
{crumbs && <div className="flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">{crumbs}</div>}
|
||
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
||
<h1 className="m-0 flex min-w-0 flex-wrap items-center gap-2 text-xl font-semibold tracking-tight md:text-2xl">{title}</h1>
|
||
{actions && <div className="ml-auto flex flex-wrap items-center gap-2">{actions}</div>}
|
||
</div>
|
||
{children && <div className="text-sm text-muted-foreground">{children}</div>}
|
||
</header>
|
||
);
|
||
}
|
||
|
||
export function Section({ title, count, actions, children, className, id }: { title: ReactNode; count?: number; actions?: ReactNode; children: ReactNode; className?: string; id?: string }) {
|
||
return (
|
||
<section id={id} className={cn("mt-8 flex flex-col gap-3 first:mt-0", className)}>
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<h2 className="m-0 text-[15px] font-semibold">{title}</h2>
|
||
{count != null && count > 0 && <span className="rounded-full bg-primary px-2 font-mono text-[11px] leading-5 font-semibold text-primary-foreground tabular-nums">{count}</span>}
|
||
{actions && <div className="ml-auto flex items-center gap-2 text-sm">{actions}</div>}
|
||
</div>
|
||
{children}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
export function MoreLink({ href, children }: { href: string; children: ReactNode }) {
|
||
return (
|
||
<Link href={href} className="text-xs text-muted-foreground hover:text-foreground">
|
||
{children} →
|
||
</Link>
|
||
);
|
||
}
|
||
|
||
export function Empty({ children }: { children: ReactNode }) {
|
||
return <p className="m-0 rounded-lg border border-dashed px-4 py-5 text-center text-sm text-muted-foreground">{children}</p>;
|
||
}
|
||
|
||
/** Monospace task/project key, optionally a link. */
|
||
export function Key({ children, href, className }: { children: ReactNode; href?: string; className?: string }) {
|
||
const cls = cn("font-mono text-[0.9em] whitespace-nowrap", href ? "text-primary hover:underline" : "text-muted-foreground", className);
|
||
return href ? <Link href={href} className={cls}>{children}</Link> : <span className={cls}>{children}</span>;
|
||
}
|
||
|
||
export async function StatusBadge({ status, kind = "task" }: { status: string; kind?: "task" | "session" }) {
|
||
const t = await getT();
|
||
const s = (kind === "task" ? TASK_STATUS : SESSION_STATUS)[status] ?? { label: status, tone: "muted" as const };
|
||
return (
|
||
<Badge variant={s.tone}>
|
||
{kind === "session" && <span className={cn("size-1.5 rounded-full", TONE_BG[s.tone], status === "running" && "animate-pulse")} />}
|
||
{t.text(s.label)}
|
||
</Badge>
|
||
);
|
||
}
|
||
|
||
export async function Flash({ error }: { error?: string }) {
|
||
const t = await getT();
|
||
return error ? (
|
||
// Sticky: an action far down the page (a board card, «Принять») must not fail silently above the fold.
|
||
<p role="alert" className="sticky top-2 z-40 mb-4 flex items-start gap-2 rounded-lg border border-destructive/60 bg-[color-mix(in_oklab,var(--destructive)_14%,var(--background))] px-4 py-3 text-sm text-foreground shadow-lg">
|
||
<CircleAlert className="mt-0.5 size-4 shrink-0 text-destructive" />
|
||
<span>{t.text(error)}</span>
|
||
</p>
|
||
) : null;
|
||
}
|
||
|
||
export function Notice({ children }: { children: ReactNode }) {
|
||
return (
|
||
<div role="status" className="mb-4 flex flex-wrap items-center gap-2 rounded-lg border border-ok/40 bg-ok/10 px-4 py-3 text-sm">
|
||
<CircleCheck className="size-4 shrink-0 text-ok" />
|
||
{children}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** Collapsible block styled as a card (native <details>: no client JS). */
|
||
export function Disclosure({ summary, children, open, className }: { summary: ReactNode; children: ReactNode; open?: boolean; className?: string }) {
|
||
return (
|
||
<details open={open} className={cn("group rounded-lg border bg-card", className)}>
|
||
<summary className="flex cursor-pointer list-none items-center gap-2 px-4 py-2.5 text-sm font-medium select-none [&::-webkit-details-marker]:hidden">
|
||
<span className="text-muted-foreground transition-transform group-open:rotate-90">›</span>
|
||
{summary}
|
||
</summary>
|
||
<div className="border-t px-4 py-3">{children}</div>
|
||
</details>
|
||
);
|
||
}
|
||
|
||
|
||
export { ago, linkify } from "@/lib/format";
|