Open History to see the last commit
1/* oxlint-disable react/no-array-index-key -- Table rows and columns have stable positions and may contain identical values. */
2import { parseDelimitedPreview } from "@t3tools/shared/delimitedPreview";
3
4import { FileSurfaceNotice } from "./fileSurfaceChrome";
5
6export function DelimitedTablePreview(props: {
7 readonly name: string;
8 readonly text: string;
9 readonly delimiter: "," | "\t";
10}) {
11 const table = parseDelimitedPreview(props.text, props.delimiter);
12 const [header, ...body] = table.rows;
13 return (
14 <div className="flex min-h-0 flex-1 flex-col">
15 {table.truncated ? (
16 <FileSurfaceNotice>
17 Table limited to the first 100 rows and 30 columns. Switch to source for the rest.
18 </FileSurfaceNotice>
19 ) : null}
20 <div className="min-h-0 flex-1 overflow-auto">
21 <table
22 className="min-w-full border-separate border-spacing-0 text-xs"
23 aria-label={props.name}
24 >
25 {header ? (
26 <thead className="sticky top-0 z-10">
27 <tr>
28 {header.map((cell, columnIndex) => (
29 <th
30 key={columnIndex}
31 scope="col"
32 className="max-w-80 border-b border-border bg-muted/60 px-3 py-1.5 text-left align-bottom font-medium whitespace-pre-wrap break-words backdrop-blur"
33 >
34 {cell}
35 </th>
36 ))}
37 </tr>
38 </thead>
39 ) : null}
40 <tbody>
41 {body.map((row, rowIndex) => (
42 <tr key={rowIndex} className="even:bg-muted/30">
43 {row.map((cell, columnIndex) => (
44 <td
45 key={columnIndex}
46 className="max-w-80 border-b border-border/60 px-3 py-1.5 align-top whitespace-pre-wrap break-words tabular-nums"
47 >
48 {cell}
49 </td>
50 ))}
51 </tr>
52 ))}
53 </tbody>
54 </table>
55 </div>
56 </div>
57 );
58}