Tabular viewer
A read-only preview of a spreadsheet or CSV document, with download and full screen, for documents already read by the platform.
A
B
C
D
Competência
Principal
Juros
Total
01/2024
1.250,00
12,50
1.262,50
02/2024
1.250,00
25,00
1.275,00
03/2024
1.250,00
37,50
1.287,50
04/2024
1.250,00
50,00
1.300,00
05/2024
1.250,00
62,50
1.312,50
06/2024
1.250,00
75,00
1.325,00
Columns are named A, B, C, as in a spreadsheet. Use Download to save the original file and Fullscreen to enlarge the table.
When to use
- To show the contents of a spreadsheet or CSV attachment inside a document viewer, without leaving the page.
- When the platform has already read the file into rows (the
tabular_datafeature of the document).
When not to use
- Editing cells. The table is read-only. Use a data table or a spreadsheet editor.
- Structured results with sorting and filters. Use Table.
- PDF files. Use the PDF viewer.
- Images. Use the Image viewer.
Two components, one page
| Export | Import path | Use for |
|---|---|---|
TabularPreview |
@repo/ui/tabular-viewer |
Presentation. You pass the rows (sheet) and the loading and error flags. Previews on this page use it. |
TabularViewer |
@repo/ui/documents/tabular-viewer |
Data. Takes a documentId or a publicDocumentKey, loads the tabular_data feature and renders TabularPreview. |
TabularViewer calls the document API, so it is not shown here. It accepts every prop of TabularPreview except the ones it fills (sheet, isLoading, isError, onRetry), plus documentId and publicDocumentKey.
States
Não foi possível ler a planilha.
Esta planilha não tem dados para exibir.
| State | When |
|---|---|
| Loading | isLoading. A skeleton named by labels.loading. |
| Error | isError. A message and a Retry button that calls onRetry. |
| Empty | The sheet has no rows. Shows labels.noTable. |
| Bundle | isBundle. The file is a workbook with several sheets, each its own document. Shows a hint to pick a sheet. |
Content
- Labels are required and come from the app:
download,downloading,enterFullscreen,exitFullscreen,loading,noTable,readError,retry,downloadError,document. - Say what happened and what to do on error: “Não foi possível ler a planilha.” and the button “Tentar novamente”.
- The bundle texts are optional but their fallbacks are English. Always pass
bundleTitle,bundleDescriptionandbundleInstruction.
Accessibility
- The table is a spreadsheet grid (
TableSpreadSheet) in read-only mode, named by the sheet name, then the file name, thenlabels.document. - The Fullscreen button uses
aria-pressedand changes its text betweenenterFullscreenandexitFullscreen.Escapeexits full screen natively. - The grid supports moving between cells with the arrow keys.
- Download shows a loading state in the button; a failure appears in a
role="alert"message. - The loading skeleton carries
aria-label, the empty state and the bundle hint are announced as status or output. - Icons are
aria-hidden; the buttons have visible text.
Code
import { TabularViewer } from "@repo/ui/documents/tabular-viewer";
<TabularViewer
documentId={document.document_service_id}
fileName={document.original_file_name}
labels={labels}
src={document.file_path}
/>;
Place it in a parent with a fixed height: the viewer fills 100% of it.
Props
TabularPreview| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Extra classes for the root. The viewer fills its parent |
fileName | string | — | Used as the download name and as the table name when the sheet has none |
isBundle | boolean | null | — | The file is a workbook whose sheets are separate documents. Shows a hint instead of a table |
isError | boolean | false | The sheet could not be read. Shows a message and Retry |
isLoading | boolean | false | The sheet is being read. Shows a skeleton |
labels | TabularViewerLabels | — | Every visible string, translated by the app. The bundle texts are optional |
onRetry | () => void | — | Called when the user selects Retry after an error |
sheet | TabularSheet | null | — | Rows and column count to show. Empty or null shows `noTable` |
src | string | — | URL of the original file. The Download button saves it and is disabled when empty |
TabularViewer (extra props)| Prop | Type | Default | Description |
|---|---|---|---|
documentId | string | null | — | Document service id. Loads the tabular data feature. |
publicDocumentKey | string | — | Key of a shared document, loaded without authentication. |
Known issues
| Issue | Effect |
|---|---|
bundleTitle, bundleDescription and bundleInstruction fall back to hardcoded English (“Workbook with sheets”, “Each sheet is a document.”, “Select a sheet to view its table.”). |
An app that omits them shows English text in a Portuguese interface. The package should have no copy of its own. |
The loading skeleton is h-40 and does not fill the preview. |
The layout shifts when the table (which fills the parent) replaces it. |
| Columns are named only by letter and every row is data; there is no header row option. | Files with column titles show them as an ordinary first row. |