@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,101 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { Button } from '../button';
4
+ import { MenuContent, MenuRoot, MenuTrigger } from '../menu';
5
+ import type { DropdownItem } from './dropdown';
6
+ import DropdownItems from './DropdownItems.vue';
7
+
8
+ /**
9
+ * A dropdown menu written as data: a trigger, a panel, and `items` that say what is in it
10
+ * (actions with an optional hint and danger ink, separators, headings that wrap their rows,
11
+ * radio lists, tickable rows and nested sub-menus). The common menu is an array and nothing
12
+ * else, and the callbacks live inside the items, in the shape `RowActions` already uses.
13
+ *
14
+ * IT COMPOSES `../menu` AND NOTHING PRIVATE. Every part it draws, and the two look strings for
15
+ * the hint and the heading, are the ones the menu family publishes, so the page a consumer
16
+ * would build by hand from those parts is this component without the loop. That is the point of
17
+ * the family: it is the proof that the published parts are enough. The only other import is the
18
+ * `Button` of the default trigger.
19
+ *
20
+ * WHAT AN ITEMS ARRAY CANNOT EXPRESS is a row whose content is not a string: a swatch beside
21
+ * the label, an avatar, a hint that is a keyboard-shortcut component. Labels and hints are
22
+ * text. A menu with such a row composes the `menu/` parts directly (`MenuRoot`, `MenuItem`, ...)
23
+ * and puts what it likes inside the row; the two are not mixed.
24
+ *
25
+ * The trigger is a plain outline `Button` named by `label` unless the `trigger` slot supplies
26
+ * its content, in which case `label` becomes the button's accessible name (an icon-only trigger
27
+ * has no text of its own). The panel takes `side` and `align` (defaults are `MenuContent`'s:
28
+ * below, aligned to the end) and `panelClass`, which reaches the panel and replaces its `min-w-*`
29
+ * floor. Sub-panels take no alignment: `MenuSubContent` offers none.
30
+ *
31
+ * Attributes (`id`, `aria-*`, `data-*`) and `class` land on the trigger, and a consumer's
32
+ * attribute beats the family's own default: its `aria-label` replaces the one the `trigger` slot
33
+ * case sets. The one exception is `type`, which is always `button`: a trigger that submitted a
34
+ * form would be a defect. The root is a fragment (a trigger and a panel), so without this
35
+ * forwarding every attribute would be dropped. Do not pass `aria-expanded`, `aria-controls` or
36
+ * `data-state`: the trigger's own state attributes come from the menu engine and a consumer's
37
+ * value would replace them. The panel is reached by `panelClass`, never by `class`.
38
+ *
39
+ * OPEN STATE. Controlled when `open` is given: the panel follows it and `update:open` says what
40
+ * the user asked for. With no `open`, the component holds its own, and still emits.
41
+ *
42
+ * TICKABLE ROWS KEEP THE PANEL OPEN. A `check` row flips and leaves the panel where it is, so
43
+ * several can be ticked in a row; the item's `closeOnSelect` brings back the close-on-choice a
44
+ * menu row otherwise has. A `radio` row closes the panel, as picking one option should.
45
+ */
46
+ defineOptions({ inheritAttrs: false });
47
+
48
+ const props = withDefaults(
49
+ defineProps<{
50
+ items: DropdownItem[];
51
+ /** Accessible name of a trigger with no text of its own. */
52
+ label?: string;
53
+ /** Where the panel sits against the trigger. Forwarded to the panel. */
54
+ side?: 'top' | 'right' | 'bottom' | 'left';
55
+ align?: 'start' | 'center' | 'end';
56
+ /**
57
+ * Controlled when given; otherwise the component holds its own open state. Decide which
58
+ * at mount: the engine fixes controlled-or-not at setup, so a dropdown mounted with
59
+ * `open` undefined ignores the prop for good, even once it becomes a boolean.
60
+ */
61
+ open?: boolean;
62
+ /** Classes for the panel. `class` itself lands on the trigger. */
63
+ panelClass?: HTMLAttributes['class'];
64
+ }>(),
65
+ { label: undefined, side: undefined, align: undefined, open: undefined, panelClass: undefined },
66
+ );
67
+
68
+ const emit = defineEmits<{ (e: 'update:open', value: boolean): void }>();
69
+
70
+ defineSlots<{
71
+ /** The trigger's content. A plain `Button` when absent. */
72
+ trigger?: (props: { open: boolean }) => unknown;
73
+ }>();
74
+ </script>
75
+
76
+ <template>
77
+ <MenuRoot
78
+ v-slot="{ open: isOpen }"
79
+ v-bind="props.open === undefined ? {} : { open: props.open }"
80
+ @update:open="emit('update:open', $event)"
81
+ >
82
+ <MenuTrigger as-child>
83
+ <Button
84
+ variant="outline"
85
+ :aria-label="$slots.trigger ? props.label : undefined"
86
+ v-bind="{ ...$attrs, type: 'button' }"
87
+ >
88
+ <slot name="trigger" :open="isOpen">{{ props.label }}</slot>
89
+ </Button>
90
+ </MenuTrigger>
91
+ <MenuContent
92
+ v-bind="{
93
+ ...(props.side === undefined ? {} : { side: props.side }),
94
+ ...(props.align === undefined ? {} : { align: props.align }),
95
+ }"
96
+ :class="props.panelClass"
97
+ >
98
+ <DropdownItems :items="props.items" />
99
+ </MenuContent>
100
+ </MenuRoot>
101
+ </template>
@@ -0,0 +1,154 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ MenuCheckboxItem,
4
+ MenuGroup,
5
+ MenuItem,
6
+ MenuLabel,
7
+ MenuRadioGroup,
8
+ MenuRadioItem,
9
+ MenuSeparator,
10
+ MenuSub,
11
+ MenuSubContent,
12
+ MenuSubTrigger,
13
+ menuItemHintClass,
14
+ menuLabelClass,
15
+ } from '../menu';
16
+ import { useId } from 'vue';
17
+ import type { DropdownItem } from './dropdown';
18
+
19
+ /**
20
+ * One list of a `Dropdown`'s items, drawn from the `menu/` parts and nothing else. It is its own
21
+ * component because a `heading` wraps a list and a `sub` holds one, so drawing a list means
22
+ * drawing lists: the template renders itself for each nested `items` array, and `Dropdown.vue`
23
+ * is left with the trigger and the panel. It is not exported from the barrel; the family's
24
+ * public surface is `Dropdown` and the `DropdownItem` type.
25
+ *
26
+ * KEYS. A row with a `testid` is keyed on it, and every other entry on its position. A label
27
+ * would collide (two "Delete" rows in two groups are ordinary), and a position alone lets Vue
28
+ * move one row's danger ink, disabled state and focus onto a neighbour when the list changes,
29
+ * which is the reason `RowAction.testid` doubles as a key.
30
+ *
31
+ * A TICKABLE ROW KEEPS THE PANEL OPEN unless its `closeOnSelect` is set: reka closes a menu after
32
+ * any `select` that is not default-prevented, and the canonical tickable menu is a column or
33
+ * filter list where several rows are ticked in a row. A radio list is left to close, since
34
+ * picking the one option ends the choice.
35
+ *
36
+ * COLOUR. A `danger` row is `text-destructive`, the ink `RowActions` uses, and only while it is
37
+ * enabled: the shared disabled form is `opacity-50` over the ordinary ink, and a tinted disabled
38
+ * row would read as a different kind of unavailable. The highlighted ink wins over it by the
39
+ * row's own `data-highlighted:text-accent-foreground`, which is what keeps the label legible on
40
+ * the accent wash.
41
+ */
42
+ defineProps<{ items: DropdownItem[] }>();
43
+
44
+ /**
45
+ * This list's own prefix for hint ids. Every nested list is another instance and so takes
46
+ * another prefix: a key is only unique within its list, and one prefix shared down the tree
47
+ * gave a hinted row at index 0 of a sub-menu the id of the one at index 0 above it, so its
48
+ * `aria-describedby` named the wrong row's hint. (`useId` is also unique across dropdowns.)
49
+ */
50
+ const uid = useId();
51
+
52
+ /** A new `DropdownItem` kind that is not drawn above is a type error here, not a blank row. */
53
+ function unreachable(item: never): never {
54
+ throw new Error(`a dropdown item of an unknown kind: ${JSON.stringify(item)}`);
55
+ }
56
+
57
+ /** The render key: the `testid` where there is one, the position otherwise. */
58
+ function keyOf(item: DropdownItem, index: number): string {
59
+ return 'testid' in item && item.testid !== undefined ? `t:${item.testid}` : `i:${index}`;
60
+ }
61
+
62
+ /**
63
+ * A hint's own id, so the row can point `aria-describedby` at it. It is built from the position
64
+ * and never from the `testid`: `aria-describedby` is a list of ids separated by spaces, and a
65
+ * consumer string interpolated into one (`'delete job'`) names two ids that do not exist and
66
+ * unlinks the hint without a sound. The `testid` stays the render key only.
67
+ */
68
+ function hintId(index: number): string {
69
+ return `${uid}-hint-i:${index}`;
70
+ }
71
+
72
+ /**
73
+ * The quiet text beside a label. On a disabled row it drops the quiet ink and keeps the size:
74
+ * the row is already at `opacity-50`, and muted ink under that fade is the pairing `RowActions`
75
+ * measured and avoided (see `hintClass` in `row-actions/RowActions.vue` for the figures, which
76
+ * are not restated here).
77
+ */
78
+ function hintClass(disabled: boolean | undefined): string {
79
+ return disabled === true ? 'text-[11px]' : menuItemHintClass;
80
+ }
81
+
82
+ /** reka reports `true`, `false` or `'indeterminate'`; the item model has no third state. */
83
+ function ticked(next: boolean | 'indeterminate'): boolean {
84
+ return next === true;
85
+ }
86
+ </script>
87
+
88
+ <template>
89
+ <template v-for="(item, index) in items" :key="keyOf(item, index)">
90
+ <MenuItem
91
+ v-if="item.kind === 'action'"
92
+ :data-testid="item.testid"
93
+ :disabled="item.disabled"
94
+ :class="item.danger === true && item.disabled !== true ? 'text-destructive' : undefined"
95
+ :aria-describedby="item.hint === undefined ? undefined : hintId(index)"
96
+ @select="item.handler()"
97
+ >
98
+ <span>{{ item.label }}</span>
99
+ <span
100
+ v-if="item.hint !== undefined"
101
+ :id="hintId(index)"
102
+ :class="hintClass(item.disabled)"
103
+ >
104
+ {{ item.hint }}
105
+ </span>
106
+ </MenuItem>
107
+
108
+ <MenuSeparator v-else-if="item.kind === 'separator'" />
109
+
110
+ <MenuGroup v-else-if="item.kind === 'heading'">
111
+ <MenuLabel :class="menuLabelClass">{{ item.label }}</MenuLabel>
112
+ <DropdownItems :items="item.items" />
113
+ </MenuGroup>
114
+
115
+ <MenuRadioGroup
116
+ v-else-if="item.kind === 'radio'"
117
+ :model-value="item.value"
118
+ @update:model-value="item.onSelect(String($event))"
119
+ >
120
+ <MenuRadioItem
121
+ v-for="option in item.options"
122
+ :key="option.value"
123
+ :value="option.value"
124
+ :disabled="option.disabled"
125
+ >
126
+ {{ option.label }}
127
+ </MenuRadioItem>
128
+ </MenuRadioGroup>
129
+
130
+ <MenuCheckboxItem
131
+ v-else-if="item.kind === 'check'"
132
+ :model-value="item.checked"
133
+ :data-testid="item.testid"
134
+ :disabled="item.disabled"
135
+ @select="
136
+ (event: Event) => {
137
+ if (item.closeOnSelect !== true) event.preventDefault();
138
+ }
139
+ "
140
+ @update:model-value="item.onChange(ticked($event))"
141
+ >
142
+ {{ item.label }}
143
+ </MenuCheckboxItem>
144
+
145
+ <MenuSub v-else-if="item.kind === 'sub'">
146
+ <MenuSubTrigger :disabled="item.disabled">{{ item.label }}</MenuSubTrigger>
147
+ <MenuSubContent>
148
+ <DropdownItems :items="item.items" />
149
+ </MenuSubContent>
150
+ </MenuSub>
151
+
152
+ <template v-else>{{ unreachable(item) }}</template>
153
+ </template>
154
+ </template>
@@ -0,0 +1,64 @@
1
+ /**
2
+ * One entry of a `Dropdown`'s panel. The kinds are the ones the `menu/` parts can draw from a
3
+ * plain description; the callback lives inside the item rather than in one event per kind,
4
+ * which is the shape `row-actions/rowActions.ts` already ships, and the `action` variant keeps
5
+ * that file's field names (`label`, `handler`, `hint`, `danger`, `disabled`, `testid`) on
6
+ * purpose, so a reader who knows one knows the other.
7
+ *
8
+ * NORMALISING THE LIST IS THE CALLER'S JOB. A `heading` whose `items` filtered down to nothing
9
+ * draws a heading over no rows, and a `separator` left at either end or doubled draws a stray
10
+ * hairline. `items.filter(...)` is the common shape of a data-driven menu, so drop the empty
11
+ * heading and the doubled separator in the same place the rows are dropped. The component draws
12
+ * what it is given.
13
+ */
14
+ export type DropdownItem =
15
+ | {
16
+ kind: 'action';
17
+ label: string;
18
+ handler: () => void;
19
+ /**
20
+ * A short note drawn on the row beside its label, typically why the action is
21
+ * disabled, and referenced by the row's `aria-describedby`.
22
+ */
23
+ hint?: string;
24
+ /** Draws the row in the destructive ink: a delete, a revoke. */
25
+ danger?: boolean;
26
+ /** Renders the row greyed out and non-interactive; its `handler` is never invoked. */
27
+ disabled?: boolean;
28
+ /**
29
+ * Stable `data-testid` for the row. It is also the row's render key where it is
30
+ * given, which is the one reason to set it on a row no test names: two rows labelled
31
+ * the same would otherwise be told apart by their position only, and Vue could hand
32
+ * one row's node (its danger ink, its disabled state, its focus) to a neighbour when
33
+ * the list changes.
34
+ */
35
+ testid?: string;
36
+ }
37
+ | { kind: 'separator' }
38
+ /** A heading names a group, so it wraps the rows it names rather than sitting between them. */
39
+ | { kind: 'heading'; label: string; items: DropdownItem[] }
40
+ | {
41
+ kind: 'radio';
42
+ /** The chosen option's value. The list is controlled: pass the new one back in. */
43
+ value: string;
44
+ options: { value: string; label: string; disabled?: boolean }[];
45
+ onSelect: (value: string) => void;
46
+ }
47
+ | {
48
+ kind: 'check';
49
+ label: string;
50
+ checked: boolean;
51
+ onChange: (checked: boolean) => void;
52
+ disabled?: boolean;
53
+ /**
54
+ * Closes the panel after the row is chosen. Off by default: a tickable row keeps the
55
+ * panel open, because the use of a tickable menu is ticking several rows (the columns
56
+ * to show, the filters to apply) and a panel that closes on every tick has to be
57
+ * reopened for each. A `radio` list closes as it always did. The parts allow
58
+ * `@select.prevent` already, so this is that capability under a field's name.
59
+ */
60
+ closeOnSelect?: boolean;
61
+ /** Test hook and render key, as on an `action`. */
62
+ testid?: string;
63
+ }
64
+ | { kind: 'sub'; label: string; items: DropdownItem[]; disabled?: boolean };
@@ -0,0 +1,2 @@
1
+ export { default as Dropdown } from './Dropdown.vue';
2
+ export type { DropdownItem } from './dropdown';
@@ -0,0 +1,78 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { computed, ref, watch } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+
6
+ /**
7
+ * The thumbnail of an uploaded file, or a frame saying it is on its way. Presentational:
8
+ * it takes no focus and no input.
9
+ *
10
+ * It renders nothing without a file. With a file and no picture, or a picture that fails to
11
+ * load, it shows the pending frame; a fresh `previewUrl` gets a fresh chance.
12
+ *
13
+ * Every colour is a role, the picture's well included: the well is what shows through a
14
+ * transparent image, and it is a surface (`muted`) rather than a chequerboard because this
15
+ * component never promised to show transparency, only to hold a place.
16
+ */
17
+ const props = withDefaults(
18
+ defineProps<{
19
+ previewUrl: string | null;
20
+ hasFile?: boolean;
21
+ /** Circular avatar-style preview (e.g. profile images) instead of the default rectangular thumbnail. */
22
+ round?: boolean;
23
+ alt?: string;
24
+ /** The words in the pending frame. */
25
+ label?: string;
26
+ class?: HTMLAttributes['class'];
27
+ }>(),
28
+ {
29
+ hasFile: false,
30
+ round: false,
31
+ alt: '',
32
+ label: 'Preview is being created…',
33
+ },
34
+ );
35
+
36
+ // A freshly-signed preview URL can 404 until the async thumbnail job writes
37
+ // it, so an image load failure falls back to the same pending placeholder.
38
+ const errored = ref(false);
39
+ watch(
40
+ () => props.previewUrl,
41
+ () => {
42
+ errored.value = false;
43
+ },
44
+ );
45
+
46
+ const showImage = computed(() => props.previewUrl !== null && !errored.value);
47
+ const showPending = computed(() => props.hasFile && !showImage.value);
48
+ </script>
49
+
50
+ <template>
51
+ <div
52
+ v-if="hasFile"
53
+ :class="
54
+ cn(
55
+ 'bg-muted relative shrink-0 overflow-hidden',
56
+ round ? 'h-20 w-20 rounded-full' : 'h-40 w-[120px] rounded-lg',
57
+ props.class,
58
+ )
59
+ "
60
+ >
61
+ <img
62
+ v-if="showImage"
63
+ :src="previewUrl!"
64
+ :alt="alt"
65
+ class="h-full w-full object-cover"
66
+ @error="errored = true"
67
+ />
68
+ <div
69
+ v-else-if="showPending"
70
+ class="text-muted-foreground border-muted-foreground flex h-full w-full flex-col items-center justify-center gap-2.5 border border-dashed px-2 text-center text-[11px]"
71
+ >
72
+ <span
73
+ class="border-border border-t-primary h-6 w-6 animate-spin rounded-full border-2 motion-reduce:animate-none"
74
+ />
75
+ <span>{{ label }}</span>
76
+ </div>
77
+ </div>
78
+ </template>
@@ -0,0 +1 @@
1
+ export { default as FilePreview } from './FilePreview.vue';
@@ -0,0 +1,234 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ fileTooLarge,
4
+ formatLabel,
5
+ formatMegabytes,
6
+ MAX_UPLOAD_BYTES,
7
+ useUiLabels,
8
+ } from '@noix-dev/brix-core';
9
+ import type { HTMLAttributes } from 'vue';
10
+ import { computed, ref, useAttrs } from 'vue';
11
+ import { cn } from '../../lib/cn';
12
+ import { PlusIcon, TriangleAlertIcon } from '../icon';
13
+
14
+ /**
15
+ * A dropzone: click it, press Enter or Space on it, or drop files onto it. It hands each
16
+ * accepted file on through `select` — once per file, never as a list — and says under itself
17
+ * which files it refused for being over `maxBytes`.
18
+ *
19
+ * WORDING. The label and the hint come from the labels contract. The hint's limit is filled
20
+ * from this component's own `maxBytes`, so it is true by construction: a hint that spelled
21
+ * out 100 MB would promise what a smaller `maxBytes` then refuses. The accepted types stay
22
+ * as wording in the contract's hint (turning `accept` into prose is editorial); pass `hint`
23
+ * to say something else.
24
+ *
25
+ * ICONS. Both glyphs sit behind named slots (ADR 0013): `icon` is the plus in the dropzone and
26
+ * `warning-icon` the triangle before each refusal message.
27
+ *
28
+ * COLOUR. Every colour is a role. The dropzone's own edge and its muted text are structure
29
+ * (`border`, `muted-foreground`), and the hover and drag state is the `primary` accent, and
30
+ * over that accent's wash the hint takes `--primary-on-wash` (see `hintClass`). The
31
+ * refusal carries meaning and takes `destructive`, for the message and for the dropzone's
32
+ * edge and halo while the field is invalid (a refusal is showing, or the host marked it). It is
33
+ * `destructive` and not `warning` because the file
34
+ * is refused outright, not let through with a caution: the component draws one kind of limit,
35
+ * a hard one, so there is no soft limit for `warning` to name. Nothing here is a swatch.
36
+ */
37
+
38
+ // Attributes (data-testid & co.) belong on the dropzone, not on the wrapper that also holds
39
+ // the size messages.
40
+ defineOptions({ inheritAttrs: false });
41
+
42
+ const props = withDefaults(
43
+ defineProps<{
44
+ accept?: string;
45
+ /** Lets the picker/drop deliver several files — `select` still fires once per file. */
46
+ multiple?: boolean;
47
+ loading?: boolean;
48
+ disabled?: boolean;
49
+ /** The dropzone's words; the labels contract's `uploadDropzone` when left out. */
50
+ label?: string;
51
+ /** The line under the label; the contract's `uploadHint`, with this limit, when left out. */
52
+ hint?: string;
53
+ /** Files above this size are not handed on; a message under the dropzone names them. */
54
+ maxBytes?: number;
55
+ class?: HTMLAttributes['class'];
56
+ }>(),
57
+ {
58
+ maxBytes: MAX_UPLOAD_BYTES,
59
+ },
60
+ );
61
+
62
+ const emit = defineEmits<{ (e: 'select', file: File): void }>();
63
+
64
+ const labels = useUiLabels();
65
+ const inputRef = ref<HTMLInputElement>();
66
+ const isDragging = ref(false);
67
+ /** One message per file of the last pick that was too large. */
68
+ const tooLarge = ref<string[]>([]);
69
+
70
+ const shownLabel = computed(() => props.label ?? labels.value.uploadDropzone);
71
+ const shownHint = computed(
72
+ () =>
73
+ props.hint ??
74
+ formatLabel(labels.value.uploadHint, { max: formatMegabytes(props.maxBytes) }),
75
+ );
76
+
77
+ /** Hands on the files that fit and keeps a message for each one that does not. */
78
+ function handOn(files: File[]): void {
79
+ tooLarge.value = [];
80
+ for (const file of files) {
81
+ const message = fileTooLarge(file, labels.value.uploadTooLarge, props.maxBytes);
82
+ if (message) {
83
+ tooLarge.value.push(message);
84
+ } else {
85
+ emit('select', file);
86
+ }
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The hint's ink. `--muted-foreground` is the caption ink on the page and on `--muted`, but the
92
+ * hover and the drag lay a 5% `--primary` wash under it, and over that wash it measures 4.35 in
93
+ * kingfisher light, under the 4.5 text needs (4.35 is `wash()`'s own arithmetic, which formats the
94
+ * washed hex before taking the ratio; the rendered colour measured in a browser is 4.36, and both
95
+ * are right). So while the wash is there (a drag, or a hover on a
96
+ * dropzone that has not refused anything) the hint takes `--primary-on-wash`, the ink that role
97
+ * exists for. Over the wash in the six theme and mode pairs it measures 5.40 to 12.50, while the
98
+ * label above it (`--foreground`) measures 14.28 to 18.21, so the hint stays the quieter line.
99
+ */
100
+ const hintClass = computed(() =>
101
+ cn(
102
+ 'text-muted-foreground text-xs',
103
+ tooLarge.value.length === 0 && 'group-hover/dropzone:text-primary-on-wash',
104
+ isDragging.value && 'text-primary-on-wash',
105
+ ),
106
+ );
107
+
108
+ /**
109
+ * Invalid is one state with two sources: this component's own refusal, and a host that marks the
110
+ * field (a `FormField` hands its control `aria-invalid`, which lands here through `$attrs`).
111
+ * The attribute is what draws the edge and the halo, so it is what the component's own refusal
112
+ * has to set too; when nothing has been refused the host's value passes through untouched.
113
+ */
114
+ const attrs = useAttrs();
115
+ // Functions rather than computeds. Not for staleness: a named-key read of `useAttrs()` is tracked,
116
+ // and a computed over one updates both when the attribute changes and when it first appears
117
+ // (measured on Vue 3.5.46, both builds). These are readings composed at call time, and the package
118
+ // keeps one attrs pattern across its families.
119
+ const hostAriaInvalid = (): boolean | 'true' | 'false' | undefined =>
120
+ attrs['aria-invalid'] as boolean | 'true' | 'false' | undefined;
121
+ const hostInvalid = (): boolean => hostAriaInvalid() === true || hostAriaInvalid() === 'true';
122
+ const isInvalid = (): boolean => tooLarge.value.length > 0 || hostInvalid();
123
+
124
+ const isInactive = (): boolean => props.disabled === true || props.loading === true;
125
+
126
+ function openPicker(): void {
127
+ if (isInactive()) {
128
+ return;
129
+ }
130
+ inputRef.value?.click();
131
+ }
132
+
133
+ function onDragOver(): void {
134
+ if (isInactive()) {
135
+ return;
136
+ }
137
+ isDragging.value = true;
138
+ }
139
+
140
+ function onDragLeave(): void {
141
+ isDragging.value = false;
142
+ }
143
+
144
+ function pickedFiles(list: FileList | null | undefined): File[] {
145
+ const all = Array.from(list ?? []);
146
+ return props.multiple ? all : all.slice(0, 1);
147
+ }
148
+
149
+ function onDrop(event: DragEvent): void {
150
+ isDragging.value = false;
151
+ if (isInactive()) {
152
+ return;
153
+ }
154
+ handOn(pickedFiles(event.dataTransfer?.files));
155
+ }
156
+
157
+ function onChange(event: Event): void {
158
+ const input = event.target as HTMLInputElement;
159
+ const files = pickedFiles(input.files);
160
+ // Reset so picking the same file again still fires a `change` event.
161
+ input.value = '';
162
+ if (isInactive()) {
163
+ return;
164
+ }
165
+ handOn(files);
166
+ }
167
+ </script>
168
+
169
+ <template>
170
+ <div>
171
+ <div
172
+ v-bind="$attrs"
173
+ role="button"
174
+ tabindex="0"
175
+ :aria-disabled="isInactive()"
176
+ :aria-invalid="tooLarge.length > 0 ? true : hostAriaInvalid()"
177
+ :class="
178
+ cn(
179
+ 'group/dropzone bg-muted/50 text-muted-foreground flex items-center gap-3 rounded-xl border-2 border-dashed px-4 py-3.5 transition-colors',
180
+ !isInvalid() &&
181
+ 'hover:border-primary hover:bg-primary/5 hover:text-primary-on-wash',
182
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
183
+ 'border-border',
184
+ // The invalid pair of the control-state recipe (CLAUDE.md, Invalid): a
185
+ // full-strength edge and the halo, as `Input` and `SegmentedChoice` draw
186
+ // it. The edge measures 4.90-7.50 against the page; the halo is weight
187
+ // (1.38-1.44 against the page, dark 1.95-2.15), which is why the edge is
188
+ // not left to it. It follows the attribute, so a host's mark draws it too.
189
+ 'aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40',
190
+ isDragging && 'border-primary bg-primary/5 text-primary-on-wash',
191
+ isInactive() && 'pointer-events-none cursor-not-allowed opacity-50',
192
+ !isInactive() && 'cursor-pointer',
193
+ props.class,
194
+ )
195
+ "
196
+ @click="openPicker"
197
+ @keydown.enter.prevent="openPicker"
198
+ @keydown.space.prevent="openPicker"
199
+ @dragover.prevent="onDragOver"
200
+ @dragleave.prevent="onDragLeave"
201
+ @drop.prevent="onDrop"
202
+ >
203
+ <input
204
+ ref="inputRef"
205
+ type="file"
206
+ class="hidden"
207
+ :accept="accept"
208
+ :multiple="multiple"
209
+ :disabled="isInactive()"
210
+ @click.stop
211
+ @change="onChange"
212
+ />
213
+ <span
214
+ class="bg-primary/10 text-primary-on-wash flex h-9 w-9 shrink-0 items-center justify-center rounded-lg"
215
+ >
216
+ <slot name="icon"><PlusIcon class="size-5" /></slot>
217
+ </span>
218
+ <div class="min-w-0">
219
+ <div class="text-foreground text-sm font-semibold">{{ shownLabel }}</div>
220
+ <div :class="hintClass">{{ shownHint }}</div>
221
+ </div>
222
+ </div>
223
+ <p
224
+ v-for="(message, index) in tooLarge"
225
+ :key="`${index}:${message}`"
226
+ role="alert"
227
+ data-testid="file-upload-too-large"
228
+ class="text-destructive mt-1.5 flex items-center gap-1 text-xs"
229
+ >
230
+ <slot name="warning-icon"><TriangleAlertIcon class="size-3.5 shrink-0" /></slot>
231
+ {{ message }}
232
+ </p>
233
+ </div>
234
+ </template>
@@ -0,0 +1 @@
1
+ export { default as FileUpload } from './FileUpload.vue';