Data display
LogViewer
Log lines with time, source and text. While live, it follows new lines only when the reader is at the end; else “Jump to newest” shows. Search marks the matches, and right click or a long press copies a line. Arrow keys move between lines. Shift+F10 opens the line menu. Ctrl+C or Cmd+C copies the current line.
import { LogViewer, type LogRow } from "@percentsa/ui";Examples
Build finished
- 10:00:00compilercompiler · step 1 of 40 done
- 10:00:01bundlerbundler · step 2 of 40 done
- 10:00:02compilercompiler · step 3 of 40 done
- 10:00:03bundlerbundler · step 4 of 40 done
- 10:00:04compilercompiler · step 5 of 40 done
- 10:00:05bundlerbundler · step 6 of 40 done
- 10:00:06compilercompiler · step 7 of 40 done
- 10:00:07bundlerbundler · step 8 of 40 done
- 10:00:08compilercompiler · step 9 of 40 done
- 10:00:09bundlerbundler · step 10 of 40 done
- 10:00:10compilercompiler · step 11 of 40 done
- 10:00:11bundlerbundler · step 12 of 40 done
- Error10:00:12compilercompiler · error: cannot find module "./missing-12"
- 10:00:13bundlerbundler · step 14 of 40 done
- 10:00:14compilercompiler · step 15 of 40 done
- 10:00:15bundlerbundler · step 16 of 40 done
- 10:00:16compilercompiler · step 17 of 40 done
- 10:00:17bundlerbundler · step 18 of 40 done
- 10:00:18compilercompiler · step 19 of 40 done
- 10:00:19bundlerbundler · step 20 of 40 done
- 10:00:20compilercompiler · step 21 of 40 done
- 10:00:21bundlerbundler · step 22 of 40 done
- 10:00:22compilercompiler · step 23 of 40 done
- 10:00:23bundlerbundler · step 24 of 40 done
- 10:00:24compilercompiler · step 25 of 40 done
- 10:00:25bundlerbundler · step 26 of 40 done
- 10:00:26compilercompiler · step 27 of 40 done
- 10:00:27bundlerbundler · step 28 of 40 done
- 10:00:28compilercompiler · step 29 of 40 done
- 10:00:29bundlerbundler · step 30 of 40 done
- 10:00:30compilercompiler · step 31 of 40 done
- Error10:00:31bundlerbundler · error: cannot find module "./missing-31"
- 10:00:32compilercompiler · step 33 of 40 done
- 10:00:33bundlerbundler · step 34 of 40 done
- 10:00:34compilercompiler · step 35 of 40 done
- 10:00:35bundlerbundler · step 36 of 40 done
- 10:00:36compilercompiler · step 37 of 40 done
- 10:00:37bundlerbundler · step 38 of 40 done
- 10:00:38compilercompiler · step 39 of 40 done
- 10:00:39bundlerbundler · step 40 of 40 done
Code
export function LogViewerExample() {
const t = useT();
const [search, setSearch] = useState("");
return (
<LogViewer
label={t("Build log", "سجل البناء")}
rows={BUILD_ROWS}
live="off"
onLiveChange={() => {}}
search={search}
onSearchChange={setSearch}
empty={t("No lines yet.", "لا توجد أسطر بعد.")}
status={t("Build finished", "اكتمل البناء")}
height="20rem"
className="w-full max-w-2xl"
/>
);
}Live
- 10:00:00compilercompiler · step 1 of 40 done
- 10:00:01bundlerbundler · step 2 of 40 done
- 10:00:02compilercompiler · step 3 of 40 done
- 10:00:03bundlerbundler · step 4 of 40 done
- 10:00:04compilercompiler · step 5 of 40 done
- 10:00:05bundlerbundler · step 6 of 40 done
- 10:00:06compilercompiler · step 7 of 40 done
- 10:00:07bundlerbundler · step 8 of 40 done
- 10:00:08compilercompiler · step 9 of 40 done
- 10:00:09bundlerbundler · step 10 of 40 done
- 10:00:10compilercompiler · step 11 of 40 done
- 10:00:11bundlerbundler · step 12 of 40 done
Code
export function LogViewerLiveExample() {
const t = useT();
const [live, setLive] = useState<LogLive>("on");
const [rows, setRows] = useState<LogRow[]>(() => BUILD_ROWS.slice(0, 12));
useEffect(() => {
if (live !== "on") return;
const id = setInterval(
() => setRows((r) => {
const n = (r.at(-1) ? Number(r.at(-1)!.key.slice(1)) : 0) + 1; // keys keep counting after old rows drop
return [...r, { key: `l${n}`, at: clock(n), source: "server", text: `request ${n} handled` }].slice(-200);
}),
2000,
);
return () => clearInterval(id);
}, [live]);
return (
<LogViewer
label={t("Server log", "سجل الخادم")}
rows={rows}
live={live}
onLiveChange={setLive}
empty={t("No lines yet.", "لا توجد أسطر بعد.")}
status={live === "on" ? t("Live", "بث مباشر") : t("Paused", "متوقف مؤقتًا")}
height="16rem"
className="w-full max-w-2xl"
/>
);
}