repospace / frontend /src /components /BuildTerminalBox.tsx
2Btainment's picture
feat(ui): central live preview SPACE + iframe/proxy hardening (part 11)
eec101d verified
Raw History Blame Contribute Delete
1.6 kB
import { useEffect, useRef } from "react";
import type { LogLine } from "../types";
import { t } from "../i18n";
interface Props {
lines: LogLine[];
open: boolean;
onToggle: () => void;
}
export function BuildTerminalBox({ lines, open, onToggle }: Props) {
const m = t();
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (ref.current && open) ref.current.scrollTop = ref.current.scrollHeight;
}, [lines, open]);
return (
<section className={`logs-dock ${open ? "open" : "collapsed"}`} data-testid="logs-dock">
<div
className="logs-head"
onClick={onToggle}
role="button"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
onToggle();
}
}}
aria-expanded={open}
>
<div className="row" style={{ gap: ".5rem" }}>
<strong>{m.logs}</strong>
<span className="meta-line">{lines.length} lines</span>
</div>
<span className="chev" aria-hidden>
▾
</span>
</div>
{open ? (
<div className="terminal" ref={ref} role="log" aria-live="polite">
{lines.length === 0 ? (
<span className="ts">waiting for logs…</span>
) : (
lines.map((l) => (
<div key={l.id}>
<span className="ts">{new Date(l.ts * 1000).toLocaleTimeString()}</span>
{l.line}
</div>
))
)}
</div>
) : null}
</section>
);
}