@estiva-app/ui 0.97.0 → 0.98.1
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.
- package/dist/ConversationCard.d.ts +24 -6
- package/dist/ConversationCard.d.ts.map +1 -1
- package/dist/ConversationLayout.d.ts +18 -6
- package/dist/ConversationLayout.d.ts.map +1 -1
- package/dist/ConversationMenu.d.ts +14 -5
- package/dist/ConversationMenu.d.ts.map +1 -1
- package/dist/ReactionHorizon.d.ts +3 -1
- package/dist/ReactionHorizon.d.ts.map +1 -1
- package/dist/Thread.d.ts +9 -2
- package/dist/Thread.d.ts.map +1 -1
- package/dist/index.js +159 -68
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/registry.json +140 -18
- package/src/ConversationCard.mdx +4 -2
- package/src/ConversationCard.states.test.tsx +25 -5
- package/src/ConversationCard.stories.tsx +3 -3
- package/src/ConversationCard.test.tsx +44 -4
- package/src/ConversationCard.tsx +69 -36
- package/src/ConversationLayout.mdx +12 -0
- package/src/ConversationLayout.stories.tsx +47 -0
- package/src/ConversationLayout.test.tsx +100 -0
- package/src/ConversationLayout.tsx +98 -20
- package/src/ConversationMenu.mdx +5 -2
- package/src/ConversationMenu.stories.tsx +19 -1
- package/src/ConversationMenu.test.tsx +17 -4
- package/src/ConversationMenu.tsx +37 -16
- package/src/ReactionHorizon.mdx +1 -0
- package/src/ReactionHorizon.test.tsx +23 -0
- package/src/ReactionHorizon.tsx +4 -2
- package/src/Thread.mdx +2 -0
- package/src/Thread.test.tsx +17 -0
- package/src/Thread.tsx +32 -8
- package/src/linkedFrom.test.tsx +18 -0
- package/src/linkedFrom.ts +2 -2
- package/stories/Choosing.mdx +1 -1
package/src/ConversationCard.tsx
CHANGED
|
@@ -34,6 +34,8 @@ export interface ConversationEntryProps {
|
|
|
34
34
|
time: ReactNode
|
|
35
35
|
/** A link to it: the time is then the link, "Link to this", as a reply's is. */
|
|
36
36
|
timeHref?: string
|
|
37
|
+
/** The time's tooltip when it is a link, in the app's words: "Link to this" by default; Peek's "Link to this message". */
|
|
38
|
+
timeLabel?: string
|
|
37
39
|
/** When it was last edited, in the app's words for the tooltip ("Edited 11:20 AM"): draws "(edited)". */
|
|
38
40
|
edited?: string
|
|
39
41
|
/** The words, as the app draws them: text, mentions, links, attached cards, quoted blocks. */
|
|
@@ -60,10 +62,19 @@ export interface ConversationEntryProps {
|
|
|
60
62
|
onEditingChange?: (editing: boolean) => void
|
|
61
63
|
/** Delete, after the card has asked. */
|
|
62
64
|
onDelete?: () => Promise<boolean | void> | boolean | void
|
|
63
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The app's own words under the delete question, what deleting does there, in place of the kit's: "It is deleted for
|
|
67
|
+
* everyone.", and on a comment how many replies stay. A string is one paragraph; a node is drawn as given.
|
|
68
|
+
*/
|
|
64
69
|
deleteNote?: ReactNode
|
|
65
|
-
/** The app's own rows in the ⋯ menu: `MenuItem`s. */
|
|
70
|
+
/** The app's own rows in the ⋯ menu, after Resolve: `MenuItem`s. */
|
|
66
71
|
menu?: ReactNode
|
|
72
|
+
/** The app's own rows in the ⋯ menu after Edit, before Delete: Peek's "View details". */
|
|
73
|
+
menuAfter?: ReactNode
|
|
74
|
+
/** A heading over the menu's first rows, in the app's words: Peek's "Utilities". */
|
|
75
|
+
menuLabel?: string
|
|
76
|
+
/** Edit's words in the ⋯ menu: "Edit" by default; Peek's "Edit message". */
|
|
77
|
+
editLabel?: string
|
|
67
78
|
/** Placement only. */
|
|
68
79
|
className?: string
|
|
69
80
|
}
|
|
@@ -76,11 +87,18 @@ export interface ConversationCardProps extends ConversationEntryProps {
|
|
|
76
87
|
/** Reply: offered on the strip. */
|
|
77
88
|
onReply?: () => void
|
|
78
89
|
/**
|
|
79
|
-
* Resolved, by whom, with what note and when (`at`, in the app's words)
|
|
80
|
-
*
|
|
81
|
-
*
|
|
90
|
+
* Resolved, by whom, with what note and when (`at`, in the app's words): "✓ Resolved" by the time, who and the note on
|
|
91
|
+
* hover; "Person two → the note · time" above the replies row. Nothing of the comment is hidden: its words, cards,
|
|
92
|
+
* files and reactions stay (Katerina, 1 November: nothing folds, in any app).
|
|
82
93
|
*/
|
|
83
94
|
resolved?: { by: string; note?: string; at?: string }
|
|
95
|
+
/**
|
|
96
|
+
* What the comment is called in the delete question: "Delete this comment?" by default. A direct message says
|
|
97
|
+
* `message` (Katerina, 1 November: "comment" reads wrong in a private chat).
|
|
98
|
+
*/
|
|
99
|
+
noun?: string
|
|
100
|
+
/** Beside Resolve in the ⋯ menu, how the app's box resolves too, as its key hint: Peek's "->". */
|
|
101
|
+
resolveHint?: string
|
|
84
102
|
/** Resolve, with the note written in the dialog the card opens. Offered on the strip and in the menu. */
|
|
85
103
|
onResolve?: (note: string) => Promise<boolean | void> | boolean | void
|
|
86
104
|
/** Why the last resolve was refused, in plain words: said under the note, while the dialog stays open (`onResolve` answered `false`). */
|
|
@@ -95,7 +113,7 @@ export interface ConversationCardProps extends ConversationEntryProps {
|
|
|
95
113
|
export type ReplyCardProps = ConversationEntryProps
|
|
96
114
|
|
|
97
115
|
/** The face, the name, the time and "(edited)", with the new mark at the far right. `meta`: after "(edited)". */
|
|
98
|
-
function Head({ author, time, timeHref, edited, isNew, urgent, meta }: Pick<ConversationEntryProps, 'author' | 'time' | 'timeHref' | 'edited' | 'isNew' | 'urgent'> & { meta?: ReactNode }) {
|
|
116
|
+
function Head({ author, time, timeHref, timeLabel = 'Link to this', edited, isNew, urgent, meta }: Pick<ConversationEntryProps, 'author' | 'time' | 'timeHref' | 'timeLabel' | 'edited' | 'isNew' | 'urgent'> & { meta?: ReactNode }) {
|
|
99
117
|
return (
|
|
100
118
|
<div className="flex w-full items-center gap-2">
|
|
101
119
|
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
@@ -104,7 +122,7 @@ function Head({ author, time, timeHref, edited, isNew, urgent, meta }: Pick<Conv
|
|
|
104
122
|
</span>
|
|
105
123
|
<span className="min-w-0 truncate text-body-2-strong text-text-primary">{author.name}</span>
|
|
106
124
|
{timeHref ? (
|
|
107
|
-
<WithTooltip label=
|
|
125
|
+
<WithTooltip label={timeLabel} wrapperClassName="shrink-0">
|
|
108
126
|
<MetaText className="contents">
|
|
109
127
|
<Link href={timeHref} variant="quiet" data-interactive>
|
|
110
128
|
{time}
|
|
@@ -129,7 +147,7 @@ function attentionOf(fresh: boolean, urgent: boolean, inThreadCard: boolean) {
|
|
|
129
147
|
}
|
|
130
148
|
|
|
131
149
|
/**
|
|
132
|
-
*
|
|
150
|
+
* Who resolved it and the note (Katerina, 1 November), "Person two → Keeping the first one. · 12:30 PM", in the
|
|
133
151
|
* thread's own line (the dot in the faces' column). No "resolved": the check by the time says it.
|
|
134
152
|
*/
|
|
135
153
|
function EndedLine({ by, note, at }: { by: string; note: string; at?: string }) {
|
|
@@ -165,18 +183,10 @@ function ResolvedCheck({ by, note, at }: { by: string; note?: string; at?: strin
|
|
|
165
183
|
)
|
|
166
184
|
}
|
|
167
185
|
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
* the cards and pictures among them held back, at either level, then one line, cut with … where the text allows.
|
|
171
|
-
* Text blocks stay: paragraphs, lists, quotes, code.
|
|
172
|
-
*/
|
|
173
|
-
const FOLDED_WORDS_CLASSES =
|
|
174
|
-
'[&>div]:line-clamp-1 [&>div]:max-h-[1lh] [&>div>*:not(p):not(ul):not(ol):not(blockquote):not(pre):not(div:only-child)]:hidden [&>div>div:only-child>*:not(p):not(ul):not(ol):not(blockquote):not(pre)]:hidden'
|
|
175
|
-
|
|
176
|
-
/** The words' own look: Peek's message body, 14px secondary, blocks 8px apart. `oneLine`: folded, the first line only. */
|
|
177
|
-
function Words({ children, oneLine = false }: { children: ReactNode; oneLine?: boolean }) {
|
|
186
|
+
/** The words' own look: Peek's message body, 14px secondary, blocks 8px apart. */
|
|
187
|
+
function Words({ children }: { children: ReactNode }) {
|
|
178
188
|
return (
|
|
179
|
-
<div className=
|
|
189
|
+
<div className="relative w-full break-words pb-2 pl-8 pr-2 pt-1">
|
|
180
190
|
<div className="flex flex-col gap-2 text-body-2 text-text-secondary">{children}</div>
|
|
181
191
|
</div>
|
|
182
192
|
)
|
|
@@ -247,11 +257,11 @@ function useEditing(editing: boolean | undefined, onEditingChange: ((editing: bo
|
|
|
247
257
|
|
|
248
258
|
/**
|
|
249
259
|
* One comment: who, when, the words, files, cards, reactions, and the way into its replies, with the strip on hover
|
|
250
|
-
* and the ⋯ menu. Resolved, it
|
|
260
|
+
* and the ⋯ menu. Resolved, it says who resolved it and the note; nothing of it is hidden.
|
|
251
261
|
* The same card in every app, each in its own colours (the record that makes one conversation). Peek's, moved.
|
|
252
262
|
*/
|
|
253
263
|
export function ConversationCard(props: ConversationCardProps) {
|
|
254
|
-
const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, deleted = false, replies, onReply, resolved, onResolve, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, menu, className, children } = props
|
|
264
|
+
const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, deleted = false, replies, onReply, resolved, noun = 'comment', onResolve, resolveHint, resolveRefused, onReopen, selected, onClick, onDelete, deleteNote, menu, menuAfter, menuLabel, editLabel, className, children } = props
|
|
255
265
|
const readOnly = (props.readOnly ?? false) || deleted
|
|
256
266
|
const inThreadCard = useContext(InThreadCard)
|
|
257
267
|
|
|
@@ -278,7 +288,7 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
278
288
|
// Once its picker or menu has closed: the strip only if the card is still pointed at.
|
|
279
289
|
const settle = () => requestAnimationFrame(() => setHovered(stillHere(root.current)))
|
|
280
290
|
// The ⋯ menu only when it has a row to show: Resolve or Reopen, the app's rows, or Edit and Delete on your own.
|
|
281
|
-
const offersMenu = !!resolves || !!menu || (own && (!!editor || !!onDelete))
|
|
291
|
+
const offersMenu = !!resolves || !!menu || !!menuAfter || (own && (!!editor || !!onDelete))
|
|
282
292
|
const showStrip = hovered && !isEditing && !readOnly
|
|
283
293
|
const react = reactions?.onToggle
|
|
284
294
|
// Read-only with no replies, there is nothing to open: no box to write in, no thread to read (Peek's way, Katerina, 1 November).
|
|
@@ -286,10 +296,6 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
286
296
|
const reply = onReply ?? item?.show
|
|
287
297
|
const marked = selected ?? (item && !item.under ? item.open : undefined)
|
|
288
298
|
const under = !!item?.under
|
|
289
|
-
// Closed: its thread is not open, under it or beside it (the layout's, or the app's own `selected`).
|
|
290
|
-
const closed = !inThreadCard && !marked
|
|
291
|
-
// Folded: resolved, its thread closed, the words' first line only (Katerina, 1 November).
|
|
292
|
-
const folded = !!resolved && closed
|
|
293
299
|
const repliesRow = replies && replies.count > 0 && (
|
|
294
300
|
<RepliesRow {...replies} onOpen={replies.onOpen ?? (under ? item?.toggle : undefined)} open={replies.open ?? (under && !!item?.open)} urgent={urgent} />
|
|
295
301
|
)
|
|
@@ -311,6 +317,19 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
311
317
|
attention={attentionOf(isNew || !!replies?.isNew, urgent, inThreadCard)}
|
|
312
318
|
className={cn('relative', className)}
|
|
313
319
|
onClick={press && !isEditing && !overlay ? (e) => pressed(e, press) : undefined}
|
|
320
|
+
// A card that opens on a press is reached by the keyboard too: Tab stops on it, which shows its strip, and Enter or
|
|
321
|
+
// Space opens it. Only the card's own focus: a key in a link, a button or a field inside it is theirs. Before, a
|
|
322
|
+
// comment with nothing focusable in it (no replies, no link) could not be opened without a pointer.
|
|
323
|
+
tabIndex={press && !isEditing ? 0 : undefined}
|
|
324
|
+
onKeyDown={
|
|
325
|
+
press && !isEditing && !overlay
|
|
326
|
+
? (e) => {
|
|
327
|
+
if (e.target !== e.currentTarget || (e.key !== 'Enter' && e.key !== ' ')) return
|
|
328
|
+
e.preventDefault()
|
|
329
|
+
press()
|
|
330
|
+
}
|
|
331
|
+
: undefined
|
|
332
|
+
}
|
|
314
333
|
onMouseEnter={() => setHovered(true)}
|
|
315
334
|
onMouseLeave={() => {
|
|
316
335
|
if (picking || menuOpen) return
|
|
@@ -334,6 +353,7 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
334
353
|
author={author}
|
|
335
354
|
time={props.time}
|
|
336
355
|
timeHref={props.timeHref}
|
|
356
|
+
timeLabel={props.timeLabel}
|
|
337
357
|
edited={props.edited}
|
|
338
358
|
isNew={isNew}
|
|
339
359
|
urgent={urgent}
|
|
@@ -343,15 +363,15 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
343
363
|
// Under the name, above the words (Katerina, 1 November).
|
|
344
364
|
<div className="relative w-full pl-8 pr-2 pt-0.5">{about}</div>
|
|
345
365
|
)}
|
|
346
|
-
<Words
|
|
366
|
+
<Words>
|
|
347
367
|
{children}
|
|
348
368
|
</Words>
|
|
349
369
|
</>
|
|
350
370
|
)}
|
|
351
|
-
{!deleted && files &&
|
|
371
|
+
{!deleted && files && (
|
|
352
372
|
<div className="relative flex w-full flex-wrap items-start gap-2 pb-2 pl-8 pr-2">{files}</div>
|
|
353
373
|
)}
|
|
354
|
-
|
|
374
|
+
<Reactions reactions={reactions} refused={reactionRefused} readOnly={readOnly} />
|
|
355
375
|
{resolved?.note && (
|
|
356
376
|
// Who resolved it and the note, above the way into the replies; the check by the time says "Resolved" (Katerina, 1 November).
|
|
357
377
|
<div className="relative w-full pb-1">
|
|
@@ -397,7 +417,11 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
397
417
|
resolved={!!resolved}
|
|
398
418
|
onResolve={onResolve && (() => setResolving(true))}
|
|
399
419
|
onReopen={onReopen}
|
|
420
|
+
resolveHint={resolveHint}
|
|
421
|
+
label={menuLabel}
|
|
400
422
|
onEdit={own && editor ? () => setEditing(true) : undefined}
|
|
423
|
+
editLabel={editLabel}
|
|
424
|
+
after={menuAfter}
|
|
401
425
|
onDelete={own && onDelete ? () => setDeleting(true) : undefined}
|
|
402
426
|
>
|
|
403
427
|
{menu}
|
|
@@ -409,9 +433,15 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
409
433
|
)}
|
|
410
434
|
</Card>
|
|
411
435
|
{deleting && onDelete && (
|
|
412
|
-
<ConfirmDialog title=
|
|
413
|
-
|
|
414
|
-
|
|
436
|
+
<ConfirmDialog title={`Delete this ${noun}?`} confirmLabel={`Delete ${noun}`} destructive onConfirm={onDelete} onClose={() => setDeleting(false)}>
|
|
437
|
+
{deleteNote !== undefined ? (
|
|
438
|
+
typeof deleteNote === 'string' ? <p>{deleteNote}</p> : deleteNote
|
|
439
|
+
) : (
|
|
440
|
+
<>
|
|
441
|
+
<p>It is deleted for everyone.</p>
|
|
442
|
+
{replies && replies.count > 0 && <p>Its {replies.count === 1 ? 'reply stays' : `${replies.count} replies stay`}.</p>}
|
|
443
|
+
</>
|
|
444
|
+
)}
|
|
415
445
|
</ConfirmDialog>
|
|
416
446
|
)}
|
|
417
447
|
{resolving && onResolve && (
|
|
@@ -434,7 +464,7 @@ export function ConversationCard(props: ConversationCardProps) {
|
|
|
434
464
|
* when it has one. Peek's, moved with the conversation.
|
|
435
465
|
*/
|
|
436
466
|
export function ReplyCard(props: ReplyCardProps) {
|
|
437
|
-
const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, menu, className, children } = props
|
|
467
|
+
const { author, about, files, reactions, reactionRefused, isNew = false, urgent = false, own = false, editor, onDelete, deleteNote, menu, menuAfter, menuLabel, editLabel, className, children } = props
|
|
438
468
|
const readOnly = props.readOnly ?? false
|
|
439
469
|
const [hovered, setHovered] = useState(false)
|
|
440
470
|
const [menuOpen, setMenuOpen] = useState(false)
|
|
@@ -442,7 +472,7 @@ export function ReplyCard(props: ReplyCardProps) {
|
|
|
442
472
|
const [deleting, setDeleting] = useState(false)
|
|
443
473
|
const [editing, setEditing] = useEditing(props.editing, props.onEditingChange)
|
|
444
474
|
const isEditing = editing && !readOnly && !!editor
|
|
445
|
-
const offersMenu = !!menu || (own && (!!editor || !!onDelete))
|
|
475
|
+
const offersMenu = !!menu || !!menuAfter || (own && (!!editor || !!onDelete))
|
|
446
476
|
const showStrip = hovered && !isEditing && !readOnly && (offersMenu || !!reactions?.onToggle)
|
|
447
477
|
const root = useRef<HTMLDivElement>(null)
|
|
448
478
|
const settle = () => requestAnimationFrame(() => setHovered(stillHere(root.current)))
|
|
@@ -474,7 +504,7 @@ export function ReplyCard(props: ReplyCardProps) {
|
|
|
474
504
|
<Editing author={author}>{editor(() => setEditing(false))}</Editing>
|
|
475
505
|
) : (
|
|
476
506
|
<div className="flex flex-col items-start px-2 pt-2">
|
|
477
|
-
<Head author={author} time={props.time} timeHref={props.timeHref} edited={props.edited} isNew={isNew} urgent={urgent} />
|
|
507
|
+
<Head author={author} time={props.time} timeHref={props.timeHref} timeLabel={props.timeLabel} edited={props.edited} isNew={isNew} urgent={urgent} />
|
|
478
508
|
{/* As on a comment: under the name, above the words. */}
|
|
479
509
|
{about && <div className="w-full pl-8 pr-2 pt-0.5">{about}</div>}
|
|
480
510
|
<Words>{children}</Words>
|
|
@@ -504,7 +534,10 @@ export function ReplyCard(props: ReplyCardProps) {
|
|
|
504
534
|
setMenuOpen(next)
|
|
505
535
|
if (!next) settle()
|
|
506
536
|
}}
|
|
537
|
+
label={menuLabel}
|
|
507
538
|
onEdit={own && editor ? () => setEditing(true) : undefined}
|
|
539
|
+
editLabel={editLabel}
|
|
540
|
+
after={menuAfter}
|
|
508
541
|
onDelete={own && onDelete ? () => setDeleting(true) : undefined}
|
|
509
542
|
>
|
|
510
543
|
{menu}
|
|
@@ -516,7 +549,7 @@ export function ReplyCard(props: ReplyCardProps) {
|
|
|
516
549
|
</Card>
|
|
517
550
|
{deleting && onDelete && (
|
|
518
551
|
<ConfirmDialog title="Delete this reply?" confirmLabel="Delete reply" destructive onConfirm={onDelete} onClose={() => setDeleting(false)}>
|
|
519
|
-
|
|
552
|
+
{deleteNote === undefined ? <p>It is deleted for everyone.</p> : typeof deleteNote === 'string' ? <p>{deleteNote}</p> : deleteNote}
|
|
520
553
|
</ConfirmDialog>
|
|
521
554
|
)}
|
|
522
555
|
</>
|
|
@@ -14,6 +14,12 @@ Where a conversation's cards sit: two columns, or one 384px column beside the pa
|
|
|
14
14
|
- `threads="beside"`, two columns: the comments fill the page; an open thread stands beside them, 384px.
|
|
15
15
|
- `threads="under"`, one column: the comments are the 384px column beside the page; a thread opens under its comment, and the two become one card.
|
|
16
16
|
- With two columns, `header` puts the comments' own **PageHeader** over their column only, and the thread runs the page's full height beside it.
|
|
17
|
+
- With two columns, each comment's `day` names its stretch with a line that stays at the top while the stretch scrolls (Peek's day lines).
|
|
18
|
+
|
|
19
|
+
<Canvas of={Stories.TwoColumnsDays} />
|
|
20
|
+
|
|
21
|
+
<Canvas of={Stories.TwoColumnsArchived} />
|
|
22
|
+
|
|
17
23
|
- With one column, an item that is `resolved` waits closed under "Resolved" at the end, and one whose part was deleted (`gone`) under "On deleted blocks" before it, each with how many. A group opens by itself for the thread open in it. With two columns they stay in their place.
|
|
18
24
|
|
|
19
25
|
<Canvas of={Stories.OneColumn} />
|
|
@@ -40,6 +46,12 @@ import { ConversationLayout } from '@estiva-app/ui'
|
|
|
40
46
|
- Write nothing on the cards for opening: no `onClick`, `selected`, `onReply`, or the replies row's `onOpen` and
|
|
41
47
|
`open`. The layout gives each **ConversationCard** its place, and the card opens its thread from it. What a card is
|
|
42
48
|
given still wins.
|
|
49
|
+
- Two columns, an app that keeps its own place in the comments (where they were left, a "New" line, following what
|
|
50
|
+
arrives) has their scrolling box with `bodyRef` and `onBodyScroll`. Each comment's `day` draws the app's day lines,
|
|
51
|
+
each staying at the top while its own day scrolls under it; `before` is a line just above one comment (a "New"
|
|
52
|
+
line); `below` is under the comments (a **ReactionHorizon**); `top` stands at the top however few the comments are
|
|
53
|
+
(an **ArchivedNotice**). Few comments sit on the box, as a chat does. `empty` may be the app's own **EmptyState**,
|
|
54
|
+
or `null` for nothing.
|
|
43
55
|
- The box at the foot of a thread that opens takes the caret, at its end, without scrolling: the layout tells it with
|
|
44
56
|
`caretOnOpen`, which **CommentBox** reads. Nothing to pass; a box outside a layout never takes it this way.
|
|
45
57
|
|
|
@@ -3,7 +3,9 @@ import { useState } from 'react'
|
|
|
3
3
|
import { ConversationCard, ReplyCard } from './ConversationCard'
|
|
4
4
|
import { ConversationLayout, type ConversationItem } from './ConversationLayout'
|
|
5
5
|
import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
|
|
6
|
+
import { ArchivedNotice } from './ArchivedNotice'
|
|
6
7
|
import { Panel } from './Panel'
|
|
8
|
+
import { ReactionHorizon } from './ReactionHorizon'
|
|
7
9
|
import { QuotedLine } from './QuotedLine'
|
|
8
10
|
import { SkeletonBar } from './Skeleton'
|
|
9
11
|
import { Thread } from './Thread'
|
|
@@ -105,6 +107,51 @@ export const TwoColumns: Story = {
|
|
|
105
107
|
},
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Two columns, as Peek's file page and DMs: each day's comments under a line naming it, which stays at the top while
|
|
112
|
+
* its stretch scrolls; the reactions note under the comments. Few comments sit on the box, as a chat does.
|
|
113
|
+
*/
|
|
114
|
+
export const TwoColumnsDays: Story = {
|
|
115
|
+
name: 'Two columns, days',
|
|
116
|
+
render: () => {
|
|
117
|
+
const card = (who: typeof ONE, time: string, words: string) => (
|
|
118
|
+
<ConversationCard author={who} time={time}>
|
|
119
|
+
{words}
|
|
120
|
+
</ConversationCard>
|
|
121
|
+
)
|
|
122
|
+
const items: ConversationItem[] = [
|
|
123
|
+
{ id: 'd1', day: 'Monday', card: card(ONE, '9:14 AM', WORDS) },
|
|
124
|
+
{ id: 'd2', day: 'Monday', card: card(TWO, '9:40 AM', 'A second comment that Monday.') },
|
|
125
|
+
{ id: 'd3', day: 'Today', card: card(ONE, '8:02 AM', 'The first comment today.') },
|
|
126
|
+
{ id: 'd4', day: 'Today', card: card(TWO, '10:21 AM', 'A second comment today.') },
|
|
127
|
+
]
|
|
128
|
+
return <ConversationLayout threads="beside" items={items} below={<ReactionHorizon limit={100} omitted={3} />} box={<WriteBox label="Comment" />} />
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Two columns, an archived file: its card at the top however few the comments, the box's line saying why nothing can be written. */
|
|
133
|
+
export const TwoColumnsArchived: Story = {
|
|
134
|
+
name: 'Two columns, archived',
|
|
135
|
+
render: () => (
|
|
136
|
+
<ConversationLayout
|
|
137
|
+
threads="beside"
|
|
138
|
+
top={<ArchivedNotice by="Person one" when="Monday" resolution="Shipped. What was left moved to the next file." />}
|
|
139
|
+
items={[
|
|
140
|
+
{
|
|
141
|
+
id: 'a1',
|
|
142
|
+
day: 'Monday',
|
|
143
|
+
card: (
|
|
144
|
+
<ConversationCard author={ONE} time="9:14 AM" readOnly>
|
|
145
|
+
{WORDS}
|
|
146
|
+
</ConversationCard>
|
|
147
|
+
),
|
|
148
|
+
},
|
|
149
|
+
]}
|
|
150
|
+
box={<WriteBox closed="Archived. Unarchive it to comment." />}
|
|
151
|
+
/>
|
|
152
|
+
),
|
|
153
|
+
}
|
|
154
|
+
|
|
108
155
|
/** One column beside the page: a thread opens under its comment. */
|
|
109
156
|
export const OneColumn: Story = {
|
|
110
157
|
name: 'One column',
|
|
@@ -238,3 +238,103 @@ describe('ConversationLayout, read-only (an archived file)', () => {
|
|
|
238
238
|
expect(asked).toHaveBeenLastCalledWith('a')
|
|
239
239
|
})
|
|
240
240
|
})
|
|
241
|
+
|
|
242
|
+
describe('ConversationLayout, two columns, what an app with its own list keeps (Peek, 1 November)', () => {
|
|
243
|
+
const card = (words: string) => (
|
|
244
|
+
<ConversationCard author={ONE} time="11:08 AM">
|
|
245
|
+
{words}
|
|
246
|
+
</ConversationCard>
|
|
247
|
+
)
|
|
248
|
+
const dayItems: ConversationItem[] = [
|
|
249
|
+
{ id: 'a', card: card('Monday one'), day: 'Monday' },
|
|
250
|
+
{ id: 'b', card: card('Monday two'), day: 'Monday', before: <p>New</p> },
|
|
251
|
+
{ id: 'c', card: card('Today one'), day: 'Today' },
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
it('names each day once, over its own stretch of comments, the line staying at the top while its stretch scrolls', () => {
|
|
255
|
+
render(<ConversationLayout threads="beside" items={dayItems} />)
|
|
256
|
+
const monday = screen.getByRole('separator', { name: 'Monday' })
|
|
257
|
+
const today = screen.getByRole('separator', { name: 'Today' })
|
|
258
|
+
expect(screen.getAllByRole('separator', { name: 'Monday' }).length).toBe(1)
|
|
259
|
+
expect(monday.className).toContain('sticky')
|
|
260
|
+
// Each line is held by its own day's stretch, so the next day's line pushes it away.
|
|
261
|
+
expect(monday.parentElement?.textContent).toContain('Monday two')
|
|
262
|
+
expect(monday.parentElement?.textContent).not.toContain('Today one')
|
|
263
|
+
expect(today.parentElement?.textContent).toContain('Today one')
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('draws a comment’s `before` just above it, outside its card', () => {
|
|
267
|
+
render(<ConversationLayout threads="beside" items={dayItems} />)
|
|
268
|
+
const line = screen.getByText('New')
|
|
269
|
+
const item = document.querySelector('[data-conversation-item="b"]')!
|
|
270
|
+
expect(line.nextElementSibling).toBe(item)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
it('gives the app its scrolling box and says when it scrolled', () => {
|
|
274
|
+
const ref = { current: null as HTMLDivElement | null }
|
|
275
|
+
const scrolled = vi.fn()
|
|
276
|
+
render(<ConversationLayout threads="beside" items={dayItems} bodyRef={ref} onBodyScroll={scrolled} />)
|
|
277
|
+
expect(ref.current?.contains(document.querySelector('[data-conversation-item="a"]'))).toBe(true)
|
|
278
|
+
fireEvent.scroll(ref.current!)
|
|
279
|
+
expect(scrolled).toHaveBeenCalled()
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('sits a short conversation on its box: the room it leaves is above it, under `top`', () => {
|
|
283
|
+
render(<ConversationLayout threads="beside" items={dayItems} top={<p>Archived</p>} below={<p>Reactions note</p>} box={<p>The box</p>} />)
|
|
284
|
+
const top = screen.getByText('Archived').parentElement!
|
|
285
|
+
const room = top.nextElementSibling as HTMLElement
|
|
286
|
+
expect(room.className).toContain('flex-1')
|
|
287
|
+
// The room grows only because the scroll content is at least as tall as the column.
|
|
288
|
+
expect(top.parentElement?.className).toContain('min-h-full')
|
|
289
|
+
expect(room.nextElementSibling?.textContent).toContain('Today one')
|
|
290
|
+
// The note is under the comments, in their list.
|
|
291
|
+
const words = ['Today one', 'Reactions note'].map((w) => screen.getByText(w))
|
|
292
|
+
expect(words[0].compareDocumentPosition(words[1]) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it('redraws no comment when older ones arrive at the top, a day of their own above (PEE-7)', () => {
|
|
296
|
+
const later: ConversationItem[] = [
|
|
297
|
+
{ id: 'b', card: card('Monday one'), day: 'Monday' },
|
|
298
|
+
{ id: 'c', card: card('Today one'), day: 'Today' },
|
|
299
|
+
]
|
|
300
|
+
const { rerender } = render(<ConversationLayout threads="beside" items={later} />)
|
|
301
|
+
const before = ['b', 'c'].map((id) => document.querySelector(`[data-conversation-item="${id}"]`))
|
|
302
|
+
rerender(<ConversationLayout threads="beside" items={[{ id: 'a', card: card('Sunday one'), day: 'Sunday' }, ...later]} />)
|
|
303
|
+
// The same elements, not equal ones: a redrawn card would lose an open menu or dialog.
|
|
304
|
+
;['b', 'c'].forEach((id, i) => expect(document.querySelector(`[data-conversation-item="${id}"]`)).toBe(before[i]))
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('draws nothing for a `top` of false, and no `below` while reading', () => {
|
|
308
|
+
const { container } = render(<ConversationLayout threads="beside" items={dayItems} top={false} />)
|
|
309
|
+
expect(container.querySelector('.pt-4.px-4')).toBeNull()
|
|
310
|
+
cleanup()
|
|
311
|
+
render(<ConversationLayout threads="beside" items={[]} loading below={<p>Reactions note</p>} />)
|
|
312
|
+
expect(screen.queryByText('Reactions note')).toBeNull()
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
it('keeps its name with the message when the column throws, and the thread beside it stays', () => {
|
|
316
|
+
const quiet = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
317
|
+
function Throws(): never {
|
|
318
|
+
throw new Error('a card that throws')
|
|
319
|
+
}
|
|
320
|
+
render(
|
|
321
|
+
<ConversationLayout
|
|
322
|
+
threads="beside"
|
|
323
|
+
title="A DM with Person one"
|
|
324
|
+
items={[{ id: 'x', card: <Throws />, thread: <p>The thread</p> }]}
|
|
325
|
+
open="x"
|
|
326
|
+
/>,
|
|
327
|
+
)
|
|
328
|
+
expect(screen.getByText('A DM with Person one')).toBeTruthy()
|
|
329
|
+
expect(screen.getByText('The thread')).toBeTruthy()
|
|
330
|
+
quiet.mockRestore()
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('says an empty conversation in the app’s own words, or nothing', () => {
|
|
334
|
+
render(<ConversationLayout threads="beside" items={[]} empty={<p>The relay could not be reached.</p>} />)
|
|
335
|
+
expect(screen.getByText('The relay could not be reached.')).toBeTruthy()
|
|
336
|
+
cleanup()
|
|
337
|
+
render(<ConversationLayout threads="beside" items={[]} empty={null} />)
|
|
338
|
+
expect(screen.queryByText('No comments yet.')).toBeNull()
|
|
339
|
+
})
|
|
340
|
+
})
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
|
|
1
|
+
import { Fragment, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type Ref, type UIEventHandler } from 'react'
|
|
2
2
|
import { Card } from './Card'
|
|
3
3
|
import { Chip } from './Chip'
|
|
4
4
|
import { CollapsibleSection } from './CollapsibleSection'
|
|
5
5
|
import { cn } from './cn'
|
|
6
|
+
import { ContainerHeader } from './ContainerHeader'
|
|
7
|
+
import { Divider } from './Divider'
|
|
6
8
|
import { EmptyState } from './EmptyState'
|
|
9
|
+
import { ErrorBoundary } from './ErrorBoundary'
|
|
7
10
|
import { Panel } from './Panel'
|
|
8
11
|
import { ScrollArea } from './ScrollArea'
|
|
9
12
|
import { SkeletonConversation } from './Skeleton'
|
|
@@ -20,6 +23,10 @@ export interface ConversationItem {
|
|
|
20
23
|
resolved?: boolean
|
|
21
24
|
/** What it was on was deleted from the page. In one column it waits under "On deleted blocks", closed, before "Resolved"; a resolved one is under "Resolved". */
|
|
22
25
|
gone?: boolean
|
|
26
|
+
/** Two columns: the day it was written, in the app's words ("Today", "Monday"). Comments of one day are one stretch under a line naming it, which stays at the top while its stretch scrolls under it. */
|
|
27
|
+
day?: string
|
|
28
|
+
/** Two columns: drawn just above it, 8px off, inside its day: the app's "New" line over the first comment not read. */
|
|
29
|
+
before?: ReactNode
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
export interface ConversationLayoutProps {
|
|
@@ -36,15 +43,23 @@ export interface ConversationLayoutProps {
|
|
|
36
43
|
onOpenChange?: (id: string | undefined) => void
|
|
37
44
|
/** The box a new comment is written in, under the comments. */
|
|
38
45
|
box?: ReactNode
|
|
39
|
-
/** Above the comments, inside their list:
|
|
46
|
+
/** Above the comments, inside their list: placeholders while older comments are read, a note. */
|
|
40
47
|
above?: ReactNode
|
|
48
|
+
/** Two columns: under the comments, inside their list, or under the empty line: a `ReactionHorizon`. Not while the comments are read. */
|
|
49
|
+
below?: ReactNode
|
|
50
|
+
/** Two columns: at the top of the column however few the comments are, over the room a short conversation leaves: an `ArchivedNotice`. */
|
|
51
|
+
top?: ReactNode
|
|
41
52
|
/** Still reading the comments. */
|
|
42
53
|
loading?: boolean
|
|
43
|
-
/** What an empty conversation says. */
|
|
44
|
-
empty?:
|
|
54
|
+
/** What an empty conversation says: words, or the app's own `EmptyState` (a read that failed says so). `null`: nothing. */
|
|
55
|
+
empty?: ReactNode
|
|
56
|
+
/** Two columns: the comments' scrolling box, for an app that keeps its own place in it (where it was left, its "New" line, following what arrives). */
|
|
57
|
+
bodyRef?: Ref<HTMLDivElement>
|
|
58
|
+
/** Two columns: the comments' box scrolled. */
|
|
59
|
+
onBodyScroll?: UIEventHandler<HTMLDivElement>
|
|
45
60
|
/** Two columns: the comments' own header, a `PageHeader`, over their column only, so the thread beside them runs the page's full height (Peek's way). */
|
|
46
61
|
header?: ReactNode
|
|
47
|
-
/**
|
|
62
|
+
/** Its name: one column's, in its header. Two columns, said with the message if the column breaks (the page's own bar is `header`). */
|
|
48
63
|
title?: ReactNode
|
|
49
64
|
/** One column: its header's actions, as a `Panel`'s. */
|
|
50
65
|
actions?: ReactNode
|
|
@@ -58,7 +73,7 @@ interface ListProps {
|
|
|
58
73
|
under: boolean
|
|
59
74
|
above?: ReactNode
|
|
60
75
|
loading: boolean
|
|
61
|
-
empty:
|
|
76
|
+
empty: ReactNode
|
|
62
77
|
/** Asked to open or close: `id` is the comment pressed, `next` what is open after; `reply`, asked by Reply. */
|
|
63
78
|
change?: (id: string, next: string | undefined, reply?: boolean) => void
|
|
64
79
|
/** How many times a thread has opened: its box takes the caret each time. */
|
|
@@ -68,7 +83,7 @@ interface ListProps {
|
|
|
68
83
|
/** The list's own room: placeholders, the empty line, or the comments 8px apart. */
|
|
69
84
|
function List({ items, open, under, above, loading, empty, change, caret }: ListProps) {
|
|
70
85
|
if (loading) return <SkeletonConversation />
|
|
71
|
-
if (items.length === 0) return <EmptyState scope="section" message={empty} />
|
|
86
|
+
if (items.length === 0) return typeof empty === 'string' ? <EmptyState scope="section" message={empty} /> : <>{empty}</>
|
|
72
87
|
// How each card opens its thread: only one that has a thread, and only when the app keeps `open`.
|
|
73
88
|
const stateOf = (item: ConversationItem): ConversationItemState | null =>
|
|
74
89
|
change && item.thread
|
|
@@ -82,18 +97,47 @@ function List({ items, open, under, above, loading, empty, change, caret }: List
|
|
|
82
97
|
const draw = (item: ConversationItem) => {
|
|
83
98
|
if (!under) {
|
|
84
99
|
return (
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
<Fragment key={item.id}>
|
|
101
|
+
{item.before}
|
|
102
|
+
<div data-conversation-item={item.id} className="flex flex-col">
|
|
103
|
+
<InConversationItem.Provider value={stateOf(item)}>{item.card}</InConversationItem.Provider>
|
|
104
|
+
</div>
|
|
105
|
+
</Fragment>
|
|
88
106
|
)
|
|
89
107
|
}
|
|
90
108
|
return <UnderItem key={item.id} item={item} isOpen={open === item.id && !!item.thread} state={stateOf(item)} caret={caret} />
|
|
91
109
|
}
|
|
92
110
|
if (!under) {
|
|
111
|
+
// Two columns: a day's comments are one stretch under its line, so the line stays at the top only while its own
|
|
112
|
+
// stretch scrolls under it, and the next day's pushes it away (Peek's day lines).
|
|
113
|
+
// Keyed by its day, not its place, so older comments arriving at the top redraw nothing under them; a day that
|
|
114
|
+
// comes back further down (an app's own order) is that day's second stretch.
|
|
115
|
+
const stretches: { key: string; day?: string; items: ConversationItem[] }[] = []
|
|
116
|
+
const seen = new Map<string, number>()
|
|
117
|
+
for (const item of items) {
|
|
118
|
+
const last = stretches[stretches.length - 1]
|
|
119
|
+
if (last && last.day === item.day) {
|
|
120
|
+
last.items.push(item)
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
const name = item.day ?? ''
|
|
124
|
+
const count = (seen.get(name) ?? 0) + 1
|
|
125
|
+
seen.set(name, count)
|
|
126
|
+
stretches.push({ key: `${item.day === undefined ? 'no-day' : `day:${name}`}#${count}`, day: item.day, items: [item] })
|
|
127
|
+
}
|
|
93
128
|
return (
|
|
94
129
|
<>
|
|
95
130
|
{above}
|
|
96
|
-
{
|
|
131
|
+
{stretches.map((stretch) =>
|
|
132
|
+
stretch.day === undefined ? (
|
|
133
|
+
<Fragment key={stretch.key}>{stretch.items.map(draw)}</Fragment>
|
|
134
|
+
) : (
|
|
135
|
+
<div key={stretch.key} className="flex flex-col gap-2">
|
|
136
|
+
<Divider look="section" label={stretch.day} sticky />
|
|
137
|
+
{stretch.items.map(draw)}
|
|
138
|
+
</div>
|
|
139
|
+
),
|
|
140
|
+
)}
|
|
97
141
|
</>
|
|
98
142
|
)
|
|
99
143
|
}
|
|
@@ -171,7 +215,24 @@ function UnderItem({ item, isOpen, state, caret }: { item: ConversationItem; isO
|
|
|
171
215
|
* comments are the 384px column beside the page, and a thread opens under its comment, the two one card. The right column is 384px in
|
|
172
216
|
* every app (Katerina, 31 October). With two columns the thread runs the full height, beside the comments' header.
|
|
173
217
|
*/
|
|
174
|
-
export function ConversationLayout({
|
|
218
|
+
export function ConversationLayout({
|
|
219
|
+
threads,
|
|
220
|
+
items,
|
|
221
|
+
open,
|
|
222
|
+
onOpenChange,
|
|
223
|
+
box,
|
|
224
|
+
above,
|
|
225
|
+
below,
|
|
226
|
+
top,
|
|
227
|
+
loading = false,
|
|
228
|
+
empty = 'No comments yet.',
|
|
229
|
+
header,
|
|
230
|
+
title = 'Comments',
|
|
231
|
+
actions,
|
|
232
|
+
bodyRef,
|
|
233
|
+
onBodyScroll,
|
|
234
|
+
className,
|
|
235
|
+
}: ConversationLayoutProps) {
|
|
175
236
|
// One column: the pressed comment stays where it was on screen. Opening one thread closes the other, and when that
|
|
176
237
|
// one stood above it, everything under it would rise by its height (Katerina, 31 October). Where it was is noted at
|
|
177
238
|
// the press; once the change is drawn, before it is painted, the column scrolls by however far it went.
|
|
@@ -215,14 +276,31 @@ export function ConversationLayout({ threads, items, open, onOpenChange, box, ab
|
|
|
215
276
|
const opened = items.find((item) => item.id === open)?.thread
|
|
216
277
|
return (
|
|
217
278
|
<div className={cn('flex min-h-0 min-w-0 flex-1', className)}>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
279
|
+
{/* If the column throws, its name stays with the message, as a Panel's does; the thread beside it stays. */}
|
|
280
|
+
<ErrorBoundary
|
|
281
|
+
label="conversation"
|
|
282
|
+
frame={(message) => (
|
|
283
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
284
|
+
<ContainerHeader title={title} />
|
|
285
|
+
<div className="flex min-h-0 flex-1 flex-col px-4">{message}</div>
|
|
286
|
+
</div>
|
|
287
|
+
)}
|
|
288
|
+
>
|
|
289
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
290
|
+
{header}
|
|
291
|
+
<ScrollArea className="min-h-0 flex-1" viewportRef={bodyRef} onScroll={onBodyScroll} contentClassName="flex min-h-full flex-col">
|
|
292
|
+
{top != null && top !== false && top !== '' && <div className="shrink-0 px-4 pt-4">{top}</div>}
|
|
293
|
+
{/* A short conversation sits on its box, as a chat does: the newest comment by the box (Peek's way). */}
|
|
294
|
+
<div className="min-h-0 flex-1" />
|
|
295
|
+
<div className="flex shrink-0 flex-col gap-2 p-4">
|
|
296
|
+
<List items={items} open={open} under={false} above={above} loading={loading} empty={empty} change={change} caret={caret} />
|
|
297
|
+
{!loading && below}
|
|
298
|
+
</div>
|
|
299
|
+
</ScrollArea>
|
|
300
|
+
{/* Peek's composer room: 12px all round (useFileConversationView's `p-3`), under the list's 16px. */}
|
|
301
|
+
{box && <div className="shrink-0 p-3">{box}</div>}
|
|
302
|
+
</div>
|
|
303
|
+
</ErrorBoundary>
|
|
226
304
|
{opened && (
|
|
227
305
|
<div className="flex w-[384px] shrink-0 flex-col border-l border-border-subtle">
|
|
228
306
|
<caretOnOpen.Provider value={caret}>{opened}</caretOnOpen.Provider>
|