@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.
Files changed (205) hide show
  1. package/dist/AppShell.d.ts +25 -7
  2. package/dist/AppShell.d.ts.map +1 -1
  3. package/dist/ArchivedNotice.d.ts +28 -0
  4. package/dist/ArchivedNotice.d.ts.map +1 -0
  5. package/dist/Avatar.d.ts +6 -1
  6. package/dist/Avatar.d.ts.map +1 -1
  7. package/dist/AvatarGroup.d.ts +2 -0
  8. package/dist/AvatarGroup.d.ts.map +1 -1
  9. package/dist/Button.d.ts +4 -3
  10. package/dist/Button.d.ts.map +1 -1
  11. package/dist/Card.d.ts.map +1 -1
  12. package/dist/CommentBox.d.ts.map +1 -1
  13. package/dist/ComposerTriggers.d.ts +2 -0
  14. package/dist/ComposerTriggers.d.ts.map +1 -1
  15. package/dist/ConversationActions.d.ts +24 -0
  16. package/dist/ConversationActions.d.ts.map +1 -0
  17. package/dist/ConversationCard.d.ts +90 -0
  18. package/dist/ConversationCard.d.ts.map +1 -0
  19. package/dist/ConversationLayout.d.ts +50 -0
  20. package/dist/ConversationLayout.d.ts.map +1 -0
  21. package/dist/ConversationMenu.d.ts +24 -0
  22. package/dist/ConversationMenu.d.ts.map +1 -0
  23. package/dist/Divider.d.ts +23 -4
  24. package/dist/Divider.d.ts.map +1 -1
  25. package/dist/EditedMarker.d.ts +11 -0
  26. package/dist/EditedMarker.d.ts.map +1 -0
  27. package/dist/IconButton.d.ts +3 -3
  28. package/dist/IconButton.d.ts.map +1 -1
  29. package/dist/LinkParts.d.ts +4 -1
  30. package/dist/LinkParts.d.ts.map +1 -1
  31. package/dist/ListColumn.d.ts +3 -1
  32. package/dist/ListColumn.d.ts.map +1 -1
  33. package/dist/MembersDialog.d.ts +4 -0
  34. package/dist/MembersDialog.d.ts.map +1 -1
  35. package/dist/MetaText.d.ts +22 -0
  36. package/dist/MetaText.d.ts.map +1 -0
  37. package/dist/NavItem.d.ts.map +1 -1
  38. package/dist/PageHeader.d.ts +50 -0
  39. package/dist/PageHeader.d.ts.map +1 -0
  40. package/dist/Panel.d.ts +6 -0
  41. package/dist/Panel.d.ts.map +1 -1
  42. package/dist/Person.d.ts +3 -1
  43. package/dist/Person.d.ts.map +1 -1
  44. package/dist/PersonTrigger.d.ts +1 -1
  45. package/dist/PersonTrigger.d.ts.map +1 -1
  46. package/dist/PinnedComment.d.ts +17 -0
  47. package/dist/PinnedComment.d.ts.map +1 -0
  48. package/dist/QuotedLine.d.ts +16 -0
  49. package/dist/QuotedLine.d.ts.map +1 -0
  50. package/dist/ReactionHorizon.d.ts +14 -0
  51. package/dist/ReactionHorizon.d.ts.map +1 -0
  52. package/dist/RepliesRow.d.ts +27 -0
  53. package/dist/RepliesRow.d.ts.map +1 -0
  54. package/dist/ResolveDialog.d.ts +13 -0
  55. package/dist/ResolveDialog.d.ts.map +1 -0
  56. package/dist/Select.d.ts +1 -1
  57. package/dist/Select.d.ts.map +1 -1
  58. package/dist/Skeleton.d.ts +8 -4
  59. package/dist/Skeleton.d.ts.map +1 -1
  60. package/dist/Thread.d.ts +38 -0
  61. package/dist/Thread.d.ts.map +1 -0
  62. package/dist/TopBar.d.ts +3 -2
  63. package/dist/TopBar.d.ts.map +1 -1
  64. package/dist/UrgentMark.d.ts +6 -0
  65. package/dist/UrgentMark.d.ts.map +1 -0
  66. package/dist/commentBoxFrame.d.ts +3 -1
  67. package/dist/commentBoxFrame.d.ts.map +1 -1
  68. package/dist/conversation.examples.d.ts +52 -0
  69. package/dist/conversation.examples.d.ts.map +1 -0
  70. package/dist/editor.js +33 -25
  71. package/dist/editor.js.map +2 -2
  72. package/dist/eslint/index.js +2 -1
  73. package/dist/eslint/index.js.map +2 -2
  74. package/dist/eslint/no-native-title.d.ts +1 -1
  75. package/dist/eslint/no-native-title.d.ts.map +1 -1
  76. package/dist/eslint/no-restyled-part.d.ts.map +1 -1
  77. package/dist/index.d.ts +18 -2
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1412 -448
  80. package/dist/index.js.map +4 -4
  81. package/dist/linked.d.ts +4 -0
  82. package/dist/linked.d.ts.map +1 -1
  83. package/dist/linkedFrom.d.ts +2 -0
  84. package/dist/linkedFrom.d.ts.map +1 -1
  85. package/dist/looks.d.ts +13 -1
  86. package/dist/looks.d.ts.map +1 -1
  87. package/dist/threadCard.d.ts +46 -0
  88. package/dist/threadCard.d.ts.map +1 -0
  89. package/package.json +1 -1
  90. package/registry.json +1889 -544
  91. package/src/AppShell.mdx +24 -10
  92. package/src/AppShell.stories.tsx +65 -31
  93. package/src/AppShell.test.tsx +92 -10
  94. package/src/AppShell.tsx +108 -18
  95. package/src/ArchivedNotice.mdx +46 -0
  96. package/src/ArchivedNotice.stories.tsx +52 -0
  97. package/src/ArchivedNotice.test.tsx +42 -0
  98. package/src/ArchivedNotice.tsx +71 -0
  99. package/src/Avatar.agent.test.tsx +63 -0
  100. package/src/Avatar.mdx +25 -0
  101. package/src/Avatar.stories.tsx +13 -0
  102. package/src/Avatar.tsx +51 -3
  103. package/src/AvatarGroup.tsx +3 -1
  104. package/src/Button.mdx +2 -2
  105. package/src/Button.tsx +8 -6
  106. package/src/Card.test.tsx +4 -4
  107. package/src/Card.tsx +6 -2
  108. package/src/CommentBox.test.tsx +2 -1
  109. package/src/CommentBox.tsx +14 -7
  110. package/src/ComposerTriggers.stories.tsx +2 -0
  111. package/src/ComposerTriggers.tsx +3 -1
  112. package/src/ConfirmDialog.stories.tsx +12 -0
  113. package/src/ConversationActions.mdx +47 -0
  114. package/src/ConversationActions.stories.tsx +39 -0
  115. package/src/ConversationActions.tsx +96 -0
  116. package/src/ConversationCard.mdx +72 -0
  117. package/src/ConversationCard.states.test.tsx +330 -0
  118. package/src/ConversationCard.stories.tsx +135 -0
  119. package/src/ConversationCard.test.tsx +159 -0
  120. package/src/ConversationCard.tsx +524 -0
  121. package/src/ConversationLayout.mdx +61 -0
  122. package/src/ConversationLayout.stories.tsx +161 -0
  123. package/src/ConversationLayout.test.tsx +240 -0
  124. package/src/ConversationLayout.tsx +233 -0
  125. package/src/ConversationMenu.mdx +47 -0
  126. package/src/ConversationMenu.stories.tsx +42 -0
  127. package/src/ConversationMenu.test.tsx +47 -0
  128. package/src/ConversationMenu.tsx +57 -0
  129. package/src/Divider.mdx +36 -1
  130. package/src/Divider.stories.tsx +57 -0
  131. package/src/Divider.test.tsx +24 -1
  132. package/src/Divider.tsx +49 -9
  133. package/src/EditedMarker.mdx +36 -0
  134. package/src/EditedMarker.stories.tsx +24 -0
  135. package/src/EditedMarker.tsx +20 -0
  136. package/src/IconButton.mdx +2 -1
  137. package/src/IconButton.tsx +8 -5
  138. package/src/LinkCard.tsx +3 -3
  139. package/src/LinkChip.tsx +1 -1
  140. package/src/LinkParts.mdx +4 -0
  141. package/src/LinkParts.stories.tsx +10 -0
  142. package/src/LinkParts.tsx +9 -5
  143. package/src/LinkRow.tsx +1 -1
  144. package/src/ListColumn.tsx +9 -3
  145. package/src/MembersDialog.stories.tsx +11 -0
  146. package/src/MembersDialog.tsx +7 -3
  147. package/src/MetaText.mdx +41 -0
  148. package/src/MetaText.stories.tsx +29 -0
  149. package/src/MetaText.tsx +38 -0
  150. package/src/NavItem.tsx +2 -11
  151. package/src/PageHeader.mdx +123 -0
  152. package/src/PageHeader.stories.tsx +174 -0
  153. package/src/PageHeader.test.tsx +99 -0
  154. package/src/PageHeader.tsx +105 -0
  155. package/src/Panel.mdx +12 -0
  156. package/src/Panel.stories.tsx +47 -5
  157. package/src/Panel.test.tsx +40 -0
  158. package/src/Panel.tsx +8 -2
  159. package/src/Person.tsx +4 -2
  160. package/src/PersonTrigger.tsx +3 -3
  161. package/src/PinnedComment.mdx +40 -0
  162. package/src/PinnedComment.stories.tsx +21 -0
  163. package/src/PinnedComment.tsx +40 -0
  164. package/src/QuotedLine.mdx +44 -0
  165. package/src/QuotedLine.stories.tsx +30 -0
  166. package/src/QuotedLine.test.tsx +34 -0
  167. package/src/QuotedLine.tsx +33 -0
  168. package/src/ReactionHorizon.mdx +36 -0
  169. package/src/ReactionHorizon.stories.tsx +27 -0
  170. package/src/ReactionHorizon.tsx +27 -0
  171. package/src/RepliesRow.mdx +45 -0
  172. package/src/RepliesRow.stories.tsx +33 -0
  173. package/src/RepliesRow.test.tsx +47 -0
  174. package/src/RepliesRow.tsx +86 -0
  175. package/src/ReplyCard.mdx +50 -0
  176. package/src/ReplyCard.stories.tsx +68 -0
  177. package/src/ResolveDialog.mdx +44 -0
  178. package/src/ResolveDialog.stories.tsx +23 -0
  179. package/src/ResolveDialog.test.tsx +53 -0
  180. package/src/ResolveDialog.tsx +58 -0
  181. package/src/Select.tsx +12 -2
  182. package/src/Skeleton.stories.tsx +4 -1
  183. package/src/Skeleton.tsx +33 -4
  184. package/src/Thread.mdx +53 -0
  185. package/src/Thread.stories.tsx +167 -0
  186. package/src/Thread.test.tsx +83 -0
  187. package/src/Thread.tsx +113 -0
  188. package/src/TopBar.mdx +8 -6
  189. package/src/TopBar.stories.tsx +4 -3
  190. package/src/TopBar.tsx +8 -3
  191. package/src/UrgentMark.mdx +37 -0
  192. package/src/UrgentMark.stories.tsx +27 -0
  193. package/src/UrgentMark.tsx +15 -0
  194. package/src/commentBoxFrame.tsx +8 -4
  195. package/src/conversation.examples.tsx +135 -0
  196. package/src/eslint/no-native-title.ts +1 -1
  197. package/src/eslint/no-restyled-part.ts +1 -0
  198. package/src/index.ts +19 -2
  199. package/src/linked.ts +4 -0
  200. package/src/linkedFrom.ts +5 -3
  201. package/src/looks.ts +18 -2
  202. package/src/registry/registry.test.ts +9 -7
  203. package/src/threadCard.ts +84 -0
  204. package/stories/Choosing.mdx +21 -1
  205. package/tokens.css +14 -10
@@ -0,0 +1,96 @@
1
+ import { useState, type ReactNode } from 'react'
2
+ import { IconCircleCheck, IconCircleDashed, IconMessage2, IconMoodPlus } from '@tabler/icons-react'
3
+ import { cn } from './cn'
4
+ import { Popover } from './Popover'
5
+ import { ReactionPicker, type ReactionOption } from './ReactionPicker'
6
+ import { Toolbar, ToolbarButton, ToolbarSeparator } from './Toolbar'
7
+
8
+ export interface ConversationActionsProps {
9
+ /** The reactions on offer: with `onReact`, "React" opens them over the strip. */
10
+ options?: readonly ReactionOption[]
11
+ onReact?: (emoji: string) => void
12
+ onReply?: () => void
13
+ /** Resolved: the strip offers Reopen in place of Resolve. */
14
+ resolved?: boolean
15
+ onResolve?: () => void
16
+ onReopen?: () => void
17
+ /** Told when the reactions open and close, so a card can keep its strip while they are up. */
18
+ onPickerOpenChange?: (open: boolean) => void
19
+ /** The ⋯ menu: a `ConversationMenu` whose trigger is a `ToolbarButton`, so the strip stays one Tab stop. */
20
+ more?: ReactNode
21
+ /** Placement only: `absolute right-1 top-1`. */
22
+ className?: string
23
+ }
24
+
25
+ /**
26
+ * The strip on a comment or a reply while it is pointed at: React · Reply · Resolve or Reopen · ⋯, each drawn only
27
+ * when the card offers it, a line only between two groups that are both there. One Tab stop; the arrow keys walk the buttons. Peek's, moved with the conversation.
28
+ */
29
+ export function ConversationActions({ options, onReact, onReply, resolved = false, onResolve, onReopen, onPickerOpenChange, more, className }: ConversationActionsProps) {
30
+ const [picking, setPicking] = useState(false)
31
+ // The reactions hang from the whole strip, right-aligned, not from their own button.
32
+ const [strip, setStrip] = useState<HTMLDivElement | null>(null)
33
+ const setOpen = (open: boolean) => {
34
+ setPicking(open)
35
+ onPickerOpenChange?.(open)
36
+ }
37
+ const resolves = resolved ? onReopen : onResolve
38
+ const answers = (!!onReact && !!options) || !!onReply
39
+ return (
40
+ <div ref={setStrip} className={cn('inline-flex', className)}>
41
+ <Toolbar aria-label="Actions">
42
+ {onReact && options && (
43
+ <Popover
44
+ side="top"
45
+ align="right"
46
+ anchor={strip}
47
+ ariaLabel="Reactions"
48
+ className="w-auto min-w-0"
49
+ contentClassName="p-1"
50
+ open={picking}
51
+ onOpenChange={setOpen}
52
+ trigger={
53
+ <ToolbarButton tooltip="React" aria-label="React">
54
+ <IconMoodPlus size={16} stroke={1.5} />
55
+ </ToolbarButton>
56
+ }
57
+ >
58
+ <ReactionPicker
59
+ options={[...options]}
60
+ surface={false}
61
+ onSelect={(emoji) => {
62
+ setOpen(false)
63
+ onReact(emoji)
64
+ }}
65
+ />
66
+ </Popover>
67
+ )}
68
+ {onReply && (
69
+ <ToolbarButton tooltip="Reply" aria-label="Reply" onClick={onReply}>
70
+ <IconMessage2 size={16} stroke={1.5} />
71
+ </ToolbarButton>
72
+ )}
73
+ {resolves && (
74
+ <>
75
+ {answers && <ToolbarSeparator />}
76
+ {resolved ? (
77
+ <ToolbarButton tooltip="Reopen" aria-label="Reopen" onClick={onReopen}>
78
+ <IconCircleDashed size={16} stroke={1.5} />
79
+ </ToolbarButton>
80
+ ) : (
81
+ <ToolbarButton variant="resolve" tooltip="Resolve" aria-label="Resolve" onClick={onResolve}>
82
+ <IconCircleCheck size={16} stroke={1.5} />
83
+ </ToolbarButton>
84
+ )}
85
+ </>
86
+ )}
87
+ {more && (
88
+ <>
89
+ {(answers || resolves) && <ToolbarSeparator />}
90
+ {more}
91
+ </>
92
+ )}
93
+ </Toolbar>
94
+ </div>
95
+ )
96
+ }
@@ -0,0 +1,72 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as Stories from './ConversationCard.stories'
3
+
4
+ <Meta of={Stories} />
5
+
6
+ # ConversationCard
7
+
8
+ One comment, the same in every app: who, when, the words, files, cards, reactions and the way into its replies, with the actions on hover and the ⋯ menu.
9
+
10
+ <Canvas of={Stories.Comment} />
11
+
12
+ ## When
13
+
14
+ - **A comment** in any conversation: in the comments beside a page, or filling the page with its thread beside it (**ConversationLayout**).
15
+ - `own` on yours: Edit (with `editor`) and Delete (with `onDelete`) in its menu. The card asks before it deletes.
16
+ - `resolved`: folded. "✓ Resolved" by the time, with who, when and the note on hover; "Person two → the note · time" above its replies row. While its thread is closed, the words fold to their first line, without files or reactions; open, it is whole.
17
+ - `about` on a comment on a part of the page: a **QuotedLine** under the name, above the words.
18
+ - `isNew`, `urgent`: the dot or the urgent mark, and a hairline, until it is read.
19
+
20
+ <Canvas of={Stories.Replies} />
21
+
22
+ <Canvas of={Stories.Resolved} />
23
+
24
+ <Canvas of={Stories.OnAPart} />
25
+
26
+ ## When not
27
+
28
+ - A reply in a thread → **ReplyCard**: no replies of its own, no Resolve.
29
+ - A link to something, alone → **LinkCard**; a card someone attached sits in the words as an **AttachedCard**.
30
+ - A row in a list of places → **NavItem**.
31
+
32
+ ## How
33
+
34
+ ```tsx
35
+ import { ConversationCard } from '@estiva-app/ui'
36
+
37
+ <ConversationCard
38
+ author={author}
39
+ time={timeOf(comment)}
40
+ edited={editedWords}
41
+ reactions={{ reactions: reactions, options: options, nameOf: nameOf, viewer: me, onToggle: (emoji: string) => react(comment, emoji) }}
42
+ replies={{ count: replyCount, faces: faces, last: lastTime, isNew: hasNew }}
43
+ resolved={resolution}
44
+ onResolve={(note) => resolve(comment, note)}
45
+ onReopen={() => reopen(comment)}
46
+ own={isMine}
47
+ editor={(done) => editBoxFor(comment, done)}
48
+ onDelete={() => remove(comment)}
49
+ onClick={() => openThread(comment)}
50
+ >
51
+ {wordsOf(comment)}
52
+ </ConversationCard>
53
+ ```
54
+
55
+ - **The words are yours to draw**: text, people named, links, attached cards and quoted blocks, with **RichText** and the link parts. The card gives them their size and colour.
56
+ - **Edit opens your box**: `editor` draws your **CommentBox** edit form; call `done` when it saves or cancels. To open it again after a refused save, hold `editing` yourself.
57
+ - **Resolve opens the dialog**: **ResolveDialog**, then `onResolve(note)`. Answer `false` when it was refused; the dialog stays.
58
+ - A press on the card is `onClick` (its thread opens); a press on a button, a link or anything marked `data-interactive` inside it is not.
59
+ - The strip shows while the card is pointed at or has focus, and holds while its reactions or its menu are open.
60
+
61
+ ## What it owns
62
+
63
+ | It does | So you never write | Refused when written by hand |
64
+ |---|---|---|
65
+ | Shows its actions while pointed at, and holds them while a menu is open | hover state and an outside-click check | |
66
+ | Asks before it deletes | a confirm dialog | |
67
+ | Opens the Resolve dialog, and closes it once resolved | a dialog and its open state | |
68
+ | Says it is resolved, with who and the note, and folds it while its thread is closed | a resolved line or chip of your own | |
69
+
70
+ ## Props
71
+
72
+ <Controls />
@@ -0,0 +1,330 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * What Peek's own card was tested for, and the kit's card now does (Katerina, 1 November: the tests move into the kit
4
+ * before Peek takes its card): who may change it, read-only, an edit the app holds, new and urgent, its files. Peek's
5
+ * wiring keeps its own tests: who the seam says owns a message, the edit box's files and mentions, a refused edit
6
+ * remembered across redraws, the thread's anchors.
7
+ */
8
+ import { afterEach, describe, expect, it, vi } from 'vitest'
9
+ import { cleanup, fireEvent, render, screen } from '@testing-library/react'
10
+ import userEvent from '@testing-library/user-event'
11
+ import { ConversationCard, ReplyCard } from './ConversationCard'
12
+ import { InThreadCard } from './threadCard'
13
+
14
+ afterEach(cleanup)
15
+
16
+ const ONE = { name: 'Person one' }
17
+ const REACTED = { reactions: [{ emoji: '👍', by: ['a'] }], options: [], nameOf: (id: string) => id }
18
+
19
+ /** Pointed at with a plain event, as in ConversationCard.test: user-event's move reads, in jsdom, as leaving. */
20
+ function point(words: string) {
21
+ fireEvent.mouseEnter(screen.getByText(words))
22
+ }
23
+
24
+ function editBox(done: () => void) {
25
+ return (
26
+ <button type="button" onClick={done}>
27
+ Save
28
+ </button>
29
+ )
30
+ }
31
+
32
+ /** Whether `b` comes after `a` in the page. */
33
+ function after(a: Node, b: Node) {
34
+ return !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING)
35
+ }
36
+
37
+ describe('who may change it (Peek: ConversationCard.ownership)', () => {
38
+ it('offers Edit and Delete on your own comment', async () => {
39
+ render(
40
+ <ConversationCard author={ONE} time="11:08 AM" own editor={editBox} onDelete={() => {}}>
41
+ Words
42
+ </ConversationCard>,
43
+ )
44
+ point('Words')
45
+ fireEvent.click(screen.getByRole('button', { name: 'More actions' }))
46
+ expect(await screen.findByRole('menuitem', { name: 'Edit' })).toBeTruthy()
47
+ expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeTruthy()
48
+ })
49
+
50
+ it('offers Edit and Delete on your own reply', async () => {
51
+ render(
52
+ <ReplyCard author={ONE} time="11:40 AM" own editor={editBox} onDelete={() => {}}>
53
+ A reply
54
+ </ReplyCard>,
55
+ )
56
+ point('A reply')
57
+ fireEvent.click(screen.getByRole('button', { name: 'More actions' }))
58
+ expect(await screen.findByRole('menuitem', { name: 'Edit' })).toBeTruthy()
59
+ expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeTruthy()
60
+ })
61
+
62
+ it('offers neither on someone else’s reply: with nothing else to offer, no ⋯ at all', () => {
63
+ render(
64
+ <ReplyCard author={ONE} time="11:40 AM" editor={editBox} onDelete={() => {}}>
65
+ A reply
66
+ </ReplyCard>,
67
+ )
68
+ point('A reply')
69
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull()
70
+ })
71
+ })
72
+
73
+ describe('read-only, an archived page (Peek: ConversationCard.readOnly)', () => {
74
+ it('draws no strip, even on your own comment', () => {
75
+ render(
76
+ <ConversationCard author={ONE} time="11:08 AM" own readOnly editor={editBox} onDelete={() => {}} onResolve={() => {}} onReply={() => {}}>
77
+ Words
78
+ </ConversationCard>,
79
+ )
80
+ point('Words')
81
+ for (const name of ['More actions', 'Resolve', 'Reply']) expect(screen.queryByRole('button', { name })).toBeNull()
82
+ })
83
+
84
+ it('shows its reactions, but they cannot be pressed and there is no way to react', () => {
85
+ const onToggle = vi.fn()
86
+ render(
87
+ <ConversationCard author={ONE} time="11:08 AM" readOnly reactions={{ ...REACTED, onToggle }}>
88
+ Words
89
+ </ConversationCard>,
90
+ )
91
+ const pill = screen.getByRole('button', { name: /👍/ }) as HTMLButtonElement
92
+ expect(pill.disabled).toBe(true)
93
+ fireEvent.click(pill)
94
+ expect(onToggle).not.toHaveBeenCalled()
95
+ expect(screen.queryByRole('button', { name: 'Add a reaction' })).toBeNull()
96
+ })
97
+
98
+ it('a read-only reply: no strip, and its reactions cannot be pressed', () => {
99
+ const onToggle = vi.fn()
100
+ render(
101
+ <ReplyCard author={ONE} time="11:40 AM" own readOnly editor={editBox} onDelete={() => {}} reactions={{ ...REACTED, onToggle }}>
102
+ A reply
103
+ </ReplyCard>,
104
+ )
105
+ point('A reply')
106
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull()
107
+ fireEvent.click(screen.getByRole('button', { name: /👍/ }))
108
+ expect(onToggle).not.toHaveBeenCalled()
109
+ })
110
+
111
+ it('offers no way to react where nothing writes a reaction, with no onToggle', () => {
112
+ render(
113
+ <ConversationCard author={ONE} time="11:08 AM" reactions={REACTED}>
114
+ Words
115
+ </ConversationCard>,
116
+ )
117
+ expect((screen.getByRole('button', { name: /👍/ }) as HTMLButtonElement).disabled).toBe(true)
118
+ expect(screen.queryByRole('button', { name: 'Add a reaction' })).toBeNull()
119
+ })
120
+
121
+ it('a deleted comment is read-only: no strip', () => {
122
+ render(
123
+ <ConversationCard author={ONE} time="11:08 AM" deleted own onDelete={() => {}} onResolve={() => {}} replies={{ count: 1 }}>
124
+ Words
125
+ </ConversationCard>,
126
+ )
127
+ point('This comment was deleted.')
128
+ expect(screen.queryByRole('button', { name: 'More actions' })).toBeNull()
129
+ })
130
+ })
131
+
132
+ describe('an edit the app holds: refused, it opens again (Peek: ConversationCard.refusedEdit)', () => {
133
+ it('opens the box while the app says it is being edited, and tells the app when the box is done', async () => {
134
+ const user = userEvent.setup()
135
+ const onEditingChange = vi.fn()
136
+ render(
137
+ <ConversationCard author={ONE} time="11:08 AM" own editing onEditingChange={onEditingChange} editor={editBox}>
138
+ Words
139
+ </ConversationCard>,
140
+ )
141
+ expect(screen.queryByText('Words')).toBeNull()
142
+ await user.click(screen.getByRole('button', { name: 'Save' }))
143
+ expect(onEditingChange).toHaveBeenCalledWith(false)
144
+ })
145
+
146
+ it('opens no box on a read-only card, even when the app says it is being edited', () => {
147
+ render(
148
+ <ConversationCard author={ONE} time="11:08 AM" own readOnly editing editor={editBox}>
149
+ Words
150
+ </ConversationCard>,
151
+ )
152
+ expect(screen.getByText('Words')).toBeTruthy()
153
+ expect(screen.queryByRole('button', { name: 'Save' })).toBeNull()
154
+ })
155
+
156
+ it('a reply too: its box opens while the app holds it', () => {
157
+ render(
158
+ <ReplyCard author={ONE} time="11:40 AM" own editing editor={editBox}>
159
+ A reply
160
+ </ReplyCard>,
161
+ )
162
+ expect(screen.getByRole('button', { name: 'Save' })).toBeTruthy()
163
+ })
164
+ })
165
+
166
+ describe('new and urgent (Peek: ConversationCard.urgent, the card’s part)', () => {
167
+ it('new: the dot, and the edge in the accent outline', () => {
168
+ const { container } = render(
169
+ <ConversationCard author={ONE} time="11:08 AM" isNew>
170
+ Words
171
+ </ConversationCard>,
172
+ )
173
+ expect(container.querySelector('[data-unread]')).not.toBeNull()
174
+ expect(container.firstElementChild?.className).toMatch(/\bborder-accent-outline\b/)
175
+ })
176
+
177
+ it('urgent: the urgent mark in place of the dot, and the edge in the warning outline', () => {
178
+ const { container } = render(
179
+ <ConversationCard author={ONE} time="11:08 AM" isNew urgent>
180
+ Words
181
+ </ConversationCard>,
182
+ )
183
+ expect(container.querySelector('[data-urgent]')).not.toBeNull()
184
+ expect(container.querySelector('[data-unread]')).toBeNull()
185
+ expect(container.firstElementChild?.className).toMatch(/\bborder-warning-outline\b/)
186
+ })
187
+
188
+ it('a new reply under it marks the comment too, and its replies row says "1 new"', () => {
189
+ const { container } = render(
190
+ <ConversationCard author={ONE} time="11:08 AM" replies={{ count: 2, isNew: true }}>
191
+ Words
192
+ </ConversationCard>,
193
+ )
194
+ expect(container.firstElementChild?.className).toMatch(/\bborder-accent-outline\b/)
195
+ expect(screen.getByText('1 new')).toBeTruthy()
196
+ })
197
+
198
+ it('read, it draws neither mark nor edge', () => {
199
+ const { container } = render(
200
+ <ConversationCard author={ONE} time="11:08 AM">
201
+ Words
202
+ </ConversationCard>,
203
+ )
204
+ expect(container.querySelector('[data-unread], [data-urgent]')).toBeNull()
205
+ expect(container.firstElementChild?.className).not.toMatch(/-outline\b/)
206
+ })
207
+
208
+ it('inside a thread drawn as one card, the dot alone says it: the one card is the edge', () => {
209
+ const { container } = render(
210
+ <InThreadCard.Provider value>
211
+ <ConversationCard author={ONE} time="11:08 AM" isNew>
212
+ Words
213
+ </ConversationCard>
214
+ </InThreadCard.Provider>,
215
+ )
216
+ expect(container.querySelector('[data-unread]')).not.toBeNull()
217
+ expect(container.firstElementChild?.className).not.toMatch(/\bborder-accent-outline\b/)
218
+ })
219
+
220
+ it('a new reply in a thread keeps its own edge', () => {
221
+ const { container } = render(
222
+ <InThreadCard.Provider value>
223
+ <ReplyCard author={ONE} time="11:40 AM" isNew>
224
+ A reply
225
+ </ReplyCard>
226
+ </InThreadCard.Provider>,
227
+ )
228
+ expect(container.firstElementChild?.className).toMatch(/\bborder-accent-outline\b/)
229
+ })
230
+ })
231
+
232
+ describe('what the review found (1 November)', () => {
233
+ it('says why a resolve was refused, under the note, while the dialog stays', async () => {
234
+ const user = userEvent.setup()
235
+ render(
236
+ <ConversationCard author={ONE} time="11:08 AM" onResolve={() => false} resolveRefused="The file is archived">
237
+ Words
238
+ </ConversationCard>,
239
+ )
240
+ point('Words')
241
+ fireEvent.click(screen.getByRole('button', { name: 'Resolve' }))
242
+ const dialog = await screen.findByRole('dialog')
243
+ await user.click(screen.getByRole('button', { name: 'Resolve' }))
244
+ expect(dialog.isConnected).toBe(true)
245
+ expect(screen.getByText(/The file is archived/)).toBeTruthy()
246
+ })
247
+
248
+ it('a double click picks a word: it is not a second press', () => {
249
+ const onClick = vi.fn()
250
+ render(
251
+ <ConversationCard author={ONE} time="11:08 AM" onClick={onClick}>
252
+ Words
253
+ </ConversationCard>,
254
+ )
255
+ fireEvent.click(screen.getByText('Words'), { detail: 1 })
256
+ fireEvent.click(screen.getByText('Words'), { detail: 2 })
257
+ expect(onClick).toHaveBeenCalledOnce()
258
+ })
259
+
260
+ it('words picked by a drag are not a press', () => {
261
+ const onClick = vi.fn()
262
+ render(
263
+ <ConversationCard author={ONE} time="11:08 AM" onClick={onClick}>
264
+ Words to pick
265
+ </ConversationCard>,
266
+ )
267
+ const words = screen.getByText('Words to pick')
268
+ const range = document.createRange()
269
+ range.setStart(words.firstChild!, 0)
270
+ range.setEnd(words.firstChild!, 5)
271
+ window.getSelection()!.removeAllRanges()
272
+ window.getSelection()!.addRange(range)
273
+ fireEvent.click(words, { detail: 1 })
274
+ expect(onClick).not.toHaveBeenCalled()
275
+ window.getSelection()!.removeAllRanges()
276
+ fireEvent.click(words, { detail: 1 })
277
+ expect(onClick).toHaveBeenCalledOnce()
278
+ })
279
+
280
+ it('open beside by the app’s own `selected`, a resolved comment is whole: its files show', () => {
281
+ render(
282
+ <ConversationCard author={ONE} time="11:08 AM" selected resolved={{ by: 'Person two' }} files={<span>plan.png</span>}>
283
+ Words
284
+ </ConversationCard>,
285
+ )
286
+ expect(screen.getByText('plan.png')).toBeTruthy()
287
+ })
288
+ })
289
+
290
+ describe('its files, what it is about, and how it was resolved', () => {
291
+ it('draws its files under the words, and holds them back while it is folded', () => {
292
+ render(
293
+ <ConversationCard author={ONE} time="11:08 AM" files={<span>plan.png</span>}>
294
+ Words
295
+ </ConversationCard>,
296
+ )
297
+ expect(after(screen.getByText('Words'), screen.getByText('plan.png'))).toBe(true)
298
+ cleanup()
299
+ render(
300
+ <ConversationCard author={ONE} time="11:08 AM" files={<span>plan.png</span>} resolved={{ by: 'Person two' }}>
301
+ Words
302
+ </ConversationCard>,
303
+ )
304
+ expect(screen.queryByText('plan.png')).toBeNull()
305
+ })
306
+
307
+ it('puts what it is about under the name and above the words (Katerina, 1 November), on a reply too', () => {
308
+ for (const Part of [ConversationCard, ReplyCard]) {
309
+ render(
310
+ <Part author={ONE} time="11:08 AM" about={<span>the quoted words</span>}>
311
+ Words
312
+ </Part>,
313
+ )
314
+ const name = screen.getByText('Person one')
315
+ const about = screen.getByText('the quoted words')
316
+ expect(after(name, about) && after(about, screen.getByText('Words'))).toBe(true)
317
+ cleanup()
318
+ }
319
+ })
320
+
321
+ it('resolved with no note: the check by the time, and no line', () => {
322
+ const { container } = render(
323
+ <ConversationCard author={ONE} time="11:08 AM" resolved={{ by: 'Person two' }}>
324
+ Words
325
+ </ConversationCard>,
326
+ )
327
+ expect(screen.getByText('Resolved')).toBeTruthy()
328
+ expect(container.querySelector('[data-resolved="line"]')).toBeNull()
329
+ })
330
+ })
@@ -0,0 +1,135 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { useState } from 'react'
3
+ import { ConversationCard, type ConversationCardProps } from './ConversationCard'
4
+ import { Column, EditBox, Files, LONG, Mentions, ONE, SOME, THREE, TWO, WithBlock, WithCard, WORDS, YOU, useReactions } from './conversation.examples'
5
+ import { RichText } from './RichText'
6
+ import { MenuItem } from './Menu'
7
+ import type { ReactionCount } from './ReactionRow'
8
+ import { QuotedLine } from './QuotedLine'
9
+
10
+ /**
11
+ * One comment, live: point at it for the strip, react, resolve with a note, and on your own edit or delete it.
12
+ */
13
+ const meta = {
14
+ title: 'Conversation/ConversationCard',
15
+ component: ConversationCard,
16
+ parameters: { layout: 'padded' },
17
+ args: { author: ONE, time: '11:08 AM', children: WORDS },
18
+ decorators: [(Story) => <Column>{Story()}</Column>],
19
+ } satisfies Meta<typeof ConversationCard>
20
+
21
+ export default meta
22
+ type Story = StoryObj<typeof meta>
23
+
24
+ /** Two paragraphs in RichText's own box, as an app's words come. */
25
+ const RICH = [
26
+ { type: 'paragraph' as const, inline: [{ text: WORDS, marks: [] }] },
27
+ { type: 'paragraph' as const, inline: [{ text: 'A second paragraph, held back while it is folded.', marks: [] }] },
28
+ ]
29
+
30
+ /** A card that answers: its reactions, resolve, edit and delete change it, as an app's would. */
31
+ function Live({ start, resolvedAt, deletable = true, ...props }: ConversationCardProps & { start?: readonly ReactionCount[]; resolvedAt?: { by: string; note?: string }; deletable?: boolean }) {
32
+ const reacting = useReactions(start)
33
+ const [resolved, setResolved] = useState(resolvedAt)
34
+ const [deleted, setDeleted] = useState(props.deleted ?? false)
35
+ return (
36
+ <ConversationCard
37
+ {...props}
38
+ deleted={deleted}
39
+ reactions={props.readOnly ? { ...reacting, onToggle: undefined } : reacting}
40
+ resolved={resolved}
41
+ onResolve={(note) => setResolved({ by: 'You', note: note || undefined })}
42
+ onReopen={() => setResolved(undefined)}
43
+ onDelete={deletable ? () => setDeleted(true) : undefined}
44
+ editor={props.own ? (done) => <EditBox text={typeof props.children === 'string' ? props.children : WORDS} done={done} /> : undefined}
45
+ />
46
+ )
47
+ }
48
+
49
+ /** Someone's comment. */
50
+ export const Comment: Story = { render: (args) => <Live {...args} /> }
51
+
52
+ /** Yours: Edit and Delete in its ⋯ menu. */
53
+ export const Yours: Story = { render: (args) => <Live {...args} author={YOU} own /> }
54
+
55
+ /** Edited since it was sent: "(edited)", its time on hover. */
56
+ export const Edited: Story = { render: (args) => <Live {...args} edited="Edited 11:20 AM" /> }
57
+
58
+ /** Deleted: its replies stay under it. */
59
+ export const Deleted: Story = { render: (args) => <Live {...args} deleted replies={{ count: 2, faces: [TWO, THREE], last: '11:40 AM' }} /> }
60
+
61
+ /** Pictures and files under the words. */
62
+ export const WithFiles: Story = { name: 'Files', render: (args) => <Live {...args} files={<Files />} /> }
63
+
64
+ /** A card its author attached. */
65
+ export const Card: Story = { render: (args) => <Live {...args}><WithCard /></Live> }
66
+
67
+ /** On a part of the page: the words it is on, under the name and above its words. */
68
+ export const OnAPart: Story = { name: 'On a part', render: (args) => <Live {...args} about={<QuotedLine words="the words this comment is on" />} /> }
69
+
70
+ /** The words changed since: the bar goes grey, and it says so. */
71
+ export const PartChanged: Story = { name: 'Part changed', render: (args) => <Live {...args} about={<QuotedLine words="the words this comment was on" state="reworded" />} /> }
72
+
73
+ /** A block quoted from something else. */
74
+ export const QuotedBlock: Story = { name: 'Quoted block', render: (args) => <Live {...args}><WithBlock /></Live> }
75
+
76
+ /** With reactions: press one to add yours or take it back. */
77
+ export const Reactions: Story = { render: (args) => <Live {...args} start={SOME} /> }
78
+
79
+ /** With replies: the row that opens its thread. */
80
+ export const Replies: Story = { render: (args) => <Live {...args} replies={{ count: 3, faces: [TWO, THREE, YOU], last: '12:02 PM' }} onReply={() => {}} onClick={() => {}} /> }
81
+
82
+ /** Not read yet. */
83
+ export const New: Story = { render: (args) => <Live {...args} isNew /> }
84
+
85
+ /** A reply under it not read yet. */
86
+ export const NewReply: Story = { name: 'New reply', render: (args) => <Live {...args} replies={{ count: 2, faces: [TWO, THREE], last: '12:02 PM', isNew: true }} onClick={() => {}} /> }
87
+
88
+ /** Urgent and not read yet. */
89
+ export const Urgent: Story = { render: (args) => <Live {...args} isNew urgent replies={{ count: 1, faces: [TWO], last: '12:02 PM', isNew: true }} /> }
90
+
91
+ /** A person named in the words, and a link. */
92
+ export const WithMentions: Story = { name: 'Mentions', render: (args) => <Live {...args}><Mentions /></Live> }
93
+
94
+ /** Resolved, folded: "Resolved" by the time, who and the note above its replies; closed, its words in one line, its reactions and files held back. */
95
+ export const Resolved: Story = { render: (args) => <Live {...args} start={SOME} resolvedAt={{ by: 'Person two', note: 'Keeping the first one.' }} replies={{ count: 2, faces: [TWO, THREE], last: '12:02 PM' }} /> }
96
+
97
+ /** Resolved, its words in a box of their own, as the apps draw them (RichText here): folded, still their first line. */
98
+ export const ResolvedInABox: Story = {
99
+ name: 'Resolved, words in a box',
100
+ render: (args) => (
101
+ <Live {...args} resolvedAt={{ by: 'Person two', note: 'Keeping the first one.' }}>
102
+ <RichText blocks={RICH} />
103
+ </Live>
104
+ ),
105
+ }
106
+
107
+ /** Resolved with a long note: the whole note, on its line above the replies. */
108
+ export const ResolvedLongNote: Story = { name: 'Resolved, long note', render: (args) => <Live {...args} resolvedAt={{ by: 'Person two', note: 'Agreed, going with the first one, and the second goes to the list of later ideas with its reasons written beside it.' }} /> }
109
+
110
+ /** The one open beside its thread. */
111
+ export const Selected: Story = { render: (args) => <Live {...args} selected replies={{ count: 2, faces: [TWO, THREE], last: '12:02 PM' }} onClick={() => {}} /> }
112
+
113
+ /** Being edited, in the kit's box. */
114
+ export const Editing: Story = { render: (args) => <Live {...args} author={YOU} own editing /> }
115
+
116
+ /** An edit that was refused: the box opens again, and says why. */
117
+ export const EditRefused: Story = {
118
+ name: 'Edit refused',
119
+ render: (args) => <ConversationCard {...args} author={YOU} own editing editor={(done) => <EditBox text={WORDS} done={done} refuse />} />,
120
+ }
121
+
122
+ /** A reaction that was refused: said under the reactions. */
123
+ export const ReactionRefused: Story = { name: 'Reaction refused', render: (args) => <Live {...args} start={SOME} reactionRefused="try again in a moment" /> }
124
+
125
+ /** Nothing can be changed: no strip, reactions only shown. */
126
+ export const ReadOnly: Story = { name: 'Read-only', render: (args) => <Live {...args} readOnly start={SOME} replies={{ count: 2, faces: [TWO, THREE], last: '12:02 PM' }} /> }
127
+
128
+ /** A long comment, at its full height. */
129
+ export const Long: Story = { render: (args) => <Live {...args}>{LONG}</Live> }
130
+
131
+ /** The app's own rows in its ⋯ menu, between Resolve and Edit. */
132
+ export const MoreRows: Story = {
133
+ name: 'More rows',
134
+ render: (args) => <Live {...args} author={YOU} own menu={<MenuItem label="Item one" onClick={() => {}} />} />,
135
+ }