@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,562 @@
1
+ <script setup lang="ts">
2
+ import { formatLabel, useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed, nextTick, ref, useAttrs, watch } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { movePanelFocus, panelFocusables } from '../../lib/panelFocus';
6
+ import { buttonVariants } from '../button';
7
+ import { Checkbox } from '../checkbox';
8
+ import { ChevronDownIcon, ChevronUpIcon } from '../icon';
9
+ import { Input } from '../input';
10
+ import { PopoverPanel } from '../popover-panel';
11
+ import type { FilterCheckOption } from './filterCheckOption';
12
+
13
+ /**
14
+ * A filter dropdown: checkboxes, one level of grouping (a group's children are leaves, never
15
+ * deeper), an optional count beside each entry, an optional search field, an optional tail
16
+ * collapsed behind a reveal, and a reset. The model is the flat list of selected values.
17
+ *
18
+ * AN EMPTY SELECTION IS VALID and means "unfiltered". That is the caller's contract and nothing
19
+ * here refuses to emit `[]`.
20
+ *
21
+ * THE PANEL is the `PopoverPanel` shell, named by its trigger: the shell has no label prop, so
22
+ * the panel's accessible name is the trigger's own content, `triggerLabel ?? label` and the
23
+ * count badge. `label` is also the panel's visible heading. The shell supplies dismissal on an
24
+ * outside press, Escape with focus back on the trigger, and the portal; it supplies no focus
25
+ * trap and no tab stop, so what sits in the panel decides its stops, and Tab here closes the
26
+ * panel and leaves focus on the trigger instead of stranding it in a portal at the end of the
27
+ * document.
28
+ *
29
+ * VALUES THE MENU DOES NOT RENDER SURVIVE. A click adds or removes the clicked entry's values
30
+ * and leaves everything else where it is: values the options do not cover, and the children of
31
+ * a group that is not expanded. A selected entry behind the reveal opens the tail when the
32
+ * menu opens, because the trigger counts it and a menu that hid it would contradict its own
33
+ * badge; that is a starting state only, and unchecking the last such entry does not shut it.
34
+ * The tail and the expanded groups belong to the component, not to one opening; the query
35
+ * belongs to one opening and is cleared when the panel closes.
36
+ *
37
+ * `collapseAfter` is the index from which entries sit behind the reveal. Omitted: nothing is
38
+ * collapsed. 0 (or less): every entry is behind the reveal. At or beyond the number of
39
+ * entries: nothing is behind it, so there is no reveal and no divider.
40
+ *
41
+ * SEARCH covers every entry, the collapsed tail included: a search that skipped them would
42
+ * answer "nothing found" about entries that are there. A group shows when its own label or a
43
+ * child's matches, with the matching children listed; a group matched on its own label alone
44
+ * stands alone and its checkbox still selects the whole group.
45
+ *
46
+ * WORDING comes from the labels contract (`revealMore`, `hideMore`, `variants`, `search`,
47
+ * `searchIn`, `nothingFound`, `reset`). A prop of the same job (`revealLabel`, `hideLabel`,
48
+ * `childrenLabel`, `searchPlaceholder`, `emptyLabel`, `resetLabel`) beats the contract for one
49
+ * call site. The trigger's text is not wording: it is the caller's `label`.
50
+ *
51
+ * EVERY NUMBER IS GROUPED, through one `Intl.NumberFormat`: an entry's count, a group's child
52
+ * count in both the label and the button, and the reveal's hidden count. `locale` names the
53
+ * grouping; left out it is the runtime's own, as the charts in the same slice have it.
54
+ *
55
+ * THE GLYPHS are slots (ADR 0013): `chevron-icon` (the trigger's), and `expand-icon` and
56
+ * `collapse-icon`, which are shared by a group's toggle and by the reveal, closed and open.
57
+ *
58
+ * Attributes (`id`, `aria-*`, `data-*`) and `class` land on the trigger, and a consumer's attribute
59
+ * beats the family's own default: its `data-testid` replaces `filter-check-trigger`. The one
60
+ * exception is `type`, which is always `button`: a trigger that submitted a form would be a defect.
61
+ * Listeners are merged, not replaced.
62
+ *
63
+ * IT ALSO BEATS THE SHELL'S OWN STATE ATTRIBUTES, which is the half of the rule a consumer
64
+ * would not guess. `PopoverPanel` renders its trigger `as-child`, and reka's `mergeProps(shell,
65
+ * child)` lets the child win, so an `aria-expanded`, `aria-controls` or `data-state` passed in
66
+ * here replaces the one the popover engine writes — a trigger that then says `aria-expanded`
67
+ * is false while its panel is open. Do not pass those three names. The rule belongs to the
68
+ * shell and is written in `PopoverPanel`'s own docblock and on its page, which is where a
69
+ * consumer of the published shell meets it; it is restated here because this family forwards
70
+ * attributes onto that trigger. The finding is parked in `CLAUDE.md`, because the fix — the
71
+ * shell reserving the three names — belongs there rather than in a consumer.
72
+ */
73
+ defineOptions({ inheritAttrs: false });
74
+
75
+ const props = withDefaults(
76
+ defineProps<{
77
+ /** The panel's heading and the trigger's text, e.g. 'Job status'. */
78
+ label: string;
79
+ /**
80
+ * Text on the trigger when it should differ from the heading, e.g. a summary of the
81
+ * selection such as 'Only: On the bench'. Omit for the trigger to show `label`.
82
+ */
83
+ triggerLabel?: string;
84
+ options: FilterCheckOption[];
85
+ /** Selected values, flat. May hold values no entry stands for; they are kept as they are. */
86
+ modelValue: string[];
87
+ /** Entries from this index on live behind the reveal. Omit for no collapsing. */
88
+ collapseAfter?: number;
89
+ /** Divider caption above the collapsed tail, e.g. 'Finished jobs from here'. */
90
+ collapseLabel?: string;
91
+ /** Overrides the contract's `revealMore`; the hidden count is appended in brackets. */
92
+ revealLabel?: string;
93
+ /** Overrides the contract's `hideMore`. */
94
+ hideLabel?: string;
95
+ /** Overrides the contract's `variants`: the noun after a group's child count. */
96
+ childrenLabel?: string;
97
+ /**
98
+ * A search field above the entries. Worth it from a few dozen entries on; below that
99
+ * it is one more thing to look past, so it is opt-in rather than a length threshold.
100
+ */
101
+ searchable?: boolean;
102
+ /** Overrides the contract's `search`. */
103
+ searchPlaceholder?: string;
104
+ /** Overrides the contract's `nothingFound`. */
105
+ emptyLabel?: string;
106
+ /** Overrides the contract's `reset`. */
107
+ resetLabel?: string;
108
+ /**
109
+ * The locale the counts are grouped in. Left out, `Intl.NumberFormat` takes the
110
+ * runtime's own locale — deliberately, and not `'en-US'` or `'de-DE'`: a consumer who
111
+ * supplies a catalogue in their language should not get American digit grouping
112
+ * beside it. A caller who wants a fixed grouping names it here.
113
+ */
114
+ locale?: string;
115
+ }>(),
116
+ {
117
+ triggerLabel: undefined,
118
+ // No default on purpose: without `collapseAfter` nothing is collapsed.
119
+ collapseAfter: undefined,
120
+ collapseLabel: undefined,
121
+ revealLabel: undefined,
122
+ hideLabel: undefined,
123
+ childrenLabel: undefined,
124
+ searchable: false,
125
+ searchPlaceholder: undefined,
126
+ emptyLabel: undefined,
127
+ resetLabel: undefined,
128
+ locale: undefined,
129
+ },
130
+ );
131
+
132
+ // An empty selection is a valid result ("unfiltered" is the caller's contract), so
133
+ // nothing here ever refuses to emit [].
134
+ const emit = defineEmits<{ (e: 'update:modelValue', values: string[]): void }>();
135
+
136
+ const attrs = useAttrs();
137
+ const contract = useUiLabels();
138
+
139
+ const text = computed(() => ({
140
+ reveal: props.revealLabel ?? contract.value.revealMore,
141
+ hide: props.hideLabel ?? contract.value.hideMore,
142
+ children: props.childrenLabel ?? contract.value.variants,
143
+ placeholder: props.searchPlaceholder ?? contract.value.search,
144
+ empty: props.emptyLabel ?? contract.value.nothingFound,
145
+ reset: props.resetLabel ?? contract.value.reset,
146
+ }));
147
+
148
+ // A plain function, not a `computed`: enumerating `useAttrs()` depends on the values of the
149
+ // attributes present when it runs and not on the key set, so a computed would never see a consumer
150
+ // add one later. Measured on Vue 3.5.46, identical in the development and the production build.
151
+ function triggerAttrs(): Record<string, unknown> {
152
+ return Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== 'class'));
153
+ }
154
+
155
+ // Every count this menu draws goes through one formatter: a four-digit facet count read 1234
156
+ // beside a chart in the same slice reading 1.234.
157
+ const numberFormatter = computed(() => new Intl.NumberFormat(props.locale));
158
+ function formatCount(value: number | undefined): string {
159
+ return numberFormatter.value.format(value ?? 0);
160
+ }
161
+
162
+ type CheckState = boolean | 'indeterminate';
163
+
164
+ interface EntryRow {
165
+ kind: 'entry';
166
+ key: string;
167
+ option: FilterCheckOption;
168
+ child: boolean;
169
+ tail: boolean;
170
+ // A group's expand/collapse button. Off while searching, where the matching children are
171
+ // already on screen and a toggle would claim to control something that is not in play.
172
+ toggleable: boolean;
173
+ }
174
+ interface DividerRow {
175
+ kind: 'divider';
176
+ key: string;
177
+ }
178
+ type Row = EntryRow | DividerRow;
179
+
180
+ /**
181
+ * What a row is, said by the component rather than read off the classes that happen to draw
182
+ * it. The playground's contrast drive keys its tail and child assertions on this: it used to
183
+ * key them on `text-muted-foreground` and `border-l-2`, which was reachable-correct and tied
184
+ * the one instrument nothing else checks to a restyle.
185
+ *
186
+ * A token list, not one value: a child of a group that sits in the tail is both, and the two
187
+ * selectors have to keep counting it twice as the classes did.
188
+ */
189
+ function rowKinds(row: EntryRow): string | undefined {
190
+ const kinds = [row.child ? 'child' : '', row.tail ? 'tail' : ''].filter((kind) => kind !== '');
191
+ return kinds.length > 0 ? kinds.join(' ') : undefined;
192
+ }
193
+
194
+ const panelEl = ref<HTMLElement | null>(null);
195
+ const open = ref(false);
196
+ // Both states belong to the component, not to one opening of the menu: once the tail or a
197
+ // group is open it stays open until the user closes it again.
198
+ const tailOpen = ref(false);
199
+ const expandedGroups = ref<Set<string>>(new Set());
200
+ // The query belongs to one opening, not to the component: a menu reopened on a stale query
201
+ // would show a handful of entries and no sign of why. Cleared when the panel closes.
202
+ const query = ref('');
203
+
204
+ const selected = computed(() => new Set(props.modelValue));
205
+
206
+ function stateOf(option: FilterCheckOption): CheckState {
207
+ const hits = option.values.filter((value) => selected.value.has(value)).length;
208
+ if (hits === 0) {
209
+ return false;
210
+ }
211
+ return hits === option.values.length ? true : 'indeterminate';
212
+ }
213
+
214
+ function isGroup(option: FilterCheckOption): boolean {
215
+ return (option.children?.length ?? 0) > 0;
216
+ }
217
+
218
+ // Top-level entries only; a group counts once, and only while every child is selected.
219
+ const selectedCount = computed(
220
+ () => props.options.filter((option) => stateOf(option) === true).length,
221
+ );
222
+
223
+ const split = computed(() => {
224
+ const at =
225
+ props.collapseAfter === undefined ? props.options.length : Math.max(0, props.collapseAfter);
226
+ return { head: props.options.slice(0, at), tail: props.options.slice(at) };
227
+ });
228
+
229
+ // The reveal counts what the user would see appear: a group is its children, not one entry.
230
+ const hiddenCount = computed(() =>
231
+ split.value.tail.reduce((sum, option) => sum + (option.children?.length || 1), 0),
232
+ );
233
+
234
+ function entryRows(list: FilterCheckOption[], tail: boolean): EntryRow[] {
235
+ return list.flatMap((option) => {
236
+ const row: EntryRow = {
237
+ kind: 'entry',
238
+ key: option.key,
239
+ option,
240
+ child: false,
241
+ tail,
242
+ toggleable: true,
243
+ };
244
+ if (!isGroup(option) || !expandedGroups.value.has(option.key)) {
245
+ return [row];
246
+ }
247
+ const children = (option.children ?? []).map((child): EntryRow => ({
248
+ kind: 'entry',
249
+ key: child.key,
250
+ option: child,
251
+ child: true,
252
+ tail,
253
+ toggleable: true,
254
+ }));
255
+ return [row, ...children];
256
+ });
257
+ }
258
+
259
+ const trimmedQuery = computed(() => (props.searchable ? query.value.trim() : ''));
260
+ const searching = computed(() => trimmedQuery.value.length > 0);
261
+
262
+ function hits(option: FilterCheckOption, needle: string): boolean {
263
+ return option.label.toLowerCase().includes(needle);
264
+ }
265
+
266
+ /**
267
+ * Search rows, drawn from every option, the collapsed tail included. A group is shown when its
268
+ * own label matches or any child's does, and the children listed are the matching ones. A
269
+ * group that matches on its own label with no matching child stands alone: its checkbox still
270
+ * selects the whole group.
271
+ */
272
+ function searchRows(): Row[] {
273
+ const needle = trimmedQuery.value.toLowerCase();
274
+ return props.options.flatMap((option): Row[] => {
275
+ const row: EntryRow = {
276
+ kind: 'entry',
277
+ key: option.key,
278
+ option,
279
+ child: false,
280
+ tail: false,
281
+ toggleable: false,
282
+ };
283
+ if (!isGroup(option)) {
284
+ return hits(option, needle) ? [row] : [];
285
+ }
286
+ const children = (option.children ?? [])
287
+ .filter((child) => hits(child, needle))
288
+ .map((child): EntryRow => ({
289
+ kind: 'entry',
290
+ key: child.key,
291
+ option: child,
292
+ child: true,
293
+ tail: false,
294
+ toggleable: false,
295
+ }));
296
+ if (children.length === 0 && !hits(option, needle)) {
297
+ return [];
298
+ }
299
+ return [row, ...children];
300
+ });
301
+ }
302
+
303
+ const rows = computed<Row[]>(() => {
304
+ if (searching.value) {
305
+ return searchRows();
306
+ }
307
+ const { head, tail } = split.value;
308
+ const list: Row[] = entryRows(head, false);
309
+ if (tail.length === 0) {
310
+ return list;
311
+ }
312
+ list.push({ kind: 'divider', key: '__divider__' });
313
+ if (tailOpen.value) {
314
+ list.push(...entryRows(tail, true));
315
+ }
316
+ return list;
317
+ });
318
+
319
+ // Adds and removes by value and leaves everything else where it is, so values the menu
320
+ // does not render (collapsed away, or unknown to `options`) survive a click on a visible one.
321
+ function toggle(option: FilterCheckOption): void {
322
+ if (stateOf(option) === false) {
323
+ const added = [...new Set(option.values)].filter((value) => !selected.value.has(value));
324
+ emit('update:modelValue', [...props.modelValue, ...added]);
325
+ return;
326
+ }
327
+ const removed = new Set(option.values);
328
+ emit(
329
+ 'update:modelValue',
330
+ props.modelValue.filter((value) => !removed.has(value)),
331
+ );
332
+ }
333
+
334
+ function toggleGroup(key: string): void {
335
+ const next = new Set(expandedGroups.value);
336
+ if (!next.delete(key)) {
337
+ next.add(key);
338
+ }
339
+ expandedGroups.value = next;
340
+ }
341
+
342
+ // In DOM order, so arrow keys walk the panel top to bottom: reset, search, entries, reveal.
343
+ function focusables(): HTMLElement[] {
344
+ return panelFocusables(panelEl.value);
345
+ }
346
+
347
+ /**
348
+ * Where focus belongs when the panel appears, or when whatever held it was removed: the
349
+ * search field, else the first entry, else anything at all inside the panel. Never the reset
350
+ * button, which is the panel's first focusable element and the last thing a user opening the
351
+ * menu wants.
352
+ *
353
+ * The last fallback is not pedantry. The panel's keyboard handlers are bound to the panel, so
354
+ * focus on `<body>` leaves an open menu that cannot be navigated and cannot be closed with
355
+ * Escape: a trap, reachable the moment a menu renders no entries.
356
+ */
357
+ function focusIntoPanel(): void {
358
+ const panel = panelEl.value;
359
+ const target =
360
+ panel?.querySelector<HTMLElement>('[data-filter-search]') ??
361
+ panel?.querySelector<HTMLElement>('[data-filter-entry]') ??
362
+ focusables()[0];
363
+ target?.focus();
364
+ }
365
+
366
+ // The shell's engine would focus the panel's first tabbable element, which is the reset button
367
+ // whenever there is a selection. Take the focus ourselves.
368
+ function onOpenAutoFocus(event: Event): void {
369
+ event.preventDefault();
370
+ focusIntoPanel();
371
+ }
372
+
373
+ function moveFocus(delta: number): void {
374
+ movePanelFocus(panelEl.value, delta);
375
+ }
376
+
377
+ watch(open, (isOpen) => {
378
+ if (!isOpen) {
379
+ query.value = '';
380
+ return;
381
+ }
382
+ // Whatever is selected is on screen from the start, tail included. The trigger counts
383
+ // those entries, so hiding them behind the reveal would have the menu contradict its
384
+ // own badge. Only the initial state: unchecking the last one must not snap it shut.
385
+ tailOpen.value ||= split.value.tail.some((option) => stateOf(option) !== false);
386
+ });
387
+
388
+ // The reset button unmounts itself the moment this lands (`v-if` on the selection it just
389
+ // emptied), taking the focus with it. Hand focus back into the panel on the next tick,
390
+ // after the parent's new modelValue has re-rendered.
391
+ function reset(): void {
392
+ emit('update:modelValue', []);
393
+ void nextTick(focusIntoPanel);
394
+ }
395
+ </script>
396
+
397
+ <template>
398
+ <PopoverPanel v-model:open="open" @open-auto-focus="onOpenAutoFocus">
399
+ <template #trigger>
400
+ <button
401
+ data-testid="filter-check-trigger"
402
+ v-bind="triggerAttrs()"
403
+ type="button"
404
+ :class="
405
+ cn(
406
+ buttonVariants({ variant: 'outline', size: 'sm' }),
407
+ // `text-primary-on-wash`, not `text-primary`: the label sits on the
408
+ // 10% wash right beside it, where not every area hue clears WCAG AA.
409
+ props.modelValue.length > 0 &&
410
+ 'border-primary bg-primary/10 text-primary-on-wash hover:bg-primary/15 dark:bg-primary/15',
411
+ attrs.class as string | undefined,
412
+ )
413
+ "
414
+ >
415
+ <span class="truncate">{{ props.triggerLabel ?? props.label }}</span>
416
+ <span
417
+ v-if="selectedCount > 0"
418
+ data-testid="filter-check-count"
419
+ class="bg-primary text-primary-foreground rounded-full px-1.5 text-[10px] leading-4 font-extrabold"
420
+ >{{ selectedCount }}</span
421
+ >
422
+ <slot name="chevron-icon"><ChevronDownIcon class="text-muted-foreground" /></slot>
423
+ </button>
424
+ </template>
425
+
426
+ <template #panel>
427
+ <div
428
+ ref="panelEl"
429
+ data-testid="filter-check-panel"
430
+ class="w-72 max-w-full"
431
+ @keydown.down.prevent="moveFocus(1)"
432
+ @keydown.up.prevent="moveFocus(-1)"
433
+ @keydown.tab="open = false"
434
+ >
435
+ <div class="flex items-center gap-2 px-2 pt-1 pb-1.5">
436
+ <span
437
+ class="text-muted-foreground text-[9.5px] font-extrabold tracking-wider uppercase"
438
+ >{{ props.label }}</span
439
+ >
440
+ <button
441
+ v-if="props.modelValue.length > 0"
442
+ type="button"
443
+ data-testid="filter-check-clear"
444
+ class="text-primary-on-wash hover:bg-primary/10 focus-visible:ring-ring focus-visible:ring-offset-background ml-auto rounded px-1 py-0.5 text-[10.5px] font-bold outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
445
+ @click="reset"
446
+ >
447
+ {{ text.reset }}
448
+ </button>
449
+ </div>
450
+
451
+ <Input
452
+ v-if="props.searchable"
453
+ v-model="query"
454
+ data-filter-search
455
+ data-testid="filter-check-search"
456
+ type="search"
457
+ :placeholder="text.placeholder"
458
+ :aria-label="formatLabel(contract.searchIn, { label: props.label })"
459
+ class="mb-1.5 h-7 px-2 text-[12.5px] md:text-[12.5px]"
460
+ />
461
+
462
+ <ul>
463
+ <template v-for="row in rows" :key="row.key">
464
+ <li
465
+ v-if="row.kind === 'divider'"
466
+ role="separator"
467
+ data-testid="filter-check-divider"
468
+ class="text-muted-foreground my-1.5 flex items-center gap-2 px-0.5 text-[10px] font-bold"
469
+ >
470
+ <span class="bg-border h-px flex-1" />
471
+ <template v-if="props.collapseLabel">
472
+ <span>{{ props.collapseLabel }}</span>
473
+ <span class="bg-border h-px flex-1" />
474
+ </template>
475
+ </li>
476
+ <li
477
+ v-else
478
+ :data-testid="`filter-check-row-${row.key}`"
479
+ :data-row="rowKinds(row)"
480
+ :class="
481
+ cn(
482
+ 'hover:bg-muted flex items-center gap-1.5 rounded px-2 py-1 text-[12.5px]',
483
+ row.child &&
484
+ 'border-border ml-4.5 rounded-l-none border-l-2 pl-2',
485
+ row.tail && 'text-muted-foreground',
486
+ )
487
+ "
488
+ >
489
+ <label
490
+ :class="
491
+ cn(
492
+ 'flex min-w-0 cursor-pointer items-center gap-2',
493
+ !(isGroup(row.option) && row.toggleable) && 'flex-1',
494
+ )
495
+ "
496
+ >
497
+ <Checkbox
498
+ class="size-4 rounded"
499
+ data-filter-entry
500
+ :data-testid="`filter-check-option-${row.key}`"
501
+ :model-value="stateOf(row.option)"
502
+ @update:model-value="toggle(row.option)"
503
+ />
504
+ <span class="min-w-0 truncate">{{ row.option.label }}</span>
505
+ </label>
506
+ <button
507
+ v-if="isGroup(row.option) && row.toggleable"
508
+ type="button"
509
+ :data-testid="`filter-check-group-toggle-${row.key}`"
510
+ :aria-expanded="expandedGroups.has(row.key)"
511
+ :aria-label="`${row.option.label}: ${formatCount(row.option.children?.length)} ${text.children}`"
512
+ class="text-muted-foreground hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background inline-flex items-center gap-0.5 rounded px-1 text-[10.5px] outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
513
+ @click="toggleGroup(row.key)"
514
+ >
515
+ <slot v-if="expandedGroups.has(row.key)" name="collapse-icon"
516
+ ><ChevronUpIcon class="size-3"
517
+ /></slot>
518
+ <slot v-else name="expand-icon"
519
+ ><ChevronDownIcon class="size-3"
520
+ /></slot>
521
+ <span
522
+ >{{ formatCount(row.option.children?.length) }}
523
+ {{ text.children }}</span
524
+ >
525
+ </button>
526
+ <span
527
+ v-if="row.option.count !== undefined"
528
+ class="text-muted-foreground ml-auto text-[10.5px] font-semibold tabular-nums"
529
+ >{{ formatCount(row.option.count) }}</span
530
+ >
531
+ </li>
532
+ </template>
533
+ </ul>
534
+
535
+ <p
536
+ v-if="searching && rows.length === 0"
537
+ data-testid="filter-check-empty"
538
+ class="text-muted-foreground px-2 py-3 text-center text-[12px]"
539
+ >
540
+ {{ text.empty }}
541
+ </p>
542
+
543
+ <button
544
+ v-if="!searching && split.tail.length > 0"
545
+ type="button"
546
+ data-testid="filter-check-reveal"
547
+ :aria-expanded="tailOpen"
548
+ class="text-primary-on-wash bg-primary/10 hover:bg-primary/15 focus-visible:ring-ring focus-visible:ring-offset-background mt-1 flex w-full items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-[11.5px] font-bold outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
549
+ @click="tailOpen = !tailOpen"
550
+ >
551
+ <slot v-if="tailOpen" name="collapse-icon"
552
+ ><ChevronUpIcon class="size-3.5"
553
+ /></slot>
554
+ <slot v-else name="expand-icon"><ChevronDownIcon class="size-3.5" /></slot>
555
+ <span>{{
556
+ tailOpen ? text.hide : `${text.reveal} (${formatCount(hiddenCount)})`
557
+ }}</span>
558
+ </button>
559
+ </div>
560
+ </template>
561
+ </PopoverPanel>
562
+ </template>
@@ -0,0 +1,10 @@
1
+ export interface FilterCheckOption {
2
+ /** Stable identity for keying and tests. Unique across the whole tree. */
3
+ key: string;
4
+ label: string;
5
+ /** The filter values this entry stands for. A leaf has one; a group has its children's union. */
6
+ values: string[];
7
+ count?: number;
8
+ /** One level only: a child's own `children` are not rendered. */
9
+ children?: FilterCheckOption[];
10
+ }
@@ -0,0 +1,2 @@
1
+ export { default as FilterCheckMenu } from './FilterCheckMenu.vue';
2
+ export type { FilterCheckOption } from './filterCheckOption';
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ import type { FormFieldLabelVariant } from './types';
3
+ import { computed, useId, useSlots } from 'vue';
4
+ import { Label } from '../label';
5
+
6
+ /**
7
+ * A label and its control. The root carries `data-slot="form-field"` and the label
8
+ * `data-slot="label"`: the page-density rules in the token package address the pair by those
9
+ * hooks, so they are part of the contract.
10
+ *
11
+ * The control goes in the default slot, which receives `{ id, describedBy }`. THE CONTROL MUST
12
+ * BIND BOTH: `:id="id"` is what the label points at, and without it the label points at
13
+ * nothing; `:aria-describedby="describedBy"` ties the control to its description, which
14
+ * `role="alert"` only announces once. `describedBy` names the `note` while a note is
15
+ * rendered and the error while an error shows — note first, which is reading order — and is
16
+ * `undefined` when there is neither. A visible hint that is never announced is a hint only
17
+ * sighted users get, which is why the note is in there and not just the error.
18
+ *
19
+ * The `id` prop only fixes the value the slot receives (for an external `<label for>` or a
20
+ * test hook); it does not put the id on anything. Without it one is generated. A hint goes in
21
+ * `note`; a validation message goes in `error`.
22
+ */
23
+ const props = defineProps<{
24
+ label: string;
25
+ id?: string;
26
+ error?: string;
27
+ /**
28
+ * `caps` is `uppercase` through CSS only, so the DOM text and the accessible name stay as
29
+ * written.
30
+ */
31
+ labelVariant?: FormFieldLabelVariant;
32
+ }>();
33
+
34
+ /**
35
+ * Typed so the contract is discoverable from the component rather than from the prose above:
36
+ * thirteen families are wired to `{ id, describedBy }` today and twenty-eight more will be.
37
+ */
38
+ defineSlots<{
39
+ /** The control. It MUST bind `:id="id"` **and** `:aria-describedby="describedBy"`. */
40
+ default: (props: { id: string; describedBy: string | undefined }) => unknown;
41
+ /**
42
+ * A hint under the control, announced with it: a wrapper carries an id that joins
43
+ * `describedBy`, so the slot's own content needs no id of its own.
44
+ */
45
+ note?: () => unknown;
46
+ }>();
47
+
48
+ const slots = useSlots();
49
+ const generatedId = useId();
50
+ const fieldId = computed(() => props.id ?? generatedId);
51
+ const errorId = computed(() => `${fieldId.value}-error`);
52
+ const noteId = computed(() => `${fieldId.value}-note`);
53
+ const describedBy = computed(
54
+ () =>
55
+ [slots.note ? noteId.value : undefined, props.error ? errorId.value : undefined]
56
+ .filter(Boolean)
57
+ .join(' ') || undefined,
58
+ );
59
+
60
+ const CAPS_LABEL = 'text-[10.5px] font-extrabold tracking-[0.1em] text-muted-foreground uppercase';
61
+ </script>
62
+
63
+ <template>
64
+ <div data-slot="form-field" class="grid gap-1.5">
65
+ <Label :for="fieldId" :class="labelVariant === 'caps' ? CAPS_LABEL : undefined">{{
66
+ label
67
+ }}</Label>
68
+ <slot :id="fieldId" :described-by="describedBy" />
69
+ <!-- The wrapper exists to carry the id `describedBy` names; the slot's content stays
70
+ whatever the caller wrote. -->
71
+ <div v-if="$slots.note" :id="noteId"><slot name="note" /></div>
72
+ <p v-if="error" :id="errorId" role="alert" class="text-destructive text-sm">{{ error }}</p>
73
+ </div>
74
+ </template>
@@ -0,0 +1,2 @@
1
+ export { default as FormField } from './FormField.vue';
2
+ export type { FormFieldLabelVariant } from './types';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `default` is the sentence-case label of a dense screen. `caps` is the small uppercase
3
+ * label of an entry surface.
4
+ */
5
+ export type FormFieldLabelVariant = 'default' | 'caps';