treege 3.0.0-beta.82 → 3.0.0-beta.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,6 +52,7 @@ Treege is a modern React library for creating and rendering interactive decision
52
52
  - **Optional Dependencies**: Graceful degradation when optional packages like `react-native-document-picker` aren't installed
53
53
  - **Theme Support**: Dark/light mode out of the box
54
54
  - **Google API Integration**: Address autocomplete support
55
+ - **Read-Only Viewer**: `TreegeViewer` renders a submitted flow as a label/value recap — same branch-visibility and formatting as the form, with a headless `getViewerFields` core for custom layouts
55
56
 
56
57
  ### Developer Experience
57
58
  - **Modular**: Import only what you need (editor, renderer, or both)
@@ -189,6 +190,73 @@ function App() {
189
190
  }
190
191
  ```
191
192
 
193
+ ## Read-Only Viewer (`TreegeViewer`)
194
+
195
+ Once a form has been submitted, `TreegeViewer` renders the result as a read-only **label / value recap** — no inputs, no validation. It takes the same `flow` and the submitted `values` (the `onSubmit` payload) and replays them through the renderer's branch-visibility logic, so only the fields that were actually reachable for those values are shown. Option values resolve to their labels, dates/ranges and i18n labels are formatted exactly like the form, and `hidden`/`submit` fields are excluded.
196
+
197
+ ```tsx
198
+ import { TreegeRenderer } from "treege/renderer";
199
+ import { TreegeViewer } from "treege/renderer";
200
+ import { useState } from "react";
201
+ import type { Flow, FormValues } from "treege";
202
+
203
+ function App({ flow }: { flow: Flow }) {
204
+ const [submitted, setSubmitted] = useState<FormValues | null>(null);
205
+
206
+ if (submitted) {
207
+ return <TreegeViewer flow={flow} values={submitted} language="en" />;
208
+ }
209
+
210
+ return <TreegeRenderer flow={flow} onSubmit={setSubmitted} />;
211
+ }
212
+ ```
213
+
214
+ ### Props
215
+
216
+ | Prop | Type | Default | Description |
217
+ |----------------------|-----------------------------------------------------|---------|--------------------------------------------------------------------------------------------------------------|
218
+ | `flow` | `Flow` | - | The flow the values were submitted against |
219
+ | `values` | `FormValues` | - | The submitted values (`name`- or `id`-keyed, e.g. the `onSubmit` payload) |
220
+ | `language` | `string` | `"en"` | Language used to resolve translatable labels/options |
221
+ | `baseUrl` | `string` | - | Resolves relative file paths into absolute URLs (same role as on `TreegeRenderer`); `data:`/`blob:`/absolute URLs are left untouched |
222
+ | `excludedFields` | `string[]` | - | Field names (or ids) to hide from the view |
223
+ | `excludeEmptyFields` | `boolean` | `false` | Hide fields that have no submitted value (instead of showing `emptyText`) |
224
+ | `emptyText` | `string` | `"—"` | Text shown when a field has no submitted value |
225
+ | `className` | `string` | - | Extra class names on the root element |
226
+ | `renderField` | `Partial<Record<InputType, (field) => ReactNode>>` | - | Per-type rendering overrides for the value cell (typically `file`) |
227
+ | `renderRow` | `(field, defaultRow) => ReactNode` | - | Wrap or replace a whole field row (label + value) |
228
+
229
+ ### Customizing rendering
230
+
231
+ Use `renderField` to override the value cell for a specific input type — most often `file`, to render thumbnails from your own storage — while every other type keeps its built-in rendering. Use `renderRow` to control the whole row layout (label + value):
232
+
233
+ ```tsx
234
+ <TreegeViewer
235
+ flow={flow}
236
+ values={submitted}
237
+ language="fr"
238
+ excludedFields={["internalNote"]}
239
+ renderField={{ file: ({ rawValue }) => <Thumbnails files={rawValue} /> }}
240
+ />
241
+ ```
242
+
243
+ ### Headless usage (`getViewerFields`)
244
+
245
+ `TreegeViewer` is a thin layer over `getViewerFields`, which returns the ordered, visible, display-ready fields. Use it directly when you want a fully custom layout (a table, a PDF, columns…):
246
+
247
+ ```tsx
248
+ import { getViewerFields } from "treege/renderer";
249
+
250
+ const fields = getViewerFields(flow, values, { language: "en", baseUrl });
251
+
252
+ fields.forEach((field) => {
253
+ // field.label, field.type, field.rawValue
254
+ // field.display — normalized, render-ready value:
255
+ // { kind: "text", text } | { kind: "boolean", checked }
256
+ // { kind: "tags", tags } | { kind: "files", files } | { kind: "empty" }
257
+ });
258
+ ```
259
+
192
260
  ## Module Structure
193
261
 
194
262
  Treege provides multiple import paths for optimal bundle size: