@noix-dev/brix-vue 0.0.0-stage → 0.2.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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/package.json +117 -3
  4. package/src/components/address-field/AddressField.vue +337 -0
  5. package/src/components/address-field/index.ts +1 -0
  6. package/src/components/appearance-picker/AppearancePicker.vue +502 -0
  7. package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
  8. package/src/components/appearance-picker/index.ts +44 -0
  9. package/src/components/autofill/AutoFillDialog.vue +264 -0
  10. package/src/components/autofill/index.ts +1 -0
  11. package/src/components/badge/Badge.vue +23 -0
  12. package/src/components/badge/index.ts +106 -0
  13. package/src/components/build-stamp/BuildStamp.vue +62 -0
  14. package/src/components/build-stamp/index.ts +1 -0
  15. package/src/components/button/Button.vue +31 -0
  16. package/src/components/button/index.ts +122 -0
  17. package/src/components/card/Card.vue +29 -0
  18. package/src/components/card/CardAction.vue +17 -0
  19. package/src/components/card/CardContent.vue +14 -0
  20. package/src/components/card/CardDescription.vue +14 -0
  21. package/src/components/card/CardFooter.vue +22 -0
  22. package/src/components/card/CardHeader.vue +22 -0
  23. package/src/components/card/CardTitle.vue +29 -0
  24. package/src/components/card/index.ts +47 -0
  25. package/src/components/chart/BarChart.vue +123 -0
  26. package/src/components/chart/StackedBarChart.vue +149 -0
  27. package/src/components/chart/appearanceRevision.ts +22 -0
  28. package/src/components/chart/chartColor.ts +59 -0
  29. package/src/components/chart/index.ts +6 -0
  30. package/src/components/checkbox/Checkbox.vue +61 -0
  31. package/src/components/checkbox/index.ts +1 -0
  32. package/src/components/code-editor/CodeEditor.vue +352 -0
  33. package/src/components/code-editor/index.ts +9 -0
  34. package/src/components/code-editor/syntaxTheme.ts +110 -0
  35. package/src/components/colour-picker/ColourPicker.vue +421 -0
  36. package/src/components/colour-picker/index.ts +1 -0
  37. package/src/components/combobox/Combobox.vue +337 -0
  38. package/src/components/combobox/index.ts +1 -0
  39. package/src/components/comments/CommentComposer.vue +302 -0
  40. package/src/components/comments/CommentMessage.vue +259 -0
  41. package/src/components/comments/CommentThread.vue +250 -0
  42. package/src/components/comments/commentBody.ts +185 -0
  43. package/src/components/comments/commentLevels.ts +139 -0
  44. package/src/components/comments/commentNode.ts +35 -0
  45. package/src/components/comments/composer.ts +20 -0
  46. package/src/components/comments/index.ts +29 -0
  47. package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
  48. package/src/components/confirm-dialog/index.ts +1 -0
  49. package/src/components/containers/Box.vue +42 -0
  50. package/src/components/containers/Section.vue +88 -0
  51. package/src/components/containers/SectionAction.vue +17 -0
  52. package/src/components/containers/SectionContent.vue +14 -0
  53. package/src/components/containers/SectionDescription.vue +14 -0
  54. package/src/components/containers/SectionHeader.vue +22 -0
  55. package/src/components/containers/SectionTitle.vue +17 -0
  56. package/src/components/containers/index.ts +9 -0
  57. package/src/components/data-table/ColumnMenu.vue +241 -0
  58. package/src/components/data-table/DataTable.vue +447 -0
  59. package/src/components/data-table/ExpandCaret.vue +34 -0
  60. package/src/components/data-table/SortableHead.vue +184 -0
  61. package/src/components/data-table/TableLoadingRow.vue +13 -0
  62. package/src/components/data-table/TableProgressRow.vue +26 -0
  63. package/src/components/data-table/columns.ts +13 -0
  64. package/src/components/data-table/index.ts +3 -0
  65. package/src/components/data-table/pinned.ts +19 -0
  66. package/src/components/data-table/rowActivation.ts +14 -0
  67. package/src/components/data-table/sort.ts +13 -0
  68. package/src/components/data-table/types.ts +23 -0
  69. package/src/components/date-picker/CalendarPanel.vue +432 -0
  70. package/src/components/date-picker/DateField.vue +293 -0
  71. package/src/components/date-picker/DatePicker.vue +147 -0
  72. package/src/components/date-picker/UntilDatePicker.vue +96 -0
  73. package/src/components/date-picker/dateFieldGuard.ts +87 -0
  74. package/src/components/date-picker/index.ts +4 -0
  75. package/src/components/date-picker/useDateField.ts +37 -0
  76. package/src/components/date-range-picker/DateRangePicker.vue +247 -0
  77. package/src/components/date-range-picker/index.ts +1 -0
  78. package/src/components/date-time-picker/DateTimePicker.vue +291 -0
  79. package/src/components/date-time-picker/index.ts +1 -0
  80. package/src/components/dialog/Dialog.vue +250 -0
  81. package/src/components/dialog/DialogSurface.vue +214 -0
  82. package/src/components/dialog/dialogEdges.ts +65 -0
  83. package/src/components/dialog/dialogSizes.ts +35 -0
  84. package/src/components/dialog/index.ts +12 -0
  85. package/src/components/dialog/toastHost.ts +18 -0
  86. package/src/components/dropdown/Dropdown.vue +101 -0
  87. package/src/components/dropdown/DropdownItems.vue +154 -0
  88. package/src/components/dropdown/dropdown.ts +64 -0
  89. package/src/components/dropdown/index.ts +2 -0
  90. package/src/components/file-preview/FilePreview.vue +78 -0
  91. package/src/components/file-preview/index.ts +1 -0
  92. package/src/components/file-upload/FileUpload.vue +234 -0
  93. package/src/components/file-upload/index.ts +1 -0
  94. package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
  95. package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
  96. package/src/components/filter-check-menu/index.ts +2 -0
  97. package/src/components/form-field/FormField.vue +74 -0
  98. package/src/components/form-field/index.ts +2 -0
  99. package/src/components/form-field/types.ts +5 -0
  100. package/src/components/frames/FrameCentred.vue +137 -0
  101. package/src/components/frames/FrameSidebar.vue +113 -0
  102. package/src/components/frames/FrameSplit.vue +109 -0
  103. package/src/components/frames/index.ts +3 -0
  104. package/src/components/icon/BellIcon.vue +27 -0
  105. package/src/components/icon/BoldIcon.vue +31 -0
  106. package/src/components/icon/CalendarDaysIcon.vue +33 -0
  107. package/src/components/icon/CheckIcon.vue +31 -0
  108. package/src/components/icon/ChevronDownIcon.vue +30 -0
  109. package/src/components/icon/ChevronLeftIcon.vue +31 -0
  110. package/src/components/icon/ChevronRightIcon.vue +31 -0
  111. package/src/components/icon/ChevronUpIcon.vue +30 -0
  112. package/src/components/icon/CircleAlertIcon.vue +29 -0
  113. package/src/components/icon/ClockIcon.vue +31 -0
  114. package/src/components/icon/Columns3Icon.vue +32 -0
  115. package/src/components/icon/FlipHorizontalIcon.vue +29 -0
  116. package/src/components/icon/ItalicIcon.vue +28 -0
  117. package/src/components/icon/LinkIcon.vue +27 -0
  118. package/src/components/icon/ListIcon.vue +29 -0
  119. package/src/components/icon/ListOrderedIcon.vue +28 -0
  120. package/src/components/icon/PenLineIcon.vue +31 -0
  121. package/src/components/icon/PlusIcon.vue +28 -0
  122. package/src/components/icon/RotateCcwIcon.vue +28 -0
  123. package/src/components/icon/RotateCwIcon.vue +28 -0
  124. package/src/components/icon/SearchIcon.vue +31 -0
  125. package/src/components/icon/StarIcon.vue +29 -0
  126. package/src/components/icon/TriangleAlertIcon.vue +29 -0
  127. package/src/components/icon/UnderlineIcon.vue +27 -0
  128. package/src/components/icon/Undo2Icon.vue +28 -0
  129. package/src/components/icon/XIcon.vue +31 -0
  130. package/src/components/icon/ZoomInIcon.vue +30 -0
  131. package/src/components/icon/ZoomOutIcon.vue +29 -0
  132. package/src/components/icon/index.ts +37 -0
  133. package/src/components/icon-picker/IconPicker.vue +560 -0
  134. package/src/components/icon-picker/index.ts +1 -0
  135. package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
  136. package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
  137. package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
  138. package/src/components/image-crop-dialog/index.ts +16 -0
  139. package/src/components/image-upload/ImageUpload.vue +345 -0
  140. package/src/components/image-upload/index.ts +2 -0
  141. package/src/components/input/Input.vue +48 -0
  142. package/src/components/input/index.ts +1 -0
  143. package/src/components/keycap/Keycap.vue +49 -0
  144. package/src/components/keycap/index.ts +1 -0
  145. package/src/components/label/Label.vue +26 -0
  146. package/src/components/label/index.ts +1 -0
  147. package/src/components/menu/MenuCheckboxItem.vue +63 -0
  148. package/src/components/menu/MenuContent.vue +45 -0
  149. package/src/components/menu/MenuGroup.vue +22 -0
  150. package/src/components/menu/MenuItem.vue +34 -0
  151. package/src/components/menu/MenuLabel.vue +22 -0
  152. package/src/components/menu/MenuRadioGroup.vue +22 -0
  153. package/src/components/menu/MenuRadioItem.vue +50 -0
  154. package/src/components/menu/MenuRoot.vue +25 -0
  155. package/src/components/menu/MenuSeparator.vue +27 -0
  156. package/src/components/menu/MenuSub.vue +29 -0
  157. package/src/components/menu/MenuSubContent.vue +48 -0
  158. package/src/components/menu/MenuSubTrigger.vue +49 -0
  159. package/src/components/menu/MenuTrigger.vue +22 -0
  160. package/src/components/menu/index.ts +20 -0
  161. package/src/components/menu/menuClasses.ts +74 -0
  162. package/src/components/morph-select/MorphSelect.vue +150 -0
  163. package/src/components/morph-select/index.ts +1 -0
  164. package/src/components/nav/NavFlyout.vue +343 -0
  165. package/src/components/nav/NavGroup.vue +306 -0
  166. package/src/components/nav/NavItem.vue +243 -0
  167. package/src/components/nav/NavNodes.ts +66 -0
  168. package/src/components/nav/NavSection.vue +105 -0
  169. package/src/components/nav/NavSidebar.vue +137 -0
  170. package/src/components/nav/index.ts +5 -0
  171. package/src/components/nav/navChain.ts +112 -0
  172. package/src/components/nav/navClasses.ts +229 -0
  173. package/src/components/nav/navNode.ts +10 -0
  174. package/src/components/nav/navRegistry.ts +24 -0
  175. package/src/components/notification-list/NotificationList.vue +314 -0
  176. package/src/components/notification-list/index.ts +2 -0
  177. package/src/components/notification-list/notifications.ts +21 -0
  178. package/src/components/pagination/Pagination.vue +296 -0
  179. package/src/components/pagination/index.ts +1 -0
  180. package/src/components/pin-field/PinField.vue +332 -0
  181. package/src/components/pin-field/index.ts +1 -0
  182. package/src/components/popover-panel/PopoverPanel.vue +115 -0
  183. package/src/components/popover-panel/index.ts +5 -0
  184. package/src/components/rating/Rating.vue +201 -0
  185. package/src/components/rating/index.ts +1 -0
  186. package/src/components/record-avatar/RecordAvatar.vue +76 -0
  187. package/src/components/record-avatar/index.ts +1 -0
  188. package/src/components/result-window/ResultWindow.vue +399 -0
  189. package/src/components/result-window/index.ts +2 -0
  190. package/src/components/result-window/results.ts +75 -0
  191. package/src/components/rich-editor/RichEditor.vue +370 -0
  192. package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
  193. package/src/components/rich-editor/index.ts +8 -0
  194. package/src/components/row-actions/RowActions.vue +262 -0
  195. package/src/components/row-actions/index.ts +2 -0
  196. package/src/components/row-actions/rowActions.ts +44 -0
  197. package/src/components/search-select/SearchSelect.vue +599 -0
  198. package/src/components/search-select/index.ts +2 -0
  199. package/src/components/search-select/types.ts +14 -0
  200. package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
  201. package/src/components/segmented-choice/index.ts +2 -0
  202. package/src/components/segmented-choice/segmentedOption.ts +6 -0
  203. package/src/components/select/Select.vue +18 -0
  204. package/src/components/select/SelectContent.vue +73 -0
  205. package/src/components/select/SelectGroup.vue +21 -0
  206. package/src/components/select/SelectItem.vue +47 -0
  207. package/src/components/select/SelectItemText.vue +12 -0
  208. package/src/components/select/SelectLabel.vue +17 -0
  209. package/src/components/select/SelectScrollDownButton.vue +36 -0
  210. package/src/components/select/SelectScrollUpButton.vue +36 -0
  211. package/src/components/select/SelectSeparator.vue +19 -0
  212. package/src/components/select/SelectTrigger.vue +52 -0
  213. package/src/components/select/SelectValue.vue +12 -0
  214. package/src/components/select/index.ts +11 -0
  215. package/src/components/session/IdleTimer.vue +71 -0
  216. package/src/components/session/SessionDialogs.vue +177 -0
  217. package/src/components/session/index.ts +2 -0
  218. package/src/components/split-button/SplitButton.vue +122 -0
  219. package/src/components/split-button/index.ts +2 -0
  220. package/src/components/split-button/splitButtonItem.ts +7 -0
  221. package/src/components/switch/Switch.vue +60 -0
  222. package/src/components/switch/index.ts +1 -0
  223. package/src/components/table/Table.vue +51 -0
  224. package/src/components/table/TableBody.vue +14 -0
  225. package/src/components/table/TableCaption.vue +17 -0
  226. package/src/components/table/TableCell.vue +22 -0
  227. package/src/components/table/TableEmpty.vue +72 -0
  228. package/src/components/table/TableFooter.vue +17 -0
  229. package/src/components/table/TableHead.vue +22 -0
  230. package/src/components/table/TableHeader.vue +14 -0
  231. package/src/components/table/TableRow.vue +22 -0
  232. package/src/components/table/index.ts +9 -0
  233. package/src/components/tabs/Tabs.vue +173 -0
  234. package/src/components/tabs/index.ts +2 -0
  235. package/src/components/tabs/tabItem.ts +12 -0
  236. package/src/components/textarea/LimitedTextarea.vue +81 -0
  237. package/src/components/textarea/TextLimitCounter.vue +107 -0
  238. package/src/components/textarea/Textarea.vue +42 -0
  239. package/src/components/textarea/index.ts +4 -0
  240. package/src/components/textarea/textLimit.ts +43 -0
  241. package/src/components/time-picker/TimePicker.vue +522 -0
  242. package/src/components/time-picker/index.ts +1 -0
  243. package/src/components/toast/ToastHost.vue +276 -0
  244. package/src/components/toast/index.ts +1 -0
  245. package/src/components/update-notice/UpdateNotice.vue +103 -0
  246. package/src/components/update-notice/index.ts +1 -0
  247. package/src/components/user-menu/UserMenu.vue +154 -0
  248. package/src/components/user-menu/index.ts +1 -0
  249. package/src/index.ts +182 -0
  250. package/src/lib/cn.ts +21 -0
  251. package/src/lib/panelFocus.ts +65 -0
  252. package/src/lib/sessionMonitor.ts +390 -0
  253. package/src/lib/slotContent.ts +17 -0
  254. package/src/lib/updateCheck.ts +133 -0
  255. package/src/styles.css +82 -0
@@ -0,0 +1,259 @@
1
+ <script setup lang="ts">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { Badge, type Tone } from '../badge';
6
+ import { RecordAvatar } from '../record-avatar';
7
+ import { levelTone, toneInk, type CommentLevel } from './commentLevels';
8
+
9
+ /**
10
+ * One comment: an avatar, who wrote it, an optional level marker, when, the body, and whether it
11
+ * has been read. The atom both of this family's surfaces are built from.
12
+ *
13
+ * **TWO DENSITIES, AND THE ANSWER ROLE IS NOT ONE OF THEM.** `density` is `card` for a reading
14
+ * surface and `row` for a dense list; both ship, because an application that reads and an
15
+ * application that works in a list need different ones and a forced middle fits neither.
16
+ * `answer` is a separate axis: an answer carries the smaller avatar at either density, which is
17
+ * the approved record's own distinction between the two.
18
+ *
19
+ * **THE LEVEL IS A 3px EDGE PLUS A BADGE, AND NEVER A WASH OF THE WHOLE MESSAGE.** That was
20
+ * settled by measurement, not taste. Four grounds were tried for a wash — `--muted`,
21
+ * `--accent-tint` and two washes of the level's own tone — over three themes and both modes, 24
22
+ * readings: none exceeded 1.29 against the card, and every light-mode reading sat between 1.07
23
+ * and 1.18. A surface nobody sees at a glance marks nothing, and a tinted ground would also move
24
+ * the timestamp onto a pairing `badge/index.ts` records at 4.34 in kingfisher light. The edge
25
+ * reads 5.94 to 9.16 on every ground tried, in both modes, with each mode's own ink.
26
+ *
27
+ * **The figures that involve a fixed-palette tone are browser readings, and no gate can
28
+ * reproduce those.** The level tones are Tailwind's fixed palette, which Tailwind 4 writes in
29
+ * `oklch()`; several of those rungs are outside sRGB, where `packages/tokens/src/contrast.ts`
30
+ * throws rather than clipping, so a `pairs` entry would make the gate throw instead of measure.
31
+ * See `CLAUDE.md`'s invariant 3. The readings over `--muted` and `--accent-tint` are a different
32
+ * case and this caveat does not cover them: both are contract roles the gate does read, in all
33
+ * three themes.
34
+ *
35
+ * **The unread dot is `--primary`.** `--brand-alt` was proposed and measured 2.82 in noix dark
36
+ * and 2.94 in graphite dark, against the 3:1 a non-text mark needs.
37
+ *
38
+ * **It formats no timestamp.** `timestamp` is already formatted and `datetime` is the machine
39
+ * value. Choosing a formatter would choose a locale, a time zone and a relative-time policy for
40
+ * every consumer, and would put a date library where ADR 0014 spent a slice keeping one out.
41
+ *
42
+ * **Editing in place is a slot, not a mode.** The `body` slot replaces the rendered body, so a
43
+ * consumer puts its own editor there and this family owns no second one.
44
+ */
45
+ const props = withDefaults(
46
+ defineProps<{
47
+ /** Who wrote it. Also the source of the initials, unless `initials` is given. */
48
+ author: string;
49
+ /** One or two letters. Without it the family derives them from `author`. */
50
+ initials?: string;
51
+ /** The author's picture. Null, undefined or empty all mean "no picture". */
52
+ avatarSrc?: string | null;
53
+ /**
54
+ * The body, as HTML. **The consumer sanitises it** — this family draws what it is given,
55
+ * which is the same contract both of the implementations it replaces work under. A
56
+ * consumer that will not hand over HTML uses the `body` slot instead.
57
+ */
58
+ body?: string;
59
+ /** Already formatted, by the consumer. */
60
+ timestamp?: string;
61
+ /** The machine value for `<time datetime>`. Without it no `<time>` element is drawn. */
62
+ datetime?: string;
63
+ density?: 'card' | 'row';
64
+ /** The answer role: the smaller avatar, at either density. */
65
+ answer?: boolean;
66
+ unread?: boolean;
67
+ /** The role pill's text — the consumer's own word for what the author is. */
68
+ role?: string;
69
+ /** The role pill's tone. Left out, `Badge`'s own default stands — this file keeps no
70
+ * second copy of it. */
71
+ roleTone?: Tone;
72
+ /** Drawn as a 3px edge in the level's tone, plus a badge carrying its label. */
73
+ level?: CommentLevel;
74
+ /** The list the fallback tone is positioned in; only needed when `level.tone` is absent. */
75
+ levels?: readonly CommentLevel[];
76
+ unreadLabel?: string;
77
+ class?: string;
78
+ }>(),
79
+ { density: 'card' },
80
+ );
81
+
82
+ const labels = useUiLabels();
83
+
84
+ const unreadText = computed(() => props.unreadLabel ?? labels.value.commentsUnread);
85
+
86
+ /** Two letters from the first two words, one from a single word, `?` from nothing at all. */
87
+ const initials = computed(() => {
88
+ if (props.initials !== undefined && props.initials !== '') {
89
+ return props.initials;
90
+ }
91
+
92
+ const letters = props.author
93
+ .trim()
94
+ .split(/\s+/)
95
+ .filter((word) => word !== '')
96
+ .slice(0, 2)
97
+ .map((word) => word.charAt(0).toUpperCase())
98
+ .join('');
99
+
100
+ return letters === '' ? '?' : letters;
101
+ });
102
+
103
+ /** The avatar shrinks for the row density and for an answer — two reasons, one size. */
104
+ const small = computed(() => props.density === 'row' || props.answer === true);
105
+
106
+ /**
107
+ * What the body draws for the markup it is handed. The figures are the approved record's: a
108
+ * paragraph gap of 6px at the card density — the record draws 5px at the row density, which
109
+ * `docs/design/README.md` carries as a deviation — lists indented one step with their own
110
+ * markers, and links in
111
+ * `--primary-on-wash`, which is the gated pair for ink on a wash of the primary.
112
+ *
113
+ * It is a constant in the script, not a class string in the template, to keep this element's
114
+ * start tag short: it already carries `v-html` and sits inside an eslint block suppression, and a
115
+ * class attribute of this length between the two makes the pair hard to read. That is a
116
+ * legibility reason and nothing more — under the block form, which is what this file uses, how
117
+ * many lines the element spans constrains nothing. (An earlier version of this note claimed
118
+ * `RichEditor` keeps a constant "for the same reason". It does not: `RichEditor` has no `v-html`
119
+ * anywhere, and its own reason is that its class string goes to an element the library owns.)
120
+ */
121
+ const BODY_CLASS =
122
+ 'text-foreground [&_a]:text-primary-on-wash break-words [&_a]:font-semibold [&_a]:underline [&_ol]:my-1 [&_ol]:list-decimal [&_ol]:ps-[18px] [&_p]:mb-1.5 [&_p:last-child]:mb-0 [&_ul]:my-1 [&_ul]:list-disc [&_ul]:ps-[18px]';
123
+
124
+ /**
125
+ * The timestamp's own classes, one constant for both branches. They were written out twice, once
126
+ * on the `<time>` element and once on the plain `<span>`, which is two places for one figure to
127
+ * drift apart in — and the density assertion touches neither.
128
+ */
129
+ const TIME_CLASS = 'text-muted-foreground ms-auto text-[11px] whitespace-nowrap';
130
+
131
+ const bodySize = computed(() => (props.density === 'row' ? 'text-[12.5px]' : 'text-[13.5px]'));
132
+
133
+ const tone = computed(() =>
134
+ props.level === undefined ? undefined : levelTone(props.levels ?? [props.level], props.level),
135
+ );
136
+ </script>
137
+
138
+ <template>
139
+ <div
140
+ data-testid="comment-message"
141
+ data-slot="comment-message"
142
+ :class="
143
+ cn(
144
+ 'relative flex gap-3',
145
+ // Room for the level edge at the message's own left, not at the card's.
146
+ props.level === undefined ? '' : '-mx-3 px-3',
147
+ props.class,
148
+ )
149
+ "
150
+ >
151
+ <span
152
+ v-if="props.level !== undefined && tone !== undefined"
153
+ data-slot="comment-level-edge"
154
+ aria-hidden="true"
155
+ :class="
156
+ cn('absolute inset-y-0 start-0 w-[3px] rounded-e-[3px] bg-current', toneInk(tone))
157
+ "
158
+ />
159
+
160
+ <RecordAvatar
161
+ shape="round"
162
+ :src="props.avatarSrc"
163
+ :initials="initials"
164
+ :class="small ? 'size-[26px] text-[10.5px]' : 'size-[34px] text-[12px]'"
165
+ />
166
+
167
+ <div data-slot="comment-body-column" class="min-w-0 flex-1">
168
+ <div data-slot="comment-meta-line" class="mb-0.5 flex flex-wrap items-center gap-2">
169
+ <span
170
+ v-if="props.unread"
171
+ data-slot="comment-unread"
172
+ role="img"
173
+ :aria-label="unreadText"
174
+ :title="unreadText"
175
+ class="bg-primary size-2 shrink-0 rounded-full"
176
+ />
177
+ <span
178
+ data-slot="comment-author"
179
+ :class="
180
+ cn('font-bold', props.density === 'row' ? 'text-[12.5px]' : 'text-[13.5px]')
181
+ "
182
+ >{{ props.author }}</span
183
+ >
184
+ <Badge
185
+ v-if="props.role !== undefined"
186
+ data-testid="comment-role"
187
+ :tone="props.roleTone"
188
+ >{{ props.role }}</Badge
189
+ >
190
+ <Badge
191
+ v-if="props.level !== undefined && tone !== undefined"
192
+ data-testid="comment-level"
193
+ :tone="tone"
194
+ >
195
+ <span class="size-1.5 shrink-0 rounded-full bg-current" aria-hidden="true" />
196
+ {{ props.level.label }}
197
+ </Badge>
198
+ <slot name="meta" />
199
+ <time
200
+ v-if="props.timestamp !== undefined && props.datetime !== undefined"
201
+ data-slot="comment-time"
202
+ :datetime="props.datetime"
203
+ :class="TIME_CLASS"
204
+ >{{ props.timestamp }}</time
205
+ >
206
+ <span
207
+ v-else-if="props.timestamp !== undefined"
208
+ data-slot="comment-time"
209
+ :class="TIME_CLASS"
210
+ >{{ props.timestamp }}</span
211
+ >
212
+ </div>
213
+
214
+ <!--
215
+ `#body` is the named form, which is what a thread forwards; the default slot is
216
+ the same door for a consumer writing the body as children. Without the default
217
+ branch `<CommentMessage>text</CommentMessage>` renders nothing at all, silently.
218
+ -->
219
+ <div
220
+ v-if="$slots.body || $slots.default"
221
+ data-slot="comment-body"
222
+ :class="cn('text-foreground break-words', bodySize)"
223
+ >
224
+ <slot name="body"><slot /></slot>
225
+ </div>
226
+ <!--
227
+ eslint-disable vue/no-v-html -- The consumer sanitises the body; this family
228
+ draws what it is given, which is the contract both implementations it replaces
229
+ already work under. The `body` slot is the escape for a consumer that will not
230
+ hand over HTML. The block form is used because an HTML comment cannot sit inside
231
+ a start tag, and Prettier breaks this element's attributes across lines, so
232
+ `eslint-disable-next-line` would reach the wrong one.
233
+ -->
234
+ <div
235
+ v-else-if="props.body !== undefined"
236
+ data-slot="comment-body"
237
+ :class="cn(BODY_CLASS, bodySize)"
238
+ v-html="props.body"
239
+ />
240
+ <!-- eslint-enable vue/no-v-html -->
241
+
242
+ <div
243
+ v-if="$slots.actions"
244
+ data-slot="comment-actions"
245
+ class="mt-[5px] flex flex-wrap gap-2.5"
246
+ >
247
+ <slot name="actions" />
248
+ </div>
249
+
250
+ <ul
251
+ v-if="$slots.answers"
252
+ data-slot="comment-answers"
253
+ class="border-border mt-3 grid list-none gap-3 border-s ps-5"
254
+ >
255
+ <slot name="answers" />
256
+ </ul>
257
+ </div>
258
+ </div>
259
+ </template>
@@ -0,0 +1,250 @@
1
+ <script setup lang="ts">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { SegmentedChoice, type SegmentedOption } from '../segmented-choice';
6
+ import CommentMessage from './CommentMessage.vue';
7
+ import { levelByKey, type CommentLevel } from './commentLevels';
8
+ import type { CommentNode } from './commentNode';
9
+
10
+ /**
11
+ * A conversation: comments in order, one level of answers under each, and — where there is more
12
+ * than one level to choose between — a filter above them.
13
+ *
14
+ * **It draws no card and no head.** No border, no radius, no background, no title, no count. The
15
+ * approved record puts the thread head out of scope, and the implementation this replaces carries
16
+ * a `flat` prop for exactly this reason: a thread that draws its own surface inside a container
17
+ * that already names the section reads as a pile of boxes. A consumer that wants a surface wraps
18
+ * it in `Card`, which is one line.
19
+ *
20
+ * **The filter hides top-level comments only.** An answer is never hidden away from the comment it
21
+ * answers, because an exchange with one half missing reads as though it never happened. Whether a
22
+ * reader may see a body at all is the backend's business, not this family's.
23
+ *
24
+ * **It owns no loading, no paging and no read state** (ADR 0017). Comments already given stay on
25
+ * screen while more are fetched — a consumer that polls would otherwise throw away the reader's
26
+ * place every time — and the status line says so above them. Where a filter is also matching
27
+ * nothing, the line still reads "loading": while a fetch is in flight it is not yet true that
28
+ * nothing matches, so that is the honest answer and not a wording bug.
29
+ */
30
+ const props = withDefaults(
31
+ defineProps<{
32
+ comments: readonly CommentNode[];
33
+ /** The levels a comment's `levelKey` is resolved against. */
34
+ levels?: readonly CommentLevel[];
35
+ /**
36
+ * The filter's value: a level key, or `''` for all of them. Controlled — the thread
37
+ * emits `update:filterLevel` and draws what it is then given.
38
+ */
39
+ filterLevel?: string;
40
+ density?: 'card' | 'row';
41
+ loading?: boolean;
42
+ loadingLabel?: string;
43
+ emptyLabel?: string;
44
+ emptyFilteredLabel?: string;
45
+ allLevelsLabel?: string;
46
+ filterLabel?: string;
47
+ class?: string;
48
+ }>(),
49
+ { density: 'card', filterLevel: '' },
50
+ );
51
+
52
+ const emit = defineEmits<{ (e: 'update:filterLevel', value: string): void }>();
53
+
54
+ const labels = useUiLabels();
55
+
56
+ /**
57
+ * One option fewer than two is a control that cannot be used: a radio group offering "all levels"
58
+ * and the single level it has says nothing a reader could act on (Review Focus 2).
59
+ */
60
+ const showFilter = computed(() => (props.levels?.length ?? 0) > 1);
61
+
62
+ /**
63
+ * "All levels" plus one option per level. `''` is the sentinel for "all" and is therefore
64
+ * **reserved**: a level declaring it is left out rather than drawn as a second option with the
65
+ * same value, which produced two `aria-checked="true"` radios in one group and emitted "all" when
66
+ * the level was chosen.
67
+ */
68
+ const filterOptions = computed<SegmentedOption[]>(() => [
69
+ { value: '', label: props.allLevelsLabel ?? labels.value.commentsAllLevels },
70
+ ...(props.levels ?? [])
71
+ .filter((level) => level.key !== '')
72
+ .map((level) => ({ value: level.key, label: level.label })),
73
+ ]);
74
+
75
+ /**
76
+ * The filter actually in force, which is not always the one the consumer passed.
77
+ *
78
+ * **A filter hides nothing it cannot offer to unhide.** Two predicates:
79
+ *
80
+ * 1. Only a **declared** level key filters. A key absent from `levels` means "all", the same rule
81
+ * the marker follows — a key the consumer no longer declares is not a level. Without this a
82
+ * stale key empties the thread at every level count.
83
+ * 2. A filter applies only where its **control is drawn**. Below two levels there is no control,
84
+ * so a non-empty `filterLevel` would hide comments with no way for the reader to clear it:
85
+ * "No comments at this level" and nothing to press. The wording is not a mitigation for that.
86
+ *
87
+ * The cost is stated plainly: a one-level consumer driving `filterLevel` from a control of its
88
+ * own gets no filtering here. That is visible at once, because nothing is hidden.
89
+ */
90
+ const activeFilter = computed(() =>
91
+ showFilter.value && levelByKey(props.levels ?? [], props.filterLevel) !== undefined
92
+ ? props.filterLevel
93
+ : '',
94
+ );
95
+
96
+ /** Top-level comments only. Their answers travel with them, whatever level each answer carries. */
97
+ const shown = computed(() =>
98
+ activeFilter.value === ''
99
+ ? props.comments
100
+ : props.comments.filter((comment) => comment.levelKey === activeFilter.value),
101
+ );
102
+
103
+ /**
104
+ * Loading first, then "none at all", then "none at this level". The middle one is the honest
105
+ * reading when there is nothing to filter: a reader told their filter is hiding things, when the
106
+ * conversation is simply empty, goes looking for a filter to clear.
107
+ */
108
+ const state = computed<'loading' | 'empty' | 'filtered' | 'ready'>(() => {
109
+ if (props.loading === true) {
110
+ return 'loading';
111
+ }
112
+ if (shown.value.length > 0) {
113
+ return 'ready';
114
+ }
115
+ return props.comments.length === 0 ? 'empty' : 'filtered';
116
+ });
117
+
118
+ const statusText = computed(() => {
119
+ if (state.value === 'loading') {
120
+ return props.loadingLabel ?? labels.value.commentsLoading;
121
+ }
122
+ if (state.value === 'empty') {
123
+ return props.emptyLabel ?? labels.value.commentsEmpty;
124
+ }
125
+ return state.value === 'filtered'
126
+ ? (props.emptyFilteredLabel ?? labels.value.commentsEmptyFiltered)
127
+ : '';
128
+ });
129
+
130
+ const levelFor = (comment: CommentNode): CommentLevel | undefined =>
131
+ levelByKey(props.levels ?? [], comment.levelKey);
132
+
133
+ const gap = computed(() => (props.density === 'row' ? 'gap-2.5' : 'gap-3.5'));
134
+ </script>
135
+
136
+ <template>
137
+ <div
138
+ data-testid="comment-thread"
139
+ data-slot="comment-thread"
140
+ :class="cn('grid gap-3', props.class)"
141
+ >
142
+ <SegmentedChoice
143
+ v-if="showFilter"
144
+ data-testid="comment-filter"
145
+ class="justify-self-start"
146
+ :model-value="activeFilter"
147
+ :options="filterOptions"
148
+ :group-label="props.filterLabel ?? labels.commentsFilterName"
149
+ testid-prefix="comment-filter"
150
+ @update:model-value="emit('update:filterLevel', $event)"
151
+ />
152
+
153
+ <ul v-if="shown.length > 0" data-slot="comment-thread-list" :class="cn('grid', gap)">
154
+ <li v-for="comment in shown" :key="comment.id">
155
+ <CommentMessage
156
+ :author="comment.author"
157
+ :initials="comment.initials"
158
+ :avatar-src="comment.avatarSrc"
159
+ :body="comment.body"
160
+ :timestamp="comment.timestamp"
161
+ :datetime="comment.datetime"
162
+ :role="comment.role"
163
+ :role-tone="comment.roleTone"
164
+ :unread="comment.unread"
165
+ :level="levelFor(comment)"
166
+ :levels="props.levels"
167
+ :density="props.density"
168
+ :answer="false"
169
+ >
170
+ <!--
171
+ Each forwarding template is conditional on the consumer having given that
172
+ slot. `CommentMessage` asks `$slots.body` to decide between a slotted body
173
+ and the rendered one, and asks `$slots.actions` before drawing a row at
174
+ all — an unconditional template here is always truthy there, so it would
175
+ silently drop every rendered body and leave an empty row under each
176
+ message.
177
+ -->
178
+ <template v-if="$slots.meta" #meta>
179
+ <slot name="meta" :comment="comment" :answer="false" />
180
+ </template>
181
+ <template v-if="$slots.body" #body>
182
+ <slot name="body" :comment="comment" :answer="false" />
183
+ </template>
184
+ <template v-if="$slots.actions" #actions>
185
+ <slot name="actions" :comment="comment" :answer="false" />
186
+ </template>
187
+
188
+ <template
189
+ v-if="comment.answers !== undefined && comment.answers.length > 0"
190
+ #answers
191
+ >
192
+ <li v-for="answer in comment.answers" :key="answer.id">
193
+ <!--
194
+ One level, and the nesting is structural rather than a depth
195
+ counter: an answer's own `answers` have nowhere to go here, so a
196
+ second level cannot appear by accident.
197
+ -->
198
+ <CommentMessage
199
+ :author="answer.author"
200
+ :initials="answer.initials"
201
+ :avatar-src="answer.avatarSrc"
202
+ :body="answer.body"
203
+ :timestamp="answer.timestamp"
204
+ :datetime="answer.datetime"
205
+ :role="answer.role"
206
+ :role-tone="answer.roleTone"
207
+ :unread="answer.unread"
208
+ :level="levelFor(answer)"
209
+ :levels="props.levels"
210
+ :density="props.density"
211
+ :answer="true"
212
+ >
213
+ <template v-if="$slots.meta" #meta>
214
+ <slot name="meta" :comment="answer" :answer="true" />
215
+ </template>
216
+ <template v-if="$slots.body" #body>
217
+ <slot name="body" :comment="answer" :answer="true" />
218
+ </template>
219
+ <template v-if="$slots.actions" #actions>
220
+ <slot name="actions" :comment="answer" :answer="true" />
221
+ </template>
222
+ </CommentMessage>
223
+ </li>
224
+ </template>
225
+ </CommentMessage>
226
+ </li>
227
+ </ul>
228
+
229
+ <!--
230
+ ONE `role="status"` node that stays put, carrying `data-state`, hidden from sight
231
+ when there is nothing to say. `NotificationList` — the nearest sibling, with the same
232
+ four states — does exactly this, and its docblock records the reason: what a screen
233
+ reader reliably gets is the TEXT CHANGING while the node stays where it is, not the
234
+ insertion of a new node. A `v-else` line is the insertion case, in a family whose
235
+ three empty states exist to tell a reader their filter is hiding something.
236
+ -->
237
+ <p
238
+ role="status"
239
+ data-slot="comment-thread-empty"
240
+ :data-state="state"
241
+ :class="
242
+ state === 'ready'
243
+ ? 'sr-only'
244
+ : 'text-muted-foreground py-6 text-center text-[12.5px]'
245
+ "
246
+ >
247
+ {{ statusText }}
248
+ </p>
249
+ </div>
250
+ </template>