@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,560 @@
1
+ <script setup lang="ts">
2
+ import { resolveGroupOrder, searchIcons, useUiLabels } from '@noix-dev/brix-core';
3
+ import type { IconEntry, IconGroup, UiLabels } from '@noix-dev/brix-core';
4
+ import { computed, nextTick, ref, useAttrs, useId, useTemplateRef, watch } from 'vue';
5
+ import type { HTMLAttributes } from 'vue';
6
+ import { cn } from '../../lib/cn';
7
+ import { ChevronDownIcon, SearchIcon, XIcon } from '../icon';
8
+ import { Label } from '../label';
9
+ import { PopoverPanel } from '../popover-panel';
10
+
11
+ /**
12
+ * A symbol field: the chosen symbol in the field, and a panel with a search field above the
13
+ * symbols, which are laid out in GROUPS, each under its own heading, with an entry for no
14
+ * symbol at the bottom. The model is the symbol itself, and `''` for none. It is stored as the
15
+ * character because every consumer can then render it as text, without an icon font, and the
16
+ * catalogue can grow or shrink without a migration.
17
+ *
18
+ * GROUPS, NOT ONE GRID. 190 symbols in a single grid is not browsable, and the
19
+ * headings are what make it so: someone who wants a ball scans ten headings, not 190
20
+ * cells. Each group has its own grid of six columns of 44px cells. Six and 44 are not arbitrary:
21
+ * 44px is the touch target, and these are picked on a phone, and six cells and their gaps are
22
+ * what fits the panel's width at that size (eight would leave cells too small to hit). The
23
+ * wording of every heading is a key of the labels contract, so the catalogue's language decides
24
+ * it; `iconCatalogue` carries only identifiers.
25
+ *
26
+ * THE PANEL is the `PopoverPanel` shell, named by its trigger. The trigger is the whole field,
27
+ * and its own `aria-label` composes the action with the field's label ("Choose a symbol,
28
+ * Category symbol"), so two pickers on one form open panels that are announced differently. It
29
+ * is the trigger's own `aria-label`, not an `aria-labelledby` pointing at the label: the panel
30
+ * reaches the trigger by `aria-labelledby`, and a name computed through one reference ignores
31
+ * the second. What the field shows is attached to the trigger as its description.
32
+ *
33
+ * FOCUS LANDS IN THE SEARCH FIELD (the first thing the panel can focus) and stays there; no symbol
34
+ * is a tab stop. With this many symbols, one tab stop each (or even one roving stop) would mean
35
+ * tabbing through the grid to get past the field. The active symbol is announced through `aria-activedescendant` instead, the usual
36
+ * pattern for a search field with a list beside it, which also lets someone keep typing
37
+ * without fetching focus back. The panel therefore holds exactly two tab stops, the search
38
+ * field and the entry for no symbol, and Tab leaves it after the second. The options are not
39
+ * buttons for the same reason: a mouse press on one is kept off the focus, so the search field
40
+ * never loses it.
41
+ *
42
+ * KEYBOARD. Left and Right move one symbol, Up and Down move six, Enter picks the active one,
43
+ * and moving picks nothing. THE VERTICAL MOVE IS EXACT INSIDE A GROUP AND APPROXIMATE ACROSS A
44
+ * BOUNDARY, and that was a trade taken knowingly. Every group is its own grid, and a group's
45
+ * length is rarely a multiple of six, so each boundary shifts the columns: "six along the flat
46
+ * list" is exactly one row inside a group and only about one row where the cursor crosses into
47
+ * the next. One global grid would make Up and Down exact everywhere, at the price of the
48
+ * headings, and the headings are what make the symbols browsable at all. Left and Right are
49
+ * exact everywhere, because the flat list the keyboard walks is derived from what is rendered.
50
+ *
51
+ * A SYMBOL THE CATALOGUE DOES NOT HOLD (stored by an older version, or by a consumer's own
52
+ * data) is shown as chosen, in a group of its own at the top headed "Currently chosen", marked
53
+ * selected, and "No symbol" clears it. That group is shown while the query is empty, and the
54
+ * chosen symbol is taken out of the group it would otherwise sit in; while a query is typed the
55
+ * group is not shown and the chosen symbol is marked where it is found.
56
+ *
57
+ * WORDING comes from the labels contract (`iconPickerChoose`, `iconPickerSearch`,
58
+ * `iconPickerCurrent`, `iconPickerNone`, and one `iconPickerGroup<Name>` per group, plus
59
+ * `noMatches`); `labels` overrides member by member and the rest keep the contract's. Search
60
+ * matches the catalogue's keys and the group names in use.
61
+ *
62
+ * SEARCH IN ANOTHER LANGUAGE is the `searchNames` prop (a symbol mapped to more search terms), not
63
+ * contract keys: 190 symbols times every language is a translation file wearing a
64
+ * contract's clothes, and every consumer would carry it whether or not it opens the picker. The
65
+ * terms ADD to the built-in English keys, so a symbol left out still matches its English key.
66
+ *
67
+ * THE CHOSEN CELL carries its own ink: `aria-selected:bg-primary` is paired with
68
+ * `aria-selected:text-primary-foreground`, and the pair is not decoration. Without the second the
69
+ * cell kept the panel's inherited ink on a `--primary` ground, which measured 1.42 to 3.00
70
+ * (2.12 kingfisher light, 1.85 graphite light), and an emoji hides that only because a glyph is
71
+ * not drawn in the text colour. A stored symbol the catalogue does not hold can be a letter or a
72
+ * star, which are. With the ink set, `--primary-foreground` on `--primary` reads, over the six
73
+ * theme and mode pairs, each by compositing the computed colours through a canvas in that
74
+ * appearance:
75
+ *
76
+ * light: kingfisher 9.34 graphite 9.65 noix 5.79
77
+ * dark: kingfisher 9.63 graphite 6.23 noix 6.05
78
+ *
79
+ * The contrast walk reads text ink, not an emoji's glyph, so it cannot confirm this on the
80
+ * playground page; the figures were taken by hand from the painted cell. The cell's outline
81
+ * (`--ring`) and the keyboard's active ring, and the `:hover` wash, are NOT measured.
82
+ *
83
+ * THE LAYOUT, MEASURED on the running page rather than argued from its classes: eleven groups
84
+ * (ten and the synthetic one), 12px between one group and the next, cells 44 by 44, and six to a
85
+ * row (the first row's left edges are 46px apart, then the seventh wraps back to the first).
86
+ *
87
+ * YOUR OWN SYMBOLS. `icons` replaces the built-in catalogue and `groupOrder` orders its groups
88
+ * (see the props). Both default to what ships, so a form that sets neither is unchanged. A
89
+ * consumer's group takes its heading from the labels contract where its identifier is one of the
90
+ * built-in ones and is headed by the identifier itself everywhere else.
91
+ *
92
+ * THE SEARCH FIELD KEEPS ITS CARET. Left and Right walk the grid only when the caret is collapsed
93
+ * at the matching end of the text (at the start for Left, at the end for Right), and any chord
94
+ * (Shift, Ctrl, Alt, Meta) is left to the field, so a mistyped query can be stepped back through
95
+ * and a word can be selected. Up and Down walk the grid from anywhere. The result is
96
+ * asymmetric once a query is typed, on purpose: Right walks the grid from the end of the text,
97
+ * while Left moves the caret back until it reaches the start and only then walks the grid, and
98
+ * Home and End are the field's own.
99
+ *
100
+ * THE GLYPHS are slots (ADR 0013): `chevron-icon` (the field's), `search-icon` and `clear-icon`
101
+ * (the "No symbol" entry). The active cell's ring is drawn whenever a cell is active and is not
102
+ * gated on `focus-visible`: focus lands on the search field from a programmatic `.focus()`, which
103
+ * sets no `:focus-visible` (CLAUDE.md, "Measuring this system in a browser"), and the colour
104
+ * picker agrees.
105
+ *
106
+ * CONTRAST of the search field's edge, MEASURED with `packages/tokens/src/contrast.ts` over the
107
+ * six theme and mode pairs (kingfisher light and dark, graphite light and dark, noix light and
108
+ * dark), against the `--popover` it sits on. It is `border-muted-foreground`, the resting edge of
109
+ * every field in the catalogue; it drew `--input` until a review measured that under 3:1:
110
+ *
111
+ * --muted-foreground on --popover: 4.73 6.91 5.60 7.20 5.54 7.61
112
+ * --input on --popover (not drawn): 1.26 1.57 1.28 1.50 1.26 1.66
113
+ *
114
+ * Attributes (`id`, `name`, `data-testid`, `aria-*`) land on the trigger, except that an
115
+ * `aria-label` passed that way does NOT win: the composed name is what the panel inherits, so a
116
+ * consumer who wants another name changes `label` or `labels.iconPickerChoose`. `class` and `style` on
117
+ * the outer element. The outer element, its label and the field box carry the `form-field`,
118
+ * `label` and `input` slots, so a page's density settings reach this field as they reach every
119
+ * other.
120
+ */
121
+ defineOptions({ inheritAttrs: false });
122
+
123
+ /** The contract key that names each group. */
124
+ const GROUP_LABEL = {
125
+ sport: 'iconPickerGroupSport',
126
+ events: 'iconPickerGroupEvents',
127
+ places: 'iconPickerGroupPlaces',
128
+ office: 'iconPickerGroupOffice',
129
+ people: 'iconPickerGroupPeople',
130
+ awards: 'iconPickerGroupAwards',
131
+ culture: 'iconPickerGroupCulture',
132
+ food: 'iconPickerGroupFood',
133
+ nature: 'iconPickerGroupNature',
134
+ symbols: 'iconPickerGroupSymbols',
135
+ } as const satisfies Record<IconGroup, keyof UiLabels>;
136
+
137
+ const LABEL_KEYS = [
138
+ 'iconPickerChoose',
139
+ 'iconPickerSearch',
140
+ 'iconPickerCurrent',
141
+ 'iconPickerNone',
142
+ 'noMatches',
143
+ ...Object.values(GROUP_LABEL),
144
+ ] as const;
145
+
146
+ type IconPickerLabels = Record<(typeof LABEL_KEYS)[number], string>;
147
+
148
+ const props = withDefaults(
149
+ defineProps<{
150
+ /** The symbol itself; `''` for none. */
151
+ modelValue?: string;
152
+ label?: string;
153
+ required?: boolean;
154
+ disabled?: boolean;
155
+ /** The error message. It marks the field invalid and is announced with it. */
156
+ error?: string;
157
+ /** A line under the field, announced with it. */
158
+ hint?: string;
159
+ /** Overrides the wording member by member; the rest keep the contract's. */
160
+ labels?: Partial<IconPickerLabels>;
161
+ /**
162
+ * A symbol mapped to further search terms, which ADD to its built-in English keys. Keys are
163
+ * compared with the emoji variation selectors (U+FE0E, U+FE0F) removed on both sides, so
164
+ * `🏋` finds `🏋️`; nothing else is normalised, so copy a symbol from the catalogue rather
165
+ * than typing a lookalike.
166
+ */
167
+ searchNames?: Record<string, readonly string[]>;
168
+ /**
169
+ * The symbols on offer, in place of the built-in catalogue. Each carries its own group
170
+ * identifier and search keys. A group whose identifier is one of the built-in ones takes
171
+ * its heading from the labels contract; any other group is headed by its identifier, so
172
+ * name the group as it should read.
173
+ */
174
+ icons?: readonly IconEntry[];
175
+ /**
176
+ * The order of the groups, top to bottom. A group the symbols use and this leaves out
177
+ * follows, in the order they first use it. Without `icons` the built-in order applies;
178
+ * with `icons` and no order, the order of first use does.
179
+ */
180
+ groupOrder?: readonly string[];
181
+ class?: HTMLAttributes['class'];
182
+ }>(),
183
+ {
184
+ modelValue: '',
185
+ label: undefined,
186
+ required: false,
187
+ disabled: false,
188
+ error: undefined,
189
+ hint: undefined,
190
+ labels: undefined,
191
+ searchNames: undefined,
192
+ icons: undefined,
193
+ groupOrder: undefined,
194
+ class: undefined,
195
+ },
196
+ );
197
+
198
+ const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>();
199
+
200
+ const attrs = useAttrs();
201
+ const contract = useUiLabels();
202
+
203
+ const text = computed(
204
+ () =>
205
+ ({
206
+ ...Object.fromEntries(LABEL_KEYS.map((key) => [key, contract.value[key]])),
207
+ // Members given as `undefined` are dropped, not spread: they would blank the contract's word.
208
+ ...Object.fromEntries(
209
+ Object.entries(props.labels ?? {}).filter(([, v]) => v !== undefined),
210
+ ),
211
+ }) as IconPickerLabels,
212
+ );
213
+
214
+ /**
215
+ * The trigger's name is the panel's name (the shell names the panel after it), so on a form
216
+ * with two of these it carries the field as well as the action. It is the trigger's own
217
+ * `aria-label`, not an `aria-labelledby` pointing at the label: see the docblock.
218
+ */
219
+ const triggerName = computed(() =>
220
+ props.label ? `${text.value.iconPickerChoose}, ${props.label}` : text.value.iconPickerChoose,
221
+ );
222
+
223
+ /** Cells in a row. Fixed rather than measured, so a vertical move is arithmetic and not geometry. */
224
+ const COLUMNS = 6;
225
+
226
+ const fallbackId = useId();
227
+ // A function for the reason `triggerAttrs` is one: a `computed` over `attrs` goes stale in production, and
228
+ // a stale id leaves the label pointing at an element that no longer exists.
229
+ function fieldId(): string {
230
+ return (attrs.id as string | undefined) ?? fallbackId;
231
+ }
232
+ const hintId = `${useId()}-hint`;
233
+ const errorId = `${useId()}-error`;
234
+ const valueId = `${useId()}-value`;
235
+ const listId = useId();
236
+
237
+ /** What is stored, as it is. An empty or blank value is no symbol. */
238
+ const stored = computed(() => props.modelValue ?? '');
239
+ const isEmpty = computed(() => stored.value.trim() === '');
240
+
241
+ // --- The panel. ---
242
+
243
+ const open = ref(false);
244
+ const query = ref('');
245
+ const active = ref(0);
246
+ const list = useTemplateRef<HTMLElement>('list');
247
+
248
+ const order = computed(() => resolveGroupOrder(props.icons, props.groupOrder));
249
+ /** A group's heading: its word in the labels contract, or its identifier where there is none. */
250
+ function headingFor(group: string): string {
251
+ return Object.hasOwn(GROUP_LABEL, group) ? text.value[GROUP_LABEL[group as IconGroup]] : group;
252
+ }
253
+ const groupNames = computed(() =>
254
+ Object.fromEntries(order.value.map((group) => [group, headingFor(group)])),
255
+ );
256
+ const matches = computed(() =>
257
+ searchIcons(query.value, groupNames.value, props.searchNames, {
258
+ icons: props.icons,
259
+ groupOrder: props.groupOrder,
260
+ }),
261
+ );
262
+
263
+ interface Section {
264
+ key: string;
265
+ heading: string;
266
+ cells: { entry: IconEntry; index: number }[];
267
+ }
268
+
269
+ /** Rendered groups: the held symbol first while no query is typed, then each group with matches. */
270
+ const sections = computed<Section[]>(() => {
271
+ const held =
272
+ !isEmpty.value && query.value.trim() === ''
273
+ ? (matches.value.find((entry) => entry.symbol === stored.value) ?? {
274
+ symbol: stored.value,
275
+ group: 'symbols' as const,
276
+ keys: [],
277
+ })
278
+ : null;
279
+ const out: { key: string; heading: string; entries: IconEntry[] }[] = [];
280
+ if (held) {
281
+ out.push({ key: 'current', heading: text.value.iconPickerCurrent, entries: [held] });
282
+ }
283
+ for (const group of order.value) {
284
+ const entries = matches.value.filter(
285
+ (entry) => entry.group === group && entry.symbol !== held?.symbol,
286
+ );
287
+ if (entries.length > 0) {
288
+ out.push({ key: group, heading: headingFor(group), entries });
289
+ }
290
+ }
291
+ let index = 0;
292
+ return out.map((section) => ({
293
+ key: section.key,
294
+ heading: section.heading,
295
+ cells: section.entries.map((entry) => ({ entry, index: index++ })),
296
+ }));
297
+ });
298
+
299
+ /** The list the keyboard walks, in rendered order: derived from the sections, so it cannot drift. */
300
+ const flat = computed(() => sections.value.flatMap((section) => section.cells.map((c) => c.entry)));
301
+ const optionId = (index: number) => `${listId}-${index}`;
302
+ const headingId = (key: string) => `${listId}-group-${key}`;
303
+
304
+ watch(open, (isOpen) => {
305
+ if (!isOpen) {
306
+ return;
307
+ }
308
+ query.value = '';
309
+ active.value = 0;
310
+ });
311
+
312
+ // The first result is where the keyboard lands, so Enter right after typing picks what was
313
+ // searched for. With no result there is nothing at the index, and Enter does nothing.
314
+ watch(query, () => {
315
+ active.value = 0;
316
+ });
317
+
318
+ function pick(next: string): void {
319
+ // Clearing is judged against what is stored, not against what is shown: a stored value
320
+ // that is blank still differs from `''`, and "No symbol" must replace it.
321
+ if (next !== stored.value) {
322
+ emit('update:modelValue', next);
323
+ }
324
+ open.value = false;
325
+ }
326
+
327
+ async function move(delta: number): Promise<void> {
328
+ const last = flat.value.length - 1;
329
+ if (last < 0) {
330
+ return;
331
+ }
332
+ active.value = Math.min(Math.max(active.value + delta, 0), last);
333
+ await nextTick();
334
+ list.value?.querySelector<HTMLElement>('[data-active]')?.scrollIntoView?.({ block: 'nearest' });
335
+ }
336
+
337
+ function onSearchKeydown(event: KeyboardEvent): void {
338
+ // A chord is the field's own business (select a word, jump to the start, a shortcut).
339
+ if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) {
340
+ return;
341
+ }
342
+ // Left and Right are the field's caret keys: they walk the grid only from where the caret
343
+ // has nowhere left to go, so a mistyped query can still be stepped back through and fixed.
344
+ // Up and Down have no meaning in a one-line field and always walk the grid.
345
+ const input = event.currentTarget as HTMLInputElement;
346
+ const collapsed = input.selectionStart === input.selectionEnd;
347
+ switch (event.key) {
348
+ case 'ArrowRight':
349
+ if (!collapsed || input.selectionStart !== input.value.length) {
350
+ return;
351
+ }
352
+ void move(1);
353
+ break;
354
+ case 'ArrowLeft':
355
+ if (!collapsed || input.selectionStart !== 0) {
356
+ return;
357
+ }
358
+ void move(-1);
359
+ break;
360
+ case 'ArrowDown':
361
+ void move(COLUMNS);
362
+ break;
363
+ case 'ArrowUp':
364
+ void move(-COLUMNS);
365
+ break;
366
+ case 'Enter': {
367
+ const entry = flat.value[active.value];
368
+ if (entry) {
369
+ pick(entry.symbol);
370
+ }
371
+ break;
372
+ }
373
+ default:
374
+ return;
375
+ }
376
+ event.preventDefault();
377
+ }
378
+
379
+ // A plain function, not a `computed`: enumerating `useAttrs()` depends on the values of the
380
+ // attributes present when it runs and not on the key set, so a computed would never see a consumer
381
+ // add one later. Measured on Vue 3.5.46, identical in the development and the production build.
382
+ function triggerAttrs(): Record<string, unknown> {
383
+ return Object.fromEntries(
384
+ Object.entries(attrs).filter(([key]) => key !== 'style' && key !== 'class'),
385
+ );
386
+ }
387
+ // Also a function, for the same reason: it reads the attributes.
388
+ function describedBy(): string | undefined {
389
+ return (
390
+ [
391
+ triggerAttrs()['aria-describedby'],
392
+ valueId,
393
+ props.hint ? hintId : null,
394
+ props.error ? errorId : null,
395
+ ]
396
+ .filter(Boolean)
397
+ .join(' ') || undefined
398
+ );
399
+ }
400
+ </script>
401
+
402
+ <template>
403
+ <div
404
+ data-slot="form-field"
405
+ :class="cn('grid gap-1.5', props.class)"
406
+ :style="attrs.style as never"
407
+ >
408
+ <Label v-if="props.label" :for="fieldId()">
409
+ {{ props.label }}
410
+ <span v-if="props.required" aria-hidden="true" class="text-destructive">*</span>
411
+ </Label>
412
+ <!-- The field box is the `input` slot: it is what a page's density settings size. -->
413
+ <div
414
+ data-slot="input"
415
+ :class="
416
+ cn(
417
+ 'border-muted-foreground dark:bg-input/30 relative flex h-9 w-full min-w-0 items-center rounded-lg border bg-transparent transition-colors',
418
+ 'focus-within:border-ring focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',
419
+ 'has-[button[aria-invalid=true]]:border-destructive has-[button[aria-invalid=true]]:ring-destructive/20 dark:has-[button[aria-invalid=true]]:ring-destructive/40 has-[button[aria-invalid=true]]:ring-3',
420
+ props.disabled && 'bg-input/50 dark:bg-input/80 cursor-not-allowed opacity-50',
421
+ )
422
+ "
423
+ >
424
+ <PopoverPanel v-model:open="open" :disabled="props.disabled">
425
+ <template #trigger>
426
+ <button
427
+ v-bind="triggerAttrs()"
428
+ :id="fieldId()"
429
+ type="button"
430
+ :aria-label="triggerName"
431
+ :aria-required="props.required || undefined"
432
+ :aria-describedby="describedBy()"
433
+ :aria-invalid="
434
+ props.error ? 'true' : (triggerAttrs()['aria-invalid'] as never)
435
+ "
436
+ class="flex h-full w-full min-w-0 items-center gap-2 rounded-lg bg-transparent px-2.5 text-left text-base outline-none disabled:pointer-events-none md:text-sm"
437
+ >
438
+ <span
439
+ :id="valueId"
440
+ :class="
441
+ cn(
442
+ 'flex-1 truncate',
443
+ isEmpty ? 'text-muted-foreground' : 'text-lg leading-none',
444
+ )
445
+ "
446
+ >
447
+ {{ isEmpty ? text.iconPickerNone : stored }}
448
+ </span>
449
+ <slot name="chevron-icon"
450
+ ><ChevronDownIcon class="text-muted-foreground"
451
+ /></slot>
452
+ </button>
453
+ </template>
454
+ <template #panel>
455
+ <div class="w-[296px] max-w-full">
456
+ <div
457
+ class="border-muted-foreground bg-background focus-within:ring-ring mx-0.5 mb-2 mt-0.5 flex h-8 items-center gap-2 rounded-[calc(var(--radius)-4px)] border px-2 focus-within:ring-2 focus-within:ring-inset"
458
+ >
459
+ <slot name="search-icon"
460
+ ><SearchIcon class="text-muted-foreground size-3.5 flex-none"
461
+ /></slot>
462
+ <input
463
+ v-model="query"
464
+ type="text"
465
+ role="combobox"
466
+ aria-autocomplete="list"
467
+ aria-expanded="true"
468
+ autocomplete="off"
469
+ spellcheck="false"
470
+ :aria-controls="listId"
471
+ :aria-activedescendant="
472
+ active >= 0 && flat[active] ? optionId(active) : undefined
473
+ "
474
+ :aria-label="text.iconPickerSearch"
475
+ :placeholder="text.iconPickerSearch"
476
+ class="placeholder:text-muted-foreground min-w-0 flex-1 bg-transparent text-sm outline-none"
477
+ @keydown="onSearchKeydown"
478
+ />
479
+ </div>
480
+ <!-- `tabindex="-1"`: a scroller with nothing focusable in it is a tab stop in some browsers. -->
481
+ <div
482
+ :id="listId"
483
+ ref="list"
484
+ role="listbox"
485
+ tabindex="-1"
486
+ :aria-label="text.iconPickerChoose"
487
+ class="max-h-[230px] overflow-auto p-0.5 outline-none"
488
+ >
489
+ <p
490
+ v-if="sections.length === 0"
491
+ class="text-muted-foreground px-1 py-6 text-center text-sm"
492
+ >
493
+ {{ text.noMatches }}
494
+ </p>
495
+ <!--
496
+ A group is named by its heading. The heading and the grid are layout,
497
+ and a plain element between a listbox and its options is not a valid
498
+ owned child, so both are presentational; the name still reads from
499
+ the heading's text.
500
+ -->
501
+ <div
502
+ v-for="section in sections"
503
+ :key="section.key"
504
+ role="group"
505
+ class="mt-3 first:mt-0"
506
+ :aria-labelledby="headingId(section.key)"
507
+ >
508
+ <p
509
+ :id="headingId(section.key)"
510
+ role="presentation"
511
+ class="text-muted-foreground mx-0.5 mb-1 mt-0.5 text-xs font-semibold"
512
+ >
513
+ {{ section.heading }}
514
+ </p>
515
+ <div
516
+ role="presentation"
517
+ class="grid grid-cols-[repeat(6,2.75rem)] gap-0.5"
518
+ >
519
+ <div
520
+ v-for="cell in section.cells"
521
+ :id="optionId(cell.index)"
522
+ :key="cell.entry.symbol"
523
+ role="option"
524
+ :aria-selected="cell.entry.symbol === stored"
525
+ :data-active="cell.index === active || undefined"
526
+ class="hover:bg-muted aria-selected:bg-primary aria-selected:text-primary-foreground aria-selected:outline-ring grid size-11 cursor-pointer place-items-center rounded-[calc(var(--radius)-6px)] text-xl leading-none select-none aria-selected:outline-2 aria-selected:-outline-offset-2 data-active:ring-foreground data-active:ring-2 data-active:ring-inset"
527
+ @mousedown.prevent
528
+ @click="pick(cell.entry.symbol)"
529
+ >
530
+ {{ cell.entry.symbol }}
531
+ </div>
532
+ </div>
533
+ </div>
534
+ </div>
535
+ <button
536
+ type="button"
537
+ :aria-pressed="isEmpty"
538
+ class="text-muted-foreground hover:bg-muted hover:text-foreground aria-pressed:text-foreground focus-visible:ring-ring mt-2 flex w-full items-center gap-2 rounded-[calc(var(--radius)-6px)] px-2 py-1.5 text-left text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-inset aria-pressed:font-semibold"
539
+ @click="pick('')"
540
+ >
541
+ <slot name="clear-icon"><XIcon class="size-3.5 flex-none" /></slot>
542
+ {{ text.iconPickerNone }}
543
+ </button>
544
+ </div>
545
+ </template>
546
+ </PopoverPanel>
547
+ </div>
548
+ <p
549
+ v-if="props.hint"
550
+ :id="hintId"
551
+ data-testid="icon-picker-hint"
552
+ class="text-muted-foreground text-xs"
553
+ >
554
+ {{ props.hint }}
555
+ </p>
556
+ <p v-if="props.error" :id="errorId" role="alert" class="text-destructive text-sm">
557
+ {{ props.error }}
558
+ </p>
559
+ </div>
560
+ </template>
@@ -0,0 +1 @@
1
+ export { default as IconPicker } from './IconPicker.vue';