@estiva-app/ui 0.95.0 → 0.97.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.
- package/dist/AppShell.d.ts +25 -7
- package/dist/AppShell.d.ts.map +1 -1
- package/dist/ArchivedNotice.d.ts +28 -0
- package/dist/ArchivedNotice.d.ts.map +1 -0
- package/dist/Avatar.d.ts +6 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/AvatarGroup.d.ts +2 -0
- package/dist/AvatarGroup.d.ts.map +1 -1
- package/dist/Button.d.ts +4 -3
- package/dist/Button.d.ts.map +1 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ComposerTriggers.d.ts +2 -0
- package/dist/ComposerTriggers.d.ts.map +1 -1
- package/dist/ConversationActions.d.ts +24 -0
- package/dist/ConversationActions.d.ts.map +1 -0
- package/dist/ConversationCard.d.ts +90 -0
- package/dist/ConversationCard.d.ts.map +1 -0
- package/dist/ConversationLayout.d.ts +50 -0
- package/dist/ConversationLayout.d.ts.map +1 -0
- package/dist/ConversationMenu.d.ts +24 -0
- package/dist/ConversationMenu.d.ts.map +1 -0
- package/dist/Divider.d.ts +23 -4
- package/dist/Divider.d.ts.map +1 -1
- package/dist/EditedMarker.d.ts +11 -0
- package/dist/EditedMarker.d.ts.map +1 -0
- package/dist/IconButton.d.ts +3 -3
- package/dist/IconButton.d.ts.map +1 -1
- package/dist/LinkParts.d.ts +4 -1
- package/dist/LinkParts.d.ts.map +1 -1
- package/dist/ListColumn.d.ts +3 -1
- package/dist/ListColumn.d.ts.map +1 -1
- package/dist/MembersDialog.d.ts +4 -0
- package/dist/MembersDialog.d.ts.map +1 -1
- package/dist/MetaText.d.ts +22 -0
- package/dist/MetaText.d.ts.map +1 -0
- package/dist/NavItem.d.ts.map +1 -1
- package/dist/PageHeader.d.ts +50 -0
- package/dist/PageHeader.d.ts.map +1 -0
- package/dist/Panel.d.ts +6 -0
- package/dist/Panel.d.ts.map +1 -1
- package/dist/Person.d.ts +3 -1
- package/dist/Person.d.ts.map +1 -1
- package/dist/PersonTrigger.d.ts +1 -1
- package/dist/PersonTrigger.d.ts.map +1 -1
- package/dist/PinnedComment.d.ts +17 -0
- package/dist/PinnedComment.d.ts.map +1 -0
- package/dist/QuotedLine.d.ts +16 -0
- package/dist/QuotedLine.d.ts.map +1 -0
- package/dist/ReactionHorizon.d.ts +14 -0
- package/dist/ReactionHorizon.d.ts.map +1 -0
- package/dist/RepliesRow.d.ts +27 -0
- package/dist/RepliesRow.d.ts.map +1 -0
- package/dist/ResolveDialog.d.ts +13 -0
- package/dist/ResolveDialog.d.ts.map +1 -0
- package/dist/Select.d.ts +1 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/Skeleton.d.ts +8 -4
- package/dist/Skeleton.d.ts.map +1 -1
- package/dist/Thread.d.ts +38 -0
- package/dist/Thread.d.ts.map +1 -0
- package/dist/TopBar.d.ts +3 -2
- package/dist/TopBar.d.ts.map +1 -1
- package/dist/UrgentMark.d.ts +6 -0
- package/dist/UrgentMark.d.ts.map +1 -0
- package/dist/commentBoxFrame.d.ts +3 -1
- package/dist/commentBoxFrame.d.ts.map +1 -1
- package/dist/conversation.examples.d.ts +52 -0
- package/dist/conversation.examples.d.ts.map +1 -0
- package/dist/editor.js +33 -25
- package/dist/editor.js.map +2 -2
- package/dist/eslint/index.js +2 -1
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-native-title.d.ts +1 -1
- package/dist/eslint/no-native-title.d.ts.map +1 -1
- package/dist/eslint/no-restyled-part.d.ts.map +1 -1
- package/dist/index.d.ts +18 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1412 -448
- package/dist/index.js.map +4 -4
- package/dist/linked.d.ts +4 -0
- package/dist/linked.d.ts.map +1 -1
- package/dist/linkedFrom.d.ts +2 -0
- package/dist/linkedFrom.d.ts.map +1 -1
- package/dist/looks.d.ts +13 -1
- package/dist/looks.d.ts.map +1 -1
- package/dist/threadCard.d.ts +46 -0
- package/dist/threadCard.d.ts.map +1 -0
- package/package.json +1 -1
- package/registry.json +1889 -544
- package/src/AppShell.mdx +24 -10
- package/src/AppShell.stories.tsx +65 -31
- package/src/AppShell.test.tsx +92 -10
- package/src/AppShell.tsx +108 -18
- package/src/ArchivedNotice.mdx +46 -0
- package/src/ArchivedNotice.stories.tsx +52 -0
- package/src/ArchivedNotice.test.tsx +42 -0
- package/src/ArchivedNotice.tsx +71 -0
- package/src/Avatar.agent.test.tsx +63 -0
- package/src/Avatar.mdx +25 -0
- package/src/Avatar.stories.tsx +13 -0
- package/src/Avatar.tsx +51 -3
- package/src/AvatarGroup.tsx +3 -1
- package/src/Button.mdx +2 -2
- package/src/Button.tsx +8 -6
- package/src/Card.test.tsx +4 -4
- package/src/Card.tsx +6 -2
- package/src/CommentBox.test.tsx +2 -1
- package/src/CommentBox.tsx +14 -7
- package/src/ComposerTriggers.stories.tsx +2 -0
- package/src/ComposerTriggers.tsx +3 -1
- package/src/ConfirmDialog.stories.tsx +12 -0
- package/src/ConversationActions.mdx +47 -0
- package/src/ConversationActions.stories.tsx +39 -0
- package/src/ConversationActions.tsx +96 -0
- package/src/ConversationCard.mdx +72 -0
- package/src/ConversationCard.states.test.tsx +330 -0
- package/src/ConversationCard.stories.tsx +135 -0
- package/src/ConversationCard.test.tsx +159 -0
- package/src/ConversationCard.tsx +524 -0
- package/src/ConversationLayout.mdx +61 -0
- package/src/ConversationLayout.stories.tsx +161 -0
- package/src/ConversationLayout.test.tsx +240 -0
- package/src/ConversationLayout.tsx +233 -0
- package/src/ConversationMenu.mdx +47 -0
- package/src/ConversationMenu.stories.tsx +42 -0
- package/src/ConversationMenu.test.tsx +47 -0
- package/src/ConversationMenu.tsx +57 -0
- package/src/Divider.mdx +36 -1
- package/src/Divider.stories.tsx +57 -0
- package/src/Divider.test.tsx +24 -1
- package/src/Divider.tsx +49 -9
- package/src/EditedMarker.mdx +36 -0
- package/src/EditedMarker.stories.tsx +24 -0
- package/src/EditedMarker.tsx +20 -0
- package/src/IconButton.mdx +2 -1
- package/src/IconButton.tsx +8 -5
- package/src/LinkCard.tsx +3 -3
- package/src/LinkChip.tsx +1 -1
- package/src/LinkParts.mdx +4 -0
- package/src/LinkParts.stories.tsx +10 -0
- package/src/LinkParts.tsx +9 -5
- package/src/LinkRow.tsx +1 -1
- package/src/ListColumn.tsx +9 -3
- package/src/MembersDialog.stories.tsx +11 -0
- package/src/MembersDialog.tsx +7 -3
- package/src/MetaText.mdx +41 -0
- package/src/MetaText.stories.tsx +29 -0
- package/src/MetaText.tsx +38 -0
- package/src/NavItem.tsx +2 -11
- package/src/PageHeader.mdx +123 -0
- package/src/PageHeader.stories.tsx +174 -0
- package/src/PageHeader.test.tsx +99 -0
- package/src/PageHeader.tsx +105 -0
- package/src/Panel.mdx +12 -0
- package/src/Panel.stories.tsx +47 -5
- package/src/Panel.test.tsx +40 -0
- package/src/Panel.tsx +8 -2
- package/src/Person.tsx +4 -2
- package/src/PersonTrigger.tsx +3 -3
- package/src/PinnedComment.mdx +40 -0
- package/src/PinnedComment.stories.tsx +21 -0
- package/src/PinnedComment.tsx +40 -0
- package/src/QuotedLine.mdx +44 -0
- package/src/QuotedLine.stories.tsx +30 -0
- package/src/QuotedLine.test.tsx +34 -0
- package/src/QuotedLine.tsx +33 -0
- package/src/ReactionHorizon.mdx +36 -0
- package/src/ReactionHorizon.stories.tsx +27 -0
- package/src/ReactionHorizon.tsx +27 -0
- package/src/RepliesRow.mdx +45 -0
- package/src/RepliesRow.stories.tsx +33 -0
- package/src/RepliesRow.test.tsx +47 -0
- package/src/RepliesRow.tsx +86 -0
- package/src/ReplyCard.mdx +50 -0
- package/src/ReplyCard.stories.tsx +68 -0
- package/src/ResolveDialog.mdx +44 -0
- package/src/ResolveDialog.stories.tsx +23 -0
- package/src/ResolveDialog.test.tsx +53 -0
- package/src/ResolveDialog.tsx +58 -0
- package/src/Select.tsx +12 -2
- package/src/Skeleton.stories.tsx +4 -1
- package/src/Skeleton.tsx +33 -4
- package/src/Thread.mdx +53 -0
- package/src/Thread.stories.tsx +167 -0
- package/src/Thread.test.tsx +83 -0
- package/src/Thread.tsx +113 -0
- package/src/TopBar.mdx +8 -6
- package/src/TopBar.stories.tsx +4 -3
- package/src/TopBar.tsx +8 -3
- package/src/UrgentMark.mdx +37 -0
- package/src/UrgentMark.stories.tsx +27 -0
- package/src/UrgentMark.tsx +15 -0
- package/src/commentBoxFrame.tsx +8 -4
- package/src/conversation.examples.tsx +135 -0
- package/src/eslint/no-native-title.ts +1 -1
- package/src/eslint/no-restyled-part.ts +1 -0
- package/src/index.ts +19 -2
- package/src/linked.ts +4 -0
- package/src/linkedFrom.ts +5 -3
- package/src/looks.ts +18 -2
- package/src/registry/registry.test.ts +9 -7
- package/src/threadCard.ts +84 -0
- package/stories/Choosing.mdx +21 -1
- package/tokens.css +14 -10
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { ConversationCard, ReplyCard } from './ConversationCard'
|
|
4
|
+
import { ConversationLayout, type ConversationItem } from './ConversationLayout'
|
|
5
|
+
import { ONE, SHORT, SOME, THREE, TWO, WORDS, WriteBox, YOU, useReactions } from './conversation.examples'
|
|
6
|
+
import { Panel } from './Panel'
|
|
7
|
+
import { QuotedLine } from './QuotedLine'
|
|
8
|
+
import { SkeletonBar } from './Skeleton'
|
|
9
|
+
import { Thread } from './Thread'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Where the cards sit. Two columns: the comments fill the page and an open thread stands beside them. One column:
|
|
13
|
+
* the comments are the 384px column beside the page, and a thread opens under its comment. Live: open a thread.
|
|
14
|
+
*/
|
|
15
|
+
const meta = {
|
|
16
|
+
title: 'Conversation/ConversationLayout',
|
|
17
|
+
component: ConversationLayout,
|
|
18
|
+
parameters: { layout: 'fullscreen' },
|
|
19
|
+
decorators: [(Story) => <div className="flex h-screen bg-bg-base">{Story()}</div>],
|
|
20
|
+
} satisfies Meta<typeof ConversationLayout>
|
|
21
|
+
|
|
22
|
+
export default meta
|
|
23
|
+
type Story = StoryObj
|
|
24
|
+
|
|
25
|
+
const COMMENTS = [
|
|
26
|
+
{ id: 'c1', author: ONE, time: '11:08 AM', words: WORDS, replies: 2, quoted: 'the words this comment is on' },
|
|
27
|
+
{ id: 'c2', author: TWO, time: '11:30 AM', words: 'A second comment, with nobody answering it yet.', replies: 0 },
|
|
28
|
+
{ id: 'c3', author: THREE, time: '12:15 PM', words: 'A third comment, resolved.', replies: 1, resolved: { by: 'You', note: 'Done.' } },
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
/** A comment whose words were deleted from the page since: only where the groups are shown. */
|
|
32
|
+
const GONE = { id: 'c4', author: TWO, time: '12:40 PM', words: 'A comment on words that were deleted since.', replies: 0, quoted: 'words since deleted from the page', resolved: undefined }
|
|
33
|
+
|
|
34
|
+
function Replies() {
|
|
35
|
+
const one = useReactions(SOME)
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<ReplyCard author={TWO} time="11:40 AM" reactions={one}>
|
|
39
|
+
{SHORT}
|
|
40
|
+
</ReplyCard>
|
|
41
|
+
<ReplyCard author={YOU} time="11:52 AM" own onDelete={() => {}}>
|
|
42
|
+
Your own reply, under the first.
|
|
43
|
+
</ReplyCard>
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The cards, each opening its thread, in either layout. */
|
|
49
|
+
function useItems(place: 'beside' | 'under', open: string | undefined, setOpen: (id: string | undefined) => void, quoted: boolean, apart = false): ConversationItem[] {
|
|
50
|
+
const reacting = useReactions(SOME)
|
|
51
|
+
const [resolved, setResolved] = useState<Record<string, { by: string; note?: string } | undefined>>(() => Object.fromEntries(COMMENTS.map((c) => [c.id, c.resolved])))
|
|
52
|
+
// Opening is the layout's: a press anywhere on a card, its replies row or Reply; the app keeps `open` (onOpenChange).
|
|
53
|
+
const comments = apart ? [...COMMENTS, GONE] : COMMENTS
|
|
54
|
+
return comments.map((c) => ({
|
|
55
|
+
id: c.id,
|
|
56
|
+
resolved: apart && !!resolved[c.id],
|
|
57
|
+
gone: apart && c.id === GONE.id,
|
|
58
|
+
card: (
|
|
59
|
+
<ConversationCard
|
|
60
|
+
author={c.author}
|
|
61
|
+
time={c.time}
|
|
62
|
+
about={quoted && c.quoted ? <QuotedLine words={c.quoted} state={c.id === GONE.id ? 'gone' : 'here'} /> : undefined}
|
|
63
|
+
reactions={reacting}
|
|
64
|
+
resolved={resolved[c.id]}
|
|
65
|
+
onResolve={(note) => setResolved((r) => ({ ...r, [c.id]: { by: 'You', note: note || undefined } }))}
|
|
66
|
+
onReopen={() => setResolved((r) => ({ ...r, [c.id]: undefined }))}
|
|
67
|
+
replies={c.replies ? { count: c.replies, faces: [TWO, YOU], last: '11:52 AM' } : undefined}
|
|
68
|
+
>
|
|
69
|
+
{c.words}
|
|
70
|
+
</ConversationCard>
|
|
71
|
+
),
|
|
72
|
+
thread:
|
|
73
|
+
place === 'beside' ? (
|
|
74
|
+
<Thread start={{ author: c.author, time: c.time, words: c.words }} onClose={() => setOpen(undefined)} box={<WriteBox />}>
|
|
75
|
+
{c.replies ? <Replies /> : undefined}
|
|
76
|
+
</Thread>
|
|
77
|
+
) : (
|
|
78
|
+
<Thread place="under" box={<WriteBox />}>
|
|
79
|
+
{c.replies ? <Replies /> : undefined}
|
|
80
|
+
</Thread>
|
|
81
|
+
),
|
|
82
|
+
}))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A page beside the column, in placeholders. */
|
|
86
|
+
function Page() {
|
|
87
|
+
return (
|
|
88
|
+
<Panel title="Item one">
|
|
89
|
+
<div className="flex max-w-3xl flex-col gap-3 px-12 pt-10">
|
|
90
|
+
<SkeletonBar className="h-6 w-1/2" />
|
|
91
|
+
<SkeletonBar className="h-3 w-[90%]" />
|
|
92
|
+
<SkeletonBar className="h-3 w-[70%]" />
|
|
93
|
+
<SkeletonBar className="h-3 w-[85%]" />
|
|
94
|
+
</div>
|
|
95
|
+
</Panel>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Two columns: the comments fill the page; the open thread stands beside them. */
|
|
100
|
+
export const TwoColumns: Story = {
|
|
101
|
+
name: 'Two columns',
|
|
102
|
+
render: function Render() {
|
|
103
|
+
const [open, setOpen] = useState<string | undefined>('c1')
|
|
104
|
+
return <ConversationLayout threads="beside" items={useItems('beside', open, setOpen, false)} open={open} onOpenChange={setOpen} box={<WriteBox label="Comment" />} />
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** One column beside the page: a thread opens under its comment. */
|
|
109
|
+
export const OneColumn: Story = {
|
|
110
|
+
name: 'One column',
|
|
111
|
+
render: function Render() {
|
|
112
|
+
const [open, setOpen] = useState<string | undefined>('c1')
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
116
|
+
<Page />
|
|
117
|
+
</div>
|
|
118
|
+
<div className="flex border-l border-border-subtle">
|
|
119
|
+
<ConversationLayout threads="under" items={useItems('under', open, setOpen, true)} open={open} onOpenChange={setOpen} box={<WriteBox label="Comment" />} />
|
|
120
|
+
</div>
|
|
121
|
+
</>
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** One column: the resolved comments and those on a deleted part wait closed under their names at the end. Resolve one: it moves there. */
|
|
127
|
+
export const Apart: Story = {
|
|
128
|
+
name: 'One column, resolved and deleted apart',
|
|
129
|
+
render: function Render() {
|
|
130
|
+
const [open, setOpen] = useState<string | undefined>(undefined)
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
134
|
+
<Page />
|
|
135
|
+
</div>
|
|
136
|
+
<div className="flex border-l border-border-subtle">
|
|
137
|
+
<ConversationLayout threads="under" items={useItems('under', open, setOpen, true, true)} open={open} onOpenChange={setOpen} box={<WriteBox label="Comment" />} />
|
|
138
|
+
</div>
|
|
139
|
+
</>
|
|
140
|
+
)
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Nobody has commented yet. */
|
|
145
|
+
export const Empty: Story = {
|
|
146
|
+
render: () => (
|
|
147
|
+
<>
|
|
148
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
149
|
+
<Page />
|
|
150
|
+
</div>
|
|
151
|
+
<div className="flex border-l border-border-subtle">
|
|
152
|
+
<ConversationLayout threads="under" items={[]} box={<WriteBox label="Comment" />} />
|
|
153
|
+
</div>
|
|
154
|
+
</>
|
|
155
|
+
),
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Still reading the comments. */
|
|
159
|
+
export const Loading: Story = {
|
|
160
|
+
render: () => <ConversationLayout threads="beside" items={[]} loading box={<WriteBox label="Comment" />} />,
|
|
161
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* What the layout owns, pinned (Katerina, 31 October): a press anywhere on a card opens its thread, and in one column
|
|
4
|
+
* a second press closes it; the replies row says it is open; a comment with no replies opens to its box; and the
|
|
5
|
+
* comment is never redrawn as it opens and closes, so it cannot blink or move.
|
|
6
|
+
*/
|
|
7
|
+
import { useContext, useState } from 'react'
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
9
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
10
|
+
import { ConversationCard } from './ConversationCard'
|
|
11
|
+
import { ConversationLayout, type ConversationItem } from './ConversationLayout'
|
|
12
|
+
import { Thread } from './Thread'
|
|
13
|
+
import { caretOnOpen } from './threadCard'
|
|
14
|
+
|
|
15
|
+
afterEach(cleanup)
|
|
16
|
+
|
|
17
|
+
const ONE = { name: 'Person one' }
|
|
18
|
+
|
|
19
|
+
function items(threads: 'beside' | 'under'): ConversationItem[] {
|
|
20
|
+
const thread = (words: string) =>
|
|
21
|
+
threads === 'under' ? (
|
|
22
|
+
<Thread place="under" box={<p>Box of {words}</p>}>
|
|
23
|
+
{words === 'With replies' ? <p>A reply</p> : undefined}
|
|
24
|
+
</Thread>
|
|
25
|
+
) : (
|
|
26
|
+
<Thread start={{ author: ONE, time: '11:08 AM', words }} box={<p>Box of {words}</p>}>
|
|
27
|
+
{words === 'With replies' ? <p>A reply</p> : undefined}
|
|
28
|
+
</Thread>
|
|
29
|
+
)
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
id: 'a',
|
|
33
|
+
card: (
|
|
34
|
+
<ConversationCard author={ONE} time="11:08 AM" replies={{ count: 1 }}>
|
|
35
|
+
With replies
|
|
36
|
+
</ConversationCard>
|
|
37
|
+
),
|
|
38
|
+
thread: thread('With replies'),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'b',
|
|
42
|
+
card: (
|
|
43
|
+
<ConversationCard author={ONE} time="11:30 AM">
|
|
44
|
+
No replies yet
|
|
45
|
+
</ConversationCard>
|
|
46
|
+
),
|
|
47
|
+
thread: thread('No replies yet'),
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The app keeps `open`, as it does in every app; the layout asks with onOpenChange. */
|
|
53
|
+
function Layout({ threads, start, asked }: { threads: 'beside' | 'under'; start?: string; asked?: (id: string | undefined) => void }) {
|
|
54
|
+
const [open, setOpen] = useState<string | undefined>(start)
|
|
55
|
+
return (
|
|
56
|
+
<ConversationLayout
|
|
57
|
+
threads={threads}
|
|
58
|
+
items={items(threads)}
|
|
59
|
+
open={open}
|
|
60
|
+
onOpenChange={(id) => {
|
|
61
|
+
asked?.(id)
|
|
62
|
+
setOpen(id)
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('ConversationLayout, one column', () => {
|
|
69
|
+
it('opens a thread from a press anywhere on its card, and closes it with a second', () => {
|
|
70
|
+
const asked = vi.fn()
|
|
71
|
+
render(<Layout threads="under" asked={asked} />)
|
|
72
|
+
fireEvent.click(screen.getByText('With replies'))
|
|
73
|
+
expect(asked).toHaveBeenLastCalledWith('a')
|
|
74
|
+
expect(screen.getByText('A reply')).toBeTruthy()
|
|
75
|
+
fireEvent.click(screen.getByText('With replies'))
|
|
76
|
+
expect(asked).toHaveBeenLastCalledWith(undefined)
|
|
77
|
+
expect(screen.queryByText('A reply')).toBeNull()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('says on the replies row that the thread is open, and the row closes it once, not twice', () => {
|
|
81
|
+
render(<Layout threads="under" start="a" />)
|
|
82
|
+
const row = screen.getByRole('button', { name: '1 reply, close the thread' })
|
|
83
|
+
expect(row.getAttribute('aria-expanded')).toBe('true')
|
|
84
|
+
fireEvent.click(row)
|
|
85
|
+
expect(screen.queryByText('A reply')).toBeNull()
|
|
86
|
+
expect(screen.getByRole('button', { name: '1 reply, open the thread' }).getAttribute('aria-expanded')).toBe('false')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('opens a comment with no replies to its box', () => {
|
|
90
|
+
render(<Layout threads="under" />)
|
|
91
|
+
fireEvent.click(screen.getByText('No replies yet'))
|
|
92
|
+
expect(screen.getByText('Box of No replies yet')).toBeTruthy()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('never redraws the comment as its thread opens and closes: the same element, in the same card', () => {
|
|
96
|
+
render(<Layout threads="under" />)
|
|
97
|
+
const words = screen.getByText('With replies')
|
|
98
|
+
const item = words.closest('[data-conversation-item]')
|
|
99
|
+
fireEvent.click(words)
|
|
100
|
+
expect(screen.getByText('With replies')).toBe(words)
|
|
101
|
+
expect(words.closest('[data-conversation-item]')).toBe(item)
|
|
102
|
+
expect(item?.hasAttribute('data-open')).toBe(true)
|
|
103
|
+
fireEvent.click(words)
|
|
104
|
+
expect(screen.getByText('With replies')).toBe(words)
|
|
105
|
+
expect(item?.hasAttribute('data-open')).toBe(false)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('opens only one thread: a press on another closes the first', () => {
|
|
109
|
+
render(<Layout threads="under" start="a" />)
|
|
110
|
+
fireEvent.click(screen.getByText('No replies yet'))
|
|
111
|
+
expect(screen.queryByText('A reply')).toBeNull()
|
|
112
|
+
expect(screen.getByText('Box of No replies yet')).toBeTruthy()
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('ConversationLayout, one column, its groups', () => {
|
|
117
|
+
const grouped = (): ConversationItem[] => [
|
|
118
|
+
{ id: 'a', card: <ConversationCard author={ONE} time="11:08 AM">Still open</ConversationCard>, thread: <Thread place="under" /> },
|
|
119
|
+
{ id: 'b', resolved: true, card: <ConversationCard author={ONE} time="11:30 AM" resolved={{ by: 'Person two' }}>Done with</ConversationCard>, thread: <Thread place="under" /> },
|
|
120
|
+
{ id: 'c', gone: true, card: <ConversationCard author={ONE} time="11:40 AM">On deleted words</ConversationCard>, thread: <Thread place="under" /> },
|
|
121
|
+
{ id: 'd', gone: true, resolved: true, card: <ConversationCard author={ONE} time="11:50 AM" resolved={{ by: 'Person two' }}>Both</ConversationCard>, thread: <Thread place="under" /> },
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
it('puts the resolved and those on a deleted part closed under their names at the end, with how many; resolved wins', () => {
|
|
125
|
+
render(<ConversationLayout threads="under" items={grouped()} />)
|
|
126
|
+
const deleted = screen.getByRole('button', { name: /^On deleted blocks/ })
|
|
127
|
+
const resolved = screen.getByRole('button', { name: /^Resolved/ })
|
|
128
|
+
expect(deleted.getAttribute('aria-expanded')).toBe('false')
|
|
129
|
+
expect(resolved.getAttribute('aria-expanded')).toBe('false')
|
|
130
|
+
// How many, beside each name: 1 after "On deleted blocks", 2 after "Resolved".
|
|
131
|
+
const after = (a: Node, b: Node) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
132
|
+
const one = screen.getByText('1')
|
|
133
|
+
const two = screen.getByText('2')
|
|
134
|
+
expect(after(deleted, one) && after(one, resolved) && after(resolved, two)).toBe(true)
|
|
135
|
+
expect(screen.getByText('Still open').closest('[hidden]')).toBeNull()
|
|
136
|
+
for (const words of ['Done with', 'On deleted words', 'Both']) expect(screen.getByText(words).closest('[hidden]')).not.toBeNull()
|
|
137
|
+
// In this order: the open ones, then the deleted, then the resolved.
|
|
138
|
+
const [open, onDeleted, done] = ['Still open', 'On deleted words', 'Done with'].map((w) => screen.getByText(w))
|
|
139
|
+
expect(after(open, onDeleted) && after(onDeleted, done)).toBe(true)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('opens a group for the thread open in it', () => {
|
|
143
|
+
render(<ConversationLayout threads="under" items={grouped()} open="b" onOpenChange={() => {}} />)
|
|
144
|
+
expect(screen.getByRole('button', { name: /^Resolved/ }).getAttribute('aria-expanded')).toBe('true')
|
|
145
|
+
expect(screen.getByRole('button', { name: /^On deleted blocks/ }).getAttribute('aria-expanded')).toBe('false')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('draws no group when nothing is resolved or on a deleted part, and none in two columns', () => {
|
|
149
|
+
render(<ConversationLayout threads="under" items={grouped().slice(0, 1)} />)
|
|
150
|
+
expect(screen.queryByRole('button', { name: /^Resolved/ })).toBeNull()
|
|
151
|
+
cleanup()
|
|
152
|
+
render(<ConversationLayout threads="beside" items={grouped()} />)
|
|
153
|
+
expect(screen.queryByRole('button', { name: /^Resolved/ })).toBeNull()
|
|
154
|
+
expect(screen.getByText('Done with').closest('[hidden]')).toBeNull()
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
/** A box that says how many times it was asked to take the caret. */
|
|
159
|
+
function CaretBox() {
|
|
160
|
+
return <p>Caret {useContext(caretOnOpen)}</p>
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
describe('ConversationLayout, Reply on the open comment (the review, 1 November)', () => {
|
|
164
|
+
it('asks the app for nothing, and puts the caret in its box again', () => {
|
|
165
|
+
const asked = vi.fn()
|
|
166
|
+
const items: ConversationItem[] = [
|
|
167
|
+
{
|
|
168
|
+
id: 'a',
|
|
169
|
+
card: (
|
|
170
|
+
<ConversationCard author={ONE} time="11:08 AM">
|
|
171
|
+
Open one
|
|
172
|
+
</ConversationCard>
|
|
173
|
+
),
|
|
174
|
+
thread: <Thread place="under" box={<CaretBox />} />,
|
|
175
|
+
},
|
|
176
|
+
]
|
|
177
|
+
render(<ConversationLayout threads="under" items={items} open="a" onOpenChange={asked} />)
|
|
178
|
+
expect(screen.getByText('Caret 0')).toBeTruthy()
|
|
179
|
+
fireEvent.mouseEnter(screen.getByText('Open one'))
|
|
180
|
+
fireEvent.click(screen.getByRole('button', { name: 'Reply' }))
|
|
181
|
+
expect(asked).not.toHaveBeenCalled()
|
|
182
|
+
expect(screen.getByText('Caret 1')).toBeTruthy()
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
describe('ConversationLayout, two columns', () => {
|
|
187
|
+
it('opens a thread beside from a press on its card, and a second press keeps it open', () => {
|
|
188
|
+
const asked = vi.fn()
|
|
189
|
+
render(<Layout threads="beside" asked={asked} />)
|
|
190
|
+
fireEvent.click(screen.getByText('With replies'))
|
|
191
|
+
expect(asked).toHaveBeenLastCalledWith('a')
|
|
192
|
+
expect(screen.getByText('A reply')).toBeTruthy()
|
|
193
|
+
fireEvent.click(screen.getAllByText('With replies')[0])
|
|
194
|
+
expect(asked).toHaveBeenLastCalledWith('a')
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
describe('ConversationLayout, with no onOpenChange', () => {
|
|
199
|
+
it('leaves the cards as the app wired them: a press opens nothing', () => {
|
|
200
|
+
render(<ConversationLayout threads="under" items={items('under')} />)
|
|
201
|
+
fireEvent.click(screen.getByText('With replies'))
|
|
202
|
+
expect(screen.queryByText('A reply')).toBeNull()
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
describe('ConversationLayout, read-only (an archived file)', () => {
|
|
207
|
+
const readOnly = (): ConversationItem[] => [
|
|
208
|
+
{
|
|
209
|
+
id: 'a',
|
|
210
|
+
card: (
|
|
211
|
+
<ConversationCard author={ONE} time="11:08 AM" replies={{ count: 1 }} readOnly>
|
|
212
|
+
With replies
|
|
213
|
+
</ConversationCard>
|
|
214
|
+
),
|
|
215
|
+
thread: (
|
|
216
|
+
<Thread start={{ author: ONE, time: '11:08 AM', words: 'With replies' }}>
|
|
217
|
+
<p>A reply</p>
|
|
218
|
+
</Thread>
|
|
219
|
+
),
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: 'b',
|
|
223
|
+
card: (
|
|
224
|
+
<ConversationCard author={ONE} time="11:30 AM" readOnly>
|
|
225
|
+
No replies yet
|
|
226
|
+
</ConversationCard>
|
|
227
|
+
),
|
|
228
|
+
thread: <Thread start={{ author: ONE, time: '11:30 AM', words: 'No replies yet' }} />,
|
|
229
|
+
},
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
it('opens a comment with replies to read them, and a comment with none opens nothing (Peek’s way)', () => {
|
|
233
|
+
const asked = vi.fn()
|
|
234
|
+
render(<ConversationLayout threads="beside" items={readOnly()} onOpenChange={asked} />)
|
|
235
|
+
fireEvent.click(screen.getByText('No replies yet'))
|
|
236
|
+
expect(asked).not.toHaveBeenCalled()
|
|
237
|
+
fireEvent.click(screen.getByText('With replies'))
|
|
238
|
+
expect(asked).toHaveBeenLastCalledWith('a')
|
|
239
|
+
})
|
|
240
|
+
})
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
|
|
2
|
+
import { Card } from './Card'
|
|
3
|
+
import { Chip } from './Chip'
|
|
4
|
+
import { CollapsibleSection } from './CollapsibleSection'
|
|
5
|
+
import { cn } from './cn'
|
|
6
|
+
import { EmptyState } from './EmptyState'
|
|
7
|
+
import { Panel } from './Panel'
|
|
8
|
+
import { ScrollArea } from './ScrollArea'
|
|
9
|
+
import { SkeletonConversation } from './Skeleton'
|
|
10
|
+
import { caretOnOpen, InConversationItem, InThreadCard, LineByLayout, useFaceLine, type ConversationItemState } from './threadCard'
|
|
11
|
+
|
|
12
|
+
/** One comment in the list, and its thread when it is open. */
|
|
13
|
+
export interface ConversationItem {
|
|
14
|
+
id: string
|
|
15
|
+
/** The comment: a `ConversationCard`. */
|
|
16
|
+
card: ReactNode
|
|
17
|
+
/** Its thread: a `Thread` with the same `place` as the layout's `threads`, drawn while it is the open one. Give every comment one, even with no replies yet: a card without one cannot be opened. */
|
|
18
|
+
thread?: ReactNode
|
|
19
|
+
/** Resolved. In one column it waits under "Resolved", closed, at the end; in two columns it stays in its place. */
|
|
20
|
+
resolved?: boolean
|
|
21
|
+
/** 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
|
+
gone?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ConversationLayoutProps {
|
|
26
|
+
/** Where an open thread stands. `beside`, two columns: the comments fill the page, the thread stands in the 384px column beside them. `under`, one column: the comments are the 384px column beside the page, and a thread opens under its comment. */
|
|
27
|
+
threads: 'beside' | 'under'
|
|
28
|
+
items: readonly ConversationItem[]
|
|
29
|
+
/** The id of the comment whose thread is open. */
|
|
30
|
+
open?: string
|
|
31
|
+
/**
|
|
32
|
+
* A comment asks to open or close its thread: a press anywhere on its card, its replies row, or Reply. In one column
|
|
33
|
+
* a second press closes it. The layout draws it open in place, with no jump, and puts the caret in its box; the app
|
|
34
|
+
* keeps `open`. `undefined`: closed.
|
|
35
|
+
*/
|
|
36
|
+
onOpenChange?: (id: string | undefined) => void
|
|
37
|
+
/** The box a new comment is written in, under the comments. */
|
|
38
|
+
box?: ReactNode
|
|
39
|
+
/** Above the comments, inside their list: a `ReactionHorizon`, a note. */
|
|
40
|
+
above?: ReactNode
|
|
41
|
+
/** Still reading the comments. */
|
|
42
|
+
loading?: boolean
|
|
43
|
+
/** What an empty conversation says. */
|
|
44
|
+
empty?: string
|
|
45
|
+
/** 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
|
+
header?: ReactNode
|
|
47
|
+
/** One column: its name, in its header. */
|
|
48
|
+
title?: ReactNode
|
|
49
|
+
/** One column: its header's actions, as a `Panel`'s. */
|
|
50
|
+
actions?: ReactNode
|
|
51
|
+
/** Placement only. */
|
|
52
|
+
className?: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ListProps {
|
|
56
|
+
items: readonly ConversationItem[]
|
|
57
|
+
open?: string
|
|
58
|
+
under: boolean
|
|
59
|
+
above?: ReactNode
|
|
60
|
+
loading: boolean
|
|
61
|
+
empty: string
|
|
62
|
+
/** Asked to open or close: `id` is the comment pressed, `next` what is open after; `reply`, asked by Reply. */
|
|
63
|
+
change?: (id: string, next: string | undefined, reply?: boolean) => void
|
|
64
|
+
/** How many times a thread has opened: its box takes the caret each time. */
|
|
65
|
+
caret: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The list's own room: placeholders, the empty line, or the comments 8px apart. */
|
|
69
|
+
function List({ items, open, under, above, loading, empty, change, caret }: ListProps) {
|
|
70
|
+
if (loading) return <SkeletonConversation />
|
|
71
|
+
if (items.length === 0) return <EmptyState scope="section" message={empty} />
|
|
72
|
+
// How each card opens its thread: only one that has a thread, and only when the app keeps `open`.
|
|
73
|
+
const stateOf = (item: ConversationItem): ConversationItemState | null =>
|
|
74
|
+
change && item.thread
|
|
75
|
+
? {
|
|
76
|
+
under,
|
|
77
|
+
open: open === item.id,
|
|
78
|
+
toggle: () => change(item.id, under && open === item.id ? undefined : item.id),
|
|
79
|
+
show: () => change(item.id, item.id, true),
|
|
80
|
+
}
|
|
81
|
+
: null
|
|
82
|
+
const draw = (item: ConversationItem) => {
|
|
83
|
+
if (!under) {
|
|
84
|
+
return (
|
|
85
|
+
<div key={item.id} data-conversation-item={item.id} className="flex flex-col">
|
|
86
|
+
<InConversationItem.Provider value={stateOf(item)}>{item.card}</InConversationItem.Provider>
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
return <UnderItem key={item.id} item={item} isOpen={open === item.id && !!item.thread} state={stateOf(item)} caret={caret} />
|
|
91
|
+
}
|
|
92
|
+
if (!under) {
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
{above}
|
|
96
|
+
{items.map(draw)}
|
|
97
|
+
</>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
// One column: the comments on a deleted part, then the resolved ones, each closed under its name at the end, with
|
|
101
|
+
// how many (Leaf's column; Katerina, 1 November: kept for every one-column app). A group opens by itself for the
|
|
102
|
+
// thread open in it, as one opened from a link.
|
|
103
|
+
const resolved = items.filter((item) => item.resolved)
|
|
104
|
+
const gone = items.filter((item) => item.gone && !item.resolved)
|
|
105
|
+
const group = (title: string, list: readonly ConversationItem[]) =>
|
|
106
|
+
list.length > 0 && (
|
|
107
|
+
<CollapsibleSection
|
|
108
|
+
title={title}
|
|
109
|
+
trailing={<Chip type="neutral" label={String(list.length)} />}
|
|
110
|
+
defaultOpen={false}
|
|
111
|
+
openFor={list.some((item) => item.id === open) ? open : undefined}
|
|
112
|
+
className="shrink-0"
|
|
113
|
+
contentClassName="flex flex-col gap-2"
|
|
114
|
+
>
|
|
115
|
+
{list.map(draw)}
|
|
116
|
+
</CollapsibleSection>
|
|
117
|
+
)
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
{above}
|
|
121
|
+
{items.filter((item) => !item.resolved && !item.gone).map(draw)}
|
|
122
|
+
{group('On deleted blocks', gone)}
|
|
123
|
+
{group('Resolved', resolved)}
|
|
124
|
+
</>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* One comment in one column, and its thread when open. Every comment stands in the same card, open or closed, so
|
|
130
|
+
* opening never rebuilds it (no blink, no jump; Katerina, 31 October). Closed, the card is invisible round it; open, it
|
|
131
|
+
* is the one card round the comment and its thread, the comment's own card quiet inside it (Ship's way), and it draws
|
|
132
|
+
* the line from the comment's face to the last reply as one measured bar (Katerina, 1 November: one straight line).
|
|
133
|
+
*/
|
|
134
|
+
function UnderItem({ item, isOpen, state, caret }: { item: ConversationItem; isOpen: boolean; state: ConversationItemState | null; caret: number }) {
|
|
135
|
+
const root = useRef<HTMLDivElement>(null)
|
|
136
|
+
const line = useFaceLine(root, isOpen)
|
|
137
|
+
return (
|
|
138
|
+
<Card
|
|
139
|
+
ref={root}
|
|
140
|
+
data-conversation-item={item.id}
|
|
141
|
+
data-open={isOpen || undefined}
|
|
142
|
+
// Open, its edge and no fill, as the comments round it (Katerina, 1 November: no background in Ship); the
|
|
143
|
+
// edge the surface fill had, held by `hovered`.
|
|
144
|
+
fill="none"
|
|
145
|
+
hover="hairline"
|
|
146
|
+
hovered={isOpen}
|
|
147
|
+
quietUntilHover={!isOpen}
|
|
148
|
+
className={cn('relative flex flex-col', isOpen && 'pb-2')}
|
|
149
|
+
>
|
|
150
|
+
<InConversationItem.Provider value={state}>
|
|
151
|
+
<InThreadCard.Provider value={isOpen}>
|
|
152
|
+
<LineByLayout.Provider value>
|
|
153
|
+
{/* Over this card's edge, 1px out each way: the comment keeps its place and width, open or closed. */}
|
|
154
|
+
<div className="-m-px flex flex-col">{item.card}</div>
|
|
155
|
+
{isOpen && <caretOnOpen.Provider value={caret}>{item.thread}</caretOnOpen.Provider>}
|
|
156
|
+
</LineByLayout.Provider>
|
|
157
|
+
</InThreadCard.Provider>
|
|
158
|
+
</InConversationItem.Provider>
|
|
159
|
+
{line && (
|
|
160
|
+
// The face's line, one bar, last so it stands over a hovered card's fill; 19px in, centred under the face.
|
|
161
|
+
// Its top and height come from the measure: where the face and the last reply end are not known ahead.
|
|
162
|
+
<span aria-hidden className="pointer-events-none absolute left-[19px] w-0.5 bg-border-default" style={{ top: line.top, height: line.height }} />
|
|
163
|
+
)}
|
|
164
|
+
</Card>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Where a conversation's cards sit, in one of two ways every app picks from (where it sits is the app's, the record
|
|
170
|
+
* says). Two columns: the comments fill the page and an open thread stands beside them, 384px. One column: the
|
|
171
|
+
* 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
|
+
* every app (Katerina, 31 October). With two columns the thread runs the full height, beside the comments' header.
|
|
173
|
+
*/
|
|
174
|
+
export function ConversationLayout({ threads, items, open, onOpenChange, box, above, loading = false, empty = 'No comments yet.', header, title = 'Comments', actions, className }: ConversationLayoutProps) {
|
|
175
|
+
// One column: the pressed comment stays where it was on screen. Opening one thread closes the other, and when that
|
|
176
|
+
// one stood above it, everything under it would rise by its height (Katerina, 31 October). Where it was is noted at
|
|
177
|
+
// the press; once the change is drawn, before it is painted, the column scrolls by however far it went.
|
|
178
|
+
const body = useRef<HTMLDivElement>(null)
|
|
179
|
+
const pressed = useRef<{ id: string; top: number } | null>(null)
|
|
180
|
+
const itemAt = (id: string) => body.current?.querySelector<HTMLElement>(`[data-conversation-item="${CSS.escape(id)}"]`) ?? null
|
|
181
|
+
// A thread that opens puts the caret in its box (Katerina, 31 October); the one open when the page is drawn does not.
|
|
182
|
+
const [caret, setCaret] = useState(0)
|
|
183
|
+
const change = onOpenChange
|
|
184
|
+
? (id: string, next: string | undefined, reply = false) => {
|
|
185
|
+
if (next !== undefined && next === open) {
|
|
186
|
+
// Already open: nothing moves. Reply on it puts the caret in its box again; nothing else is asked of the app.
|
|
187
|
+
if (reply) setCaret((n) => n + 1)
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
const item = threads === 'under' ? itemAt(id) : null
|
|
191
|
+
pressed.current = item ? { id, top: item.getBoundingClientRect().top } : null
|
|
192
|
+
onOpenChange(next)
|
|
193
|
+
}
|
|
194
|
+
: undefined
|
|
195
|
+
useLayoutEffect(() => {
|
|
196
|
+
const at = pressed.current
|
|
197
|
+
pressed.current = null
|
|
198
|
+
const item = at && itemAt(at.id)
|
|
199
|
+
if (!at || !item || !body.current) return
|
|
200
|
+
const moved = item.getBoundingClientRect().top - at.top
|
|
201
|
+
if (moved !== 0) body.current.scrollTop += moved
|
|
202
|
+
}, [open])
|
|
203
|
+
const was = useRef(open)
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (open !== undefined && open !== was.current) setCaret((n) => n + 1)
|
|
206
|
+
was.current = open
|
|
207
|
+
}, [open])
|
|
208
|
+
if (threads === 'under') {
|
|
209
|
+
return (
|
|
210
|
+
<Panel className={cn('w-[384px] flex-none', className)} title={title} actions={actions} bodyRef={body} bodyClassName="flex flex-col gap-2 p-3" footer={box && <div className="p-3">{box}</div>}>
|
|
211
|
+
<List items={items} open={open} under above={above} loading={loading} empty={empty} change={change} caret={caret} />
|
|
212
|
+
</Panel>
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
const opened = items.find((item) => item.id === open)?.thread
|
|
216
|
+
return (
|
|
217
|
+
<div className={cn('flex min-h-0 min-w-0 flex-1', className)}>
|
|
218
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
219
|
+
{header}
|
|
220
|
+
<ScrollArea className="min-h-0 flex-1" contentClassName="flex flex-col gap-2 p-4">
|
|
221
|
+
<List items={items} open={open} under={false} above={above} loading={loading} empty={empty} change={change} caret={caret} />
|
|
222
|
+
</ScrollArea>
|
|
223
|
+
{/* Peek's composer room: 12px all round (useFileConversationView's `p-3`), under the list's 16px. */}
|
|
224
|
+
{box && <div className="shrink-0 p-3">{box}</div>}
|
|
225
|
+
</div>
|
|
226
|
+
{opened && (
|
|
227
|
+
<div className="flex w-[384px] shrink-0 flex-col border-l border-border-subtle">
|
|
228
|
+
<caretOnOpen.Provider value={caret}>{opened}</caretOnOpen.Provider>
|
|
229
|
+
</div>
|
|
230
|
+
)}
|
|
231
|
+
</div>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
|
|
2
|
+
import * as Stories from './ConversationMenu.stories'
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# ConversationMenu
|
|
7
|
+
|
|
8
|
+
The ⋯ menu of a comment or a reply: Resolve or Reopen, the app's own rows, then Edit and Delete on your own.
|
|
9
|
+
|
|
10
|
+
<Canvas of={Stories.Yours} />
|
|
11
|
+
|
|
12
|
+
## When
|
|
13
|
+
|
|
14
|
+
- Inside **ConversationCard** and **ReplyCard**, which draw it for you.
|
|
15
|
+
- Its `children` are the app's own rows.
|
|
16
|
+
|
|
17
|
+
<Canvas of={Stories.Theirs} />
|
|
18
|
+
|
|
19
|
+
<Canvas of={Stories.MoreRows} />
|
|
20
|
+
|
|
21
|
+
## When not
|
|
22
|
+
|
|
23
|
+
- Any other menu → **Menu**.
|
|
24
|
+
|
|
25
|
+
## How
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { ConversationMenu, MenuItem } from '@estiva-app/ui'
|
|
29
|
+
|
|
30
|
+
<ConversationMenu onResolve={resolve} onEdit={edit} onDelete={askToDelete}>
|
|
31
|
+
<MenuItem label="Item one" onClick={doSomething} />
|
|
32
|
+
</ConversationMenu>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- Edit and Delete are offered on your own only: pass them only there.
|
|
36
|
+
|
|
37
|
+
## What it owns
|
|
38
|
+
|
|
39
|
+
| It does | So you never write | Refused when written by hand |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| Offers Reopen in place of Resolve once resolved | the swap | |
|
|
42
|
+
| Draws Edit and Delete only when handed them | a check for whose it is | |
|
|
43
|
+
| Puts the app's own rows between Resolve and Edit, with the lines between groups | separators | |
|
|
44
|
+
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
<Controls />
|