@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,293 @@
1
+ <script setup lang="ts">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import {
4
+ DialogContent,
5
+ DialogOverlay,
6
+ DialogPortal,
7
+ DialogRoot,
8
+ DialogTitle,
9
+ PopoverAnchor,
10
+ PopoverContent,
11
+ PopoverPortal,
12
+ PopoverRoot,
13
+ PopoverTrigger,
14
+ } from 'reka-ui';
15
+ import { computed, nextTick, useAttrs, useId, useTemplateRef, watch } from 'vue';
16
+ import type { HTMLAttributes } from 'vue';
17
+ import { cn } from '../../lib/cn';
18
+ import { CalendarDaysIcon, XIcon } from '../icon';
19
+
20
+ /**
21
+ * The shell every date picker shares: the text input with its clear and open-calendar
22
+ * buttons, the layer the calendar sits in (a popover, or a bottom sheet when `narrow`), and
23
+ * the component's own error text. The calendar is the default slot's business. It owns no
24
+ * date: the picker holds the value and the open state, passes the text and its error in, and
25
+ * handles `update:text`, `commit` (blur, Enter), `clear` and `opened` (the layer is up and
26
+ * focus may move into it).
27
+ *
28
+ * The picker forwards its attributes here (`v-bind="$attrs"`): everything but `style` lands
29
+ * on the input; `style` and `class` go on the outer element. A `readonly` attribute locks the
30
+ * buttons like `disabled` does. The glyphs are the `calendar-icon` and `clear-icon` slots (ADR 0013).
31
+ *
32
+ * The error's native validity is the picker's to set (see `useDateField`): a prop reaches this
33
+ * component only on the next render, too late for an Enter's implicit submit.
34
+ */
35
+ defineOptions({ inheritAttrs: false });
36
+
37
+ const props = withDefaults(
38
+ defineProps<{
39
+ /** `data-slot` of the outer element. */
40
+ slotName: string;
41
+ text: string;
42
+ placeholder: string;
43
+ open: boolean;
44
+ /** Below the picker's breakpoint: the calendar opens as a bottom sheet. */
45
+ narrow: boolean;
46
+ /** The picker's own parse or bounds error; a parent's aria-invalid is separate. */
47
+ error?: boolean;
48
+ disabled?: boolean;
49
+ /**
50
+ * The input's `inputmode`: the number pad for dates, the text keyboard where `:` and a
51
+ * space are typed. Not named `inputmode`, so a caller's forwarded `inputmode` attribute
52
+ * stays an attribute and this value still wins over it.
53
+ */
54
+ keyboard?: 'numeric' | 'text';
55
+ /**
56
+ * Rewrites the text while it is typed at its end (the date pickers put in the dots).
57
+ * Deleting, typing in the middle and pasting are left alone.
58
+ */
59
+ mask?: (text: string) => string;
60
+ class?: HTMLAttributes['class'];
61
+ }>(),
62
+ { error: false, disabled: false, keyboard: 'numeric', mask: undefined, class: undefined },
63
+ );
64
+
65
+ const emit = defineEmits<{
66
+ (e: 'update:open', value: boolean): void;
67
+ (e: 'update:text', value: string): void;
68
+ (e: 'commit'): void;
69
+ (e: 'clear'): void;
70
+ (e: 'opened'): void;
71
+ }>();
72
+
73
+ defineSlots<{
74
+ default?: () => unknown;
75
+ 'calendar-icon'?: () => unknown;
76
+ 'clear-icon'?: () => unknown;
77
+ }>();
78
+
79
+ const labels = useUiLabels();
80
+ const attrs = useAttrs();
81
+
82
+ /** Everything but `style` goes to the input; `style` and the `class` prop go on the outer element. */
83
+ const inputAttrs = computed(() =>
84
+ Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== 'style')),
85
+ );
86
+
87
+ const readonly = computed(() => attrs.readonly !== undefined && attrs.readonly !== false);
88
+ const locked = computed(() => props.disabled || readonly.value);
89
+
90
+ const inputEl = useTemplateRef<HTMLInputElement>('input');
91
+ const fieldEl = useTemplateRef<HTMLElement>('field');
92
+
93
+ const errorId = `${useId()}-error`;
94
+
95
+ // --- The layer: a popover, or a bottom sheet on a phone. ---
96
+
97
+ /** Set when the layer closes because of a click or focus elsewhere: focus stays there. */
98
+ let closedFromOutside = false;
99
+
100
+ watch(
101
+ () => props.open,
102
+ (isOpen) => {
103
+ if (isOpen) {
104
+ closedFromOutside = false;
105
+ }
106
+ },
107
+ );
108
+
109
+ function setOpen(value: boolean): void {
110
+ emit('update:open', value && !locked.value);
111
+ }
112
+
113
+ function onInput(event: Event): void {
114
+ const el = event.target as HTMLInputElement;
115
+ const typedAtEnd =
116
+ event instanceof InputEvent &&
117
+ event.inputType === 'insertText' &&
118
+ el.selectionStart === el.value.length;
119
+ if (props.mask && typedAtEnd) {
120
+ // Written to the element as well: when the mask swallows a keystroke (a dot after an
121
+ // automatic one) the text prop does not change, so Vue would not touch the input.
122
+ el.value = props.mask(el.value);
123
+ }
124
+ emit('update:text', el.value);
125
+ }
126
+
127
+ function clear(): void {
128
+ emit('clear');
129
+ inputEl.value?.focus();
130
+ }
131
+
132
+ function onKeydown(event: KeyboardEvent): void {
133
+ if (event.key === 'ArrowDown' && !props.open) {
134
+ event.preventDefault();
135
+ setOpen(true);
136
+ } else if (event.key === 'Escape' && props.open) {
137
+ // Claimed, so a surrounding dialog does not take the same Escape: in a browser the
138
+ // popover layer is gone before the key reaches the document. A closed popover leaves
139
+ // Escape alone, for the dialog to close.
140
+ event.preventDefault();
141
+ emit('update:open', false);
142
+ } else if (event.key === 'Enter') {
143
+ // No preventDefault: the surrounding form still submits, with the committed value.
144
+ emit('commit');
145
+ }
146
+ }
147
+
148
+ // Opening hands focus to the calendar (onto the selected day), so the arrow keys walk the grid.
149
+ function onOpenAutoFocus(event: Event): void {
150
+ event.preventDefault();
151
+ void nextTick(() => emit('opened'));
152
+ }
153
+
154
+ function onCloseAutoFocus(event: Event): void {
155
+ event.preventDefault();
156
+ if (!closedFromOutside) {
157
+ inputEl.value?.focus();
158
+ }
159
+ }
160
+
161
+ // The field itself (input, clear, open) is not "outside": typing on while the calendar is open
162
+ // is fine, and the open button toggles it itself.
163
+ function onInteractOutside(event: Event): void {
164
+ const target = event.target;
165
+ if (target instanceof Node && fieldEl.value?.contains(target)) {
166
+ event.preventDefault();
167
+ return;
168
+ }
169
+ closedFromOutside = true;
170
+ }
171
+
172
+ defineExpose({
173
+ /** The text input, for the picker's native validity. */
174
+ input: inputEl,
175
+ });
176
+
177
+ // The resting edge, the full-strength focus ring on a background gap and the invalid edge are
178
+ // the Input's own control-state recipe, moved to the wrapper so the two buttons sit inside it.
179
+ const iconButton =
180
+ 'text-muted-foreground hover:bg-primary/10 hover:text-primary grid size-7 shrink-0 place-items-center rounded-md transition-colors outline-none focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-inset disabled:pointer-events-none';
181
+ </script>
182
+
183
+ <template>
184
+ <div
185
+ :data-slot="props.slotName"
186
+ :class="cn('w-full', props.class)"
187
+ :style="attrs.style as never"
188
+ >
189
+ <PopoverRoot :open="props.open && !props.narrow" @update:open="setOpen">
190
+ <PopoverAnchor as-child>
191
+ <div
192
+ ref="field"
193
+ :class="
194
+ cn(
195
+ 'border-muted-foreground dark:bg-input/30 flex h-8 w-full min-w-0 items-center rounded-lg border bg-transparent pr-0.5 transition-colors',
196
+ 'focus-within:border-ring focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',
197
+ 'has-[input[aria-invalid=true]]:border-destructive has-[input[aria-invalid=true]]:ring-destructive/20 dark:has-[input[aria-invalid=true]]:ring-destructive/40 has-[input[aria-invalid=true]]:ring-3',
198
+ props.disabled &&
199
+ 'bg-input/50 dark:bg-input/80 cursor-not-allowed opacity-50',
200
+ )
201
+ "
202
+ >
203
+ <input
204
+ ref="input"
205
+ v-bind="inputAttrs"
206
+ type="text"
207
+ :inputmode="props.keyboard"
208
+ autocomplete="off"
209
+ :value="props.text"
210
+ :placeholder="props.placeholder"
211
+ :disabled="props.disabled"
212
+ :aria-invalid="props.error ? 'true' : (inputAttrs['aria-invalid'] as never)"
213
+ :aria-describedby="
214
+ [inputAttrs['aria-describedby'], props.error ? errorId : null]
215
+ .filter(Boolean)
216
+ .join(' ') || undefined
217
+ "
218
+ class="placeholder:text-muted-foreground h-full min-w-0 flex-1 bg-transparent px-2.5 text-base tabular-nums outline-none disabled:cursor-not-allowed md:text-sm"
219
+ @input="onInput"
220
+ @blur="emit('commit')"
221
+ @keydown="onKeydown"
222
+ />
223
+ <button
224
+ type="button"
225
+ tabindex="-1"
226
+ data-testid="date-field-clear"
227
+ :aria-label="labels.dateClear"
228
+ :disabled="locked"
229
+ :class="cn(iconButton, props.text === '' && 'invisible')"
230
+ @click="clear"
231
+ >
232
+ <slot name="clear-icon"><XIcon class="size-3.5" /></slot>
233
+ </button>
234
+ <PopoverTrigger as-child>
235
+ <button
236
+ type="button"
237
+ data-testid="date-field-open"
238
+ :aria-label="labels.dateOpen"
239
+ :disabled="locked"
240
+ :class="iconButton"
241
+ >
242
+ <slot name="calendar-icon"><CalendarDaysIcon /></slot>
243
+ </button>
244
+ </PopoverTrigger>
245
+ </div>
246
+ </PopoverAnchor>
247
+ <PopoverPortal>
248
+ <PopoverContent
249
+ align="start"
250
+ :side-offset="4"
251
+ :collision-padding="8"
252
+ class="border-border bg-popover z-50 rounded-xl border p-2.5 shadow-lg outline-none"
253
+ @open-auto-focus="onOpenAutoFocus"
254
+ @close-auto-focus="onCloseAutoFocus"
255
+ @interact-outside="onInteractOutside"
256
+ >
257
+ <slot />
258
+ </PopoverContent>
259
+ </PopoverPortal>
260
+ </PopoverRoot>
261
+
262
+ <!-- Phone: the same content as a sheet from the bottom. -->
263
+ <DialogRoot :open="props.open && props.narrow" @update:open="setOpen">
264
+ <DialogPortal>
265
+ <!-- The scrim is the one fixed swatch, as in Dialog: no role exists for it. -->
266
+ <DialogOverlay class="fixed inset-0 z-50 bg-black/40" />
267
+ <DialogContent
268
+ data-testid="date-field-sheet"
269
+ :aria-describedby="undefined"
270
+ class="bg-popover ring-foreground/10 fixed inset-x-0 bottom-0 z-50 max-h-[90dvh] overflow-y-auto rounded-t-[18px] px-4 pt-3 pb-4 shadow-xl ring-1 outline-none"
271
+ @open-auto-focus="onOpenAutoFocus"
272
+ @close-auto-focus="onCloseAutoFocus"
273
+ >
274
+ <DialogTitle class="sr-only">{{ labels.dateCalendar }}</DialogTitle>
275
+ <div
276
+ aria-hidden="true"
277
+ class="bg-border mx-auto mb-2.5 h-1 w-10 rounded-full"
278
+ />
279
+ <slot />
280
+ </DialogContent>
281
+ </DialogPortal>
282
+ </DialogRoot>
283
+
284
+ <p
285
+ v-if="props.error"
286
+ :id="errorId"
287
+ data-testid="date-field-error"
288
+ class="text-destructive mt-1 text-[11px]"
289
+ >
290
+ {{ labels.dateInvalid }}
291
+ </p>
292
+ </div>
293
+ </template>
@@ -0,0 +1,147 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ formatIsoDate,
4
+ isWithin,
5
+ maskDateTyping,
6
+ parseDateInput,
7
+ useUiLabels,
8
+ } from '@noix-dev/brix-core';
9
+ import { useMediaQuery } from '@vueuse/core';
10
+ import { ref, useTemplateRef, watch } from 'vue';
11
+ import type { HTMLAttributes } from 'vue';
12
+ import CalendarPanel from './CalendarPanel.vue';
13
+ import DateField from './DateField.vue';
14
+ import { useDateField } from './useDateField';
15
+
16
+ /**
17
+ * A single date field: type `DD.MM.YYYY` (the dots go in by themselves where they can only go,
18
+ * see `maskDateTyping`; short forms are normalised when the field is left) or pick from the
19
+ * calendar. A drop-in for `<input type="date">`: the model is the ISO date ('YYYY-MM-DD'),
20
+ * `''` when empty, and id / name / data-testid / aria-* / required land on the inner text input.
21
+ *
22
+ * A typed date that does not parse, or lies outside `min`/`max`, keeps its text, shows the
23
+ * field's own error and leaves the model as it was.
24
+ *
25
+ * It owns the calendar (`CalendarPanel`), which needs the optional peer
26
+ * `@internationalized/date`; this is why the component is published on its own subpath,
27
+ * `@noix-dev/brix-vue/date-picker`, and not through the root barrel (ADR 0014).
28
+ *
29
+ * Hidden default: when `document.documentElement.lang` is empty, the calendar panel falls back
30
+ * to the `'de'` locale for its month and weekday names. Set `<html lang>` to get another one.
31
+ */
32
+ defineOptions({ inheritAttrs: false });
33
+
34
+ const props = withDefaults(
35
+ defineProps<{
36
+ modelValue: string;
37
+ min?: string;
38
+ max?: string;
39
+ disabled?: boolean;
40
+ class?: HTMLAttributes['class'];
41
+ }>(),
42
+ { min: '', max: '', disabled: false, class: undefined },
43
+ );
44
+
45
+ const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>();
46
+
47
+ const labels = useUiLabels();
48
+
49
+ const fieldRef = useTemplateRef<InstanceType<typeof DateField>>('field');
50
+ const panelRef = useTemplateRef<InstanceType<typeof CalendarPanel>>('panel');
51
+
52
+ const { open, error } = useDateField(() => fieldRef.value?.input, seed);
53
+
54
+ /** The value this field last showed as committed: the model, or what it just emitted. */
55
+ const current = ref(props.modelValue);
56
+ const text = ref(formatIsoDate(props.modelValue));
57
+
58
+ /** Shows the model and drops a pending error. Also a date field guard's `reset()`. */
59
+ function seed(): void {
60
+ current.value = props.modelValue;
61
+ text.value = formatIsoDate(props.modelValue);
62
+ error.value = false;
63
+ }
64
+
65
+ // A form that re-seeds or resets replaces what is shown and drops a pending error.
66
+ watch(() => props.modelValue, seed);
67
+
68
+ function emitValue(iso: string): void {
69
+ current.value = iso;
70
+ text.value = formatIsoDate(iso);
71
+ error.value = false;
72
+ emit('update:modelValue', iso);
73
+ }
74
+
75
+ /** Reads the typed text. Synchronous, so an Enter that submits a form submits this value. */
76
+ function commit(): void {
77
+ // Untouched text is left alone: a stored date outside min/max (an old record) stays
78
+ // without an error until someone edits it.
79
+ if (text.value.trim() === formatIsoDate(current.value)) {
80
+ text.value = formatIsoDate(current.value);
81
+ error.value = false;
82
+ return;
83
+ }
84
+ // Pasted digits ('9999') read the way typed ones would have been masked.
85
+ const parsed = parseDateInput(maskDateTyping(text.value));
86
+ if (parsed.kind === 'empty') {
87
+ emitValue('');
88
+ return;
89
+ }
90
+ if (parsed.kind === 'invalid' || !isWithin(parsed.iso, props.min, props.max)) {
91
+ error.value = true;
92
+ return;
93
+ }
94
+ emitValue(parsed.iso);
95
+ }
96
+
97
+ // --- The calendar: a popover, or a bottom sheet on a phone. ---
98
+
99
+ const narrow = useMediaQuery('(max-width: 639px)');
100
+
101
+ function pick(iso: string): void {
102
+ emitValue(iso);
103
+ open.value = false;
104
+ }
105
+
106
+ function pickToday(): void {
107
+ const now = new Date();
108
+ pick(
109
+ `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`,
110
+ );
111
+ }
112
+
113
+ function reset(): void {
114
+ pick('');
115
+ }
116
+ </script>
117
+
118
+ <template>
119
+ <DateField
120
+ ref="field"
121
+ v-bind="$attrs"
122
+ v-model:open="open"
123
+ v-model:text="text"
124
+ slot-name="date-picker"
125
+ :class="props.class"
126
+ :placeholder="labels.datePlaceholder"
127
+ :mask="maskDateTyping"
128
+ :narrow="narrow"
129
+ :error="error"
130
+ :disabled="props.disabled"
131
+ @commit="commit"
132
+ @clear="emitValue('')"
133
+ @opened="panelRef?.focus()"
134
+ >
135
+ <!-- On a phone (the sheet) with larger days. -->
136
+ <CalendarPanel
137
+ ref="panel"
138
+ :large="narrow"
139
+ :selected="current"
140
+ :min="props.min"
141
+ :max="props.max"
142
+ @pick="pick"
143
+ @today="pickToday"
144
+ @clear="reset"
145
+ />
146
+ </DateField>
147
+ </template>
@@ -0,0 +1,96 @@
1
+ <script setup lang="ts">
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed, useAttrs } from 'vue';
4
+ import type { HTMLAttributes } from 'vue';
5
+ import { cn } from '../../lib/cn';
6
+ import { CheckIcon } from '../icon';
7
+ import DatePicker from './DatePicker.vue';
8
+
9
+ /**
10
+ * The end of a period that may still be running: a date field with an open-end button
11
+ * attached to its right. Pressed, the period has no end date: the date is emptied and the
12
+ * field shows "Today" until the button is pressed again. Only the button switches, never
13
+ * the row around it. The button's text is the `dateOpenEnd` label; `openEndLabel` overrides it.
14
+ *
15
+ * Models: `v-model` is the ISO date ('' when empty), `v-model:open-end` the switch. Like
16
+ * `DatePicker`, id / name / data-testid / aria-* land on the inner text input; the button
17
+ * gets the data-testid with `-open-end`, the "Today" box with `-today`.
18
+ *
19
+ * Published on `@noix-dev/brix-vue/date-picker` with `DatePicker`, for the same reason (ADR 0014).
20
+ * The calendar falls back to the `'de'` locale when `<html lang>` is empty (see `DatePicker`).
21
+ */
22
+ defineOptions({ inheritAttrs: false });
23
+
24
+ const props = withDefaults(
25
+ defineProps<{
26
+ modelValue: string;
27
+ openEnd: boolean;
28
+ /** Overrides the `dateOpenEnd` label. */
29
+ openEndLabel?: string;
30
+ min?: string;
31
+ max?: string;
32
+ disabled?: boolean;
33
+ class?: HTMLAttributes['class'];
34
+ }>(),
35
+ { openEndLabel: undefined, min: '', max: '', disabled: false, class: undefined },
36
+ );
37
+
38
+ const emit = defineEmits<{
39
+ (e: 'update:modelValue', value: string): void;
40
+ (e: 'update:openEnd', value: boolean): void;
41
+ }>();
42
+
43
+ const attrs = useAttrs();
44
+ const labels = useUiLabels();
45
+
46
+ const testId = computed(() => attrs['data-testid'] as string | undefined);
47
+ const buttonLabel = computed(() => props.openEndLabel ?? labels.value.dateOpenEnd);
48
+
49
+ function toggle(): void {
50
+ const next = !props.openEnd;
51
+ emit('update:openEnd', next);
52
+ if (next && props.modelValue !== '') {
53
+ emit('update:modelValue', '');
54
+ }
55
+ }
56
+ </script>
57
+
58
+ <template>
59
+ <div data-slot="until-date-picker" :class="cn('flex w-full min-w-0', props.class)">
60
+ <div
61
+ v-if="props.openEnd"
62
+ :data-testid="testId ? `${testId}-today` : undefined"
63
+ class="border-input bg-input/50 dark:bg-input/80 text-primary flex h-8 min-w-0 flex-1 items-center rounded-l-lg border px-2.5 text-sm font-semibold"
64
+ >
65
+ {{ labels.dateToday }}
66
+ </div>
67
+ <DatePicker
68
+ v-else
69
+ v-bind="attrs"
70
+ class="min-w-0 flex-1 [&>div]:rounded-r-none"
71
+ :model-value="props.modelValue"
72
+ :min="props.min"
73
+ :max="props.max"
74
+ :disabled="props.disabled"
75
+ @update:model-value="(value) => emit('update:modelValue', value)"
76
+ />
77
+ <button
78
+ type="button"
79
+ :data-testid="testId ? `${testId}-open-end` : undefined"
80
+ :aria-pressed="props.openEnd ? 'true' : 'false'"
81
+ :disabled="props.disabled"
82
+ :class="
83
+ cn(
84
+ 'flex h-8 shrink-0 items-center gap-1 rounded-r-lg border border-l-0 px-2.5 text-xs font-semibold whitespace-nowrap transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:cursor-not-allowed disabled:opacity-50',
85
+ props.openEnd
86
+ ? 'border-primary bg-primary text-primary-foreground focus-visible:ring-primary-foreground hover:opacity-90'
87
+ : 'border-input bg-muted/50 text-foreground hover:bg-muted',
88
+ )
89
+ "
90
+ @click="toggle"
91
+ >
92
+ <CheckIcon v-if="props.openEnd" aria-hidden="true" class="size-3.5" />
93
+ {{ buttonLabel }}
94
+ </button>
95
+ </div>
96
+ </template>
@@ -0,0 +1,87 @@
1
+ import { inject, onScopeDispose, provide, type InjectionKey, type Ref } from 'vue';
2
+
3
+ /**
4
+ * Lets a form hold its save while a date field shows a rejected typed value.
5
+ *
6
+ * A typed impossible or out-of-bounds date keeps the text, shows the field's own error and
7
+ * leaves the model as it was. The native validity blocks a native submit, but a host that
8
+ * saves from a click handler would post the old value. The host calls
9
+ * `provideDateFieldGuard()` in its setup and starts its submit with
10
+ * `if (!dateFields.ensureValid()) return;`. Every date picker below it in the component tree
11
+ * (dialog content is portaled, but inject follows the component tree) registers itself.
12
+ */
13
+ export interface DateFieldGuard {
14
+ /**
15
+ * True when no registered field shows its own parse or bounds error. Otherwise focuses the
16
+ * first such field in document order and returns false.
17
+ */
18
+ ensureValid(): boolean;
19
+ /**
20
+ * Re-shows every field's model and drops its error. For an in-place reset or re-seed that
21
+ * may write the value a field already holds: Vue reports no change then, so the field
22
+ * cannot see the write and would keep the rejected text.
23
+ */
24
+ reset(): void;
25
+ }
26
+
27
+ /** What a date field registers: its own error, its input, and how it re-shows its model. */
28
+ export interface DateFieldEntry {
29
+ error: Ref<boolean>;
30
+ input: () => HTMLInputElement | null | undefined;
31
+ reseed: () => void;
32
+ }
33
+
34
+ interface DateFieldRegistry {
35
+ add(entry: DateFieldEntry): () => void;
36
+ }
37
+
38
+ const REGISTRY: InjectionKey<DateFieldRegistry> = Symbol('dateFieldGuard');
39
+
40
+ /** Element order in the document: the earlier one first; detached elements last. */
41
+ function byDocumentOrder(a: HTMLElement | null, b: HTMLElement | null): number {
42
+ if (a === null || b === null) {
43
+ return a === b ? 0 : a === null ? 1 : -1;
44
+ }
45
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
46
+ }
47
+
48
+ /** Provides the guard to the date fields below the calling component; call in setup. */
49
+ export function provideDateFieldGuard(): DateFieldGuard {
50
+ const entries = new Set<DateFieldEntry>();
51
+
52
+ provide(REGISTRY, {
53
+ add(entry) {
54
+ entries.add(entry);
55
+ return () => entries.delete(entry);
56
+ },
57
+ });
58
+
59
+ return {
60
+ ensureValid() {
61
+ const invalid = [...entries]
62
+ .filter((entry) => entry.error.value)
63
+ .map((entry) => entry.input() ?? null)
64
+ .sort(byDocumentOrder);
65
+ if (invalid.length === 0) {
66
+ return true;
67
+ }
68
+ invalid[0]?.focus();
69
+ return false;
70
+ },
71
+ reset() {
72
+ entries.forEach((entry) => entry.reseed());
73
+ },
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Registers a date field with the nearest guard, until the field's scope ends (a field
79
+ * removed by `v-if` no longer counts). Without a guard above it, does nothing.
80
+ */
81
+ export function registerDateField(entry: DateFieldEntry): void {
82
+ const registry = inject(REGISTRY, null);
83
+ if (registry === null) {
84
+ return;
85
+ }
86
+ onScopeDispose(registry.add(entry));
87
+ }
@@ -0,0 +1,4 @@
1
+ export { default as DatePicker } from './DatePicker.vue';
2
+ export { default as UntilDatePicker } from './UntilDatePicker.vue';
3
+ export { provideDateFieldGuard } from './dateFieldGuard';
4
+ export type { DateFieldGuard } from './dateFieldGuard';
@@ -0,0 +1,37 @@
1
+ import { ref, watch, type Ref } from 'vue';
2
+ import { useUiLabels } from '@noix-dev/brix-core';
3
+ import { registerDateField } from './dateFieldGuard';
4
+
5
+ /**
6
+ * The state every date picker keeps around its `DateField`: whether the calendar is open, and
7
+ * the component's own error, mirrored into the input's native validity.
8
+ *
9
+ * The validity is set synchronously from here rather than inside `DateField`: a prop reaches
10
+ * the field only on its next render, and an Enter that commits invalid text must block the
11
+ * browser's implicit submit, which follows the keydown at once.
12
+ *
13
+ * The field also registers with a host's date field guard, if one is provided (see
14
+ * `dateFieldGuard.ts`): `reseed` re-shows the model and drops the error when the host resets.
15
+ */
16
+ export function useDateField(
17
+ input: () => HTMLInputElement | null | undefined,
18
+ reseed: () => void,
19
+ ): {
20
+ open: Ref<boolean>;
21
+ error: Ref<boolean>;
22
+ } {
23
+ const labels = useUiLabels();
24
+ const open = ref(false);
25
+ /** Only the component's own parse or min/max error; a parent's aria-invalid is separate. */
26
+ const error = ref(false);
27
+
28
+ watch(
29
+ [error, () => labels.value.dateInvalid],
30
+ ([invalid, message]) => input()?.setCustomValidity(invalid ? message : ''),
31
+ { flush: 'sync' },
32
+ );
33
+
34
+ registerDateField({ error, input, reseed });
35
+
36
+ return { open, error };
37
+ }