@estiva-app/ui 0.98.0 → 0.99.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 (193) hide show
  1. package/README.md +1 -1
  2. package/dist/AppProvider.d.ts +6 -3
  3. package/dist/AppProvider.d.ts.map +1 -1
  4. package/dist/ArchiveDialog.d.ts +35 -0
  5. package/dist/ArchiveDialog.d.ts.map +1 -0
  6. package/dist/AttachedCard.d.ts +13 -2
  7. package/dist/AttachedCard.d.ts.map +1 -1
  8. package/dist/Card.d.ts +6 -1
  9. package/dist/Card.d.ts.map +1 -1
  10. package/dist/ChipInput.d.ts +3 -1
  11. package/dist/ChipInput.d.ts.map +1 -1
  12. package/dist/CollapsibleSection.d.ts +27 -2
  13. package/dist/CollapsibleSection.d.ts.map +1 -1
  14. package/dist/CommentBox.d.ts +2 -2
  15. package/dist/CommentBox.d.ts.map +1 -1
  16. package/dist/ConfirmDialog.d.ts +15 -2
  17. package/dist/ConfirmDialog.d.ts.map +1 -1
  18. package/dist/ConversationCard.d.ts +6 -1
  19. package/dist/ConversationCard.d.ts.map +1 -1
  20. package/dist/ConversationLayout.d.ts +19 -4
  21. package/dist/ConversationLayout.d.ts.map +1 -1
  22. package/dist/ConversationPlace.d.ts +17 -0
  23. package/dist/ConversationPlace.d.ts.map +1 -0
  24. package/dist/DocumentEditor.d.ts +38 -0
  25. package/dist/DocumentEditor.d.ts.map +1 -1
  26. package/dist/DocumentField.d.ts +50 -0
  27. package/dist/DocumentField.d.ts.map +1 -0
  28. package/dist/EditableText.d.ts +38 -4
  29. package/dist/EditableText.d.ts.map +1 -1
  30. package/dist/EmptyState.d.ts +10 -5
  31. package/dist/EmptyState.d.ts.map +1 -1
  32. package/dist/FormDialog.d.ts +38 -0
  33. package/dist/FormDialog.d.ts.map +1 -0
  34. package/dist/InlineText.d.ts.map +1 -1
  35. package/dist/MoveDialog.d.ts +61 -0
  36. package/dist/MoveDialog.d.ts.map +1 -0
  37. package/dist/NavItem.d.ts +9 -2
  38. package/dist/NavItem.d.ts.map +1 -1
  39. package/dist/NavTree.d.ts +16 -3
  40. package/dist/NavTree.d.ts.map +1 -1
  41. package/dist/PinnedComment.d.ts +3 -1
  42. package/dist/PinnedComment.d.ts.map +1 -1
  43. package/dist/ReactionHorizon.d.ts +5 -1
  44. package/dist/ReactionHorizon.d.ts.map +1 -1
  45. package/dist/ResolveDialog.d.ts +3 -1
  46. package/dist/ResolveDialog.d.ts.map +1 -1
  47. package/dist/SelectionToolbar.d.ts +2 -2
  48. package/dist/Thread.d.ts +6 -3
  49. package/dist/Thread.d.ts.map +1 -1
  50. package/dist/commentBoxFrame.d.ts.map +1 -1
  51. package/dist/conversation.examples.d.ts +4 -1
  52. package/dist/conversation.examples.d.ts.map +1 -1
  53. package/dist/conversationScroll.d.ts +80 -0
  54. package/dist/conversationScroll.d.ts.map +1 -0
  55. package/dist/editor.d.ts +1 -0
  56. package/dist/editor.d.ts.map +1 -1
  57. package/dist/editor.js +228 -69
  58. package/dist/editor.js.map +4 -4
  59. package/dist/eslint/index.js +2 -2
  60. package/dist/eslint/index.js.map +2 -2
  61. package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
  62. package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
  63. package/dist/eslint/no-native-title.d.ts +1 -1
  64. package/dist/eslint/no-native-title.d.ts.map +1 -1
  65. package/dist/formBusy.d.ts +5 -2
  66. package/dist/formBusy.d.ts.map +1 -1
  67. package/dist/index.d.ts +14 -6
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +2210 -1458
  70. package/dist/index.js.map +4 -4
  71. package/dist/looks.d.ts +8 -0
  72. package/dist/looks.d.ts.map +1 -1
  73. package/dist/seenOnScreen.d.ts +27 -0
  74. package/dist/seenOnScreen.d.ts.map +1 -0
  75. package/dist/showInConversation.d.ts +31 -0
  76. package/dist/showInConversation.d.ts.map +1 -0
  77. package/dist/threadCard.d.ts +13 -0
  78. package/dist/threadCard.d.ts.map +1 -1
  79. package/package.json +1 -1
  80. package/registry.json +904 -139
  81. package/src/AppProvider.mdx +4 -0
  82. package/src/AppProvider.test.tsx +34 -2
  83. package/src/AppProvider.tsx +17 -6
  84. package/src/ArchiveDialog.mdx +70 -0
  85. package/src/ArchiveDialog.stories.tsx +64 -0
  86. package/src/ArchiveDialog.test.tsx +90 -0
  87. package/src/ArchiveDialog.tsx +70 -0
  88. package/src/AttachedCard.mdx +6 -0
  89. package/src/AttachedCard.stories.tsx +9 -1
  90. package/src/AttachedCard.test.tsx +111 -2
  91. package/src/AttachedCard.tsx +77 -7
  92. package/src/Card.mdx +20 -1
  93. package/src/Card.stories.tsx +20 -0
  94. package/src/Card.test.tsx +87 -1
  95. package/src/Card.tsx +51 -3
  96. package/src/ChipInput.mdx +7 -1
  97. package/src/ChipInput.stories.tsx +9 -0
  98. package/src/ChipInput.test.tsx +42 -0
  99. package/src/ChipInput.tsx +7 -3
  100. package/src/CollapsibleSection.mdx +20 -1
  101. package/src/CollapsibleSection.stories.tsx +19 -1
  102. package/src/CollapsibleSection.test.tsx +85 -2
  103. package/src/CollapsibleSection.tsx +54 -15
  104. package/src/CommentBox.mdx +2 -1
  105. package/src/CommentBox.test.tsx +81 -1
  106. package/src/CommentBox.tsx +32 -11
  107. package/src/ConfirmDialog.mdx +25 -3
  108. package/src/ConfirmDialog.stories.tsx +27 -0
  109. package/src/ConfirmDialog.test.tsx +87 -1
  110. package/src/ConfirmDialog.tsx +39 -8
  111. package/src/ConversationCard.mdx +4 -0
  112. package/src/ConversationCard.stories.tsx +11 -1
  113. package/src/ConversationCard.test.tsx +116 -0
  114. package/src/ConversationCard.tsx +53 -36
  115. package/src/ConversationLayout.mdx +30 -4
  116. package/src/ConversationLayout.scroll.test.tsx +411 -0
  117. package/src/ConversationLayout.stories.tsx +79 -1
  118. package/src/ConversationLayout.test.tsx +79 -0
  119. package/src/ConversationLayout.tsx +136 -15
  120. package/src/ConversationPlace.mdx +53 -0
  121. package/src/ConversationPlace.stories.tsx +48 -0
  122. package/src/ConversationPlace.test.tsx +51 -0
  123. package/src/ConversationPlace.tsx +30 -0
  124. package/src/DocumentEditor.mdx +2 -1
  125. package/src/DocumentEditor.tsx +118 -64
  126. package/src/DocumentField.mdx +83 -0
  127. package/src/DocumentField.stories.tsx +110 -0
  128. package/src/DocumentField.test.tsx +281 -0
  129. package/src/DocumentField.tsx +199 -0
  130. package/src/EditableText.buttons.test.tsx +318 -0
  131. package/src/EditableText.mdx +50 -2
  132. package/src/EditableText.stories.tsx +96 -2
  133. package/src/EditableText.tsx +189 -5
  134. package/src/EmptyState.mdx +33 -8
  135. package/src/EmptyState.stories.tsx +26 -1
  136. package/src/EmptyState.test.tsx +63 -2
  137. package/src/EmptyState.tsx +28 -6
  138. package/src/Form.mdx +3 -1
  139. package/src/FormDialog.mdx +78 -0
  140. package/src/FormDialog.stories.tsx +90 -0
  141. package/src/FormDialog.test.tsx +183 -0
  142. package/src/FormDialog.tsx +93 -0
  143. package/src/InlineText.mdx +1 -0
  144. package/src/InlineText.tsx +2 -1
  145. package/src/MoveDialog.mdx +74 -0
  146. package/src/MoveDialog.stories.tsx +121 -0
  147. package/src/MoveDialog.test.tsx +203 -0
  148. package/src/MoveDialog.tsx +183 -0
  149. package/src/NavItem.mdx +15 -0
  150. package/src/NavItem.stories.tsx +15 -0
  151. package/src/NavItem.test.tsx +64 -1
  152. package/src/NavItem.tsx +10 -2
  153. package/src/NavTree.mdx +26 -4
  154. package/src/NavTree.stories.tsx +59 -0
  155. package/src/NavTree.test.tsx +232 -2
  156. package/src/NavTree.tsx +93 -43
  157. package/src/PinnedComment.mdx +6 -1
  158. package/src/PinnedComment.stories.tsx +11 -1
  159. package/src/PinnedComment.tsx +15 -2
  160. package/src/ReactionHorizon.mdx +3 -0
  161. package/src/ReactionHorizon.stories.tsx +3 -0
  162. package/src/ReactionHorizon.test.tsx +55 -0
  163. package/src/ReactionHorizon.tsx +30 -11
  164. package/src/ReplyCard.mdx +3 -0
  165. package/src/ReplyCard.stories.tsx +19 -1
  166. package/src/ResolveDialog.mdx +2 -0
  167. package/src/ResolveDialog.test.tsx +21 -0
  168. package/src/ResolveDialog.tsx +11 -39
  169. package/src/SelectionToolbar.tsx +2 -2
  170. package/src/Textarea.mdx +1 -0
  171. package/src/Thread.mdx +18 -1
  172. package/src/Thread.stories.tsx +55 -3
  173. package/src/Thread.test.tsx +11 -0
  174. package/src/Thread.tsx +53 -11
  175. package/src/commentBoxFrame.tsx +2 -2
  176. package/src/conversation.examples.tsx +10 -2
  177. package/src/conversationScroll.ts +155 -0
  178. package/src/editor.ts +1 -0
  179. package/src/editorSelection.test.tsx +53 -0
  180. package/src/eslint/no-field-outside-a-form.test.ts +4 -0
  181. package/src/eslint/no-field-outside-a-form.ts +2 -2
  182. package/src/eslint/no-native-title.ts +1 -1
  183. package/src/formBusy.ts +5 -2
  184. package/src/index.ts +16 -6
  185. package/src/looks.ts +10 -0
  186. package/src/registry/registry.test.ts +12 -6
  187. package/src/seenOnScreen.test.tsx +182 -0
  188. package/src/seenOnScreen.ts +146 -0
  189. package/src/showInConversation.test.tsx +168 -0
  190. package/src/showInConversation.ts +93 -0
  191. package/src/threadCard.ts +16 -0
  192. package/stories/Choosing.mdx +7 -2
  193. package/tailwind-preset.js +7 -0
@@ -0,0 +1,318 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * EditableText's `buttons` manner: the text with a button beside it, a field
4
+ * with Save and Cancel, and what happened said under it — Peek's Details,
5
+ * where a name and a summary were each built by hand with the only key
6
+ * handlers left in Peek (C13, 2 November). Peek's tests for both, pinned on
7
+ * the kit's part.
8
+ */
9
+ import { afterEach, describe, expect, it, vi } from 'vitest'
10
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
11
+ import userEvent from '@testing-library/user-event'
12
+ import { useState } from 'react'
13
+ import { DialogShell } from './DialogShell'
14
+ import { EditableText, type EditableTextProps } from './EditableText'
15
+ import { FieldLine } from './Field'
16
+
17
+ afterEach(cleanup)
18
+
19
+ const oneLine = (text: string) => text.replace(/\s+/g, ' ').trim()
20
+
21
+ /** The name, as Peek's Details has it. */
22
+ function Name(props: Partial<EditableTextProps>) {
23
+ const [value, setValue] = useState(props.value ?? 'Launch naming')
24
+ return (
25
+ <EditableText
26
+ manner="buttons"
27
+ label="Name"
28
+ placeholder="Untitled"
29
+ editLabel="Rename"
30
+ required
31
+ {...props}
32
+ value={value}
33
+ onCommit={async (next) => {
34
+ const answer = props.onCommit ? await props.onCommit(next) : true
35
+ if (answer === true || (typeof answer === 'object' && answer.kind !== 'error')) setValue(next)
36
+ return answer
37
+ }}
38
+ />
39
+ )
40
+ }
41
+
42
+ /** The summary, as Peek's Details has it. */
43
+ function Summary(props: Partial<EditableTextProps>) {
44
+ const [value, setValue] = useState(props.value ?? '')
45
+ return (
46
+ <EditableText
47
+ manner="buttons"
48
+ multiline
49
+ label="Summary"
50
+ placeholder="No summary yet."
51
+ fieldPlaceholder="What is it for, in a sentence?"
52
+ editLabel="Edit"
53
+ addLabel="Add a summary"
54
+ clean={oneLine}
55
+ {...props}
56
+ value={value}
57
+ onCommit={async (next) => {
58
+ const answer = props.onCommit ? await props.onCommit(next) : true
59
+ if (answer === true) setValue(next)
60
+ return answer
61
+ }}
62
+ />
63
+ )
64
+ }
65
+
66
+ const field = (name = 'Name') => screen.getByRole('textbox', { name }) as HTMLInputElement
67
+ const button = (name: string) => screen.getByRole('button', { name }) as HTMLButtonElement
68
+
69
+ describe('EditableText, buttons: a name (Peek’s Details)', () => {
70
+ it('reads as the text with Rename beside it, and Rename opens the field holding the name', async () => {
71
+ const user = userEvent.setup()
72
+ render(<Name />)
73
+ expect(screen.getByText('Launch naming').className).toContain('truncate')
74
+ expect(screen.queryByRole('textbox')).toBeNull()
75
+ await user.click(button('Rename'))
76
+ expect(field().value).toBe('Launch naming')
77
+ expect(document.activeElement).toBe(field())
78
+ // Nothing changed yet: nothing to save.
79
+ expect(button('Save').disabled).toBe(true)
80
+ expect(button('Cancel')).toBeTruthy()
81
+ })
82
+
83
+ it('Enter saves the trimmed name, and the field closes on the new text', async () => {
84
+ const user = userEvent.setup()
85
+ const onCommit = vi.fn(async () => true as const)
86
+ render(<Name onCommit={onCommit} />)
87
+ await user.click(button('Rename'))
88
+ await user.clear(field())
89
+ await user.type(field(), ' Launch name {Enter}')
90
+ expect(onCommit).toHaveBeenCalledWith('Launch name')
91
+ await waitFor(() => expect(screen.queryByRole('textbox')).toBeNull())
92
+ expect(screen.getByText('Launch name')).toBeTruthy()
93
+ })
94
+
95
+ it('Escape in the field abandons the edit, and only the edit: the dialog around it stays', async () => {
96
+ const user = userEvent.setup()
97
+ const onCommit = vi.fn()
98
+ const onClose = vi.fn()
99
+ render(
100
+ <DialogShell title="Details" onClose={onClose}>
101
+ <Name onCommit={onCommit} />
102
+ </DialogShell>,
103
+ )
104
+ await user.click(button('Rename'))
105
+ await user.type(field(), ' two{Escape}')
106
+ expect(screen.queryByRole('textbox')).toBeNull()
107
+ expect(screen.getByText('Launch naming')).toBeTruthy()
108
+ expect(onCommit).not.toHaveBeenCalled()
109
+ expect(onClose).not.toHaveBeenCalled()
110
+ })
111
+
112
+ it('Cancel abandons it too, and the next open starts from the name again', async () => {
113
+ const user = userEvent.setup()
114
+ render(<Name />)
115
+ await user.click(button('Rename'))
116
+ await user.type(field(), ' two')
117
+ await user.click(button('Cancel'))
118
+ expect(screen.queryByRole('textbox')).toBeNull()
119
+ await user.click(button('Rename'))
120
+ expect(field().value).toBe('Launch naming')
121
+ })
122
+
123
+ it('an emptied name cannot be saved', async () => {
124
+ const user = userEvent.setup()
125
+ const onCommit = vi.fn()
126
+ render(<Name onCommit={onCommit} />)
127
+ await user.click(button('Rename'))
128
+ await user.clear(field())
129
+ expect(button('Save').disabled).toBe(true)
130
+ await user.keyboard('{Enter}')
131
+ expect(onCommit).not.toHaveBeenCalled()
132
+ })
133
+
134
+ it('a refusal keeps the field open with the text, and says why under it', async () => {
135
+ const user = userEvent.setup()
136
+ render(<Name onCommit={async () => ({ kind: 'error', message: 'The relay refused the rename: relay_membership_required.' })} />)
137
+ await user.click(button('Rename'))
138
+ await user.type(field(), ' two{Enter}')
139
+ const line = await screen.findByRole('alert')
140
+ expect(line.textContent).toBe('The relay refused the rename: relay_membership_required.')
141
+ expect(line.className).toContain('text-error-default')
142
+ expect(field().value).toBe('Launch naming two')
143
+ // The line is under the field, in the field's form, 8px down.
144
+ const form = line.closest('form')!
145
+ expect(form.contains(field())).toBe(true)
146
+ expect(form.className.split(' ')).toEqual(expect.arrayContaining(['flex', 'flex-col', 'gap-2']))
147
+ expect(form.lastElementChild!.lastElementChild).toBe(line)
148
+ })
149
+
150
+ it('a warning saves, closes, and says it under the text', async () => {
151
+ const user = userEvent.setup()
152
+ render(<Name onCommit={async () => ({ kind: 'warning', message: 'Renamed here; Ship shows the old name until it reloads.' })} />)
153
+ await user.click(button('Rename'))
154
+ await user.type(field(), ' two{Enter}')
155
+ const line = await screen.findByRole('status')
156
+ expect(line.textContent).toBe('Renamed here; Ship shows the old name until it reloads.')
157
+ expect(screen.queryByRole('textbox')).toBeNull()
158
+ // Under the text, 12px down.
159
+ expect(line.parentElement!.className.split(' ')).toEqual(expect.arrayContaining(['flex', 'flex-col', 'gap-3']))
160
+ })
161
+
162
+ it('a save that throws keeps the field open and says the error’s words', async () => {
163
+ const user = userEvent.setup()
164
+ render(
165
+ <Name
166
+ onCommit={async () => {
167
+ throw new Error('The relay did not answer.')
168
+ }}
169
+ />,
170
+ )
171
+ await user.click(button('Rename'))
172
+ await user.type(field(), ' two{Enter}')
173
+ expect((await screen.findByRole('alert')).textContent).toBe('The relay did not answer.')
174
+ // Nothing is left stuck on "Saving…".
175
+ expect(button('Save').disabled).toBe(false)
176
+ })
177
+
178
+ it('says it is saving, and switches the field and both buttons off', async () => {
179
+ const user = userEvent.setup()
180
+ render(<Name onCommit={() => new Promise<boolean>(() => {})} />)
181
+ await user.click(button('Rename'))
182
+ await user.type(field(), ' two{Enter}')
183
+ expect(button('Saving…').disabled).toBe(true)
184
+ expect(button('Cancel').disabled).toBe(true)
185
+ // Off through the form's fieldset, as every field in a busy Form is.
186
+ expect(field().matches(':disabled')).toBe(true)
187
+ })
188
+
189
+ it('read-only: the text, and no way in', () => {
190
+ render(<Name readOnly />)
191
+ expect(screen.getByText('Launch naming')).toBeTruthy()
192
+ expect(screen.queryByRole('button')).toBeNull()
193
+ })
194
+
195
+ it('defaultEditing opens as the field, holding the name (a menu’s Rename)', () => {
196
+ render(<Name defaultEditing />)
197
+ expect(field().value).toBe('Launch naming')
198
+ })
199
+ })
200
+
201
+ describe('EditableText, buttons: a summary (Peek’s Details, SPEC §6.12)', () => {
202
+ it('offers its add words with a plus when there is none, and saves on one line', async () => {
203
+ const user = userEvent.setup()
204
+ const onCommit = vi.fn(async () => true as const)
205
+ render(<Summary onCommit={onCommit} />)
206
+ const empty = screen.getByText('No summary yet.')
207
+ expect(empty.className).toContain('text-text-muted')
208
+ await user.click(button('Add a summary'))
209
+ expect(field('Summary').getAttribute('placeholder')).toBe('What is it for, in a sentence?')
210
+ fireEvent.change(field('Summary'), { target: { value: ' Where we pick\nthe name. ' } })
211
+ await user.click(button('Save'))
212
+ await waitFor(() => expect(onCommit).toHaveBeenCalledWith('Where we pick the name.'))
213
+ await waitFor(() => expect(screen.queryByRole('textbox')).toBeNull())
214
+ expect(button('Edit')).toBeTruthy()
215
+ })
216
+
217
+ it('draws its placeholder, when empty, as the kit’s empty line for one part of a page (12px caption, muted), as Peek’s "No summary yet." was', () => {
218
+ render(<Summary />)
219
+ const empty = screen.getByText('No summary yet.')
220
+ expect(empty.className).toContain('text-caption')
221
+ expect(empty.className).toContain('text-text-muted')
222
+ expect(empty.className).not.toContain('text-body-2')
223
+ // It still takes the row's room, the button at its end.
224
+ expect(empty.className).toContain('flex-1')
225
+ })
226
+
227
+ it('a one-line value, when empty, draws the same empty line', () => {
228
+ render(<Name value="" />)
229
+ const empty = screen.getByText('Untitled')
230
+ expect(empty.className).toContain('text-caption')
231
+ expect(empty.className).not.toContain('text-body-2')
232
+ })
233
+
234
+ it('edits the whole value it was given', async () => {
235
+ const user = userEvent.setup()
236
+ render(<Summary value={'x'.repeat(300)} />)
237
+ await user.click(button('Edit'))
238
+ expect(field('Summary').value).toBe('x'.repeat(300))
239
+ })
240
+
241
+ it('saving an empty field clears it, when the value is not required', async () => {
242
+ const user = userEvent.setup()
243
+ const onCommit = vi.fn(async () => true as const)
244
+ render(<Summary value="Where we pick the name." onCommit={onCommit} />)
245
+ await user.click(button('Edit'))
246
+ fireEvent.change(field('Summary'), { target: { value: ' ' } })
247
+ await user.click(button('Save'))
248
+ await waitFor(() => expect(onCommit).toHaveBeenCalledWith(''))
249
+ })
250
+
251
+ it('a change only in spaces is no change', async () => {
252
+ const user = userEvent.setup()
253
+ render(<Summary value="Where we pick the name." />)
254
+ await user.click(button('Edit'))
255
+ fireEvent.change(field('Summary'), { target: { value: 'Where we pick\nthe name.' } })
256
+ expect(button('Save').disabled).toBe(true)
257
+ })
258
+
259
+ it('says its note under the field as it is typed, and still lets it save', async () => {
260
+ const user = userEvent.setup()
261
+ render(<Summary draftNote={(draft) => (draft.length > 240 ? <FieldLine tone="warning">{`${draft.length} characters.`}</FieldLine> : null)} />)
262
+ await user.click(button('Add a summary'))
263
+ fireEvent.change(field('Summary'), { target: { value: 'a'.repeat(250) } })
264
+ const note = screen.getByText('250 characters.')
265
+ // Between the field and its buttons.
266
+ expect(note.previousElementSibling).toBe(field('Summary'))
267
+ expect(note.nextElementSibling!.contains(button('Save'))).toBe(true)
268
+ expect(button('Save').disabled).toBe(false)
269
+ })
270
+
271
+ it('Enter in it is a new line; Ctrl+Enter saves', async () => {
272
+ const user = userEvent.setup()
273
+ const onCommit = vi.fn(async () => true as const)
274
+ render(<Summary onCommit={onCommit} />)
275
+ await user.click(button('Add a summary'))
276
+ await user.type(field('Summary'), 'One{Enter}two')
277
+ expect(onCommit).not.toHaveBeenCalled()
278
+ await user.keyboard('{Control>}{Enter}{/Control}')
279
+ expect(onCommit).toHaveBeenCalledWith('One two')
280
+ })
281
+
282
+ it('a refusal keeps your text and the reason; the same text can be sent again, and changing it takes the reason away', async () => {
283
+ const user = userEvent.setup()
284
+ const onCommit = vi.fn(async () => ({ kind: 'error' as const, message: 'Summary not saved. relay_membership_required Your text is still here.' }))
285
+ render(<Summary onCommit={onCommit} />)
286
+ await user.click(button('Add a summary'))
287
+ fireEvent.change(field('Summary'), { target: { value: 'Mine' } })
288
+ await user.click(button('Save'))
289
+ expect((await screen.findByRole('alert')).textContent).toBe('Summary not saved. relay_membership_required Your text is still here.')
290
+ expect(field('Summary').value).toBe('Mine')
291
+ await user.click(button('Save'))
292
+ await waitFor(() => expect(onCommit).toHaveBeenCalledTimes(2))
293
+ fireEvent.change(field('Summary'), { target: { value: 'Mine, again' } })
294
+ expect(screen.queryByRole('alert')).toBeNull()
295
+ })
296
+
297
+ it('back at the saved text once the reason has gone, there is nothing to send', async () => {
298
+ const user = userEvent.setup()
299
+ const onCommit = vi.fn(async () => ({ kind: 'error' as const, message: 'Not saved.' }))
300
+ render(<Summary value="Where we pick the name." onCommit={onCommit} />)
301
+ await user.click(button('Edit'))
302
+ fireEvent.change(field('Summary'), { target: { value: 'Where we pick the name!' } })
303
+ await user.click(button('Save'))
304
+ await screen.findByRole('alert')
305
+ fireEvent.change(field('Summary'), { target: { value: 'Where we pick the name.' } })
306
+ // Back to the saved text and no reason standing: nothing to send.
307
+ expect(button('Save').disabled).toBe(true)
308
+ })
309
+
310
+ it('Escape in it abandons the edit', async () => {
311
+ const user = userEvent.setup()
312
+ render(<Summary value="Where we pick the name." />)
313
+ await user.click(button('Edit'))
314
+ await user.type(field('Summary'), ' More.{Escape}')
315
+ expect(screen.queryByRole('textbox')).toBeNull()
316
+ expect(screen.getByText('Where we pick the name.')).toBeTruthy()
317
+ })
318
+ })
@@ -20,14 +20,19 @@ edit is never silently lost.
20
20
  form.
21
21
  - A reader who cannot write gets `readOnly` — the value without the edit
22
22
  affordance, because an action appears only where it can succeed.
23
+ - **An edit to confirm, in a dialog** — a file's name or summary in its
24
+ Details → `manner="buttons"`: the text with a button beside it ("Rename"),
25
+ then a field with Save and Cancel, and what happened said under it.
26
+
27
+ <Canvas of={EditableTextStories.ButtonsName} />
23
28
 
24
29
  ## When not
25
30
 
26
31
  - A field in a form or dialog → **TextInput** / **Textarea** in a
27
32
  **Field**.
28
33
  - Composing something new → the field, not an edit-in-place of nothing.
29
- - An edit that publishes something, like a message → **Textarea** with Save
30
- and Cancel. EditableText saves when you leave it.
34
+ - An edit that publishes something, like a message → **CommentBox**, which
35
+ edits in place with its own Save and Cancel.
31
36
 
32
37
  ## How
33
38
 
@@ -62,6 +67,45 @@ import { EditableText } from '@estiva-app/ui'
62
67
 
63
68
  - **Planned:** rich text edited where it is shown (UIG-30).
64
69
 
70
+ ### `manner="buttons"`
71
+
72
+ ```tsx
73
+ <EditableText
74
+ manner="buttons"
75
+ label="Name"
76
+ value={title}
77
+ placeholder="Untitled"
78
+ editLabel="Rename"
79
+ required
80
+ onCommit={async (next) => (await rename(next)) ?? true}
81
+ />
82
+ ```
83
+
84
+ - Leaving the field saves nothing: Save does, and Enter in a one-line field;
85
+ in a `multiline` one Enter is a new line and Ctrl+Enter saves. Escape, or
86
+ Cancel, abandons the edit — and only the edit: a dialog around it stays for a
87
+ second Escape.
88
+ - `onCommit` answers `true` (saved), `false` (refused, you have said why), or
89
+ an outcome: `{ kind: 'error', message }` keeps the field open with the text
90
+ and says why under it; `{ kind: 'warning', message }` saved, and says so under
91
+ the text. A throw is an `error` in its own words. Changing a refused text
92
+ takes the reason away, and a refused text can be sent again as it is.
93
+ - One line: the field, Save and Cancel in one row. `multiline`: Save and Cancel
94
+ under the field, and `draftNote` between them — a count past a limit.
95
+ - `editLabel` is the button's words ("Edit" when absent); `addLabel` its words
96
+ while the value is empty, with a plus. `fieldPlaceholder` is the field's own;
97
+ `placeholder` is what shows when there is nothing, as the kit's empty line
98
+ for one part of a page (`EmptyState scope="section"`: 12px, muted).
99
+ - `required`: an empty value cannot be saved. `clean`: what a draft becomes
100
+ before it is compared and saved, trimmed when absent — one line for a summary.
101
+ - `defaultEditing` opens it as the field, holding the value: a menu's Rename.
102
+ - **Its size is its own here**, body-2, the size of the field beside it (its empty
103
+ line 12px); `className` places the whole.
104
+
105
+ <Canvas of={EditableTextStories.ButtonsSummary} />
106
+
107
+ <Canvas of={EditableTextStories.ButtonsRefused} />
108
+
65
109
  ## What it owns
66
110
 
67
111
  It does these by itself. Write none of them around it.
@@ -70,6 +114,7 @@ It does these by itself. Write none of them around it.
70
114
  |---|---|---|
71
115
  | Opens its field on a click, with the value selected | an edit mode of your own | |
72
116
  | Enter and leaving the field save; Escape cancels and puts the value back (`multiline`: Shift+Enter is a new line) | key or blur handlers | |
117
+ | `buttons`: Save, Enter (Ctrl+Enter when `multiline`) save; Escape and Cancel abandon the edit without closing the dialog around it; it waits while it saves and says what happened under it | key handlers, a busy state, or an outcome line | |
73
118
 
74
119
  ## Keys
75
120
 
@@ -79,6 +124,9 @@ It does these by itself. Write none of them around it.
79
124
  | Enter | commits (`multiline`: Shift+Enter is a new line) |
80
125
  | Escape | cancels, restores the value |
81
126
  | blur | commits |
127
+ | `buttons`: Enter | saves (`multiline`: a new line; Ctrl+Enter saves) |
128
+ | `buttons`: Escape | abandons the edit; the dialog around it stays |
129
+ | `buttons`: blur | nothing |
82
130
 
83
131
  ## Props
84
132
 
@@ -1,6 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
2
  import { useState } from 'react'
3
- import { EditableText } from './EditableText'
3
+ import { userEvent, within } from 'storybook/test'
4
+ import { EditableText, type EditableTextAnswer } from './EditableText'
5
+ import { FieldLine } from './Field'
4
6
 
5
7
  const meta = {
6
8
  title: 'Forms & fields/EditableText',
@@ -9,7 +11,7 @@ const meta = {
9
11
  value: 'Team charter',
10
12
  placeholder: 'Add a title',
11
13
  label: 'Title',
12
- onCommit: () => true as boolean,
14
+ onCommit: (): EditableTextAnswer => true,
13
15
  className: 'text-body-1 font-medium',
14
16
  },
15
17
  argTypes: { onCommit: { control: false } },
@@ -66,3 +68,95 @@ export const ReadOnly: Story = { args: { readOnly: true } }
66
68
  export const RefusedCommit: Story = {
67
69
  args: { onCommit: () => false },
68
70
  }
71
+
72
+ const inADialogsWidth = (Story: () => React.ReactNode) => <div className="w-[522px]">{Story()}</div>
73
+ const NAME = {
74
+ manner: 'buttons',
75
+ value: 'Folders: Universal navigation concept',
76
+ label: 'Name',
77
+ placeholder: 'Untitled',
78
+ editLabel: 'Rename',
79
+ required: true,
80
+ className: undefined,
81
+ } as const
82
+ const SUMMARY_TEXT = 'Where we work out how people move between Folders, files and apps, before the navigation rework starts.'
83
+ const SUMMARY = {
84
+ manner: 'buttons',
85
+ multiline: true,
86
+ value: SUMMARY_TEXT,
87
+ label: 'Summary',
88
+ placeholder: 'No summary yet.',
89
+ fieldPlaceholder: 'What is it for, in a sentence?',
90
+ editLabel: 'Edit',
91
+ addLabel: 'Add a summary',
92
+ clean: (draft: string) => draft.replace(/\s+/g, ' ').trim(),
93
+ className: undefined,
94
+ } as const
95
+
96
+ /** `buttons`: the text with Rename beside it. Rename opens a field with Save and Cancel; Enter saves, Escape abandons. */
97
+ export const ButtonsName: Story = {
98
+ name: 'Buttons: a name',
99
+ args: NAME,
100
+ decorators: [inADialogsWidth],
101
+ }
102
+
103
+ /** `buttons`, opened as the field, holding the value: what a menu's Rename opens. */
104
+ export const ButtonsOpen: Story = {
105
+ name: 'Buttons: open',
106
+ args: { ...NAME, defaultEditing: true },
107
+ decorators: [inADialogsWidth],
108
+ }
109
+
110
+ /** `buttons`, refused: the field stays with the text, and the reason is said under it. */
111
+ export const ButtonsRefused: Story = {
112
+ name: 'Buttons: refused',
113
+ args: { ...NAME, defaultEditing: true, onCommit: () => ({ kind: 'error', message: 'The relay refused the rename: relay_membership_required.' }) },
114
+ decorators: [inADialogsWidth],
115
+ play: async ({ canvasElement }) => {
116
+ const name = within(canvasElement).getByRole('textbox', { name: 'Name' })
117
+ await userEvent.type(name, ' two{Enter}')
118
+ },
119
+ }
120
+
121
+ /** `buttons`, saved with a warning: the field closes, and the warning is said under the text. */
122
+ export const ButtonsWarning: Story = {
123
+ name: 'Buttons: saved with a warning',
124
+ args: { ...NAME, defaultEditing: true, onCommit: () => ({ kind: 'warning', message: 'Saved here; another app shows the old name until it reloads.' }) },
125
+ decorators: [inADialogsWidth],
126
+ play: ButtonsRefused.play,
127
+ }
128
+
129
+ /** `buttons` and `multiline`: the text wraps, Edit beside it; the field's Save and Cancel go under it. */
130
+ export const ButtonsSummary: Story = {
131
+ name: 'Buttons: a summary',
132
+ args: SUMMARY,
133
+ decorators: [inADialogsWidth],
134
+ }
135
+
136
+ /** `buttons`, empty: the placeholder as the kit's empty line (12px, muted), and the add words with a plus. */
137
+ export const ButtonsEmpty: Story = {
138
+ name: 'Buttons: empty',
139
+ args: { ...SUMMARY, value: '' },
140
+ decorators: [inADialogsWidth],
141
+ parameters: { a11y: { config: { rules: [{ id: 'color-contrast', enabled: false }] } } },
142
+ }
143
+
144
+ /** `buttons`, with a note under the field as it is typed: a count past 240. */
145
+ export const ButtonsNote: Story = {
146
+ name: 'Buttons: a note while typing',
147
+ args: {
148
+ ...SUMMARY,
149
+ defaultEditing: true,
150
+ value: `${SUMMARY_TEXT} ${SUMMARY_TEXT} ${SUMMARY_TEXT}`,
151
+ draftNote: (draft: string) =>
152
+ draft.length > 240 ? <FieldLine tone="warning">{`${draft.length} characters. A summary reads best in one or two sentences, under 240.`}</FieldLine> : null,
153
+ },
154
+ decorators: [inADialogsWidth],
155
+ }
156
+
157
+ /** `buttons`, for a reader who cannot write: the text, and no button. */
158
+ export const ButtonsReadOnly: Story = {
159
+ name: 'Buttons: read-only',
160
+ args: { ...SUMMARY, readOnly: true },
161
+ decorators: [inADialogsWidth],
162
+ }