@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,296 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ asPageSize,
4
+ formatLabel,
5
+ PAGE_SIZE_OPTIONS,
6
+ type PerPageChoice,
7
+ SHOW_ALL_LIMIT,
8
+ useUiLabels,
9
+ } from '@noix-dev/brix-core';
10
+ import { computed, ref, watch } from 'vue';
11
+ import { Button } from '../button';
12
+ import { ConfirmDialog } from '../confirm-dialog';
13
+ import { ChevronDownIcon } from '../icon';
14
+ import {
15
+ MenuContent,
16
+ MenuRadioGroup,
17
+ MenuRadioItem,
18
+ MenuRoot,
19
+ MenuSeparator,
20
+ MenuTrigger,
21
+ } from '../menu';
22
+
23
+ /**
24
+ * The strip under a list: which entries are on screen, an optional switch for how many there
25
+ * are per page, and the two arrows. It only reports what a reader asked for (`update:page`,
26
+ * `update:perPage`); fetching, and holding the page, are the parent's.
27
+ *
28
+ * AT ITS EDGES it says nothing false, and each of these is asserted rather than assumed:
29
+ * - **no entries** reads as page 1 of 1 with "0 entries" and both arrows disabled (a parent
30
+ * that has not heard from the server yet passes `lastPage: 0`, which is the same case);
31
+ * - **exactly one page** keeps its whole range and has nowhere to go;
32
+ * - **a page past the last one** (a filter narrowed the result while the parent still held
33
+ * page 7 of what is now 2) is shown as the last page, with that page's range, and the
34
+ * arrows step from the page it shows. When the inputs change while the pager is on screen
35
+ * and the result is not empty, it also asks the parent for that page, once
36
+ * (`update:page`). It never emits on mount, because a parent that has not heard from the
37
+ * server yet passes a placeholder `lastPage` beside a page restored from the address; and
38
+ * never for `total: 0`, which cannot be told from "not loaded yet".
39
+ * **It announces the clamp only when the inputs agree with each other**
40
+ * (`lastPage === ceil(total / perPage)`). A parent that writes `total` a tick before
41
+ * `lastPage` passes through a contradictory state, and acting on it would overwrite a
42
+ * restored page; the check is what makes that harmless, so it is not redundant. A parent
43
+ * whose `lastPage` legitimately differs from the arithmetic never hears the clamp. A parent that clamps
44
+ * its own page makes the shown page equal the held one, so nothing loops.
45
+ *
46
+ * THE SIZE SWITCH is a dropdown of radio rows, composed from the `../menu` family
47
+ * (the first consumer of `MenuRadioItem`, and of its `indicator-icon` slot). It opens above
48
+ * its button, aligned to its start, and is `min-w-40` rather than the menu's 256px default: a
49
+ * short list of short numbers. "Show all" sits below a separator and does not take effect on
50
+ * its own: it asks first through `ConfirmDialog` (the load is five hundred rows), and the
51
+ * switch keeps showing the previous size until the answer is yes. What the switch shows is
52
+ * always what the list is really using (`perPage`, `showAll`), never the last thing picked, so
53
+ * a reload that failed does not leave the pager claiming a size the list does not have.
54
+ *
55
+ * KEYBOARD. The button opens the menu with ArrowDown, Enter or Space; arrows move between rows
56
+ * and stop at the ends (the menu is a listbox shape, not a wrapping radio group); **only
57
+ * Enter, Space or a click chooses**, so walking the rows commits nothing; Escape closes it and
58
+ * focus returns to the button. `Pagination.test.ts` drives those rather than assuming them.
59
+ *
60
+ * AND IT DIVERGES on one thing the split button and row actions state the opposite of in their
61
+ * own docblocks: this menu is `:modal="false"`, the only one in `packages/vue/src`. A modal menu
62
+ * locks the body (`overflow: hidden`, `pointer-events: none`) and marks everything outside the
63
+ * panel `aria-hidden`, so Tab is held inside it. This one does none of that: the page behind
64
+ * the panel stays live, announced and tabbable, and **Tab leaves the menu** rather than cycling
65
+ * inside it.
66
+ *
67
+ * Why it is `false` is not recorded anywhere, here or in the port it came from, and nothing
68
+ * depends on it: making the menu modal fails exactly one case in `Pagination.test.ts` and that
69
+ * is the case written to pin this paragraph. So this is a divergence described rather than
70
+ * justified — the prop is a decision still open, not a constraint. Whoever closes it should
71
+ * know that the case which reads like its guard, the pointer-events one under "show all", is
72
+ * about the **dialog**'s lock and stays green either way.
73
+ *
74
+ * COLOUR. Nothing here names a ramp rung. The arrows and the size button are `Button`'s
75
+ * `outline` variant, so their focus ring, disabled fade and hover are the recipe's own. The
76
+ * menu is `--popover` (see `menu/menuClasses.ts`).
77
+ *
78
+ * COPY comes from the label contract: `pagerRange`, `pagerEmpty`, `pagerPerPage`,
79
+ * `pagerPerPageName`, `pagerShowAll*`, `pagerPage`, `pagerPrevious` and `pagerNext`.
80
+ * `pageLabel` replaces the position text with a function when a sentence needs more than a
81
+ * template.
82
+ *
83
+ * GLYPHS are named slots (ADR 0013): `trigger-icon` on the size button, `previous-icon` and
84
+ * `next-icon` on the arrows. The arrows default to the characters ‹ and ›, which are text, not
85
+ * an SVG, and are hidden from assistive technology: the buttons are named by `aria-label`.
86
+ *
87
+ * Test ids are fixed (`page-range`, `page-prev`, `page-next`, `page-size-select`,
88
+ * `page-size-option-{size|all}`, `page-limit-hint`, `page-show-all-dialog`), because the family
89
+ * is one fixed shape; `data-testid` and `class` given to `Pagination` itself reach its root.
90
+ */
91
+ const props = withDefaults(
92
+ defineProps<{
93
+ currentPage: number;
94
+ lastPage: number;
95
+ total: number;
96
+ perPage: number;
97
+ /** Replaces the position text; receives the shown page and the clamped last page. */
98
+ pageLabel?: (current: number, last: number) => string;
99
+ /** Shows the page-size switch; list views opt in. */
100
+ pageSizeSwitch?: boolean;
101
+ /** True while the list shows all entries (up to the cap): the switch reads "All". */
102
+ showAll?: boolean;
103
+ }>(),
104
+ { pageLabel: undefined, pageSizeSwitch: false, showAll: false },
105
+ );
106
+
107
+ const emit = defineEmits<{
108
+ (e: 'update:page', page: number): void;
109
+ /** The list resets to page 1 itself; the pager never also emits `update:page`. */
110
+ (e: 'update:perPage', choice: PerPageChoice): void;
111
+ }>();
112
+
113
+ defineSlots<{
114
+ /** The glyph on the size button. Defaults to the package's own chevron. */
115
+ 'trigger-icon'?: () => unknown;
116
+ /** The glyph on the previous-page arrow. Defaults to the character ‹. */
117
+ 'previous-icon'?: () => unknown;
118
+ /** The glyph on the next-page arrow. Defaults to the character ›. */
119
+ 'next-icon'?: () => unknown;
120
+ }>();
121
+
122
+ const labels = useUiLabels();
123
+
124
+ /** There is always a last page, even for an empty result: "page 1 of 1", never "0 / 0". */
125
+ const last = computed(() => Math.max(1, props.lastPage));
126
+ /** The page shown: never below the first, never past the last, whatever the parent holds. */
127
+ const current = computed(() => Math.min(Math.max(1, props.currentPage), last.value));
128
+
129
+ /**
130
+ * Whether the four inputs describe one result: `lastPage` is what `total` and `perPage` work
131
+ * out to. A store that writes them one at a time passes through states that contradict each
132
+ * other (312 entries at 25 a page, one page), and a clamp decided on those would overwrite a
133
+ * page restored from the address with 1. A page size of 0 divides to Infinity and agrees with
134
+ * nothing, which is deliberate: silent. A parent whose `lastPage` legitimately differs from
135
+ * the arithmetic (a server-capped count) is silent too, which is the behaviour of a pager that
136
+ * never emitted.
137
+ */
138
+ const agree = computed(() => props.lastPage === Math.ceil(props.total / props.perPage));
139
+
140
+ // Ask the parent for the page this pager shows when a change of inputs left them apart. Not
141
+ // immediate (no emit on mount), and not for an empty total (see the docblock).
142
+ watch(
143
+ () => [props.currentPage, props.lastPage, props.total, props.perPage],
144
+ () => {
145
+ if (props.total > 0 && agree.value && current.value !== props.currentPage) {
146
+ emit('update:page', current.value);
147
+ }
148
+ },
149
+ );
150
+
151
+ const isFirst = computed(() => current.value <= 1);
152
+ const isLast = computed(() => current.value >= last.value);
153
+
154
+ const pageText = computed(() =>
155
+ props.pageLabel !== undefined
156
+ ? props.pageLabel(current.value, last.value)
157
+ : formatLabel(labels.value.pagerPage, { current: current.value, last: last.value }),
158
+ );
159
+
160
+ const rangeText = computed(() => {
161
+ if (props.total === 0) {
162
+ return labels.value.pagerEmpty;
163
+ }
164
+
165
+ return formatLabel(labels.value.pagerRange, {
166
+ from: (current.value - 1) * props.perPage + 1,
167
+ to: Math.min(current.value * props.perPage, props.total),
168
+ total: props.total,
169
+ });
170
+ });
171
+
172
+ const showLimitHint = computed(() => props.showAll && props.total > SHOW_ALL_LIMIT);
173
+
174
+ /** Always what the list is really using (the props), never the last thing picked. */
175
+ const selected = computed<string>(() =>
176
+ props.showAll ? 'all' : String(asPageSize(props.perPage)),
177
+ );
178
+
179
+ const selectedLabel = computed(() =>
180
+ props.showAll
181
+ ? labels.value.pagerShowAllActive
182
+ : formatLabel(labels.value.pagerPerPage, { size: asPageSize(props.perPage) }),
183
+ );
184
+
185
+ const confirmOpen = ref(false);
186
+
187
+ /** Runs on an explicit pick only (click, or Enter/Space on a row), never on arrow keys. */
188
+ function pick(value: string): void {
189
+ if (value === selected.value) {
190
+ return;
191
+ }
192
+ if (value === 'all') {
193
+ // The choice only counts once confirmed; until then the previous size stays shown.
194
+ confirmOpen.value = true;
195
+
196
+ return;
197
+ }
198
+ emit('update:perPage', asPageSize(Number(value)));
199
+ }
200
+
201
+ function confirmShowAll(): void {
202
+ confirmOpen.value = false;
203
+ emit('update:perPage', 'all');
204
+ }
205
+ </script>
206
+
207
+ <template>
208
+ <div data-slot="pagination" class="text-muted-foreground flex flex-col gap-1.5 pt-1 text-xs">
209
+ <p
210
+ v-if="showLimitHint"
211
+ data-testid="page-limit-hint"
212
+ class="border-border bg-muted/40 rounded-md border px-2 py-1"
213
+ >
214
+ {{ labels.pagerShowAllHint }}
215
+ </p>
216
+ <div class="flex items-center gap-2.5">
217
+ <span data-testid="page-range">{{ rangeText }}</span>
218
+ <MenuRoot v-if="pageSizeSwitch" :modal="false">
219
+ <MenuTrigger as-child>
220
+ <Button
221
+ type="button"
222
+ variant="outline"
223
+ size="xs"
224
+ data-testid="page-size-select"
225
+ :aria-label="`${labels.pagerPerPageName}: ${selectedLabel}`"
226
+ :data-value="selected"
227
+ class="text-foreground"
228
+ >
229
+ {{ selectedLabel }}
230
+ <slot name="trigger-icon">
231
+ <ChevronDownIcon class="size-3" />
232
+ </slot>
233
+ </Button>
234
+ </MenuTrigger>
235
+ <MenuContent align="start" side="top" class="min-w-40">
236
+ <!-- The group's model only draws the tick from the props; choosing is each
237
+ row's `select`, so a pick is reported and never applied here. -->
238
+ <MenuRadioGroup :model-value="selected">
239
+ <MenuRadioItem
240
+ v-for="size in PAGE_SIZE_OPTIONS"
241
+ :key="size"
242
+ :value="String(size)"
243
+ :data-testid="`page-size-option-${size}`"
244
+ @select="pick(String(size))"
245
+ >
246
+ {{ formatLabel(labels.pagerPerPage, { size }) }}
247
+ </MenuRadioItem>
248
+ <MenuSeparator />
249
+ <MenuRadioItem
250
+ value="all"
251
+ data-testid="page-size-option-all"
252
+ @select="pick('all')"
253
+ >
254
+ {{ labels.pagerShowAll }}
255
+ </MenuRadioItem>
256
+ </MenuRadioGroup>
257
+ </MenuContent>
258
+ </MenuRoot>
259
+ <span class="ml-auto">{{ pageText }}</span>
260
+ <Button
261
+ type="button"
262
+ variant="outline"
263
+ size="xs"
264
+ data-testid="page-prev"
265
+ :aria-label="labels.pagerPrevious"
266
+ :disabled="isFirst"
267
+ class="text-foreground"
268
+ @click="emit('update:page', current - 1)"
269
+ >
270
+ <slot name="previous-icon"><span aria-hidden="true">‹</span></slot>
271
+ </Button>
272
+ <Button
273
+ type="button"
274
+ variant="outline"
275
+ size="xs"
276
+ data-testid="page-next"
277
+ :aria-label="labels.pagerNext"
278
+ :disabled="isLast"
279
+ class="text-foreground"
280
+ @click="emit('update:page', current + 1)"
281
+ >
282
+ <slot name="next-icon"><span aria-hidden="true">›</span></slot>
283
+ </Button>
284
+ </div>
285
+ <ConfirmDialog
286
+ v-if="pageSizeSwitch"
287
+ v-model:open="confirmOpen"
288
+ data-testid="page-show-all-dialog"
289
+ :title="labels.pagerShowAllTitle"
290
+ :description="labels.pagerShowAllText"
291
+ :confirm-label="labels.pagerShowAllConfirm"
292
+ :cancel-label="labels.pagerShowAllCancel"
293
+ @confirm="confirmShowAll"
294
+ />
295
+ </div>
296
+ </template>
@@ -0,0 +1 @@
1
+ export { default as Pagination } from './Pagination.vue';
@@ -0,0 +1,332 @@
1
+ <script setup lang="ts">
2
+ import { formatLabel, useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed, nextTick, onMounted, useAttrs, useId } from 'vue';
4
+ import type { HTMLAttributes } from 'vue';
5
+ import { cn } from '../../lib/cn';
6
+ import { Label } from '../label';
7
+
8
+ /**
9
+ * A code field, one box per digit. The model is the digits as a string, dense from the left:
10
+ * `'12'` is two boxes filled and four empty, never a gap. It is the only shape the model can
11
+ * take, so a box beyond the first empty one is not a place to type: a digit typed there lands
12
+ * in the first empty box, and focus follows it.
13
+ *
14
+ * TWO MODES share the boxes. Interactive (the default) draws one `<input>` per digit. Not
15
+ * interactive, it draws plain boxes on `--muted` that only reflect the value and emit nothing,
16
+ * for a screen where something else (an on-screen keypad) owns the input. Those boxes are
17
+ * hidden from a screen reader, which is told instead how many digits there are, or the digits
18
+ * themselves where the field is not masked, since a row of bullets reads as nothing.
19
+ *
20
+ * TYPING. A digit fills its box and focus moves to the next. Backspace on a filled box takes
21
+ * its digit out (the ones after it close up); on an empty box it only walks back one, and the
22
+ * next Backspace takes that box's digit. Left and Right move between boxes. A paste, or
23
+ * several characters arriving in one box, spreads from the box it landed in and stops at the
24
+ * last. The second is reachable only programmatically: `maxlength="1"` makes a browser cut a
25
+ * multi-character autofill down to one, and `autocomplete="off"` keeps the platform's
26
+ * one-time-code suggestion away, both on purpose for a PIN. Anything that is not a digit is refused and is not left standing in the
27
+ * box. Only ONE box is in the tab order (the first empty one, or the last when the code is
28
+ * whole), so Tab leaves the field and does not walk six boxes.
29
+ *
30
+ * `complete` is for a person finishing a code, and ONLY for that: it fires from the typing and
31
+ * pasting paths, never from the model changing from outside, so a form that is seeded or reset
32
+ * with a whole code does not behave as if someone had just entered it. It fires when what a
33
+ * person did changed the model to a whole code, so typing the digit a box already holds,
34
+ * which changes nothing, fires nothing.
35
+ *
36
+ * A VALUE THE FIELD WOULD NOT ITSELF HAVE PRODUCED is shown as far as the boxes can show it,
37
+ * and left alone until a person acts. Longer than `length`: the first digits are drawn, and
38
+ * the model keeps its length until a person edits (the next edit takes the rest with it).
39
+ * Shorter: the boxes fill from the left and typing continues from where it stops. With
40
+ * non-digits in it (`12ab34`): the digits are drawn, closed up, as `1234`. Without any digit,
41
+ * or empty: empty boxes. The model is not rewritten on mount, since that would make a pristine
42
+ * form dirty and silently drop what a form was seeded with. EVERY ONE OF THESE CAN BE LEFT: a
43
+ * digit typed or deleted emits the value the boxes show, and so does Backspace or Delete in an
44
+ * empty box, which is the only way to clear a stored value that draws as nothing (`abc`).
45
+ * The model is therefore NOT normalised until a person edits: a person sees `1234` while it
46
+ * may hold `123456`, and a plain submit sends the stored value. The consumer owns validation
47
+ * and should validate on submit.
48
+ *
49
+ * THE READ-ONLY DIGIT IS `--foreground`, NOT `--muted-foreground`. A box is 18px at weight 600,
50
+ * which WCAG counts as normal text (large is 18pt regular or 14pt bold) and holds to 4.5, and
51
+ * `--muted-foreground` on the box's `--muted` ground read 4.35 in kingfisher light, 0.15 under.
52
+ * It is the pairing the crop family's ratio row met with the same shortfall and fixed the same
53
+ * way. `--foreground` on `--muted`, read over the six theme and mode pairs by compositing the
54
+ * computed colours through a canvas in each appearance:
55
+ *
56
+ * light: kingfisher 18.16 graphite 16.31 noix 15.96
57
+ * dark: kingfisher 14.50 graphite 12.18 noix 12.58
58
+ *
59
+ * A DISABLED readout fades to half and is measured and EXEMPT (WCAG 1.4.3 exempts inactive
60
+ * components): painted, the ink reads 3.69 over the page in kingfisher light; taken against the
61
+ * box's own unfaded ground it reads 3.67, 3.34 and 3.28 in light and 4.74, 4.22 and 4.28 in dark
62
+ * (kingfisher, graphite, noix), the two methods differing in what the fade is composited over.
63
+ * The interactive box's input ink is `--foreground` and was not part of this measurement.
64
+ *
65
+ * ONE INPUT SLOT PER BOX, not one for the row. A density setting sets the HEIGHT of whatever
66
+ * carries the `input` slot; on the row it would stretch a flex row whose boxes ignore it, and
67
+ * each box would stay 46px tall. The boxes are the controls, so each is a slot, and a page's
68
+ * density settings reach them as they reach every other field. The outer element and its label
69
+ * carry the `form-field` and `label` slots.
70
+ *
71
+ * The focus ring is the rest of the system's (a full-strength ring on a `--background` gap)
72
+ * and not the mockup's 30% halo, which measured too faint against the page.
73
+ *
74
+ * WORDING comes from the labels contract (`pinFieldGroup`, `pinFieldDigit`, `pinFieldFilled`);
75
+ * `labels` overrides member by member and the rest keep the contract's. With a `label`, the
76
+ * group is named after it and `pinFieldGroup` is not used.
77
+ *
78
+ * Attributes (`id`, `data-*`, `aria-*`) land on the group of boxes; `class` and `style` on the
79
+ * outer element.
80
+ */
81
+ defineOptions({ inheritAttrs: false });
82
+
83
+ interface PinFieldLabels {
84
+ pinFieldGroup: string;
85
+ pinFieldDigit: string;
86
+ pinFieldFilled: string;
87
+ }
88
+
89
+ const props = withDefaults(
90
+ defineProps<{
91
+ /** The digits, as a string. */
92
+ modelValue?: string | null;
93
+ /** The number of boxes. */
94
+ length?: number;
95
+ /** Boxes you type into (`true`), or boxes that only reflect the value (`false`). */
96
+ interactive?: boolean;
97
+ /** Draw a bullet for a digit, and use a password input for the typed ones. */
98
+ masked?: boolean;
99
+ /** Focus the first empty box on mount (interactive only). */
100
+ autofocus?: boolean;
101
+ disabled?: boolean;
102
+ label?: string;
103
+ /** Overrides the three phrases below member by member; the rest keep the contract's. */
104
+ labels?: Partial<PinFieldLabels>;
105
+ class?: HTMLAttributes['class'];
106
+ }>(),
107
+ {
108
+ modelValue: '',
109
+ length: 6,
110
+ interactive: true,
111
+ masked: true,
112
+ autofocus: false,
113
+ disabled: false,
114
+ label: undefined,
115
+ labels: undefined,
116
+ class: undefined,
117
+ },
118
+ );
119
+
120
+ const emit = defineEmits<{
121
+ (e: 'update:modelValue', value: string): void;
122
+ (e: 'complete', value: string): void;
123
+ }>();
124
+
125
+ const attrs = useAttrs();
126
+ const contract = useUiLabels();
127
+
128
+ const text = computed<PinFieldLabels>(() => ({
129
+ pinFieldGroup: contract.value.pinFieldGroup,
130
+ pinFieldDigit: contract.value.pinFieldDigit,
131
+ pinFieldFilled: contract.value.pinFieldFilled,
132
+ // Members given as `undefined` are dropped, not spread: they would blank the contract's word.
133
+ ...Object.fromEntries(Object.entries(props.labels ?? {}).filter(([, v]) => v !== undefined)),
134
+ }));
135
+
136
+ const labelId = useId();
137
+
138
+ const onlyDigits = (raw: string): string => raw.replace(/[^0-9]/g, '');
139
+
140
+ /** The model as it was stored, whatever it is. */
141
+ const stored = computed(() => props.modelValue ?? '');
142
+ /** The digits the boxes can show: the stored digits, closed up, as many as there are boxes. */
143
+ const digits = computed(() => onlyDigits(stored.value).slice(0, props.length));
144
+ /** The one box in the tab order: the first empty one, or the last when the code is whole. */
145
+ const tabStop = computed(() => Math.min(digits.value.length, props.length - 1));
146
+
147
+ const readout = computed(() =>
148
+ !props.masked && digits.value
149
+ ? digits.value
150
+ : formatLabel(text.value.pinFieldFilled, {
151
+ filled: digits.value.length,
152
+ total: props.length,
153
+ }),
154
+ );
155
+
156
+ const inputs: (HTMLInputElement | null)[] = [];
157
+
158
+ async function focusBox(index: number): Promise<void> {
159
+ // After the render the model change causes: the box may not exist or be enabled before it.
160
+ await nextTick();
161
+ const box = inputs[Math.max(0, Math.min(index, props.length - 1))];
162
+ box?.focus();
163
+ }
164
+
165
+ /** A person changed the digits: say so, and say `complete` if it made a whole code. */
166
+ function commit(next: string, focusAt: number): void {
167
+ if (next !== stored.value) {
168
+ emit('update:modelValue', next);
169
+ if (next.length === props.length) {
170
+ emit('complete', next);
171
+ }
172
+ }
173
+ void focusBox(focusAt);
174
+ }
175
+
176
+ /** Puts `pasted` over the digits from the box `index`, keeping what follows it. */
177
+ function spread(pasted: string, index: number): void {
178
+ const at = Math.min(index, digits.value.length);
179
+ const next = (
180
+ digits.value.slice(0, at) +
181
+ pasted +
182
+ digits.value.slice(at + pasted.length)
183
+ ).slice(0, props.length);
184
+ commit(next, at + pasted.length);
185
+ }
186
+
187
+ function onInput(index: number, event: Event): void {
188
+ if (props.disabled) {
189
+ return;
190
+ }
191
+ const box = event.target as HTMLInputElement;
192
+ const typed = onlyDigits(box.value);
193
+ if (box.value !== '' && typed === '') {
194
+ // Not a digit: put back what the box held. The model did not change, so nothing
195
+ // re-renders the box, and the letter would stay standing in it.
196
+ box.value = digits.value[index] ?? '';
197
+ return;
198
+ }
199
+ if (typed.length > 1) {
200
+ spread(typed, index);
201
+ return;
202
+ }
203
+ const at = Math.min(index, digits.value.length);
204
+ if (typed === '') {
205
+ // A box emptied: its digit goes and the ones after it close up.
206
+ commit(digits.value.slice(0, index) + digits.value.slice(index + 1), index);
207
+ return;
208
+ }
209
+ const next = digits.value.slice(0, at) + typed + digits.value.slice(at + 1);
210
+ commit(next, at + 1);
211
+ }
212
+
213
+ function onPaste(index: number, event: ClipboardEvent): void {
214
+ if (props.disabled) {
215
+ return;
216
+ }
217
+ event.preventDefault();
218
+ const pasted = onlyDigits(event.clipboardData?.getData('text') ?? '');
219
+ if (pasted !== '') {
220
+ spread(pasted, index);
221
+ }
222
+ }
223
+
224
+ function onKeydown(index: number, event: KeyboardEvent): void {
225
+ if (props.disabled) {
226
+ return;
227
+ }
228
+ if (event.key === 'Backspace' || event.key === 'Delete') {
229
+ if (digits.value[index] !== undefined) {
230
+ return; // A filled box: the input event takes its digit out.
231
+ }
232
+ // An empty box. A stored value that draws as less than it holds (or as nothing at
233
+ // all) is put right here, because there is no other keystroke that reaches it.
234
+ if (stored.value !== digits.value) {
235
+ emit('update:modelValue', digits.value);
236
+ }
237
+ if (event.key === 'Backspace' && index > 0) {
238
+ event.preventDefault();
239
+ void focusBox(index - 1);
240
+ }
241
+ return;
242
+ }
243
+ if (event.key === 'ArrowLeft' && index > 0) {
244
+ event.preventDefault();
245
+ void focusBox(index - 1);
246
+ } else if (event.key === 'ArrowRight' && index < props.length - 1) {
247
+ event.preventDefault();
248
+ void focusBox(index + 1);
249
+ }
250
+ }
251
+
252
+ /** A box takes the focus with its digit selected, so the next digit replaces it. */
253
+ function onFocus(event: FocusEvent): void {
254
+ (event.target as HTMLInputElement).select();
255
+ }
256
+
257
+ onMounted(() => {
258
+ if (props.interactive && props.autofocus && !props.disabled) {
259
+ void focusBox(tabStop.value);
260
+ }
261
+ });
262
+
263
+ const groupAttrs = computed(() =>
264
+ Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== 'style' && key !== 'class')),
265
+ );
266
+
267
+ const BOX =
268
+ 'h-[46px] w-10 rounded-lg border text-center text-lg font-semibold tabular-nums transition-colors';
269
+ const BOX_INPUT = cn(
270
+ BOX,
271
+ 'border-muted-foreground text-foreground dark:bg-input/30 bg-transparent outline-none',
272
+ 'focus-visible:border-ring focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-2',
273
+ 'disabled:cursor-not-allowed disabled:opacity-50',
274
+ );
275
+ const BOX_READOUT = cn(BOX, 'border-input bg-muted text-foreground grid place-items-center');
276
+ </script>
277
+
278
+ <template>
279
+ <div
280
+ data-slot="form-field"
281
+ :class="cn('grid gap-1.5', props.class)"
282
+ :style="attrs.style as never"
283
+ >
284
+ <Label v-if="props.label" :id="labelId">{{ props.label }}</Label>
285
+ <div
286
+ v-bind="groupAttrs"
287
+ role="group"
288
+ :aria-labelledby="props.label ? labelId : undefined"
289
+ :aria-label="props.label ? undefined : text.pinFieldGroup"
290
+ class="flex gap-2"
291
+ >
292
+ <template v-if="props.interactive">
293
+ <input
294
+ v-for="(_, index) in length"
295
+ :key="index"
296
+ :ref="(el) => (inputs[index] = el as HTMLInputElement | null)"
297
+ data-slot="input"
298
+ :type="props.masked ? 'password' : 'text'"
299
+ inputmode="numeric"
300
+ autocomplete="off"
301
+ maxlength="1"
302
+ :value="digits[index] ?? ''"
303
+ :disabled="props.disabled"
304
+ :tabindex="index === tabStop ? 0 : -1"
305
+ :aria-label="
306
+ formatLabel(text.pinFieldDigit, { position: index + 1, total: length })
307
+ "
308
+ :class="BOX_INPUT"
309
+ @input="onInput(index, $event)"
310
+ @paste="onPaste(index, $event)"
311
+ @keydown="onKeydown(index, $event)"
312
+ @focus="onFocus"
313
+ />
314
+ </template>
315
+ <template v-else>
316
+ <span
317
+ v-for="(_, index) in length"
318
+ :key="index"
319
+ data-pin-box
320
+ data-slot="input"
321
+ aria-hidden="true"
322
+ :class="cn(BOX_READOUT, props.disabled && 'opacity-50')"
323
+ >
324
+ <template v-if="digits[index] !== undefined">{{
325
+ props.masked ? '•' : digits[index]
326
+ }}</template>
327
+ </span>
328
+ <span data-pin-readout class="sr-only">{{ readout }}</span>
329
+ </template>
330
+ </div>
331
+ </div>
332
+ </template>
@@ -0,0 +1 @@
1
+ export { default as PinField } from './PinField.vue';