torch-glare 2.4.1 → 2.4.3

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.
Files changed (85) hide show
  1. package/apps/lib/components/Button.tsx +1 -1
  2. package/apps/lib/components/Card.tsx +47 -20
  3. package/apps/lib/components/ColorPicker.tsx +441 -0
  4. package/apps/lib/components/ConclusionHeader.tsx +148 -0
  5. package/apps/lib/components/DatePicker.tsx +2 -0
  6. package/apps/lib/components/Drawer.tsx +66 -24
  7. package/apps/lib/components/FormBuilder/context.ts +68 -0
  8. package/apps/lib/components/FormBuilder/fields/ChoiceFields.tsx +60 -0
  9. package/apps/lib/components/FormBuilder/fields/ColorField.tsx +59 -0
  10. package/apps/lib/components/FormBuilder/fields/CustomField.tsx +11 -0
  11. package/apps/lib/components/FormBuilder/fields/DateField.tsx +32 -0
  12. package/apps/lib/components/FormBuilder/fields/FieldArray.tsx +74 -0
  13. package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +148 -0
  14. package/apps/lib/components/FormBuilder/fields/FileField.tsx +39 -0
  15. package/apps/lib/components/FormBuilder/fields/OptionListFields.tsx +132 -0
  16. package/apps/lib/components/FormBuilder/fields/OtpField.tsx +31 -0
  17. package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +83 -0
  18. package/apps/lib/components/FormBuilder/fields/RichTextEditorField.tsx +31 -0
  19. package/apps/lib/components/FormBuilder/fields/SelectField.tsx +91 -0
  20. package/apps/lib/components/FormBuilder/fields/SignatureField.tsx +157 -0
  21. package/apps/lib/components/FormBuilder/fields/SliderField.tsx +67 -0
  22. package/apps/lib/components/FormBuilder/fields/SwitchBoxField.tsx +41 -0
  23. package/apps/lib/components/FormBuilder/fields/TableField.tsx +308 -0
  24. package/apps/lib/components/FormBuilder/fields/TextField.tsx +213 -0
  25. package/apps/lib/components/FormBuilder/fields/TreeSelectField.tsx +43 -0
  26. package/apps/lib/components/FormBuilder/fields/countries.ts +303 -0
  27. package/apps/lib/components/FormBuilder/fields/index.ts +25 -0
  28. package/apps/lib/components/FormBuilder/form-builder.tsx +279 -0
  29. package/apps/lib/components/FormBuilder/header.tsx +101 -0
  30. package/apps/lib/components/FormBuilder/index.ts +33 -0
  31. package/apps/lib/components/FormBuilder/numberFormat.ts +16 -0
  32. package/apps/lib/components/FormBuilder/stepper.tsx +290 -0
  33. package/apps/lib/components/FormBuilder/submit.tsx +38 -0
  34. package/apps/lib/components/FormBuilder/types.ts +261 -0
  35. package/apps/lib/components/FormRenderer/FormDrawer.tsx +128 -0
  36. package/apps/lib/components/FormRenderer/form-renderer.tsx +111 -0
  37. package/apps/lib/components/FormRenderer/index.ts +4 -0
  38. package/apps/lib/components/FormRenderer/types.ts +77 -0
  39. package/apps/lib/components/FormSummary.tsx +282 -0
  40. package/apps/lib/components/ImageAttachment.tsx +36 -61
  41. package/apps/lib/components/Label.tsx +49 -42
  42. package/apps/lib/components/Popover.tsx +6 -2
  43. package/apps/lib/components/RadioCard.tsx +2 -0
  44. package/apps/lib/components/SearchableSelect.tsx +16 -5
  45. package/apps/lib/components/SectionBlock.tsx +16 -8
  46. package/apps/lib/components/Select.tsx +41 -120
  47. package/apps/lib/components/TextEditor/RichTextField.tsx +46 -0
  48. package/apps/lib/components/{TextEditor.tsx → TextEditor/TextEditor.tsx} +63 -9
  49. package/apps/lib/components/TextEditor/TextEditorToolbar.tsx +429 -0
  50. package/apps/lib/components/TextEditor/editor-tools/AlignmentTune.ts +70 -0
  51. package/apps/lib/components/TextEditor/editor-tools/ColorInlineTool.ts +50 -0
  52. package/apps/lib/components/TextEditor/editor-tools/StrikethroughInlineTool.ts +48 -0
  53. package/apps/lib/components/TextEditor/editor-tools/inlineFormat.ts +98 -0
  54. package/apps/lib/{types → components/TextEditor}/editorjs.d.ts +19 -0
  55. package/apps/lib/components/TextEditor/index.ts +7 -0
  56. package/apps/lib/components/Textarea.tsx +1 -1
  57. package/apps/lib/layouts/FieldSection.tsx +25 -22
  58. package/apps/lib/registry.json +51 -58
  59. package/apps/lib/tsconfig.tsbuildinfo +1 -0
  60. package/apps/lib/utils/color.ts +175 -0
  61. package/dist/src/shared/tailwindInit.d.ts.map +1 -1
  62. package/dist/src/shared/tailwindInit.js +3 -0
  63. package/dist/src/shared/tailwindInit.js.map +1 -1
  64. package/docs/components/card.md +4 -2
  65. package/docs/components/chart-block-tool.md +5 -4
  66. package/docs/components/color-picker.md +101 -0
  67. package/docs/components/conclusion-header.md +80 -0
  68. package/docs/components/drawer.md +153 -102
  69. package/docs/components/form-builder.md +260 -0
  70. package/docs/components/form-renderer.md +234 -0
  71. package/docs/components/form-summary.md +123 -0
  72. package/docs/components/image-attachment.md +10 -4
  73. package/docs/components/searchable-select.md +50 -46
  74. package/docs/components/table-dnd-wrapper.md +5 -3
  75. package/docs/components/text-editor.md +18 -0
  76. package/docs/how-to/form-and-list-recipes.md +26 -19
  77. package/docs/how-to/forms-with-form-builder.md +411 -0
  78. package/docs/how-to/guides.md +153 -179
  79. package/docs/reference/tailwind-plugins.md +11 -1
  80. package/docs/tutorials/building-first-form.md +150 -159
  81. package/docs/tutorials/getting-started.md +9 -0
  82. package/package.json +1 -1
  83. /package/apps/lib/components/{ChartBlockTool.ts → TextEditor/ChartBlockTool.ts} +0 -0
  84. /package/apps/lib/components/{TableDnDWrapper.ts → TextEditor/TableDnDWrapper.ts} +0 -0
  85. /package/apps/lib/{utils → components/TextEditor}/markdownParser.ts +0 -0
@@ -0,0 +1,260 @@
1
+ ---
2
+ title: FormBuilder
3
+ description: A compound, composition-based form. Author forms as JSX children (FormBuilder.Text, FormBuilder.Select, …) with steps-as-components, a drawer wrapper, and any react-hook-form resolver.
4
+ component: true
5
+ group: Forms
6
+ keywords:
7
+ [form-builder, form, compound, composition, react-hook-form, resolver, stepper, drawer, fields]
8
+ ---
9
+
10
+ # FormBuilder
11
+
12
+ A **compound, composition-based** form. You author a form as JSX children — each
13
+ field is a `FormBuilder.*` component wired to [react-hook-form](https://react-hook-form.com/)
14
+ for you. Steps are components and the drawer is a wrapper.
15
+
16
+ ```tsx
17
+ <FormBuilder onSubmit={save} resolver={zodResolver(schema)} defaultValues={d}>
18
+ <FormBuilder.Section title="Identity" color="Blue">
19
+ <FormBuilder.Text name="name" label="Name" required />
20
+ <FormBuilder.Currency name="price" label="Price" currencySymbol="$" />
21
+ </FormBuilder.Section>
22
+ <FormBuilder.Submit>Save</FormBuilder.Submit>
23
+ </FormBuilder>
24
+ ```
25
+
26
+ > Need the same form to render as a page _or_ a drawer, with a title header and an
27
+ > `actions` slot for the Save? Wrap these same children in
28
+ > [FormRenderer](./form-renderer.md).
29
+
30
+ ## Installation
31
+
32
+ TORCH Glare is a copy-in library: the CLI copies this component's source into your project.
33
+
34
+ ```bash
35
+ npx torch-glare@latest init
36
+ npx torch-glare@latest add FormBuilder
37
+ ```
38
+
39
+ ## Imports
40
+
41
+ ```tsx
42
+ import { FormBuilder } from "@/components/FormBuilder";
43
+ ```
44
+
45
+ ## Root props
46
+
47
+ | Prop | Type | Notes |
48
+ | ---------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
49
+ | `onSubmit` | `(values) => void \| Promise<void>` | Called on a valid submit. |
50
+ | `onInvalid` | `(errors) => void` | Called when validation fails. |
51
+ | `resolver` | `Resolver` | Any react-hook-form resolver, e.g. `zodResolver(schema)`. |
52
+ | `defaultValues` | `DefaultValues` | Initial values (create). |
53
+ | `values` | `T` | Controlled values (edit) — the form re-syncs when this changes. |
54
+ | `loading` | `boolean` | Submit shows a spinner; inputs disable. |
55
+ | `fieldDirection` | `'horizontal' \| 'vertical'` | Row layout (auto-vertical inside a drawer). |
56
+ | `resetOnSuccess` | `boolean` | Reset to defaults after a successful submit. |
57
+ | `form` | `UseFormReturn` | A hoisted `useForm` to bind to — pass when a `conclusion` panel must read the same values. |
58
+ | `conclusion` | `ReactNode` | A live panel (e.g. `FormSummary`) rendered **outside** the `<form>` as the grid's right column. |
59
+ | `id` | `string` | Sets the underlying `<form id>`, so a button outside the form can submit it via `form={id}` (e.g. a drawer header's Save). |
60
+ | `className` | `string` | Lands on the form's outermost element — e.g. `"min-w-0 flex-1"` to fill the space beside a `conclusion` panel. |
61
+
62
+ **Adaptive layout.** FormBuilder lays out responsively: a `FormBuilder.Stepper` puts its nav rail in
63
+ a **left** column beside the fields (both inside the form surface, under the title header), and a
64
+ `conclusion` renders as its own panel **outside** the form surface, beside it — the same structure
65
+ `FormDrawer` uses in the drawer tray (6px gutter). So a stepper + conclusion reads as three columns
66
+ (nav · fields · conclusion), a conclusion alone as two, and a plain form as one. The fields column
67
+ caps at 1100px and centers. The conclusion is outside the `<form>` and reads values via its own
68
+ `form` prop.
69
+
70
+ ## Field components
71
+
72
+ Each is a JSX child taking at least `name`, plus `label`, `placeholder`,
73
+ `description`, `required`, `disabled`, `hidden`, `fullWidth`.
74
+
75
+ | Component | Input | Value |
76
+ | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
77
+ | `FormBuilder.Text` / `.Email` / `.Password` | `InputField` | `string` |
78
+ | `FormBuilder.Number` | numeric `InputField` | `number` |
79
+ | `FormBuilder.Currency` (`currencySymbol`) | `InputField` + symbol | `number` |
80
+ | `FormBuilder.Textarea` | `Textarea` | `string` |
81
+ | `FormBuilder.Slider` (`min,max,step,range`) | `@radix-ui/react-slider` | `number` / `[number,number]` |
82
+ | `FormBuilder.Color` (`presets`, `alpha`) | `ColorPicker` (full palette: SV area, hue, opacity, eyedropper, HEX/RGB/HSL, presets) | hex `string` (`#rrggbb`, or `#rrggbbaa` when opacity < 100%) |
83
+ | `FormBuilder.Phone` (`defaultCountry`) | `SearchableSelect` + `InputField` | `string` |
84
+ | `FormBuilder.Select` / `.SearchableSelect` (`options`, async props) | `SearchableSelect` | `string` |
85
+ | `FormBuilder.MultiSelect` / `.Tags` (`options`) | `BadgeField` | `string[]` |
86
+ | `FormBuilder.RadioList` (`options`, each with optional `description`) | boxed radio list | `string` |
87
+ | `FormBuilder.CheckboxGroup` (`options`, each with optional `description`) | boxed checkbox list | `string[]` |
88
+ | `FormBuilder.RadioCards` (`options` with `description`) | `RadioCard` | `string` |
89
+ | `FormBuilder.Checkbox` (`subLabel`) | `Checkbox` + inline label | `boolean` |
90
+ | `FormBuilder.SwitchBox` (`subLabel`) | `Switch` in a `#f9f9f9` box | `boolean` |
91
+ | `FormBuilder.Otp` (`length`) | `InputOTP` | `string` |
92
+ | `FormBuilder.Date` | `DatePicker` | `Date` |
93
+ | `FormBuilder.DateRange` | `DatePicker` (range) | `{from,to}` |
94
+ | `FormBuilder.DateMultiple` | `DatePicker` (multiple) | `Date[]` |
95
+ | `FormBuilder.DateTime` | `DatePicker` (timePicker) | `Date` |
96
+ | `FormBuilder.TreeSelect` (`nodes`, `getNodeId`, `getNodeLabel`, …) | `SearchableTree` | node id (`string`) |
97
+ | `FormBuilder.File` / `.Image` (`accept`, `multiple`) | `ImageAttachment` | `File \| File[]` |
98
+ | `FormBuilder.RichText` | `TextEditor` (EditorJS) | `OutputData` |
99
+ | `FormBuilder.Signature` (`penColor`) | canvas pad | PNG data-URL `string` |
100
+ | `FormBuilder.FieldArray` (`children` render fn, `defaultItem`) | RHF `useFieldArray` | `object[]` |
101
+ | `FormBuilder.Table` (`columns`, `selectable`, `reorderable`, `defaultItem`) | editable grid in a `SectionBlock` | `object[]` |
102
+ | `FormBuilder.Custom` (`render`, `formatView`) | your control | anything |
103
+
104
+ `FormBuilder.Password` accepts `strengthMeter` (shows a `PasswordLevel` meter). `FormBuilder.FieldArray`
105
+ renders a repeating list — its `children` is a render fn `(rowName, index, remove) => …` and sub-fields
106
+ are named `${rowName}.field`.
107
+
108
+ `FormBuilder.Table` is the **table-shaped** counterpart of `FieldArray` (value `object[]`): an editable
109
+ grid where each row is a record and each column cell is any `FormBuilder.*` field. It renders **inside a
110
+ `SectionBlock`**, so place it as a **top-level child** of the form (not inside a `FormBuilder.Section`).
111
+ Each column pairs a `header` with a `cell(rowName, index)` renderer — name the cell's field
112
+ `${rowName}.<key>`. The section header carries the actions: a **Add New** button (also repeated as the
113
+ bottom footer) and a **Delete Row** button that's disabled until rows are checkbox-selected. Rows support
114
+ **checkbox selection** (+ select-all), **drag-drop reordering**, and — per column, via `sortKey` — a
115
+ sort toggle in the header. Cells render
116
+ "bare" (control only) with validation errors shown as a tooltip on the control, so a row stays one line
117
+ tall, and each field passes `onTable` so it's borderless and blends into the grid. Practical cell fields
118
+ are the compact ones — `Text`, `Number`, `Currency`, `Select`, `SearchableSelect`, `Date`, `Phone`,
119
+ `Checkbox`, `SwitchBox`; wide fields (`RichText`, `Signature`, `File`) work but aren't suited to a cell.
120
+
121
+ ```tsx
122
+ <FormBuilder.Table
123
+ name="items"
124
+ title="Items"
125
+ color="Green"
126
+ addLabel="Add item"
127
+ defaultItem={{ item: "", category: "hardware", qty: 1, price: 0 }}
128
+ columns={[
129
+ {
130
+ header: "Item",
131
+ width: 200,
132
+ cell: (row) => <FormBuilder.Text name={`${row}.item`} required />,
133
+ },
134
+ {
135
+ header: "Category",
136
+ cell: (row) => <FormBuilder.Select name={`${row}.category`} options={CATEGORY} required />,
137
+ },
138
+ {
139
+ header: "Qty",
140
+ width: 110,
141
+ cell: (row) => <FormBuilder.Number name={`${row}.qty`} required />,
142
+ },
143
+ {
144
+ header: "Price",
145
+ width: 140,
146
+ cell: (row) => <FormBuilder.Currency name={`${row}.price`} currencySymbol="$" required />,
147
+ },
148
+ ]}
149
+ />
150
+ ```
151
+
152
+ `FormBuilder.RadioList` (single-select, `string`) and `FormBuilder.CheckboxGroup` (multi-select,
153
+ `string[]`) render their `options` as a boxed, divided list — control on the left, primary
154
+ label, and an optional per-option `description` shown as a secondary label. The whole row is
155
+ clickable. Multi-select is also available as `.MultiSelect` / `.Tags` (a tag-chip picker).
156
+
157
+ `FormBuilder.SwitchBox` (value `boolean`) is a switch wrapped in a `#f9f9f9` field box. It
158
+ renders like any other field — the `label` sits in the normal label column — and the box holds
159
+ an optional inline `subLabel`, a vertical divider, and the switch.
160
+
161
+ `FormBuilder.Section` (props `title`, `color`, `icon`) groups fields in a Glare
162
+ `SectionBlock`. `FormBuilder.Submit` is a loading-aware submit button. It
163
+ **auto-associates with the enclosing form** (via context), so it submits even when placed in a
164
+ header / action bar that renders _outside_ the `<form>` — no manual `form={id}` wiring.
165
+
166
+ ## Title header + action bar
167
+
168
+ `FormBuilder.Header` renders a **title pill** (Glare `HeaderBar`) on the left and an
169
+ **action bar** (your buttons) on the right, **absolutely positioned** over a
170
+ scrollable form body — the products-services item-edit look. Place it as a direct
171
+ child of `<FormBuilder>`; the root then switches to the scroll-shell layout.
172
+
173
+ ```tsx
174
+ <FormBuilder onSubmit={save} resolver={r} defaultValues={d}>
175
+ <FormBuilder.Header title="Item" variant="new">
176
+ <FormBuilder.Submit>Save</FormBuilder.Submit>
177
+ {/* add more actions, e.g. a "Save as draft" Button */}
178
+ </FormBuilder.Header>
179
+
180
+ <FormBuilder.Section title="Identity" color="Blue">
181
+ <FormBuilder.Text name="name" label="Name" required />
182
+ </FormBuilder.Section>
183
+ </FormBuilder>
184
+ ```
185
+
186
+ - `title` — plain text (uppercased). `label` — badge text (defaults from `variant`).
187
+ - `variant` — `"new" | "edit" | "detail"` (badge color; default `"new"`). `children` are
188
+ the action buttons; `FormBuilder.Submit` submits the form (it auto-associates with it, even
189
+ though the header sits outside `<form>`).
190
+
191
+ ## Stepper (steps are components)
192
+
193
+ Wrap steps in `FormBuilder.Stepper`; each `FormBuilder.Step` holds a step's fields.
194
+ **Every step's fields are always mounted and registered** — the whole form is live
195
+ regardless of which step is showing; the stepper only toggles _visibility_.
196
+ **Navigation is the step buttons themselves**: click a step to go there. Backward is
197
+ free; clicking forward validates the steps in between and stops at the first one with
198
+ errors (shown with a red indicator). A step that **passes validation stays checked** even
199
+ after you navigate back to it. Put the **Submit** in the `FormBuilder.Header` (or the
200
+ `FormRenderer` `actions`) — it submits every step's fields at once, from any step.
201
+
202
+ `FormBuilder.Back` / `FormBuilder.Next` are **chevron step-nav buttons** (previous / next,
203
+ disabled at the ends; `Next` validates the current step first). Place them in a
204
+ `FormBuilder.Header`, or use `FormRenderer` — it prepends them before your Submit for a stepper
205
+ automatically.
206
+
207
+ ```tsx
208
+ <FormBuilder onSubmit={save} resolver={r} defaultValues={d}>
209
+ <FormBuilder.Header title="Item" variant="new">
210
+ <FormBuilder.Submit>Save</FormBuilder.Submit>
211
+ </FormBuilder.Header>
212
+
213
+ <FormBuilder.Stepper>
214
+ <FormBuilder.Step title="Basics">
215
+ <FormBuilder.Text name="name" label="Name" required />
216
+ </FormBuilder.Step>
217
+ <FormBuilder.Step title="Details">
218
+ <FormBuilder.Select name="category" label="Category" required options={cats} />
219
+ </FormBuilder.Step>
220
+ </FormBuilder.Stepper>
221
+ </FormBuilder>
222
+ ```
223
+
224
+ > **In a drawer?** `FormBuilder` is drawer-unaware — it only displays inputs. To
225
+ > show a form in a drawer, wrap it in `FormDrawer` from
226
+ > [FormRenderer](./form-renderer.md) (pass `fieldDirection="vertical"` to the
227
+ > form), or use `FormRenderer` with `display="drawer"`.
228
+
229
+ ## Calculation panel
230
+
231
+ To show computed totals **beside** the form, render a [FormSummary](./form-summary.md)
232
+ next to it (not inside it) and share one hoisted form via the `form` prop:
233
+
234
+ ```tsx
235
+ const form = useForm({ resolver: r, defaultValues: d })
236
+
237
+ <div className="flex items-start gap-4">
238
+ <FormBuilder form={form} onSubmit={save} className="min-w-0 flex-1">…fields…</FormBuilder>
239
+ <FormSummary form={form} title="Invoice">…rows…</FormSummary>
240
+ </div>
241
+ ```
242
+
243
+ `form` makes FormBuilder use an existing react-hook-form instance instead of creating its
244
+ own — that's what lets something outside the form read the same live values.
245
+
246
+ ## Editing a record
247
+
248
+ Pass `values` (not just `defaultValues`); the form repopulates when the data loads. Use a
249
+ remount `key` so initial-only inputs (date, rich text) re-seed.
250
+
251
+ ```tsx
252
+ <FormBuilder key={entity.id} values={entity} onSubmit={save} resolver={r} defaultValues={d}>
253
+ …the same fields…
254
+ </FormBuilder>
255
+ ```
256
+
257
+ ## Validation
258
+
259
+ Resolver-agnostic — pass any react-hook-form `resolver` (`zodResolver`, a plain
260
+ resolver function, etc.). The library never depends on zod.
@@ -0,0 +1,234 @@
1
+ ---
2
+ title: FormRenderer
3
+ description: A thin wrapper around FormBuilder. Author fields as JSX children; FormRenderer owns page-vs-drawer display, the absolute title header, and drawer field layout. You compose the Save and pass it via the actions prop.
4
+ component: true
5
+ group: Forms
6
+ keywords: [form-renderer, form, drawer, header, display, actions, react-hook-form]
7
+ ---
8
+
9
+ # FormRenderer
10
+
11
+ A thin wrapper around the compound [FormBuilder](./form-builder.md). You author the
12
+ fields as **JSX children** exactly as you would with `FormBuilder`; `FormRenderer`
13
+ takes care of the surrounding concerns:
14
+
15
+ - **page vs drawer** display (`display="drawer"` hosts the form in a `FormDrawer`),
16
+ - the **absolute title header** + action bar (page display),
17
+ - **vertical field layout** inside a drawer.
18
+
19
+ FormRenderer never manufactures a Submit — **you compose the Save and hand it to `actions`**.
20
+ It renders in the form's header action pill (page) or the drawer header (drawer), and a bare
21
+ `<FormBuilder.Submit>` auto-targets this form (even though the header sits outside the `<form>`).
22
+
23
+ Reach for `FormBuilder` directly when you just want the form. Reach for
24
+ `FormRenderer` when you want the same form to render as a page _or_ a drawer with
25
+ the standard chrome.
26
+
27
+ ```tsx
28
+ <FormRenderer
29
+ onSubmit={save}
30
+ resolver={zodResolver(schema)}
31
+ defaultValues={d}
32
+ header={{ title: "Item", variant: "new" }}
33
+ actions={<FormBuilder.Submit>Save</FormBuilder.Submit>}
34
+ >
35
+ <FormBuilder.Section title="Identity" color="Blue">
36
+ <FormBuilder.Text name="name" label="Name" required />
37
+ <FormBuilder.Currency name="price" label="Price" currencySymbol="$" />
38
+ </FormBuilder.Section>
39
+ </FormRenderer>
40
+ ```
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ npx torch-glare@latest init
46
+ npx torch-glare@latest add FormRenderer
47
+ ```
48
+
49
+ `add` also pulls in `FormBuilder`, which FormRenderer renders through.
50
+
51
+ ## Imports
52
+
53
+ ```tsx
54
+ import { FormRenderer, FormDrawer } from "@/components/FormRenderer";
55
+ import { FormBuilder } from "@/components/FormBuilder";
56
+ ```
57
+
58
+ ## Props
59
+
60
+ | Prop | Type | Notes |
61
+ | -------------------------------------------------------------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | `children` | `ReactNode` | The form body — `FormBuilder.Section` / field / `FormBuilder.Stepper` JSX. |
63
+ | `onSubmit` / `onInvalid` | fns | Submit / validation-fail callbacks. |
64
+ | `resolver` | `Resolver` | Any react-hook-form resolver, e.g. `zodResolver(schema)`. |
65
+ | `defaultValues` / `values` | `DefaultValues` / `T` | Initial values; `values` re-syncs on change (edit). |
66
+ | `loading` / `resetOnSuccess` | `boolean` | Forwarded to `FormBuilder`. |
67
+ | `fieldDirection` | `'horizontal' \| 'vertical'` | Defaults to vertical inside a drawer. |
68
+ | `form` | `UseFormReturn<T>` | A hoisted `useForm` to bind to — pass when a sibling (e.g. a `summary` `FormSummary`) must read the same live values; the caller owns `resolver`/`defaultValues` on it. Omit to let FormRenderer create its own. |
69
+ | `display` | `'page' \| 'drawer'` | `'drawer'` wraps the form in `FormDrawer`. |
70
+ | `header` | `{ title; label?; variant? }` | Absolute title header + action bar (page display); `actions` render in it. |
71
+ | `summary` | `ReactNode` | A live panel (typically `FormSummary`) rendered beside the form (page) or in the drawer tray (drawer). Give the same hoisted `form` so it reads live values. On a page, a `summary` **plus** a `FormBuilder.Stepper` lays out as three columns — stepper nav · fields · summary. |
72
+ | `actions` | `ReactNode` | The form's action bar — rendered in the header action pill (page) or drawer header (drawer). Put the Save here: `actions={<FormBuilder.Submit>Save</FormBuilder.Submit>}`. A bare `FormBuilder.Submit` auto-targets this form. |
73
+ | `id` | `string` | `id` on the underlying `<form>`. Optional — FormRenderer generates and wires one otherwise. |
74
+ | `open` / `onOpenChange` / `title` / `badge` / `onOpenInNewTab` | — | Drawer control (when `display="drawer"`). `title` / `badge` are strings that override `header.title` / `header.label`. |
75
+
76
+ ## Drawer
77
+
78
+ ```tsx
79
+ // drawer — pass the Save via `actions`; it renders in the drawer header
80
+ <FormRenderer
81
+ display="drawer"
82
+ open={open}
83
+ onOpenChange={setOpen}
84
+ title="New item"
85
+ badge="New"
86
+ onSubmit={save}
87
+ resolver={r}
88
+ defaultValues={d}
89
+ actions={<FormBuilder.Submit>Save</FormBuilder.Submit>}
90
+ >
91
+ {fields}
92
+ </FormRenderer>
93
+ ```
94
+
95
+ ## Stepper
96
+
97
+ Drop a `FormBuilder.Stepper` in as the child. The Save lives in the header `actions` and
98
+ submits every step's registered fields at once (steps stay mounted, so the whole form is live).
99
+
100
+ For a stepper, FormRenderer **automatically prepends chevron Back/Next nav + a divider** before
101
+ your Submit, so the action bar reads `[◀] [▶] │ Save`. Back is disabled on the first step; Next
102
+ validates the current step, then advances (disabled on the last step). A step that passes
103
+ validation **stays checked** in the rail — even after you navigate back — while a live validation
104
+ error overrides it to red. You still pass just the Submit; the nav is wired for you:
105
+
106
+ ```tsx
107
+ <FormRenderer
108
+ onSubmit={save}
109
+ resolver={r}
110
+ defaultValues={d}
111
+ header={{ title: "New item", variant: "new" }}
112
+ actions={<FormBuilder.Submit>Save</FormBuilder.Submit>}
113
+ >
114
+ <FormBuilder.Stepper>
115
+ <FormBuilder.Step title="Basics">
116
+ <FormBuilder.Text name="name" label="Name" required />
117
+ </FormBuilder.Step>
118
+ </FormBuilder.Stepper>
119
+ </FormRenderer>
120
+ ```
121
+
122
+ ## Summary panel
123
+
124
+ Pass a hoisted `useForm` as `form` and a `FormSummary` as `summary` — FormRenderer binds
125
+ the form to that instance and lays the panel beside the form (page) or in the drawer tray
126
+ (drawer), so it recomputes live as fields change.
127
+
128
+ ```tsx
129
+ const form = useForm<Invoice>({ resolver, defaultValues })
130
+
131
+ <FormRenderer
132
+ form={form}
133
+ onSubmit={save}
134
+ header={{ title: 'Invoice', variant: 'new' }}
135
+ actions={<FormBuilder.Submit>Save invoice</FormBuilder.Submit>}
136
+ summary={
137
+ <FormSummary form={form} title="Invoice" subtitle="Summary">
138
+ <FormSummary.Group title="Total">
139
+ <FormSummary.Row label="Overall Total" emphasized compute={overallTotal} />
140
+ </FormSummary.Group>
141
+ </FormSummary>
142
+ }
143
+ >
144
+ {fields}
145
+ </FormRenderer>
146
+ ```
147
+
148
+ Works with `display="drawer"` too — the summary moves into the drawer's tray.
149
+
150
+ ## `FormDrawer` — the drawer wrapper
151
+
152
+ `FormRenderer` uses `FormDrawer` internally for `display: 'drawer'`. It's also exported
153
+ so you can put a hand-composed `FormBuilder` in a drawer directly. Since the header sits
154
+ outside the `<form>`, wire the Save button to the form via `id` / `form={id}`:
155
+
156
+ ```tsx
157
+ <FormDrawer
158
+ open={open}
159
+ onOpenChange={setOpen}
160
+ title="New item"
161
+ badge="New"
162
+ actions={
163
+ <Button type="submit" form="item-form" is_loading={saving}>
164
+ Save
165
+ </Button>
166
+ }
167
+ >
168
+ <FormBuilder
169
+ id="item-form"
170
+ onSubmit={save}
171
+ resolver={r}
172
+ defaultValues={d}
173
+ fieldDirection="vertical"
174
+ >
175
+ …fields…
176
+ </FormBuilder>
177
+ </FormDrawer>
178
+ ```
179
+
180
+ `FormDrawer` props: `open`, `onOpenChange`, `title`, `badge`, `variant`, `actions`,
181
+ `onOpenInNewTab`, `children`, `summary`. It owns no form state.
182
+
183
+ ### The title
184
+
185
+ The drawer renders the **same floating header as the page form** — a [HeaderBar](./header-bar.md)
186
+ title pill on the left, a dark action pill on the right — so a form's title looks identical in
187
+ either display. `title` is the plain (uppercased) text, `badge` the colored emphasis pill, and
188
+ `variant` (`new` / `edit` / `detail`) picks the badge colors; `badge` defaults from it
189
+ (New / Edit / View).
190
+
191
+ ```tsx
192
+ <FormDrawer title="Sales Invoice" badge="New" variant="new" … />
193
+ ```
194
+
195
+ Driving it through `FormRenderer`, the `header` prop feeds both displays — including
196
+ `header.variant`, which the drawer previously ignored:
197
+
198
+ ```tsx
199
+ <FormRenderer display="drawer" header={{ title: "Sales Invoice", variant: "edit" }} … />
200
+ ```
201
+
202
+ `title` and `badge` are **plain strings** (they were `ReactNode` before this shared-header
203
+ change) because they render through `HeaderBar`'s uppercase text treatment.
204
+
205
+ ### A summary beside the form
206
+
207
+ `summary` renders a conclusion panel — typically a [FormSummary](./form-summary.md) — _beside_
208
+ the form rather than inside its scrollable body. `FormDrawer` puts the form in a
209
+ [`DrawerPanel`](./drawer.md#drawerpanel) (the light surface) and the summary next to it with a
210
+ 6px gutter; the tray paints nothing, so the summary keeps its own dark background and full
211
+ height, scrolling internally when it outruns the drawer.
212
+
213
+ Hoist the form so both read the same instance:
214
+
215
+ ```tsx
216
+ const form = useForm({ resolver, defaultValues })
217
+
218
+ <FormDrawer
219
+ open={open} onOpenChange={setOpen} title="New item" badge="New"
220
+ summary={
221
+ <FormSummary form={form} title="Item" subtitle="Summary">
222
+ <FormSummary.Group title="Pricing">…rows…</FormSummary.Group>
223
+ </FormSummary>
224
+ }
225
+ >
226
+ <FormBuilder form={form} id="item-form" onSubmit={save} fieldDirection="vertical">
227
+ …fields…
228
+ </FormBuilder>
229
+ </FormDrawer>
230
+ ```
231
+
232
+ > `childrenOutside` is the deprecated former name for `summary`. It still works.
233
+
234
+ `FormRenderer` does **not** forward `summary` — use `FormDrawer` directly when you need one.
@@ -0,0 +1,123 @@
1
+ ---
2
+ title: FormSummary
3
+ description: A read-only calculation panel displayed beside a form. Each row declares a compute(values) that runs against the live form values, so totals recalculate as the user types.
4
+ component: true
5
+ group: Forms
6
+ keywords: [form-summary, summary, totals, calculation, invoice, panel, react-hook-form, useWatch]
7
+ ---
8
+
9
+ # FormSummary
10
+
11
+ A read-only **calculation panel** that sits **beside a form** — the invoice-summary
12
+ look: grouped rows of computed totals, right-aligned, in Glare's dark `SystemStyle`
13
+ fields.
14
+
15
+ Each `FormSummary.Row` declares a **`compute(values)`** that runs against the **live**
16
+ form values, so every total recalculates as the user types.
17
+
18
+ The panel renders **outside** the form, beside it. Both read the same form, so
19
+ **hoist `useForm`** and hand the instance to each:
20
+
21
+ ```tsx
22
+ const form = useForm({ resolver: zodResolver(schema), defaultValues })
23
+
24
+ <div className="flex gap-4">
25
+ <FormBuilder form={form} onSubmit={save} className="min-w-0 flex-1">
26
+ <FormBuilder.Section title="Line items">…fields…</FormBuilder.Section>
27
+ </FormBuilder>
28
+
29
+ <FormSummary form={form} title="Invoice" subtitle="Summary">
30
+ <FormSummary.Group title="Total">
31
+ <FormSummary.Row label="Total Discount" compute={totalDiscount} />
32
+ <FormSummary.Row label="Overall Total" emphasized compute={overallTotal} />
33
+ <FormSummary.Row label="Overall Total" currency="IQD" tone="success"
34
+ compute={v => overallTotal(v) * v.iqdRate} decimals={0} />
35
+ <FormSummary.Row label="Overall Total" currency="USD" tone="info" compute={overallTotal} />
36
+ </FormSummary.Group>
37
+ </FormSummary>
38
+ </div>
39
+ ```
40
+
41
+ `FormBuilder` stays purely an input renderer — it knows nothing about the panel, and
42
+ **you** own the side-by-side layout. Passing `form` to `FormBuilder` makes it use that
43
+ instance instead of creating its own.
44
+
45
+ ### Height
46
+
47
+ The panel is `h-full` and fills whatever height its parent gives it, scrolling its groups
48
+ (header pinned) once they outrun it. That means **the parent has to have a height** — the
49
+ usual mistake is `items-start` on the flex row, which collapses the panel to its content
50
+ instead. Leave the row at its default `items-stretch`, as above.
51
+
52
+ To make the panel own the viewport rather than grow with the form, bound the row:
53
+
54
+ ```tsx
55
+ <div className="flex h-[calc(100vh-2rem)] gap-4">
56
+ <FormBuilder … className="min-w-0 flex-1 overflow-y-auto" />
57
+ <FormSummary … />
58
+ </div>
59
+ ```
60
+
61
+ > Hoisting the form means a remount `key` no longer resets it. Call `form.reset(defaults)`
62
+ > instead (e.g. when opening a drawer).
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ npx torch-glare@latest init
68
+ npx torch-glare@latest add FormSummary
69
+ ```
70
+
71
+ ## Imports
72
+
73
+ ```tsx
74
+ import { FormSummary } from '@/components/FormSummary'
75
+ ```
76
+
77
+ ## `FormSummary` props
78
+
79
+ | Prop | Type | Notes |
80
+ |---|---|---|
81
+ | `title` | `ReactNode` | Panel title, e.g. `"Invoice"`. |
82
+ | `subtitle` | `ReactNode` | Muted text beside the title, e.g. `"Summary"`. |
83
+ | `form` | `UseFormReturn` | The form to read values from — required when rendered outside the `<FormBuilder>`. |
84
+ | `width` | `number \| string` | Panel width; default `228`. |
85
+ | `children` | `ReactNode` | `FormSummary.Group` children. |
86
+
87
+ ## `FormSummary.Group` props
88
+
89
+ | Prop | Type | Notes |
90
+ |---|---|---|
91
+ | `title` | `ReactNode` | The group heading (Customer / Total / Tax / …). Groups are separated by a divider. |
92
+ | `collapsible` | `boolean` | When titled, the heading is a [ConclusionHeader](./conclusion-header.md) that opens/closes **this group's** rows; default `true`. |
93
+ | `defaultOpen` | `boolean` | Initial open state when collapsible; default `true`. |
94
+
95
+ The main panel title is a plain header — collapsing happens **per group**, not on the whole panel.
96
+
97
+ ## `FormSummary.Row` props
98
+
99
+ | Prop | Type | Notes |
100
+ |---|---|---|
101
+ | `label` | `ReactNode` | Row label, above the value. |
102
+ | `compute` | `(values) => number \| string` | **The calculation** — receives the live form values. |
103
+ | `value` | `number \| string` | Static value, when there's nothing to compute. |
104
+ | `currency` | `ReactNode` | Currency code, e.g. `"IQD"` — rendered **inside** the field's trailing edge. |
105
+ | `tone` | `'neutral' \| 'success' \| 'info'` | Color of the currency code (green / blue). |
106
+ | `emphasized` | `boolean` | The primary result — lighter, emphasized border. |
107
+ | `decimals` | `number` | Decimal places; default `2` (→ `0.00`). |
108
+ | `action` | `ReactNode` | Trailing slot inside the field, e.g. an `ActionButton`. Shares the slot with `currency`. |
109
+ | `format` | `(value) => string` | Override the default number formatting. |
110
+
111
+ ## Computing totals
112
+
113
+ `compute` is a plain function of the form values — keep the maths outside the JSX:
114
+
115
+ ```tsx
116
+ const subTotal = v => v.items.reduce((s, i) => s + i.qty * i.price, 0)
117
+ const totalDiscount = v => v.items.reduce((s, i) => s + i.discount, 0)
118
+ const taxable = v => Math.max(0, subTotal(v) - totalDiscount(v))
119
+ const totalTax = v => taxable(v) * (v.taxRate / 100)
120
+ const overallTotal = v => taxable(v) + totalTax(v)
121
+ ```
122
+
123
+ The panel is **read-only** — it contributes nothing to the submitted values.
@@ -875,10 +875,16 @@ describe('AttachmentImagePreview', () => {
875
875
 
876
876
  ### Default Styling
877
877
 
878
- - Drop Zone: 200px min-width, 65px height, dashed border
879
- - Preview: 180px max-width, 65px height, rounded corners
880
- - Active State: Background and border color change
881
- - Hover: Expand button overlay with icon
878
+ Matches the *Attachment-Field-1.0 / Pic-Container-1.0* design:
879
+
880
+ - **Field box** (`ImageAttachment`): a `#f9f9f9` (`background-presentation-form-field-primary`)
881
+ rounded container holding an optional preview and the drop zone, `gap-[10px]`.
882
+ - **Drop zone**: fills the box (`flex-1`), 65px tall, transparent with a dashed
883
+ `border-presentation-action-borderstyle` border; drag-active tints it gray.
884
+ - **Preview thumbnail** (`ExpandableImage`): a fixed **65×65** square, `object-cover`, rounded.
885
+ - **Placeholder** (no image): ocean fill (`badge-ocean-subtle`) + dashed `blue-purple-300`
886
+ border + paperclip icon; on hover it goes gray (`badge-gray-subtle` / `badge-gray`).
887
+ - **Hover (has image)**: a `black/50` overlay with a fullscreen icon + the `expandLabel`.
882
888
 
883
889
  ## Best Practices
884
890