@estiva-app/ui 0.75.0 → 0.77.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.
@@ -0,0 +1,472 @@
1
+ import { useCallback, useEffect, useRef, useState, type ComponentType, type DragEvent, type ReactNode } from 'react'
2
+ import { Extension, type AnyExtension } from '@tiptap/core'
3
+ import { EditorContent, useEditor, type Editor, type JSONContent } from '@tiptap/react'
4
+ import StarterKit from '@tiptap/starter-kit'
5
+ import { IconLock, IconPaperclip, IconSquareRounded } from '@tabler/icons-react'
6
+ import { AttachmentCard } from './AttachmentCard'
7
+ import { ReferenceNode, type ReferenceViewProps } from './BlockNodes'
8
+ import { Button } from './Button'
9
+ import { Card } from './Card'
10
+ import { cn } from './cn'
11
+ import { ComposeBox, ComposeKeys, COMPOSE_EDITOR_CLASSES, isEmptyDoc as isEmpty } from './ComposeBox'
12
+ import {
13
+ CaptionedReference,
14
+ PersonMention,
15
+ ReferenceTrigger,
16
+ SlashCommands,
17
+ UrgentPersonMention,
18
+ formatSection,
19
+ typeTrigger,
20
+ type CodeFormat,
21
+ type MentionPerson,
22
+ type ReferenceSection,
23
+ type SlashCommand,
24
+ type SlashSection,
25
+ } from './ComposerTriggers'
26
+ import { FieldLine } from './Field'
27
+ import { FilePicker } from './FilePicker'
28
+ import { Kbd } from './Kbd'
29
+ import { WRITING_BOX_CLASSES } from './looks'
30
+ import { PastedImages } from './PastedImages'
31
+ import { KeptSelection } from './SelectionToolbar'
32
+ import { isSuggestionOpen } from './suggestionPopup'
33
+ import { ToolbarButton } from './Toolbar'
34
+
35
+ /**
36
+ * The one box every app writes a comment, a reply and a chat line in, from the
37
+ * approved prototype (`concept/comments-everywhere`, Miky 17 October): the
38
+ * package's `ComposeBox` with everything each app built around it — `@`,
39
+ * `!@`, `[` and `/`, the keys, drafts, files, the edit mode, sending and a
40
+ * refused send. An app hands over only its people, its `[` sections, its `/`
41
+ * Insert rows and a send that says whether the relay accepted it.
42
+ *
43
+ * It speaks the editor's document. What that document writes as a message,
44
+ * and the document an edit or a draft opens with, are `@estiva-app/conversation`'s
45
+ * (`composerText`, `composerDocument`, `composerDraft`).
46
+ *
47
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/every-app-writes-and-reacts-with-one-shared-box.md
48
+ */
49
+
50
+ /** What the relay said about a send, an edit or an upload. */
51
+ export type SendAnswer = { accepted: true } | { accepted: false; reason: string }
52
+
53
+ /** What an upload answered: the app's own record of the file, or why not. */
54
+ export type UploadAnswer = { accepted: true; value: unknown } | { accepted: false; reason: string }
55
+
56
+ /** Where a file in the box is: Send waits for one uploading. */
57
+ export type BoxFileState = 'uploading' | 'ready' | 'failed'
58
+
59
+ /** A file in the box. */
60
+ export interface BoxFile {
61
+ id: string
62
+ name: string
63
+ size?: number
64
+ contentType?: string
65
+ state: BoxFileState
66
+ /** Why it failed, under its name. */
67
+ note?: string
68
+ /** What `upload` answered for it: the app's own record (an `imeta`, a URL). */
69
+ value?: unknown
70
+ }
71
+
72
+ /** A draft, in the box's terms — `@estiva-app/conversation`'s `composerDraft` is one. */
73
+ export interface CommentBoxDraft {
74
+ read(): JSONContent | undefined
75
+ write(body: JSONContent): void
76
+ clear(): void
77
+ }
78
+
79
+ /** Editing something already sent: the same box, with Cancel and Save. */
80
+ export interface CommentBoxEdit {
81
+ /** What it says now, as `composerDocument` opens it. */
82
+ body: JSONContent
83
+ /** Its files, which can be taken off; none can be added. */
84
+ files?: BoxFile[]
85
+ onCancel: () => void
86
+ /** Save; the box holds the words until the answer, and a refusal is said under it. */
87
+ onSave: (body: JSONContent, files: BoxFile[]) => Promise<SendAnswer>
88
+ }
89
+
90
+ export interface CommentBoxProps {
91
+ /** Who `@` and `!@` offer. */
92
+ people: readonly MentionPerson[]
93
+ /** What `[` lists for what was typed, already in the app's order. Absent, `[` opens nothing. */
94
+ references?: (query: string) => readonly ReferenceSection[]
95
+ /** Called with a listener while `[` is open; call it when `references` would answer differently (a search landed). */
96
+ referencesChanged?: (listener: () => void) => () => void
97
+ /** A `[` row's and chip's 16px icon from what it points at; absent, a neutral square. */
98
+ referenceIcon?: (uri: string | null) => ReactNode | undefined
99
+ /** The app's own `/` Insert rows, after the shared Format section: {@link commentBoxRows} and its own. */
100
+ insert?: readonly SlashCommand[]
101
+ /** `/` → Code: a mark inside the line, or a block. */
102
+ code?: CodeFormat
103
+ /** Send what is written, with the files that are ready; resolves with the relay's answer. */
104
+ send: (body: JSONContent, files: BoxFile[]) => Promise<SendAnswer>
105
+ /**
106
+ * The app shows a send before the relay answers: the box empties at once,
107
+ * and a refusal puts the words back. Otherwise the box holds the words, shut,
108
+ * until the answer.
109
+ */
110
+ showsAtOnce?: boolean
111
+ /** The editor's accessible name: what the box is for. */
112
+ label: string
113
+ /** Said in the empty box. */
114
+ placeholder: ReactNode
115
+ /** Keeps what is written when the box goes away. Give the box a React `key` per destination. */
116
+ draft?: CommentBoxDraft
117
+ /** Editing something already sent. */
118
+ edit?: CommentBoxEdit
119
+ /** Offers the paperclip, `/` → File, a pasted picture and a dropped file: uploads one, and answers. */
120
+ upload?: (file: File) => Promise<UploadAnswer>
121
+ /** The file picker's `accept`. */
122
+ accept?: string
123
+ /** The box cannot write here (an archived file, signed out): a line saying why takes its place. */
124
+ closed?: { reason: ReactNode }
125
+ /** How a `nostr:` reference the box holds is drawn — the app's own chip. Absent, as its URI. */
126
+ referenceView?: ComponentType<ReferenceViewProps>
127
+ /** The app's own extra editor extensions: link chips, highlights. */
128
+ extensions?: readonly AnyExtension[]
129
+ autoFocus?: boolean
130
+ /** Called with what was sent once it went out: at once when `showsAtOnce`, else on the answer. */
131
+ onSent?: (body: JSONContent, files: BoxFile[]) => void
132
+ /** Called when a send shown at once was refused, so the app takes it back. */
133
+ onRefused?: () => void
134
+ className?: string
135
+ }
136
+
137
+ const ATTACH_EVENT = 'commentbox:attach'
138
+
139
+ /** Asks the box around the editor for a file, as the paperclip does. */
140
+ const askForFile = (editor: Editor) => editor.view.dom.dispatchEvent(new CustomEvent(ATTACH_EVENT, { bubbles: true }))
141
+
142
+ /**
143
+ * The `/` Insert rows the kit offers. Pass the ones an app can perform, in
144
+ * its order, with its own after them; an edit drops File and Urgent itself.
145
+ */
146
+ export const commentBoxRows: Readonly<Record<'file' | 'mention' | 'urgent' | 'reference', SlashCommand>> = {
147
+ file: { key: 'insert-file', row: { label: 'File' }, keywords: ['attach', 'upload'], run: askForFile },
148
+ mention: { key: 'insert-mention', row: { label: 'Mention', shortcut: '@' }, keywords: ['@', 'Mention a person'], run: typeTrigger('@') },
149
+ urgent: { key: 'insert-urgent', row: { label: 'Urgent', shortcut: '!@' }, keywords: ['!@', 'Urgent mention'], run: typeTrigger('!@') },
150
+ reference: { key: 'insert-reference', row: { label: 'Reference', shortcut: '[' }, keywords: ['[', 'Reference'], run: typeTrigger('[') },
151
+ }
152
+
153
+ /** Ctrl/Cmd+Enter sends as Enter does; Escape cancels an edit (an open list takes Escape first). */
154
+ const BoxKeys = Extension.create<{ onEscape: () => boolean }>({
155
+ name: 'commentBoxKeys',
156
+ addOptions() {
157
+ return { onEscape: () => false }
158
+ },
159
+ addKeyboardShortcuts() {
160
+ return {
161
+ 'Mod-Enter': ({ editor }) => (editor.storage as unknown as { composeKeys?: { send: (() => boolean) | null } }).composeKeys?.send?.() ?? false,
162
+ // Open now, with no grace: the first Escape closes a list, the next is a deliberate cancel (suggestionPopup).
163
+ Escape: () => (isSuggestionOpen() ? false : this.options.onEscape()),
164
+ }
165
+ },
166
+ })
167
+
168
+ const SQUARE = <IconSquareRounded size={16} stroke={1.5} className="text-text-secondary" />
169
+ const SMALL_SQUARE = <IconSquareRounded size={14} stroke={1.5} />
170
+
171
+ let fileCount = 0
172
+
173
+ export function CommentBox({
174
+ people,
175
+ references,
176
+ referencesChanged,
177
+ referenceIcon,
178
+ insert = [],
179
+ code = 'block',
180
+ send,
181
+ showsAtOnce = false,
182
+ label,
183
+ placeholder,
184
+ draft,
185
+ edit,
186
+ upload,
187
+ accept,
188
+ closed,
189
+ referenceView,
190
+ extensions = [],
191
+ autoFocus,
192
+ onSent,
193
+ onRefused,
194
+ className,
195
+ }: CommentBoxProps) {
196
+ const [files, setFiles] = useState<BoxFile[]>(edit?.files ?? [])
197
+ const [sending, setSending] = useState(false)
198
+ const [refused, setRefused] = useState<string | null>(null)
199
+ const picker = useRef<HTMLInputElement>(null)
200
+ const root = useRef<HTMLDivElement>(null)
201
+ // The latest props, for the editor's callbacks, which are made once.
202
+ const latest = useRef({ edit, people, references, referencesChanged, referenceIcon, upload, draft })
203
+ latest.current = { edit, people, references, referencesChanged, referenceIcon, upload, draft }
204
+ const save = useRef<() => boolean>(() => false)
205
+
206
+ const attachFiles = useCallback((picked: File[]): boolean => {
207
+ const uploadOne = latest.current.upload
208
+ if (!uploadOne || latest.current.edit) return false
209
+ for (const file of picked) {
210
+ fileCount += 1
211
+ const id = `file-${fileCount}`
212
+ setFiles((all) => [...all, { id, name: file.name, size: file.size, contentType: file.type, state: 'uploading' }])
213
+ uploadOne(file).then(
214
+ (answer) =>
215
+ setFiles((all) =>
216
+ all.map((f) => (f.id !== id ? f : answer.accepted ? { ...f, state: 'ready', value: answer.value } : { ...f, state: 'failed', note: answer.reason })),
217
+ ),
218
+ () => setFiles((all) => all.map((f) => (f.id === id ? { ...f, state: 'failed', note: 'It could not be uploaded.' } : f))),
219
+ )
220
+ }
221
+ return true
222
+ }, [])
223
+
224
+ // An edit cannot add a file or make a mention urgent, as in every app before the box; no upload, no File.
225
+ const rows = insert.filter((c) => !((edit || !upload) && c.key === commentBoxRows.file.key) && !(edit && c.key === commentBoxRows.urgent.key))
226
+ // `/` reads its sections each time it opens, from this one array: refilled every render, so a row that
227
+ // comes or goes with `upload`, `insert` or `code` after the box opened is offered as it is now.
228
+ const sections = useRef<SlashSection[]>([]).current
229
+ sections.splice(0, sections.length, formatSection(code), ...(rows.length > 0 ? [{ label: 'Insert', commands: rows }] : []))
230
+ const iconFor = useCallback((uri: string | null) => latest.current.referenceIcon?.(uri), [])
231
+
232
+ const editor = useEditor({
233
+ extensions: [
234
+ StarterKit.configure({ link: { openOnClick: false } }),
235
+ KeptSelection,
236
+ ComposeKeys,
237
+ BoxKeys.configure({
238
+ onEscape: () => {
239
+ const editing = latest.current.edit
240
+ if (!editing) return false
241
+ editing.onCancel()
242
+ return true
243
+ },
244
+ }),
245
+ PersonMention.configure({ people: () => latest.current.people }),
246
+ // An edit makes nobody urgent (CON-24): `!@` opens no list there, as `/` offers no Urgent.
247
+ UrgentPersonMention.extend({
248
+ addOptions() {
249
+ const parent = this.parent!()
250
+ return { ...parent, suggestion: { ...parent.suggestion, allow: () => !latest.current.edit } }
251
+ },
252
+ }).configure({ people: () => latest.current.people }),
253
+ CaptionedReference.configure({ icon: SMALL_SQUARE, iconFor }),
254
+ ReferenceTrigger.configure({
255
+ items: () => [],
256
+ sections: (query) => latest.current.references?.(query) ?? [],
257
+ subscribe: (listener) => latest.current.referencesChanged?.(listener) ?? (() => {}),
258
+ ariaLabel: 'References',
259
+ sectionLabel: 'References',
260
+ icon: SQUARE,
261
+ iconFor,
262
+ }),
263
+ SlashCommands.configure({ sections }),
264
+ ReferenceNode.configure({ view: referenceView ?? null }),
265
+ PastedImages.configure({ onImages: attachFiles }),
266
+ ...extensions,
267
+ ],
268
+ content: edit?.body ?? draft?.read(),
269
+ editable: !closed,
270
+ editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES, role: 'textbox', 'aria-multiline': 'true', 'aria-label': label } },
271
+ })
272
+
273
+ // Drafts: every change is kept, and an empty box is no draft.
274
+ useEffect(() => {
275
+ if (!editor || edit) return
276
+ const keep = () => {
277
+ const kept = latest.current.draft
278
+ if (!kept) return
279
+ if (isEmpty(editor)) kept.clear()
280
+ else kept.write(editor.getJSON())
281
+ }
282
+ editor.on('update', keep)
283
+ return () => {
284
+ editor.off('update', keep)
285
+ }
286
+ }, [editor, edit])
287
+
288
+ useEffect(() => {
289
+ editor?.setEditable(!closed && !sending)
290
+ }, [editor, closed, sending])
291
+
292
+ useEffect(() => {
293
+ if (!editor || !(autoFocus || edit)) return
294
+ const frame = requestAnimationFrame(() => editor.commands.focus('end'))
295
+ return () => cancelAnimationFrame(frame)
296
+ // Once, as the box opens.
297
+ }, [editor])
298
+
299
+ // `/` → File asks for a file the way the paperclip does.
300
+ useEffect(() => {
301
+ const box = root.current
302
+ if (!box || !upload || edit) return
303
+ const ask = () => picker.current?.click()
304
+ box.addEventListener(ATTACH_EVENT, ask)
305
+ return () => box.removeEventListener(ATTACH_EVENT, ask)
306
+ }, [upload, edit])
307
+
308
+ const uploading = files.some((f) => f.state === 'uploading')
309
+ const ready = files.some((f) => f.state === 'ready')
310
+
311
+ const go = useCallback(
312
+ (ed: Editor): boolean => {
313
+ const body = ed.getJSON()
314
+ const sent = files.filter((f) => f.state === 'ready')
315
+ setRefused(null)
316
+ const answered = (answer: Promise<SendAnswer>) => answer.catch((): SendAnswer => ({ accepted: false, reason: 'try again in a moment' }))
317
+ if (showsAtOnce) {
318
+ // Shown at once: the box empties now (ComposeBox clears it); a refusal puts the words back above anything written since.
319
+ setFiles((all) => all.filter((f) => f.state !== 'ready'))
320
+ draft?.clear()
321
+ onSent?.(body, sent)
322
+ void answered(send(body, sent)).then((answer) => {
323
+ if (answer.accepted) return
324
+ onRefused?.()
325
+ if (ed.isDestroyed) {
326
+ // The box went away before the answer: the words wait in its draft.
327
+ draft?.write(body)
328
+ return
329
+ }
330
+ if (isEmpty(ed)) ed.commands.setContent(body)
331
+ else ed.commands.insertContentAt(0, body.content ?? [])
332
+ ed.commands.focus('end')
333
+ setFiles((all) => [...sent, ...all])
334
+ setRefused(answer.reason)
335
+ })
336
+ return true
337
+ }
338
+ // Held: the words stay, shut, until the relay answers.
339
+ setSending(true)
340
+ void answered(send(body, sent)).then((answer) => {
341
+ setSending(false)
342
+ if (!answer.accepted) {
343
+ setRefused(answer.reason)
344
+ return
345
+ }
346
+ if (!ed.isDestroyed) ed.commands.clearContent(true)
347
+ setFiles((all) => all.filter((f) => !sent.includes(f)))
348
+ draft?.clear()
349
+ onSent?.(body, sent)
350
+ })
351
+ return false
352
+ },
353
+ [files, showsAtOnce, send, draft, onSent, onRefused],
354
+ )
355
+
356
+ save.current = () => {
357
+ if (!editor || !edit || sending || uploading) return true
358
+ setRefused(null)
359
+ setSending(true)
360
+ void edit
361
+ .onSave(editor.getJSON(), files)
362
+ .catch((): SendAnswer => ({ accepted: false, reason: 'try again in a moment' }))
363
+ .then((answer) => {
364
+ setSending(false)
365
+ if (!answer.accepted) setRefused(answer.reason)
366
+ })
367
+ return true
368
+ }
369
+
370
+ // Enter and Ctrl/Cmd+Enter save an edit; the send box wires them through ComposeBox.
371
+ useEffect(() => {
372
+ if (!editor || !edit) return
373
+ const storage = (editor.storage as unknown as { composeKeys?: { send: (() => boolean) | null } }).composeKeys
374
+ if (!storage) return
375
+ storage.send = () => save.current()
376
+ return () => {
377
+ storage.send = null
378
+ }
379
+ }, [editor, edit])
380
+
381
+ if (closed) {
382
+ return (
383
+ <Card fill="inset" className={cn('flex items-start gap-3 px-4 py-3', className)}>
384
+ <IconLock size={16} stroke={1.5} className="mt-0.5 shrink-0 text-text-muted" aria-hidden />
385
+ <p className="text-body-2 text-text-secondary">{closed.reason}</p>
386
+ </Card>
387
+ )
388
+ }
389
+
390
+ const fileCards =
391
+ files.length > 0 ? (
392
+ <>
393
+ {files.map((f) => (
394
+ <AttachmentCard
395
+ key={f.id}
396
+ pending
397
+ name={f.name}
398
+ size={f.size}
399
+ contentType={f.contentType}
400
+ state={f.state}
401
+ note={f.note}
402
+ onRemove={() => setFiles((all) => all.filter((one) => one !== f))}
403
+ />
404
+ ))}
405
+ </>
406
+ ) : undefined
407
+
408
+ const refusedLine = refused && (
409
+ <FieldLine tone="error">
410
+ {edit ? `Not saved: ${refused}. Your changes are still in the box.` : `Not sent: ${refused}. Your text is back in the box.`}
411
+ </FieldLine>
412
+ )
413
+
414
+ if (edit) {
415
+ return (
416
+ <div className={cn('flex flex-col gap-1', className)}>
417
+ <div className={cn(WRITING_BOX_CLASSES, 'focus-within:border-border-strong transition-colors', sending && '[&_.ProseMirror]:text-text-muted')}>
418
+ <EditorContent editor={editor} />
419
+ {fileCards && <div className="flex flex-wrap gap-2">{fileCards}</div>}
420
+ <div className="flex items-center justify-between gap-2">
421
+ <span className="flex items-center gap-1 text-caption text-text-muted">
422
+ <Kbd>Esc</Kbd> to cancel · <Kbd>Enter</Kbd> to save
423
+ </span>
424
+ <div className="flex items-center gap-2">
425
+ <Button variant="outlined" size="small" onClick={edit.onCancel}>
426
+ Cancel
427
+ </Button>
428
+ <Button variant="primary" size="small" disabled={uploading || sending} onClick={() => save.current()}>
429
+ Save
430
+ </Button>
431
+ </div>
432
+ </div>
433
+ </div>
434
+ {sending && <FieldLine>Saving…</FieldLine>}
435
+ {refusedLine}
436
+ </div>
437
+ )
438
+ }
439
+
440
+ const onDrop = (event: DragEvent<HTMLDivElement>) => {
441
+ const dropped = Array.from(event.dataTransfer?.files ?? [])
442
+ if (dropped.length === 0 || !upload) return
443
+ event.preventDefault()
444
+ attachFiles(dropped)
445
+ }
446
+
447
+ return (
448
+ <div ref={root} className={cn('flex flex-col gap-1', className)} onDragOver={upload ? (e) => e.preventDefault() : undefined} onDrop={onDrop}>
449
+ <ComposeBox
450
+ editor={editor}
451
+ onSend={go}
452
+ placeholder={placeholder}
453
+ tools={
454
+ upload ? (
455
+ <ToolbarButton tooltip="Attach a file" aria-label="Attach a file" disabled={sending} onClick={() => picker.current?.click()}>
456
+ <IconPaperclip size={16} stroke={1.5} />
457
+ </ToolbarButton>
458
+ ) : undefined
459
+ }
460
+ attachments={fileCards}
461
+ ready={ready}
462
+ holding={uploading || sending}
463
+ selection={{ link: true }}
464
+ className={cn(sending && '[&_[data-composer-editor]]:text-text-muted')}
465
+ />
466
+ {upload && <FilePicker ref={picker} multiple accept={accept} onPick={attachFiles} />}
467
+ {sending && <FieldLine>Sending…</FieldLine>}
468
+ {uploading && !sending && <FieldLine>Uploading… Send waits for the file.</FieldLine>}
469
+ {refusedLine}
470
+ </div>
471
+ )
472
+ }
@@ -59,13 +59,14 @@ export const ComposeKeys = Extension.create<Record<string, never>, ComposeKeysSt
59
59
  },
60
60
  })
61
61
 
62
- /** Nothing written: no text, no chip and no picture — empty lines, lists or quotes only. */
63
- function isEmptyDoc(editor: Editor): boolean {
62
+ /** Nothing written: no text, no chip and no picture — empty lines, spaces, lists or quotes only. */
63
+ export function isEmptyDoc(editor: Editor): boolean {
64
64
  const doc = editor.state.doc
65
- if (doc.textContent.length > 0) return false
65
+ if (doc.textContent.trim().length > 0) return false
66
66
  let empty = true
67
67
  doc.descendants((node) => {
68
- if (node.isAtom && node.type.name !== 'hardBreak') empty = false
68
+ // A text node is a leaf, so an atom too: only spaces are left of it here.
69
+ if (node.isAtom && !node.isText && node.type.name !== 'hardBreak') empty = false
69
70
  })
70
71
  return empty
71
72
  }
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from 'react'
2
2
  import { IconMessage2 } from '@tabler/icons-react'
3
- import { Button } from './Button'
3
+ import { Button, type ButtonAction } from './Button'
4
4
  import { cn } from './cn'
5
5
 
6
6
  /**
@@ -34,7 +34,7 @@ export interface EmptyStateProps {
34
34
  * the line as the package's Button, outlined (Katerina, 2026-09-18). A `page`
35
35
  * only: a section's empty line is one line among others, not a stage.
36
36
  */
37
- action?: { label: string; onClick: () => void }
37
+ action?: ButtonAction
38
38
  className?: string
39
39
  }
40
40
 
@@ -0,0 +1,69 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as EntryShellStories from './EntryShell.stories'
3
+
4
+ <Meta of={EntryShellStories} />
5
+
6
+ # EntryShell
7
+
8
+ What an app shows while nobody is signed in to it: its logo, one line saying
9
+ why, and at most one button.
10
+
11
+ <Canvas of={EntryShellStories.MessageWithAction} />
12
+
13
+ ## When
14
+
15
+ - **`busy`**: entry is still being decided. The logo alone, faded in after
16
+ 150ms, so an entry that resolves at once flashes nothing. It carries the
17
+ pulse class too, as Peek's did; the reveal overrides it here, and an app
18
+ that themes the pulse draws its own instead.
19
+ - **A `message` and an `action`**: entry stopped and one thing would get the
20
+ person in.
21
+ - **A `message` alone**: entry stopped and nothing the person can do would
22
+ help, so there is no button.
23
+ - **An `action` alone**: the button with no line over it.
24
+ - **`action.disabled`**: the button held while what it started is still
25
+ running, so a second tap starts nothing.
26
+
27
+ <Canvas of={EntryShellStories.Busy} />
28
+
29
+ <Canvas of={EntryShellStories.MessageOnly} />
30
+
31
+ ## When not
32
+
33
+ - Inside the app's frame. It stands in *for* the whole app while entry is
34
+ decided; a page or a section with nothing to show inside the frame is an
35
+ [**EmptyState**](?path=/docs/feedback-emptystate--docs).
36
+
37
+ ## How
38
+
39
+ ```tsx
40
+ import { EntryShell } from '@estiva-app/ui'
41
+
42
+ <EntryShell logo={appLogo} busy busyLabel="Opening" />
43
+
44
+ <EntryShell
45
+ logo={appLogo}
46
+ message={why}
47
+ action={canRecover ? { label: continueLabel, onClick: start, disabled: starting } : undefined}
48
+ />
49
+ ```
50
+
51
+ - **The words are the caller's**: the line, the button's label and
52
+ `busyLabel`.
53
+ - **`action.onClick` runs from the tap itself.** Start anything that needs the
54
+ person's gesture there, not behind anything asynchronous, and pass
55
+ `disabled` while it runs.
56
+ - **The logo is drawn as given**, at the size the app draws its mark. While
57
+ `busy`, the pulse goes on that element itself, so it must take a
58
+ `className`.
59
+ - **What a screen reader hears**: while `busy`, a busy status named
60
+ `busyLabel` ("Loading" when you pass none); afterwards the line is a polite
61
+ status, read when it appears.
62
+
63
+ ## What it owns
64
+
65
+ Nothing. It only draws. Clicks and keys are yours.
66
+
67
+ ## Props
68
+
69
+ <Controls of={EntryShellStories.MessageWithAction} />
@@ -0,0 +1,48 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { IconSquareRounded } from '@tabler/icons-react'
3
+ import { EntryShell } from './EntryShell'
4
+
5
+ // A stand-in for an app's mark, at the 40px an app's logo badge is drawn at.
6
+ const logo = (
7
+ <div role="img" aria-label="Logo" className="flex size-10 items-center justify-center rounded-xl bg-accent-muted text-accent-text">
8
+ <IconSquareRounded size={16} stroke={1.5} />
9
+ </div>
10
+ )
11
+
12
+ const meta = {
13
+ title: 'Frame/EntryShell',
14
+ component: EntryShell,
15
+ parameters: { layout: 'fullscreen' },
16
+ args: { logo },
17
+ argTypes: { logo: { control: false } },
18
+ } satisfies Meta<typeof EntryShell>
19
+
20
+ export default meta
21
+ type Story = StoryObj<typeof meta>
22
+
23
+ /** The line and the one thing to do about it. */
24
+ export const MessageWithAction: Story = {
25
+ args: { message: 'One line saying why the app cannot open yet.', action: { label: 'Continue', onClick: () => {} } },
26
+ }
27
+
28
+ /** The logo alone, faded in after 150ms. */
29
+ export const Busy: Story = {
30
+ args: { busy: true },
31
+ }
32
+
33
+ /** The line alone, when nothing the person can do would help. A longer line wraps at its width. */
34
+ export const MessageOnly: Story = {
35
+ args: {
36
+ message: 'A longer line, for a reason that needs two sentences. It wraps at the width the line is given and stays centred under the logo.',
37
+ },
38
+ }
39
+
40
+ /** The button held while what it started is still running. */
41
+ export const ActionDisabled: Story = {
42
+ args: { message: 'One line saying why the app cannot open yet.', action: { label: 'Continue', onClick: () => {}, disabled: true } },
43
+ }
44
+
45
+ /** The button alone, with no line. */
46
+ export const ActionOnly: Story = {
47
+ args: { action: { label: 'Try again', onClick: () => {} } },
48
+ }