@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,26 @@
1
+ <script setup lang="ts">
2
+ import { TableCell, TableRow } from '../table';
3
+
4
+ // A reload of a table that already shows rows: the stale rows stay (the caller dims them) and
5
+ // a 2px bar runs right under the header. Belongs in the table header, after the header row.
6
+ //
7
+ // The sweep is `animate-table-progress`, declared with its keyframes in `styles.css`.
8
+ defineProps<{ colspan: number; label: string }>();
9
+ </script>
10
+
11
+ <template>
12
+ <TableRow class="border-0 hover:bg-transparent">
13
+ <TableCell :colspan="colspan" class="!p-0">
14
+ <div
15
+ data-testid="data-table-progress"
16
+ role="progressbar"
17
+ :aria-label="label"
18
+ class="bg-primary/20 relative h-0.5 w-full overflow-hidden"
19
+ >
20
+ <span
21
+ class="bg-primary animate-table-progress absolute inset-y-0 left-0 w-1/3 motion-reduce:w-full motion-reduce:animate-none motion-reduce:opacity-60"
22
+ />
23
+ </div>
24
+ </TableCell>
25
+ </TableRow>
26
+ </template>
@@ -0,0 +1,13 @@
1
+ import type { DataTableColumn } from './types';
2
+
3
+ /**
4
+ * The one definition of "visible by default", shared by the column menu's reset and by any
5
+ * per-user preference default a caller keeps: a column is on unless it opts out with
6
+ * `defaultVisible: false`, and an `alwaysVisible` column is on regardless (it cannot be hidden,
7
+ * so a reset must keep it).
8
+ */
9
+ export function defaultVisibleKeys(columns: readonly DataTableColumn[]): string[] {
10
+ return columns
11
+ .filter((c) => c.alwaysVisible === true || c.defaultVisible !== false)
12
+ .map((c) => c.key);
13
+ }
@@ -0,0 +1,3 @@
1
+ export { defaultVisibleKeys } from './columns';
2
+ export { default as DataTable } from './DataTable.vue';
3
+ export type { DataTableColumn, DataTableSortChoice, TableSort } from './types';
@@ -0,0 +1,19 @@
1
+ // A cell pinned to the table's right edge (the actions cell) while wide columns scroll sideways.
2
+ // It needs an opaque background, or scrolled cells show through it.
3
+ //
4
+ // There is no lift for an open menu: the menus of this package are portalled to the document
5
+ // body, so one opened from a pinned cell is never inside it and sits above the table whatever
6
+ // the cells' stacking.
7
+ //
8
+ // "Portalled" is not true of every overlay this package draws, and the reader this comment
9
+ // exists for is someone asking whether their overlay is safe inside a pinned cell. Two of
10
+ // brix's own are drawn IN PLACE, absolutely positioned inside the component with a `z-20` of
11
+ // their own: `Combobox`'s listbox and `AppearancePicker`'s `popover` panel. Those stack against
12
+ // the cells around them, not above the table, so a pinned cell is not a safe host for either —
13
+ // and a consumer who draws a menu in place inside the cell owns its z-index.
14
+ export const PINNED = 'sticky right-0 bg-card';
15
+
16
+ // The header and hover washes (`bg-muted/50`) mixed onto the card, for a pinned cell.
17
+ export const PINNED_WASH = 'bg-[color-mix(in_oklab,var(--muted)_50%,var(--card))]';
18
+ export const PINNED_HOVER_WASH =
19
+ '[tr:hover>&]:bg-[color-mix(in_oklab,var(--muted)_50%,var(--card))]';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether a click on a body row should activate the row (open it, expand it): true for a
3
+ * click on the plain cells, false for one on a genuine control (a link, a button, the kebab's
4
+ * menu items, a form field) or anywhere in the trailing actions cell, which keep their own
5
+ * click.
6
+ */
7
+ export function isRowActivationTarget(event: Event): boolean {
8
+ const target = event.target;
9
+ return (
10
+ target instanceof Element &&
11
+ target.closest('a, button, input, select, textarea, label, [role="menuitem"]') === null &&
12
+ target.closest('[data-actions-cell]') === null
13
+ );
14
+ }
@@ -0,0 +1,13 @@
1
+ import type { TableSort } from './types';
2
+
3
+ /**
4
+ * The sort after a click on a sortable header: asc -> desc -> none; any other column starts
5
+ * at asc. `key` is the column's own key; a caller that needs another name for it (`sortKey`)
6
+ * maps it itself.
7
+ */
8
+ export function nextSort(sort: TableSort, key: string): TableSort {
9
+ if (sort?.column !== key) {
10
+ return { column: key, direction: 'asc' };
11
+ }
12
+ return sort.direction === 'asc' ? { column: key, direction: 'desc' } : null;
13
+ }
@@ -0,0 +1,23 @@
1
+ export interface DataTableColumn {
2
+ key: string;
3
+ label: string;
4
+ defaultVisible?: boolean;
5
+ sortable?: boolean;
6
+ // The sort key a caller wants back when it differs from `key`. The table never reads it:
7
+ // a click emits `key`, and what the caller does with `sortKey` is the caller's business.
8
+ sortKey?: string;
9
+ align?: 'left' | 'right';
10
+ // Cannot be hidden through the column menu.
11
+ alwaysVisible?: boolean;
12
+ // A column that shows several fields and sorts by one of them: its header opens a menu
13
+ // with an ascending and a descending entry per choice instead of cycling. Each `column` is
14
+ // the key of another, sortable column, so the sort it sets is that column's sort.
15
+ sortChoices?: DataTableSortChoice[];
16
+ }
17
+
18
+ export interface DataTableSortChoice {
19
+ column: string;
20
+ label: string;
21
+ }
22
+
23
+ export type TableSort = { column: string; direction: 'asc' | 'desc' } | null;
@@ -0,0 +1,432 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ CalendarDate,
4
+ getLocalTimeZone,
5
+ parseDate,
6
+ today as todayIn,
7
+ type DateValue,
8
+ } from '@internationalized/date';
9
+ import {
10
+ CalendarCell,
11
+ CalendarCellTrigger,
12
+ CalendarGrid,
13
+ CalendarGridBody,
14
+ CalendarGridHead,
15
+ CalendarGridRow,
16
+ CalendarHeadCell,
17
+ CalendarNext,
18
+ CalendarPrev,
19
+ CalendarRoot,
20
+ } from 'reka-ui';
21
+ import { isWithin, useUiLabels } from '@noix-dev/brix-core';
22
+ import { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue';
23
+ import { cn } from '../../lib/cn';
24
+ import { ChevronLeftIcon, ChevronRightIcon } from '../icon';
25
+
26
+ /**
27
+ * The calendar the date fields open: header variant A (‹ month ▾ year ▾ ›), a Monday-first
28
+ * grid and the "Today" / "Clear" footer. It only reports what was chosen; the field decides
29
+ * what a pick means (commit and close, set one end of a range, stay open for a time).
30
+ *
31
+ * Dates go in and out as 'YYYY-MM-DD' strings and are only ever converted through
32
+ * `@internationalized/date`'s CalendarDate, which has no time and no timezone. This is the one
33
+ * file in the package that imports that library, which is why it is an optional peer.
34
+ *
35
+ * The chevrons are the `prev-icon` and `next-icon` slots (ADR 0013); each is used at both of the
36
+ * places the header can sit (above one month, or on either side of two).
37
+ */
38
+ const props = withDefaults(
39
+ defineProps<{
40
+ selected: string;
41
+ min?: string;
42
+ max?: string;
43
+ months?: 1 | 2;
44
+ /** Shows a range instead of one selected day; the caller drives the selection. */
45
+ range?: { from: string; to: string };
46
+ /** Larger day cells, for the phone bottom sheet. */
47
+ large?: boolean;
48
+ /** Footer text on the left in range mode (e.g. "pick the end"); range mode has no "Today". */
49
+ hint?: string;
50
+ }>(),
51
+ { min: '', max: '', months: 1, range: undefined, large: false, hint: '' },
52
+ );
53
+
54
+ const emit = defineEmits<{
55
+ (e: 'pick', iso: string): void;
56
+ (e: 'today'): void;
57
+ (e: 'clear'): void;
58
+ }>();
59
+
60
+ const labels = useUiLabels();
61
+
62
+ /** The first year the year list offers when no `min` narrows it. */
63
+ const FIRST_YEAR = 1920;
64
+ /** How far past the current year the year list reaches when no `max` narrows it. */
65
+ const YEARS_AHEAD = 20;
66
+
67
+ const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
68
+
69
+ function toDate(iso: string | undefined): CalendarDate | undefined {
70
+ return iso && ISO_DATE.test(iso) ? parseDate(iso) : undefined;
71
+ }
72
+
73
+ // Month and weekday names follow the document language; the typed format does not.
74
+ const locale = (typeof document !== 'undefined' && document.documentElement.lang) || 'de';
75
+
76
+ const todayDate = todayIn(getLocalTimeZone());
77
+ const todayIso = todayDate.toString();
78
+
79
+ const minDate = computed(() => toDate(props.min));
80
+ const maxDate = computed(() => toDate(props.max));
81
+ const selectedDate = computed(() => toDate(props.selected));
82
+
83
+ /** Where the calendar opens: the selection, else today kept inside the bounds. */
84
+ function initialView(): CalendarDate {
85
+ const anchor = selectedDate.value ?? toDate(props.range?.from) ?? toDate(props.range?.to);
86
+ if (anchor) {
87
+ return anchor;
88
+ }
89
+ if (minDate.value && todayDate.compare(minDate.value) < 0) {
90
+ return minDate.value;
91
+ }
92
+ if (maxDate.value && todayDate.compare(maxDate.value) > 0) {
93
+ return maxDate.value;
94
+ }
95
+ return todayDate;
96
+ }
97
+
98
+ // reka's "placeholder": the focused day, which also decides the month on show.
99
+ const view = shallowRef<DateValue>(initialView());
100
+
101
+ watch(selectedDate, (date) => {
102
+ if (date) {
103
+ view.value = date;
104
+ }
105
+ });
106
+
107
+ const monthNames = computed(() => {
108
+ const format = new Intl.DateTimeFormat(locale, { month: 'long' });
109
+ return Array.from({ length: 12 }, (_, i) => format.format(new Date(2024, i, 1)));
110
+ });
111
+
112
+ // 1 January 2024 was a Monday. Some locales end the short form with a dot ("Mo."); the grid
113
+ // header does without.
114
+ const weekdayNames = computed(() => {
115
+ const format = new Intl.DateTimeFormat(locale, { weekday: 'short' });
116
+ return Array.from({ length: 7 }, (_, i) =>
117
+ format.format(new Date(2024, 0, 1 + i)).replace(/\.$/, ''),
118
+ );
119
+ });
120
+
121
+ /** Newest first. Stretched to the month on show, so an old stored date still has its year. */
122
+ const years = computed(() => {
123
+ const first = Math.min(minDate.value?.year ?? FIRST_YEAR, view.value.year);
124
+ const last = Math.max(maxDate.value?.year ?? todayDate.year + YEARS_AHEAD, view.value.year);
125
+ return Array.from({ length: last - first + 1 }, (_, i) => last - i);
126
+ });
127
+
128
+ /** "Oktober 2026": the plain title above each month of the two-month view. */
129
+ const titleFormat = computed(
130
+ () => new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }),
131
+ );
132
+
133
+ function monthTitle(month: DateValue): string {
134
+ return titleFormat.value.format(new Date(month.year, month.month - 1, 1));
135
+ }
136
+
137
+ /** Two months side by side show each day once: the days spilling in from a neighbour stay blank. */
138
+ const twoMonths = computed(() => props.months === 2);
139
+
140
+ function setMonth(event: Event): void {
141
+ view.value = view.value.set({ month: Number((event.target as HTMLSelectElement).value) });
142
+ }
143
+
144
+ function setYear(event: Event): void {
145
+ view.value = view.value.set({ year: Number((event.target as HTMLSelectElement).value) });
146
+ }
147
+
148
+ const todayAllowed = computed(() => isWithin(todayIso, props.min, props.max));
149
+
150
+ // In range mode reka holds no selection (`null` keeps it controlled, so a click does not
151
+ // select the clicked day inside reka): the ends are marked and styled from `range`.
152
+ const model = computed(() => (props.range ? null : selectedDate.value));
153
+
154
+ function onPick(value: DateValue | DateValue[] | undefined): void {
155
+ if (value && !Array.isArray(value)) {
156
+ emit('pick', value.toString());
157
+ }
158
+ }
159
+
160
+ /** Range marks for one day, as data attributes (empty when no range is shown). */
161
+ function rangeAttrs(iso: string): Record<string, string> {
162
+ const from = props.range?.from ?? '';
163
+ const to = props.range?.to ?? '';
164
+ const attrs: Record<string, string> = {};
165
+ if (from !== '' && iso === from) {
166
+ attrs['data-range-start'] = '';
167
+ }
168
+ if (to !== '' && iso === to) {
169
+ attrs['data-range-end'] = '';
170
+ }
171
+ if (from !== '' && to !== '' && iso > from && iso < to) {
172
+ attrs['data-in-range'] = '';
173
+ }
174
+ return attrs;
175
+ }
176
+
177
+ /** In range mode, the ends are the selected days: reka's own marks on the cell and the day. */
178
+ function isRangeEnd(iso: string): boolean {
179
+ return (
180
+ props.range !== undefined &&
181
+ iso !== '' &&
182
+ (iso === props.range.from || iso === props.range.to)
183
+ );
184
+ }
185
+
186
+ function rangeCellAttrs(iso: string): Record<string, string> {
187
+ return isRangeEnd(iso) ? { 'aria-selected': 'true' } : {};
188
+ }
189
+
190
+ function rangeDayAttrs(iso: string): Record<string, string> {
191
+ return isRangeEnd(iso) ? { ...rangeAttrs(iso), 'data-selected': 'true' } : rangeAttrs(iso);
192
+ }
193
+
194
+ /**
195
+ * The look of one day. Worked out here rather than from reka's slot props, which only reach
196
+ * the cell's content, not the button itself; reka's data attributes (data-today,
197
+ * data-selected, data-disabled …) are set on the button all the same.
198
+ */
199
+ function dayClass(iso: string, viewMonth: number, dayMonth: number): string {
200
+ const marks = rangeAttrs(iso);
201
+ const start = 'data-range-start' in marks;
202
+ const end = 'data-range-end' in marks;
203
+ const bothEnds = Boolean(props.range?.from && props.range?.to);
204
+ const selected = !props.range && iso === props.selected;
205
+ return cn(
206
+ 'text-foreground hover:bg-primary/10 w-full rounded-lg tabular-nums transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset',
207
+ props.large ? 'h-10 text-sm' : 'h-8 text-[12.5px]',
208
+ dayMonth !== viewMonth && 'text-muted-foreground/60',
209
+ // Today: an orange ring, next to the aria-current mark.
210
+ iso === todayIso &&
211
+ 'shadow-[inset_0_0_0_1.5px_var(--brand-alt)] dark:shadow-[inset_0_0_0_1.5px_var(--brand-alt-light)]',
212
+ 'data-in-range' in marks && 'bg-primary/20 rounded-none',
213
+ bothEnds && start && !end && 'rounded-r-none',
214
+ bothEnds && end && !start && 'rounded-l-none',
215
+ (selected || start || end) &&
216
+ 'bg-primary text-primary-foreground hover:bg-primary focus-visible:ring-primary-foreground font-bold',
217
+ !isWithin(iso, props.min, props.max) &&
218
+ 'text-muted-foreground/50 cursor-not-allowed line-through hover:bg-transparent',
219
+ );
220
+ }
221
+
222
+ const root = useTemplateRef<HTMLElement>('root');
223
+
224
+ /** The day reka keeps in the tab order: the selection, or the focused day after paging. */
225
+ function focusDay(): void {
226
+ root.value
227
+ ?.querySelector<HTMLElement>('[data-reka-calendar-cell-trigger][tabindex="0"]')
228
+ ?.focus();
229
+ }
230
+
231
+ // reka moves by day and week; PageUp / PageDown on a day move by a month, keeping the day.
232
+ // Elsewhere (the month and year selects) the keys keep their native meaning. Caught in the
233
+ // capture phase: reka (2.11+) pages on its own, but only when the target day lies outside the
234
+ // visible weeks, so 10 April from a March grid stayed in March.
235
+ function onKeydown(event: KeyboardEvent): void {
236
+ const onDay =
237
+ event.target instanceof Element &&
238
+ event.target.closest('[data-reka-calendar-cell-trigger]') !== null;
239
+ if (onDay && (event.key === 'PageUp' || event.key === 'PageDown')) {
240
+ event.preventDefault();
241
+ event.stopPropagation();
242
+ void page(event.key === 'PageUp' ? -1 : 1);
243
+ }
244
+ }
245
+
246
+ async function page(delta: number): Promise<void> {
247
+ view.value = view.value.add({ months: delta });
248
+ await nextTick();
249
+ focusDay();
250
+ }
251
+
252
+ defineExpose({
253
+ /** Moves focus into the grid, onto the selected (or focused) day. */
254
+ focus: focusDay,
255
+ });
256
+
257
+ const navButton =
258
+ '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-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50';
259
+ const headerSelect =
260
+ 'border-border bg-popover text-foreground focus-visible:ring-ring focus-visible:ring-inset rounded-md border px-1 py-0.5 text-[12.5px] font-semibold outline-none focus-visible:ring-2';
261
+ const footerButton =
262
+ 'hover:bg-primary/10 rounded-md px-1.5 py-1 text-xs font-semibold transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50';
263
+ </script>
264
+
265
+ <template>
266
+ <div
267
+ ref="root"
268
+ data-testid="date-picker-panel"
269
+ :class="
270
+ cn('text-popover-foreground', props.large ? 'w-full' : twoMonths ? 'w-130' : 'w-63')
271
+ "
272
+ @keydown.capture="onKeydown"
273
+ >
274
+ <CalendarRoot
275
+ v-slot="{ grid }"
276
+ v-model:placeholder="view"
277
+ :model-value="model"
278
+ :min-value="minDate"
279
+ :max-value="maxDate"
280
+ :locale="locale"
281
+ :week-starts-on="1"
282
+ :number-of-months="props.months"
283
+ :calendar-label="labels.dateCalendar"
284
+ prevent-deselect
285
+ fixed-weeks
286
+ @update:model-value="onPick"
287
+ >
288
+ <div v-if="!twoMonths" class="mb-1.5 flex items-center gap-1">
289
+ <CalendarPrev :aria-label="labels.datePrevMonth" :class="navButton">
290
+ <slot name="prev-icon"><ChevronLeftIcon /></slot>
291
+ </CalendarPrev>
292
+ <div class="flex flex-1 justify-center gap-1">
293
+ <select
294
+ data-testid="date-picker-month"
295
+ :aria-label="labels.dateMonth"
296
+ :value="view.month"
297
+ :class="headerSelect"
298
+ @change="setMonth"
299
+ >
300
+ <option v-for="(name, i) in monthNames" :key="i" :value="i + 1">
301
+ {{ name }}
302
+ </option>
303
+ </select>
304
+ <select
305
+ data-testid="date-picker-year"
306
+ :aria-label="labels.dateYear"
307
+ :value="view.year"
308
+ :class="headerSelect"
309
+ @change="setYear"
310
+ >
311
+ <option v-for="year in years" :key="year" :value="year">
312
+ {{ year }}
313
+ </option>
314
+ </select>
315
+ </div>
316
+ <CalendarNext :aria-label="labels.dateNextMonth" :class="navButton">
317
+ <slot name="next-icon"><ChevronRightIcon /></slot>
318
+ </CalendarNext>
319
+ </div>
320
+
321
+ <div :class="cn(twoMonths && 'flex gap-3.5')">
322
+ <div
323
+ v-for="(month, index) in grid"
324
+ :key="month.value.toString()"
325
+ class="min-w-0 flex-1"
326
+ >
327
+ <div v-if="twoMonths" class="mb-1.5 flex items-center gap-1">
328
+ <CalendarPrev
329
+ v-if="index === 0"
330
+ :aria-label="labels.datePrevMonth"
331
+ :class="navButton"
332
+ >
333
+ <slot name="prev-icon"><ChevronLeftIcon /></slot>
334
+ </CalendarPrev>
335
+ <span v-else aria-hidden="true" class="size-7 shrink-0" />
336
+ <div
337
+ data-testid="date-picker-month-title"
338
+ class="flex-1 text-center text-[12.5px] font-semibold"
339
+ >
340
+ {{ monthTitle(month.value) }}
341
+ </div>
342
+ <CalendarNext
343
+ v-if="index === grid.length - 1"
344
+ :aria-label="labels.dateNextMonth"
345
+ :class="navButton"
346
+ >
347
+ <slot name="next-icon"><ChevronRightIcon /></slot>
348
+ </CalendarNext>
349
+ <span v-else aria-hidden="true" class="size-7 shrink-0" />
350
+ </div>
351
+ <CalendarGrid class="w-full border-separate border-spacing-0.5">
352
+ <CalendarGridHead>
353
+ <CalendarGridRow>
354
+ <CalendarHeadCell
355
+ v-for="name in weekdayNames"
356
+ :key="name"
357
+ class="text-muted-foreground py-1 text-center text-[10.5px] font-semibold"
358
+ >
359
+ {{ name }}
360
+ </CalendarHeadCell>
361
+ </CalendarGridRow>
362
+ </CalendarGridHead>
363
+ <CalendarGridBody>
364
+ <CalendarGridRow
365
+ v-for="(week, w) in month.rows"
366
+ :key="`${month.value.toString()}-${w}`"
367
+ >
368
+ <template v-for="date in week" :key="date.toString()">
369
+ <td
370
+ v-if="twoMonths && date.month !== month.value.month"
371
+ aria-hidden="true"
372
+ :class="cn('p-0', props.large ? 'h-10' : 'h-8')"
373
+ />
374
+ <CalendarCell
375
+ v-else
376
+ :date="date"
377
+ class="p-0"
378
+ v-bind="rangeCellAttrs(date.toString())"
379
+ >
380
+ <CalendarCellTrigger
381
+ as="button"
382
+ type="button"
383
+ :day="date"
384
+ :month="month.value"
385
+ :data-date="date.toString()"
386
+ v-bind="rangeDayAttrs(date.toString())"
387
+ :disabled="
388
+ !isWithin(date.toString(), props.min, props.max)
389
+ "
390
+ :aria-current="
391
+ date.toString() === todayIso ? 'date' : undefined
392
+ "
393
+ :class="
394
+ dayClass(
395
+ date.toString(),
396
+ month.value.month,
397
+ date.month,
398
+ )
399
+ "
400
+ />
401
+ </CalendarCell>
402
+ </template>
403
+ </CalendarGridRow>
404
+ </CalendarGridBody>
405
+ </CalendarGrid>
406
+ </div>
407
+ </div>
408
+ </CalendarRoot>
409
+
410
+ <div class="border-border mt-2 flex items-center justify-between border-t pt-2">
411
+ <button
412
+ v-if="!props.range"
413
+ type="button"
414
+ data-testid="date-picker-today"
415
+ :disabled="!todayAllowed"
416
+ :class="cn(footerButton, 'text-primary')"
417
+ @click="emit('today')"
418
+ >
419
+ {{ labels.dateToday }}
420
+ </button>
421
+ <span v-else class="text-muted-foreground px-1.5 text-xs">{{ props.hint }}</span>
422
+ <button
423
+ type="button"
424
+ data-testid="date-picker-reset"
425
+ :class="cn(footerButton, 'text-muted-foreground')"
426
+ @click="emit('clear')"
427
+ >
428
+ {{ labels.dateClear }}
429
+ </button>
430
+ </div>
431
+ </div>
432
+ </template>