@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,358 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import type { Editor } from "@tiptap/core"
5
+ import { useEditorState } from "@tiptap/react"
6
+
7
+ import {
8
+ DropdownMenu,
9
+ DropdownMenuContent,
10
+ DropdownMenuItem,
11
+ DropdownMenuShortcut,
12
+ DropdownMenuTrigger,
13
+ } from "../dropdown-menu"
14
+ import { Icon } from "../icon"
15
+ import { IconButton } from "../icon-button"
16
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover"
17
+ import { ToggleGroup } from "../toggle-group"
18
+ import { cn } from "../utils"
19
+ import { CATALOGUE, applyItem, currentItem } from "./catalogue"
20
+ import { turnInto } from "./behaviour"
21
+ import { FieldPicker, flatFields } from "./field-picker"
22
+ import { filterFields, type FieldDef, type FieldGroup } from "./fields"
23
+ import { fill, type EditorLabels } from "./labels"
24
+
25
+ /** E.7: the page view's zoom steps; "fit" fits the page to the canvas width. */
26
+ export type PageZoom = "fit" | 50 | 75 | 100 | 125
27
+ export const ZOOM_STEPS: PageZoom[] = ["fit", 50, 75, 100, 125]
28
+ export type EditorView = "continuous" | "page"
29
+
30
+ /** Inserts a merge field at the caret as one character, followed by a space. */
31
+ export function insertField(editor: Editor, field: FieldDef) {
32
+ editor
33
+ .chain()
34
+ .focus()
35
+ .insertContent([
36
+ { type: "field", attrs: { path: field.path, label: field.label, required: field.required ? true : null } },
37
+ { type: "text", text: " " },
38
+ ])
39
+ .run()
40
+ }
41
+
42
+ const STYLE_IDS = ["text", "h1", "h2", "h3"]
43
+ const STYLE_SHORTCUTS: Record<string, string> = { text: "⌘⌥0", h1: "⌘⌥1", h2: "⌘⌥2", h3: "⌘⌥3" }
44
+
45
+ function Sep() {
46
+ return <span aria-hidden="true" className="mx-1.5 h-5 w-px shrink-0 bg-border" />
47
+ }
48
+
49
+ /** A text dropdown in the bar: "Normal text ▾", "Insert ▾" (`.wy-edx__drop`). */
50
+ const BarDrop = React.forwardRef<HTMLButtonElement, React.ComponentProps<"button">>(function BarDrop(
51
+ { className, children, ...props },
52
+ ref
53
+ ) {
54
+ return (
55
+ <button
56
+ ref={ref}
57
+ type="button"
58
+ className={cn(
59
+ "inline-flex h-7 shrink-0 cursor-pointer items-center gap-1 rounded-control-sm border-0 bg-transparent ps-2 pe-1.5 text-[0.8125rem] whitespace-nowrap text-foreground hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-40",
60
+ className
61
+ )}
62
+ {...props}
63
+ >
64
+ {children}
65
+ <Icon name="chevron-down" size={14} className="text-muted-foreground" />
66
+ </button>
67
+ )
68
+ })
69
+
70
+ /** Field ▾ (EditorInline): the field picker with its own search box. */
71
+ function FieldMenu({
72
+ editor,
73
+ groups,
74
+ labels,
75
+ disabled,
76
+ onCreate,
77
+ }: {
78
+ editor: Editor
79
+ groups: FieldGroup[]
80
+ labels: EditorLabels
81
+ disabled: boolean
82
+ /** A template's own field named `label`, added to the document (editor M4b). */
83
+ onCreate?: (label: string) => FieldDef
84
+ }) {
85
+ const [open, setOpen] = React.useState(false)
86
+ const [query, setQuery] = React.useState("")
87
+ const [active, setActive] = React.useState(0)
88
+ const shown = React.useMemo(() => filterFields(groups, query), [groups, query])
89
+ const flat = flatFields(shown)
90
+ React.useEffect(() => setActive(0), [query, open])
91
+ const pick = (field: FieldDef) => {
92
+ setOpen(false)
93
+ setQuery("")
94
+ insertField(editor, field)
95
+ }
96
+ const name = query.trim()
97
+ const exists = flatFields(groups).some((f) => f.label.toLowerCase() === name.toLowerCase())
98
+ const create = onCreate && name && !exists ? () => pick(onCreate(name)) : undefined
99
+ return (
100
+ <Popover open={open} onOpenChange={setOpen}>
101
+ <PopoverTrigger asChild>
102
+ <BarDrop disabled={disabled}>
103
+ <Icon name="field" size={14} />
104
+ {labels.field}
105
+ </BarDrop>
106
+ </PopoverTrigger>
107
+ <PopoverContent align="start" className="w-auto border-0 bg-transparent p-0 shadow-none" onCloseAutoFocus={(e) => e.preventDefault()}>
108
+ <FieldPicker
109
+ id="wy-fieldmenu"
110
+ groups={shown}
111
+ active={Math.min(active, Math.max(0, flat.length - 1))}
112
+ onActive={setActive}
113
+ onPick={pick}
114
+ labels={labels}
115
+ search={
116
+ <label className="flex items-center gap-1.5 border-b border-border px-2 pb-1.5 pt-1 text-muted-foreground">
117
+ <Icon name="search" size={14} />
118
+ <input
119
+ autoFocus
120
+ value={query}
121
+ onChange={(e) => setQuery(e.target.value)}
122
+ onKeyDown={(e) => {
123
+ const n = flat.length || 1
124
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
125
+ e.preventDefault()
126
+ setActive((i) => (i + (e.key === "ArrowDown" ? 1 : n - 1)) % n)
127
+ } else if (e.key === "Enter" && flat[active]) {
128
+ e.preventDefault()
129
+ pick(flat[active])
130
+ } else if (e.key === "Enter" && create) {
131
+ e.preventDefault()
132
+ create()
133
+ }
134
+ }}
135
+ placeholder={labels.fieldSearch}
136
+ aria-label={labels.fieldSearch}
137
+ aria-controls="wy-fieldmenu"
138
+ aria-activedescendant={flat.length ? `wy-fieldmenu-${active}` : undefined}
139
+ className="h-7 min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"
140
+ />
141
+ </label>
142
+ }
143
+ footer={
144
+ onCreate && (
145
+ <div className="border-t border-border pt-1">
146
+ {create ? (
147
+ <button
148
+ type="button"
149
+ onClick={create}
150
+ className="flex w-full items-center gap-1.5 rounded-control px-2 py-1.5 text-start text-sm hover:bg-accent"
151
+ >
152
+ <Icon name="plus" size={14} />
153
+ <span className="min-w-0 truncate" dir="auto">
154
+ {fill(labels.fieldNew, { name })}
155
+ </span>
156
+ </button>
157
+ ) : (
158
+ <p className="m-0 px-2 py-1.5 text-xs text-muted-foreground">{labels.fieldNewHint}</p>
159
+ )}
160
+ </div>
161
+ )
162
+ }
163
+ />
164
+ </PopoverContent>
165
+ </Popover>
166
+ )
167
+ }
168
+
169
+ /**
170
+ * The fixed formatting toolbar, in Google Docs order (E.5, EditorShell):
171
+ * undo and redo · style · bold, italic, underline, strikethrough · link,
172
+ * highlight · lists · Insert ▾ · Field ▾ · zoom, view, outline. Every icon
173
+ * button has a tooltip with its shortcut; pressed states use the tint. Under
174
+ * 768px it scrolls sideways.
175
+ */
176
+ function EditorToolbar({
177
+ editor,
178
+ labels,
179
+ editable,
180
+ outline,
181
+ onOutline,
182
+ onLink,
183
+ fields,
184
+ view,
185
+ onView,
186
+ zoom,
187
+ onZoom,
188
+ sheet,
189
+ onCreateField,
190
+ onComment,
191
+ }: {
192
+ editor: Editor
193
+ labels: EditorLabels
194
+ editable: boolean
195
+ outline: boolean
196
+ onOutline: () => void
197
+ onLink: () => void
198
+ /** The template's fields; Field ▾ shows only when there are some. */
199
+ fields?: FieldGroup[]
200
+ view?: EditorView
201
+ /** Omitted when the document can't switch (label sheets are page view only, E.43). */
202
+ onView?: (view: EditorView) => void
203
+ zoom?: PageZoom
204
+ onZoom?: (zoom: PageZoom) => void
205
+ /** Label sheets: the sheet setup, beside the zoom (E.43). */
206
+ sheet?: React.ReactNode
207
+ /** A template's own field, made from Field ▾. */
208
+ onCreateField?: (label: string) => FieldDef
209
+ /** M5: comment on the selection (⌥⌘M); offered with comment permission, editable or not. */
210
+ onComment?: () => void
211
+ }) {
212
+ const s = useEditorState({
213
+ editor,
214
+ selector: ({ editor: e }) => ({
215
+ bold: e.isActive("bold"),
216
+ italic: e.isActive("italic"),
217
+ underline: e.isActive("underline"),
218
+ strike: e.isActive("strike"),
219
+ link: e.isActive("link"),
220
+ highlight: e.isActive("highlight"),
221
+ canUndo: e.can().undo(),
222
+ canRedo: e.can().redo(),
223
+ item: currentItem(e)?.id ?? "text",
224
+ empty: e.state.selection.empty,
225
+ }),
226
+ })
227
+ const mark = (name: string) => () => editor.chain().focus().toggleMark(name).run()
228
+ const list = (id: string) => () => {
229
+ const item = CATALOGUE.find((i) => i.id === id)!
230
+ if (s.item === id) turnInto(editor, "paragraph")
231
+ else turnInto(editor, item.node.type, item.node.attrs)
232
+ }
233
+ const styleItem = CATALOGUE.find((i) => i.id === (STYLE_IDS.includes(s.item) ? s.item : "text"))!
234
+ const tb = (icon: React.ComponentProps<typeof IconButton>["icon"], label: string, pressed: boolean, onClick: () => void, shortcut?: string) => (
235
+ <IconButton
236
+ icon={icon}
237
+ label={label}
238
+ size="sm"
239
+ tooltip="bottom"
240
+ shortcut={shortcut}
241
+ pressed={pressed}
242
+ disabled={!editable}
243
+ onMouseDown={(e) => e.preventDefault()}
244
+ onClick={onClick}
245
+ />
246
+ )
247
+
248
+ return (
249
+ <div
250
+ role="toolbar"
251
+ aria-label={labels.formatting}
252
+ data-slot="editor-toolbar"
253
+ className="flex h-11 items-center gap-0.5 overflow-x-auto border-b border-border bg-card px-3 [scrollbar-width:none]"
254
+ >
255
+ <IconButton icon="undo" label={labels.undo} size="sm" tooltip="bottom" shortcut="⌘Z" disabled={!editable || !s.canUndo} onMouseDown={(e) => e.preventDefault()} onClick={() => editor.chain().focus().undo().run()} />
256
+ <IconButton icon="redo" label={labels.redo} size="sm" tooltip="bottom" shortcut="⇧⌘Z" disabled={!editable || !s.canRedo} onMouseDown={(e) => e.preventDefault()} onClick={() => editor.chain().focus().redo().run()} />
257
+ <Sep />
258
+ <DropdownMenu modal={false}>
259
+ <DropdownMenuTrigger asChild>
260
+ <BarDrop aria-label={labels.styleMenu} disabled={!editable} className="min-w-28 justify-between">
261
+ {styleItem.id === "text" ? labels.normalText : labels[styleItem.label]}
262
+ </BarDrop>
263
+ </DropdownMenuTrigger>
264
+ <DropdownMenuContent align="start" onCloseAutoFocus={(e) => { e.preventDefault(); editor.commands.focus() }}>
265
+ {STYLE_IDS.map((id) => {
266
+ const item = CATALOGUE.find((i) => i.id === id)!
267
+ return (
268
+ <DropdownMenuItem key={id} onSelect={() => turnInto(editor, item.node.type, item.node.attrs)} className={cn(s.item === id && "bg-primary-tint text-primary-tint-foreground")}>
269
+ <Icon name={item.icon} /> {id === "text" ? labels.normalText : labels[item.label]}
270
+ <DropdownMenuShortcut>{STYLE_SHORTCUTS[id]}</DropdownMenuShortcut>
271
+ </DropdownMenuItem>
272
+ )
273
+ })}
274
+ </DropdownMenuContent>
275
+ </DropdownMenu>
276
+ <Sep />
277
+ {tb("bold", labels.bold, s.bold, mark("bold"), "⌘B")}
278
+ {tb("italic", labels.italic, s.italic, mark("italic"), "⌘I")}
279
+ {tb("underline", labels.underline, s.underline, mark("underline"), "⌘U")}
280
+ {tb("strike", labels.strike, s.strike, mark("strike"), "⇧⌘X")}
281
+ <Sep />
282
+ {tb("link", labels.link, s.link, onLink, "⌘K")}
283
+ {tb("highlight", labels.highlight, s.highlight, mark("highlight"))}
284
+ <Sep />
285
+ {tb("list-bullet", labels.blockBullet, s.item === "bullet", list("bullet"), "⇧⌘8")}
286
+ {tb("list-numbered", labels.blockNumber, s.item === "number", list("number"), "⇧⌘7")}
287
+ {tb("list-todo", labels.blockChecklist, s.item === "checklist", list("checklist"), "⇧⌘9")}
288
+ <Sep />
289
+ <DropdownMenu modal={false}>
290
+ <DropdownMenuTrigger asChild>
291
+ <BarDrop disabled={!editable}>
292
+ <Icon name="plus" size={14} />
293
+ {labels.insert}
294
+ </BarDrop>
295
+ </DropdownMenuTrigger>
296
+ <DropdownMenuContent align="start" onCloseAutoFocus={(e) => { e.preventDefault(); editor.commands.focus() }}>
297
+ {CATALOGUE.map((item) => (
298
+ <DropdownMenuItem key={item.id} onSelect={() => applyItem(editor, item)}>
299
+ <Icon name={item.icon} /> {labels[item.label]}
300
+ {item.markdown && <DropdownMenuShortcut>{item.markdown}</DropdownMenuShortcut>}
301
+ </DropdownMenuItem>
302
+ ))}
303
+ </DropdownMenuContent>
304
+ </DropdownMenu>
305
+ {fields && (fields.length > 0 || onCreateField) && (
306
+ <FieldMenu editor={editor} groups={fields} labels={labels} disabled={!editable} onCreate={onCreateField} />
307
+ )}
308
+ {onComment && (
309
+ <IconButton
310
+ icon="comment-add"
311
+ label={labels.comment}
312
+ size="sm"
313
+ tooltip="bottom"
314
+ shortcut="⌥⌘M"
315
+ disabled={s.empty}
316
+ onMouseDown={(e) => e.preventDefault()}
317
+ onClick={onComment}
318
+ />
319
+ )}
320
+ <span className="min-w-2 flex-1" />
321
+ {sheet}
322
+ {view === "page" && onZoom && (
323
+ <DropdownMenu modal={false}>
324
+ <DropdownMenuTrigger asChild>
325
+ <BarDrop aria-label={labels.zoom}>{zoomLabel(zoom ?? "fit", labels)}</BarDrop>
326
+ </DropdownMenuTrigger>
327
+ <DropdownMenuContent align="end">
328
+ {ZOOM_STEPS.map((step) => (
329
+ <DropdownMenuItem key={String(step)} onSelect={() => onZoom(step)} className={cn(step === (zoom ?? "fit") && "bg-primary-tint text-primary-tint-foreground")}>
330
+ {zoomLabel(step, labels)}
331
+ </DropdownMenuItem>
332
+ ))}
333
+ </DropdownMenuContent>
334
+ </DropdownMenu>
335
+ )}
336
+ {view && onView && (
337
+ <ToggleGroup
338
+ size="sm"
339
+ label={labels.view}
340
+ required
341
+ value={view}
342
+ onChange={(v) => v && onView(v as EditorView)}
343
+ options={[
344
+ { value: "continuous", label: labels.viewContinuous, icon: "continuous", iconOnly: true },
345
+ { value: "page", label: labels.viewPage, icon: "page", iconOnly: true },
346
+ ]}
347
+ />
348
+ )}
349
+ <IconButton icon="outline" label={labels.outline} size="sm" tooltip="bottom" pressed={outline} onClick={onOutline} />
350
+ </div>
351
+ )
352
+ }
353
+
354
+ function zoomLabel(zoom: PageZoom, labels: EditorLabels): string {
355
+ return zoom === "fit" ? labels.zoomFit : fill(labels.zoomPercent, { n: zoom })
356
+ }
357
+
358
+ export { EditorToolbar }
@@ -0,0 +1,51 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import { IconPlus, IconRefresh } from "@tabler/icons-react"
3
+
4
+ import { EmptyState, ErrorState } from "./empty-state"
5
+ import { Button } from "./button"
6
+
7
+ const meta = {
8
+ title: "Primitives/EmptyState",
9
+ component: EmptyState,
10
+ tags: ["autodocs"],
11
+ argTypes: {
12
+ variant: { control: "select", options: ["empty", "error"] },
13
+ },
14
+ } satisfies Meta<typeof EmptyState>
15
+
16
+ export default meta
17
+ type Story = StoryObj<typeof meta>
18
+
19
+ export const Default: Story = {
20
+ args: {
21
+ title: "No tenants yet",
22
+ description: "Create your first tenant to get started.",
23
+ },
24
+ render: (args) => <EmptyState {...args} className="max-w-sm" />,
25
+ }
26
+
27
+ export const WithAction: Story = {
28
+ args: {
29
+ title: "No roles found",
30
+ description: "Roles you create will show up here.",
31
+ action: (
32
+ <Button size="sm" variant="outline">
33
+ <IconPlus /> Create role
34
+ </Button>
35
+ ),
36
+ },
37
+ render: (args) => <EmptyState {...args} className="max-w-sm" />,
38
+ }
39
+
40
+ export const Error: Story = {
41
+ args: {
42
+ title: "Couldn't load audit logs",
43
+ description: "The request failed. Check your connection and try again.",
44
+ action: (
45
+ <Button size="sm" variant="outline">
46
+ <IconRefresh /> Retry
47
+ </Button>
48
+ ),
49
+ },
50
+ render: (args) => <ErrorState {...args} className="max-w-sm" />,
51
+ }
@@ -0,0 +1,100 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { IconInbox, IconAlertTriangle } from "@tabler/icons-react"
4
+
5
+ import { cn } from "./utils"
6
+
7
+ /**
8
+ * Shared shape for EmptyState ("nothing here yet") and ErrorState ("something
9
+ * went wrong") — the two states share every prop; only the tone/default icon
10
+ * and the announced ARIA role differ. Kept as one variant-driven component so
11
+ * the two never drift apart visually.
12
+ *
13
+ * PLATFORM NOTE: `icon` and `action` are optional slot overrides (web-only —
14
+ * arbitrary React nodes cannot cross to a future Flutter/Dart port). Every
15
+ * OTHER prop (`variant`, `title`, `description`) is a plain string/enum, so a
16
+ * Flutter implementation can mirror the same contract and supply its own
17
+ * platform-appropriate default icon/action per variant.
18
+ */
19
+ const emptyStateVariants = cva(
20
+ "flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border p-8 text-center",
21
+ {
22
+ variants: {
23
+ variant: {
24
+ empty: "text-muted-foreground",
25
+ error: "border-destructive/30 text-destructive",
26
+ },
27
+ },
28
+ defaultVariants: {
29
+ variant: "empty",
30
+ },
31
+ }
32
+ )
33
+
34
+ export interface EmptyStateProps
35
+ extends Omit<React.ComponentProps<"div">, "title">,
36
+ VariantProps<typeof emptyStateVariants> {
37
+ /** Slot override for the icon; falls back to a sensible per-variant default. */
38
+ icon?: React.ReactNode
39
+ title: string
40
+ description?: string
41
+ /** Slot for a retry/create/etc. control — typically a <Button>. */
42
+ action?: React.ReactNode
43
+ }
44
+
45
+ function EmptyState({
46
+ className,
47
+ variant,
48
+ icon,
49
+ title,
50
+ description,
51
+ action,
52
+ ...props
53
+ }: EmptyStateProps) {
54
+ const resolvedVariant = variant ?? "empty"
55
+ const defaultIcon =
56
+ resolvedVariant === "error" ? <IconAlertTriangle /> : <IconInbox />
57
+
58
+ return (
59
+ <div
60
+ data-slot="empty-state"
61
+ // Errors interrupt (assertive); an empty list is just informational
62
+ // (polite) — matches the same distinction Alert/ErrorState conventions
63
+ // draw elsewhere in this package.
64
+ role={resolvedVariant === "error" ? "alert" : "status"}
65
+ className={cn(emptyStateVariants({ variant }), className)}
66
+ {...props}
67
+ >
68
+ <div
69
+ data-slot="empty-state-icon"
70
+ aria-hidden="true"
71
+ className="text-muted-foreground [&>svg]:size-8 [&>svg]:stroke-1"
72
+ >
73
+ {icon ?? defaultIcon}
74
+ </div>
75
+ <div data-slot="empty-state-title" className="text-sm font-medium text-foreground">
76
+ {title}
77
+ </div>
78
+ {description ? (
79
+ <div
80
+ data-slot="empty-state-description"
81
+ className="max-w-sm text-xs/relaxed text-muted-foreground text-balance"
82
+ >
83
+ {description}
84
+ </div>
85
+ ) : null}
86
+ {action ? (
87
+ <div data-slot="empty-state-action" className="mt-2">
88
+ {action}
89
+ </div>
90
+ ) : null}
91
+ </div>
92
+ )
93
+ }
94
+
95
+ /** ErrorState is EmptyState pinned to variant="error" — same contract, error tone. */
96
+ function ErrorState(props: Omit<EmptyStateProps, "variant">) {
97
+ return <EmptyState {...props} variant="error" />
98
+ }
99
+
100
+ export { EmptyState, ErrorState, emptyStateVariants }
@@ -0,0 +1,30 @@
1
+ # EmptyState / ErrorState — usage notes (for the gallery/showcase task)
2
+
3
+ Import: `import { EmptyState, ErrorState } from '@whity/ui/empty-state'` (or the root barrel).
4
+
5
+ `ErrorState` is `EmptyState` pinned to `variant="error"` — identical props minus `variant`.
6
+
7
+ ## Props
8
+
9
+ | Prop | Type | Required | Notes |
10
+ |---|---|---|---|
11
+ | `variant` | `'empty' \| 'error'` | no (default `'empty'`) | Not settable on `ErrorState` (always `'error'`). Drives tone + default icon + ARIA role. |
12
+ | `icon` | `React.ReactNode` | no | Slot override. Falls back to `IconInbox` (empty) / `IconAlertTriangle` (error) from `@tabler/icons-react`. Web-only slot — see platform note below. |
13
+ | `title` | `string` | **yes** | |
14
+ | `description` | `string` | no | |
15
+ | `action` | `React.ReactNode` | no | Typically a `<Button>` (e.g. "Retry" / "Create X"). |
16
+ | ...rest | `React.ComponentProps<'div'>` | no | Spread onto the root element (e.g. `className`). |
17
+
18
+ ## Accessibility
19
+
20
+ - `EmptyState` renders `role="status"` (polite announcement — informational).
21
+ - `ErrorState` renders `role="alert"` (assertive announcement — interrupts, matching real error semantics).
22
+ - Verified via a real axe-core scan in `web/__tests__/empty-state.a11y.test.tsx` (0 violations across default, error, and with-action renders).
23
+
24
+ ## Platform note (Flutter-forward design)
25
+
26
+ `variant`, `title`, and `description` are plain string/enum props — directly mirrorable by a future Flutter/Dart component. `icon` and `action` are React-node slots and are **web-only**; a Flutter implementation should supply its own platform-appropriate default icon/action per `variant` rather than trying to accept an arbitrary widget through the same prop name.
27
+
28
+ ## Gallery / Storybook
29
+
30
+ Story file: `packages/ui/src/empty-state.stories.tsx` — `Default`, `WithAction`, `Error` stories under `Primitives/EmptyState`.
@@ -0,0 +1,112 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import { fn } from "storybook/test"
3
+ import { useForm } from "react-hook-form"
4
+
5
+ import {
6
+ Form,
7
+ FormField,
8
+ FormItem,
9
+ FormLabel,
10
+ FormControl,
11
+ FormDescription,
12
+ FormMessage,
13
+ } from "./form"
14
+ import { Input } from "./input"
15
+ import { Button } from "./button"
16
+
17
+ type Values = { name: string; email: string }
18
+
19
+ interface TenantFormProps {
20
+ /** Seeds the fields — the shape a real screen would hydrate from the API. */
21
+ defaultValues?: Values
22
+ /** Label of the submit button. */
23
+ submitLabel?: string
24
+ /** Fired with the validated values once the form submits cleanly. */
25
+ onSubmit?: (values: Values) => void
26
+ }
27
+
28
+ /**
29
+ * A representative form assembled from this module's primitives. `Form` is
30
+ * react-hook-form's `FormProvider`, whose props are a live `useForm()` return
31
+ * value — it can only be produced by a hook at render time, never by static
32
+ * story args — so the stories document the composition through this wrapper
33
+ * instead of the provider itself.
34
+ */
35
+ function TenantForm({
36
+ defaultValues = { name: "", email: "" },
37
+ submitLabel = "Create tenant",
38
+ onSubmit = () => {},
39
+ }: TenantFormProps) {
40
+ const form = useForm<Values>({ defaultValues, mode: "onTouched" })
41
+
42
+ return (
43
+ <Form {...form}>
44
+ <form onSubmit={form.handleSubmit(onSubmit)} className="flex w-80 flex-col gap-4">
45
+ <FormField
46
+ control={form.control}
47
+ name="name"
48
+ rules={{ required: "Name is required" }}
49
+ render={({ field }) => (
50
+ <FormItem>
51
+ <FormLabel>Tenant name</FormLabel>
52
+ <FormControl>
53
+ <Input placeholder="Acme" {...field} />
54
+ </FormControl>
55
+ <FormDescription>Shown across the dashboard.</FormDescription>
56
+ <FormMessage />
57
+ </FormItem>
58
+ )}
59
+ />
60
+ <FormField
61
+ control={form.control}
62
+ name="email"
63
+ rules={{
64
+ required: "Email is required",
65
+ pattern: { value: /^[^@]+@[^@]+$/, message: "Enter a valid email" },
66
+ }}
67
+ render={({ field }) => (
68
+ <FormItem>
69
+ <FormLabel>Admin email</FormLabel>
70
+ <FormControl>
71
+ <Input type="email" placeholder="admin@acme.com" {...field} />
72
+ </FormControl>
73
+ <FormMessage />
74
+ </FormItem>
75
+ )}
76
+ />
77
+ <Button type="submit">{submitLabel}</Button>
78
+ </form>
79
+ </Form>
80
+ )
81
+ }
82
+
83
+ const meta = {
84
+ title: "Primitives/Form",
85
+ component: TenantForm,
86
+ tags: ["autodocs"],
87
+ parameters: {
88
+ layout: "padded",
89
+ docs: {
90
+ description: {
91
+ component:
92
+ "`Form`, `FormField`, `FormItem`, `FormLabel`, `FormControl`, `FormDescription` and `FormMessage` are the react-hook-form bindings shipped by this package. The stories exercise them through a representative tenant-creation form.",
93
+ },
94
+ },
95
+ },
96
+ args: {
97
+ onSubmit: fn(),
98
+ },
99
+ } satisfies Meta<typeof TenantForm>
100
+
101
+ export default meta
102
+ type Story = StoryObj<typeof meta>
103
+
104
+ export const Default: Story = {}
105
+
106
+ /** Prefilled the way an edit screen hydrates the form from an existing record. */
107
+ export const Prefilled: Story = {
108
+ args: {
109
+ defaultValues: { name: "Acme Inc.", email: "admin@acme.com" },
110
+ submitLabel: "Save changes",
111
+ },
112
+ }