@whity/ui 0.0.0-stage → 0.5.0

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 (169) hide show
  1. package/README.md +107 -3
  2. package/package.json +192 -6
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +302 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +500 -0
  16. package/src/approval-queue.tsx +108 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar.tsx +83 -0
  22. package/src/badge.stories.tsx +105 -0
  23. package/src/badge.tsx +68 -0
  24. package/src/beta-warning.stories.tsx +79 -0
  25. package/src/beta-warning.tsx +189 -0
  26. package/src/bilingual-input.stories.tsx +82 -0
  27. package/src/bilingual-input.tsx +183 -0
  28. package/src/breadcrumb.stories.tsx +51 -0
  29. package/src/breadcrumb.tsx +90 -0
  30. package/src/button.stories.tsx +87 -0
  31. package/src/button.tsx +118 -0
  32. package/src/card.stories.tsx +423 -0
  33. package/src/card.tsx +180 -0
  34. package/src/chart.stories.tsx +66 -0
  35. package/src/chart.tsx +228 -0
  36. package/src/checkbox.stories.tsx +62 -0
  37. package/src/checkbox.tsx +54 -0
  38. package/src/collapsible.stories.tsx +48 -0
  39. package/src/collapsible.tsx +34 -0
  40. package/src/color-card.stories.tsx +61 -0
  41. package/src/color-card.tsx +270 -0
  42. package/src/color-picker.stories.tsx +65 -0
  43. package/src/color-picker.tsx +425 -0
  44. package/src/command-palette.tsx +306 -0
  45. package/src/copy-block.stories.tsx +38 -0
  46. package/src/copy-block.tsx +85 -0
  47. package/src/data-table.stories.tsx +200 -0
  48. package/src/data-table.tsx +1106 -0
  49. package/src/date-picker.stories.tsx +61 -0
  50. package/src/date-picker.tsx +422 -0
  51. package/src/design-cards.stories.tsx +458 -0
  52. package/src/dialog.stories.tsx +48 -0
  53. package/src/dialog.tsx +166 -0
  54. package/src/documents/barcode-svg.stories.tsx +72 -0
  55. package/src/documents/barcode-svg.tsx +79 -0
  56. package/src/dropdown-menu.stories.tsx +77 -0
  57. package/src/dropdown-menu.tsx +271 -0
  58. package/src/editor/behaviour.ts +279 -0
  59. package/src/editor/block-ids.ts +44 -0
  60. package/src/editor/block-list.tsx +101 -0
  61. package/src/editor/block-toolbar.tsx +477 -0
  62. package/src/editor/bubble.tsx +93 -0
  63. package/src/editor/catalogue.ts +103 -0
  64. package/src/editor/collab-rail.tsx +746 -0
  65. package/src/editor/collab.stories.tsx +207 -0
  66. package/src/editor/collab.ts +87 -0
  67. package/src/editor/contract.ts +408 -0
  68. package/src/editor/convert.ts +362 -0
  69. package/src/editor/doc-editor.stories.tsx +98 -0
  70. package/src/editor/doc-editor.tsx +1287 -0
  71. package/src/editor/editor.css +536 -0
  72. package/src/editor/extensions.ts +86 -0
  73. package/src/editor/field-picker.tsx +107 -0
  74. package/src/editor/fields.ts +100 -0
  75. package/src/editor/gutter.tsx +367 -0
  76. package/src/editor/index.ts +22 -0
  77. package/src/editor/label-sheet.tsx +289 -0
  78. package/src/editor/labels.ts +310 -0
  79. package/src/editor/link-tools.tsx +141 -0
  80. package/src/editor/node-views.tsx +450 -0
  81. package/src/editor/page-view.tsx +353 -0
  82. package/src/editor/publish-check.tsx +182 -0
  83. package/src/editor/rich-blocks.stories.tsx +146 -0
  84. package/src/editor/sample.ts +40 -0
  85. package/src/editor/schema-rich.ts +150 -0
  86. package/src/editor/schema.ts +315 -0
  87. package/src/editor/services.tsx +127 -0
  88. package/src/editor/slash.ts +64 -0
  89. package/src/editor/suggesting.ts +372 -0
  90. package/src/editor/suggestions.ts +763 -0
  91. package/src/editor/table-keys.ts +66 -0
  92. package/src/editor/templates.stories.tsx +324 -0
  93. package/src/editor/toolbar.tsx +358 -0
  94. package/src/empty-state.stories.tsx +51 -0
  95. package/src/empty-state.tsx +100 -0
  96. package/src/empty-state.usage-notes.md +30 -0
  97. package/src/form.stories.tsx +112 -0
  98. package/src/form.tsx +176 -0
  99. package/src/globals.css +20 -0
  100. package/src/icon-button.tsx +85 -0
  101. package/src/icon-map.ts +244 -0
  102. package/src/icon.tsx +41 -0
  103. package/src/index.ts +67 -0
  104. package/src/input.stories.tsx +157 -0
  105. package/src/input.tsx +759 -0
  106. package/src/locked-screen.stories.tsx +29 -0
  107. package/src/locked-screen.tsx +61 -0
  108. package/src/mark.tsx +62 -0
  109. package/src/math-text.stories.tsx +33 -0
  110. package/src/math-text.tsx +43 -0
  111. package/src/menu-bar.stories.tsx +198 -0
  112. package/src/menu-bar.tsx +373 -0
  113. package/src/money/currency.ts +230 -0
  114. package/src/page-header.stories.tsx +95 -0
  115. package/src/page-header.tsx +122 -0
  116. package/src/page-shell.stories.tsx +42 -0
  117. package/src/page-shell.tsx +32 -0
  118. package/src/pagination.stories.tsx +45 -0
  119. package/src/pagination.tsx +98 -0
  120. package/src/plugin-card.stories.tsx +180 -0
  121. package/src/plugin-card.tsx +848 -0
  122. package/src/popover.stories.tsx +48 -0
  123. package/src/popover.tsx +55 -0
  124. package/src/radio-group.stories.tsx +26 -0
  125. package/src/radio-group.tsx +44 -0
  126. package/src/route-flow/editor.tsx +1014 -0
  127. package/src/route-flow/model.ts +716 -0
  128. package/src/scope-grant.tsx +139 -0
  129. package/src/screen-too-small.stories.tsx +61 -0
  130. package/src/screen-too-small.tsx +104 -0
  131. package/src/select.stories.tsx +44 -0
  132. package/src/select.tsx +197 -0
  133. package/src/separator.stories.tsx +34 -0
  134. package/src/separator.tsx +34 -0
  135. package/src/sheet.stories.tsx +49 -0
  136. package/src/sheet.tsx +168 -0
  137. package/src/skeleton.stories.tsx +28 -0
  138. package/src/skeleton.tsx +19 -0
  139. package/src/slider.stories.tsx +78 -0
  140. package/src/slider.tsx +300 -0
  141. package/src/spinner.stories.tsx +33 -0
  142. package/src/spinner.tsx +55 -0
  143. package/src/switch.stories.tsx +42 -0
  144. package/src/switch.tsx +41 -0
  145. package/src/switcher.stories.tsx +111 -0
  146. package/src/switcher.tsx +131 -0
  147. package/src/table.stories.tsx +48 -0
  148. package/src/table.tsx +121 -0
  149. package/src/tabs.stories.tsx +74 -0
  150. package/src/tabs.tsx +90 -0
  151. package/src/tag-input.stories.tsx +67 -0
  152. package/src/tag-input.tsx +117 -0
  153. package/src/tenant-logo.tsx +63 -0
  154. package/src/tenant-switcher.stories.tsx +38 -0
  155. package/src/tenant-switcher.tsx +164 -0
  156. package/src/textarea.stories.tsx +27 -0
  157. package/src/textarea.tsx +18 -0
  158. package/src/theme-mode.ts +52 -0
  159. package/src/time-picker.stories.tsx +62 -0
  160. package/src/time-picker.tsx +615 -0
  161. package/src/toggle-group.tsx +138 -0
  162. package/src/tooltip.stories.tsx +43 -0
  163. package/src/tooltip.tsx +73 -0
  164. package/src/top-nav.stories.tsx +58 -0
  165. package/src/top-nav.tsx +324 -0
  166. package/src/undo-bar.tsx +107 -0
  167. package/src/utils.ts +45 -0
  168. package/src/view-toggle.stories.tsx +84 -0
  169. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,66 @@
1
+ import { Extension } from "@tiptap/core"
2
+ import type { Node as PmNode } from "@tiptap/pm/model"
3
+ import type { EditorState } from "@tiptap/pm/state"
4
+ import { TextSelection } from "@tiptap/pm/state"
5
+
6
+ /** The cell the caret is in: its table, row and column. */
7
+ function cellAt(state: EditorState) {
8
+ const { $from } = state.selection
9
+ for (let d = $from.depth; d > 2; d--) {
10
+ if ($from.node(d).type.name !== "tableCell") continue
11
+ return { table: $from.node(d - 2), tablePos: $from.before(d - 2), row: $from.index(d - 2), col: $from.index(d - 1) }
12
+ }
13
+ return null
14
+ }
15
+
16
+ /** Position just inside cell (row, col) of the table at tablePos. */
17
+ function cellStart(doc: PmNode, tablePos: number, row: number, col: number) {
18
+ const table = doc.nodeAt(tablePos)
19
+ if (!table) return null
20
+ let pos = tablePos + 1
21
+ for (let r = 0; r < row; r++) pos += table.child(r).nodeSize
22
+ pos += 1
23
+ const tr = table.child(row)
24
+ for (let c = 0; c < col; c++) pos += tr.child(c).nodeSize
25
+ return pos + 1
26
+ }
27
+
28
+ /**
29
+ * Tab and Shift-Tab move between table cells (E.8); Tab on the last cell adds
30
+ * a row. Outside a table they fall through to the list indent keys.
31
+ */
32
+ export const TableKeys = Extension.create({
33
+ name: "tableKeys",
34
+ priority: 200,
35
+ addKeyboardShortcuts() {
36
+ const move = (dir: 1 | -1) => () => {
37
+ const { state, view } = this.editor
38
+ const at = cellAt(state)
39
+ if (!at) return false
40
+ const width = at.table.child(at.row).childCount
41
+ let row = at.row
42
+ let col = at.col + dir
43
+ if (col >= width) {
44
+ row += 1
45
+ col = 0
46
+ } else if (col < 0) {
47
+ row -= 1
48
+ col = row >= 0 ? at.table.child(row).childCount - 1 : 0
49
+ }
50
+ if (row < 0) return true
51
+ let tr = state.tr
52
+ if (row >= at.table.childCount) {
53
+ const { tableRow, tableCell } = state.schema.nodes
54
+ const blank = tableRow.create(null, Array.from({ length: width }, () => tableCell.create()))
55
+ tr = tr.insert(at.tablePos + at.table.nodeSize - 1, blank)
56
+ }
57
+ const pos = cellStart(tr.doc, at.tablePos, row, col)
58
+ if (pos === null) return true
59
+ const cell = tr.doc.nodeAt(pos - 1)
60
+ tr.setSelection(TextSelection.create(tr.doc, pos, pos + (cell?.content.size ?? 0)))
61
+ view.dispatch(tr.scrollIntoView())
62
+ return true
63
+ }
64
+ return { Tab: move(1), "Shift-Tab": move(-1) }
65
+ },
66
+ })
@@ -0,0 +1,324 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import * as React from "react"
3
+
4
+ import type { Block, FieldRef, PublishBlocker, ResolvedThemeTokens, WhityDocument } from "./contract"
5
+ import { DocEditor } from "./doc-editor"
6
+ import type { FieldGroup } from "./fields"
7
+ import { themedLetterhead, type Letterhead } from "./page-view"
8
+ import { SAMPLE_DOCUMENT } from "./sample"
9
+ import type { FieldPreview } from "./services"
10
+
11
+ const meta = {
12
+ title: "Editor/Templates",
13
+ parameters: { layout: "fullscreen", fullBleed: true },
14
+ } satisfies Meta
15
+
16
+ export default meta
17
+ type Story = StoryObj<typeof meta>
18
+
19
+ const t = (text: string) => ({ type: "text" as const, text })
20
+ const f = (path: string, label: string, required?: boolean): FieldRef => ({ type: "field", path, label, ...(required ? { required } : {}) })
21
+ const wait = <T,>(value: T, ms = 500) => new Promise<T>((done) => setTimeout(() => done(value), ms))
22
+
23
+ /** What an invoice template's record type offers (EditorInline). */
24
+ const FIELDS: FieldGroup[] = [
25
+ {
26
+ group: "Customer",
27
+ items: [
28
+ { path: "customer.name", label: "Customer name", sample: "Example Clinic" },
29
+ { path: "customer.tax_number", label: "Customer tax number", sample: "0987654" },
30
+ ],
31
+ },
32
+ {
33
+ group: "Invoice",
34
+ items: [
35
+ { path: "invoice.number", label: "Invoice number", sample: "INV-1042", required: true },
36
+ { path: "invoice.total", label: "Invoice total", sample: "JOD 301.600", required: true },
37
+ { path: "invoice.due_date", label: "Due date", sample: "14 Oct 2026" },
38
+ { path: "invoice.days_overdue", label: "Days overdue", sample: "15" },
39
+ ],
40
+ },
41
+ {
42
+ group: "Company",
43
+ items: [
44
+ { path: "company.name", label: "Company name", sample: "Example Bakery" },
45
+ { path: "company.iban", label: "Company IBAN", sample: "JO94 CBJO 0010 0000 0000 0131 0003 02" },
46
+ { path: "sender.name", label: "Sender name", sample: "Rana Haddad" },
47
+ ],
48
+ },
49
+ { group: "Today", items: [{ path: "today", label: "Today", sample: "29 October 2026" }] },
50
+ ]
51
+
52
+ const LETTERHEAD: Letterhead = {
53
+ name: "Example Bakery",
54
+ lines: ["Mecca Street 112, Amman · Tax no. 0123456", "+962 6 555 0100 · accounts@bakery.example.jo"],
55
+ }
56
+
57
+ const BLOCKS: Block[] = [
58
+ { id: "t1", type: "paragraph", content: [t("Dear "), f("customer.name", "Customer name"), t(",")] },
59
+ {
60
+ id: "t2",
61
+ type: "paragraph",
62
+ content: [
63
+ t("Invoice "),
64
+ f("invoice.number", "Invoice number", true),
65
+ t(" for "),
66
+ f("invoice.total", "Invoice total", true),
67
+ t(" was due on "),
68
+ f("invoice.due_date", "Due date"),
69
+ t(". Please pay within 14 days of this letter."),
70
+ ],
71
+ },
72
+ {
73
+ id: "t3",
74
+ type: "callout",
75
+ kind: "note",
76
+ content: [
77
+ t("Pay by bank transfer to "),
78
+ { type: "text", text: "Example Bank", marks: [{ type: "bold" }] },
79
+ t(", IBAN "),
80
+ f("company.iban", "Company IBAN"),
81
+ t(", with the invoice number as the reference."),
82
+ ],
83
+ },
84
+ { id: "t4", type: "heading", level: 2, content: [t("Open invoices")] },
85
+ {
86
+ id: "t5",
87
+ type: "table",
88
+ headerRow: true,
89
+ columns: [{ align: "start" }, { align: "start" }, { align: "end" }],
90
+ rows: [
91
+ [[t("Invoice")], [t("Due")], [t("Amount")]],
92
+ [[t("INV-1042")], [t("14 Oct 2026")], [t("JOD 301.600")]],
93
+ [[t("INV-1051")], [t("21 Oct 2026")], [t("JOD 96.000")]],
94
+ ],
95
+ },
96
+ { id: "t6", type: "paragraph", content: [t("Customer tax number: "), f("customer.tax_number", "Customer tax number")] },
97
+ { id: "t7", type: "paragraph", content: [t("Kind regards,")] },
98
+ { id: "t8", type: "paragraph", content: [f("sender.name", "Sender name"), { type: "break" }, f("company.name", "Company name")] },
99
+ ]
100
+
101
+ /** INV-1042's values; Example Clinic has no tax number on file (E.27). */
102
+ const PREVIEW: FieldPreview = {
103
+ label: "INV-1042 · Example Clinic",
104
+ values: {
105
+ "customer.name": "Example Clinic",
106
+ "customer.tax_number": null,
107
+ "invoice.number": "INV-1042",
108
+ "invoice.total": "JOD 301.600",
109
+ "invoice.due_date": "14 Oct 2026",
110
+ "invoice.days_overdue": "15",
111
+ "company.name": "Example Bakery",
112
+ "company.iban": "JO94 CBJO 0010 0000 0000 0131 0003 02",
113
+ "sender.name": "Rana Haddad",
114
+ today: "29 October 2026",
115
+ },
116
+ }
117
+
118
+ const TEMPLATE: WhityDocument = {
119
+ ...SAMPLE_DOCUMENT,
120
+ id: "tpl-payment-reminder",
121
+ kind: "template",
122
+ title: "Payment reminder",
123
+ defaultView: "page",
124
+ recordType: "invoice",
125
+ page: { size: "A4", marginMm: 16, letterhead: true },
126
+ status: "draft",
127
+ publishedVersion: 3,
128
+ blocks: BLOCKS,
129
+ }
130
+
131
+ function Live({
132
+ initial,
133
+ blockers = [],
134
+ startPreview = false,
135
+ theme = null,
136
+ letterhead = LETTERHEAD,
137
+ }: {
138
+ initial: WhityDocument
139
+ blockers?: PublishBlocker[]
140
+ startPreview?: boolean
141
+ theme?: ResolvedThemeTokens | null
142
+ letterhead?: Letterhead
143
+ }) {
144
+ const [doc, setDoc] = React.useState(initial)
145
+ const [preview, setPreview] = React.useState<FieldPreview | null>(startPreview ? PREVIEW : null)
146
+ const [version, setVersion] = React.useState<number | null>(initial.publishedVersion ?? null)
147
+ return (
148
+ <div style={{ height: "100vh" }}>
149
+ <DocEditor
150
+ document={doc}
151
+ onChange={setDoc}
152
+ canEdit
153
+ back={{ label: "Back to templates", onClick: () => {} }}
154
+ path="Templates · Letters"
155
+ save={{ state: "saved", at: "14:02" }}
156
+ fields={FIELDS}
157
+ letterhead={letterhead}
158
+ theme={theme}
159
+ pageFields={{ reference: FIELDS[1].items[0], date: FIELDS[3].items[0] }}
160
+ preview={preview}
161
+ onPreview={() => setPreview(PREVIEW)}
162
+ onClosePreview={() => setPreview(null)}
163
+ onExportPdf={() => wait(undefined)}
164
+ publish={{
165
+ publishedVersion: version,
166
+ recordLabel: "payment reminder",
167
+ check: () => wait(blockers),
168
+ publish: () => wait(undefined).then(() => setVersion((v) => (v ?? 0) + 1)),
169
+ }}
170
+ />
171
+ </div>
172
+ )
173
+ }
174
+
175
+ /** A33: the template in the page view, with fields as chips. Type {{ or use Field ▾. */
176
+ export const Designer: Story = { render: () => <Live initial={TEMPLATE} /> }
177
+
178
+ /** E.12: the pages as they will print with INV-1042, read-only, a missing value flagged. */
179
+ export const PreviewWithRecord: Story = { render: () => <Live initial={TEMPLATE} startPreview /> }
180
+
181
+ /** E.37: Publish opens the check; it stays disabled while anything blocks it. */
182
+ export const PublishBlocked: Story = {
183
+ render: () => (
184
+ <Live
185
+ initial={TEMPLATE}
186
+ blockers={[
187
+ { kind: "open-suggestions", count: 2 },
188
+ { kind: "unknown-field", path: "customer.vat" },
189
+ { kind: "theme-unavailable", ref: "tenant.autumn" },
190
+ ]}
191
+ />
192
+ ),
193
+ }
194
+
195
+ /**
196
+ * E.44 and E.45: a workspace theme as the server resolves it, with the print
197
+ * colour on the title and H1-H3, the phone and address lines in that order,
198
+ * and no logo (the name alone).
199
+ */
200
+ const THEME: ResolvedThemeTokens = {
201
+ accent: "#8A3D12",
202
+ accentOnDark: "#E7A27A",
203
+ accentUse: "title-and-headings",
204
+ letterhead: { logo: "none", lines: ["phone", "address"] },
205
+ }
206
+
207
+ export const Themed: Story = {
208
+ render: () => (
209
+ <Live
210
+ initial={TEMPLATE}
211
+ theme={THEME}
212
+ letterhead={themedLetterhead(
213
+ LETTERHEAD,
214
+ THEME,
215
+ { address: "Mecca Street 112, Amman", taxId: "Tax no. 0123456", phone: "+962 6 555 0101", email: null },
216
+ { wide: null, square: null }
217
+ )}
218
+ />
219
+ ),
220
+ }
221
+
222
+ /** E.11: the continuous sheet follows the app theme; in dark mode its title takes `accentOnDark`. */
223
+ export const ThemedContinuous: Story = {
224
+ render: () => <Live initial={{ ...TEMPLATE, defaultView: "continuous" }} theme={THEME} />,
225
+ }
226
+
227
+ /** Long enough for the running header, a page break and "Page x of y". */
228
+ export const TwoPages: Story = {
229
+ render: () => (
230
+ <Live
231
+ initial={{
232
+ ...TEMPLATE,
233
+ blocks: [
234
+ ...BLOCKS,
235
+ { id: "pb", type: "pageBreak" },
236
+ { id: "n1", type: "heading", level: 2, content: [t("Terms")] },
237
+ ...Array.from({ length: 6 }, (_, i): Block => ({
238
+ id: `n${i + 2}`,
239
+ type: "paragraph",
240
+ content: [t("Payments are due within 30 days of the invoice date. Late payments may be charged a fee as agreed in the contract, and goods stay ours until paid in full.")],
241
+ })),
242
+ ],
243
+ }}
244
+ />
245
+ ),
246
+ }
247
+
248
+ export const Arabic: Story = {
249
+ globals: { direction: "rtl" },
250
+ render: () => <Live initial={{ ...TEMPLATE, lang: "ar", title: "تذكير بالدفع" }} />,
251
+ }
252
+
253
+ const LABELS: WhityDocument = {
254
+ ...SAMPLE_DOCUMENT,
255
+ id: "tpl-shipping-labels",
256
+ kind: "label",
257
+ title: "Shipping labels",
258
+ defaultView: "page",
259
+ page: { size: "A4", marginMm: 16, letterhead: false },
260
+ labels: { columns: 2, rows: 4, size: { widthMm: 99.1, heightMm: 67.7 }, gapMm: 2.5, gapYMm: 0 },
261
+ ownFields: [
262
+ { key: "ship_to", label: "Ship to", sample: "Example Clinic" },
263
+ { key: "address", label: "Address", sample: "Rainbow Street 21, Amman" },
264
+ { key: "tracking", label: "Tracking number", sample: "TRK000123456" },
265
+ ],
266
+ status: "draft",
267
+ blocks: [
268
+ { id: "l1", type: "paragraph", content: [t("From "), f("company.name", "Company name")] },
269
+ {
270
+ id: "l2",
271
+ type: "paragraph",
272
+ content: [{ ...f("template.ship_to", "Ship to"), marks: [{ type: "bold" }] }, { type: "break" }, f("template.address", "Address")],
273
+ },
274
+ { id: "l3", type: "barcode", symbology: "code128", value: [f("template.tracking", "Tracking number")], showText: true, heightMm: 12 },
275
+ ],
276
+ }
277
+
278
+ /**
279
+ * E.43: a label sheet. The first label is edited and the others repeat it;
280
+ * the stock is set beside the zoom; Print labels replaces PDF. Ship to,
281
+ * Address and Tracking number are the template's own fields (Field ▾ → This template).
282
+ */
283
+ export const LabelSheet: Story = { render: () => <LabelLive initial={LABELS} /> }
284
+
285
+ function LabelLive({ initial }: { initial: WhityDocument }) {
286
+ const [doc, setDoc] = React.useState(initial)
287
+ return (
288
+ <div style={{ height: "100vh" }}>
289
+ <DocEditor
290
+ document={doc}
291
+ onChange={setDoc}
292
+ canEdit
293
+ back={{ label: "Back to templates", onClick: () => {} }}
294
+ path="Templates · Labels"
295
+ save={{ state: "saved", at: "14:02" }}
296
+ fields={[FIELDS[2]]}
297
+ onPrintLabels={() => {}}
298
+ publish={{ publishedVersion: null, check: () => wait([]), publish: () => wait(undefined) }}
299
+ />
300
+ </div>
301
+ )
302
+ }
303
+
304
+ /** A label whose content runs past its edge is flagged; on paper it would be cut. */
305
+ export const LabelOverflow: Story = {
306
+ render: () => (
307
+ <div style={{ height: "100vh" }}>
308
+ <DocEditor
309
+ document={{
310
+ ...LABELS,
311
+ labels: { columns: 3, rows: 8, size: { widthMm: 63.5, heightMm: 33.9 }, gapMm: 2.5, gapYMm: 0 },
312
+ blocks: [
313
+ ...LABELS.blocks,
314
+ { id: "l4", type: "paragraph", content: [t("Handle with care. Keep upright and away from heat.")] },
315
+ ],
316
+ }}
317
+ onChange={() => {}}
318
+ canEdit
319
+ fields={[FIELDS[2]]}
320
+ onPrintLabels={() => {}}
321
+ />
322
+ </div>
323
+ ),
324
+ }