@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,173 @@
1
+ <script setup lang="ts">
2
+ import { TabsContent, TabsList, TabsRoot, TabsTrigger } from 'reka-ui';
3
+ import { computed } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { Badge } from '../badge';
6
+ import type { TabItem } from './tabItem';
7
+
8
+ /**
9
+ * A tab bar with one panel slot per item, named after the item's `value`.
10
+ *
11
+ * Controlled, like the rest of this package's stateful components: the caller owns the
12
+ * value. A page that keeps it in the URL lands on the tab that was meant after a reload,
13
+ * or when someone follows a link.
14
+ *
15
+ * Keyboard, as the ARIA tabs pattern: the tab list is the single tab stop and hands focus to the
16
+ * selected tab (reka's roving group: the list is `tabindex=0`, every trigger starts at `-1`,
17
+ * and the focused one takes `0`; do not "fix" either), the left and
18
+ * right arrows move to the previous or next tab and select it, **wrapping at the ends**
19
+ * (a tab bar is the radio-group shape in CLAUDE.md's "Keyboard ends", not the listbox
20
+ * one), and Home and End jump to the first and last. The suite drives each of these.
21
+ *
22
+ * Focus is the recipe ring, full strength with a gap of `--background`. The underline
23
+ * bar scrolls sideways, and a scrolling axis clips the other one too, so the scroller
24
+ * (the tab list) extends 4px past the triggers — exactly the ring's 2px gap plus its 2px
25
+ * width — with `py-1 -my-1`: padding for the ring, an equal negative margin so the
26
+ * triggers do not move. The 1px rule is the border of a non-scrolling parent, because a
27
+ * border on the scroller would sit outside its clip; the active underline, drawn on the
28
+ * trigger, then meets the rule instead of floating above it.
29
+ *
30
+ * The scroller takes `no-scrollbar`, and that is load-bearing: a space-taking horizontal
31
+ * scrollbar sits in the band below the triggers and floats the underline off the rule by its
32
+ * height (15px measured) whenever the list overflows. The cost is that an overflowing bar
33
+ * shows no scrollbar, only clipped text at the edge. Recorded, with two cues that could be
34
+ * added later (an edge fade, arrow buttons), in `docs/design/README.md`, together with two
35
+ * more residuals: the scroller's 4px band above the triggers takes pointer events meant for
36
+ * whatever precedes the bar, and a caller's `overflow-hidden` flush against the top of a
37
+ * Tabs clips the ring's 4px.
38
+ *
39
+ * Wraps reka-ui rather than being a row of buttons: that is what makes the arrow keys,
40
+ * the roving tabindex and the trigger/panel wiring correct. The wiring in particular is
41
+ * reka's to do — it gives every instance its own id prefix and points each trigger's
42
+ * aria-controls at its panel. Setting our own ids here broke exactly that, pointing the
43
+ * triggers at elements that did not exist, so none of that is overridden.
44
+ */
45
+ const props = defineProps<{
46
+ items: TabItem[];
47
+ modelValue: string;
48
+ /**
49
+ * The tab list's accessible name. Required: a page with two of them must not
50
+ * have two unnamed lists.
51
+ *
52
+ * Not called `ariaLabel`: TypeScript resolves a template's `aria-label` to the
53
+ * HTML attribute of that name rather than to the prop, so the two silently
54
+ * compete.
55
+ */
56
+ listLabel: string;
57
+ /**
58
+ * Keep every panel mounted and hide the inactive ones, instead of mounting
59
+ * a panel when its tab is chosen.
60
+ *
61
+ * For a page whose panels fetch on mount, the default costs a request and a
62
+ * loading flash on every switch back. Set this where the page has already
63
+ * loaded what the panels show; leave it alone where a panel is expensive and
64
+ * most readers never open it.
65
+ *
66
+ * reka leaves the hiding to the caller once a panel is force-mounted — it
67
+ * assumes you want to animate it — so the `hidden` attribute is set here.
68
+ * Without it every panel would simply be on screen at once.
69
+ *
70
+ * Only then: reka hides an unselected panel itself, and a `hidden` key present with an
71
+ * `undefined` value would replace that and leave every inactive panel an unhidden tab
72
+ * stop, which is why the attribute is spread conditionally and not bound.
73
+ */
74
+ forceMount?: boolean;
75
+ /**
76
+ * `underline` is the page's own tab bar. `pill` is for a second set nested
77
+ * inside a panel — two underlined bars on one screen read as one bar that
78
+ * has lost its place, so the inner set has to look different in kind.
79
+ */
80
+ variant?: 'underline' | 'pill';
81
+ class?: string;
82
+ }>();
83
+
84
+ defineEmits<{ (e: 'update:modelValue', value: string): void }>();
85
+
86
+ defineSlots<{ [K: string]: (props: Record<string, never>) => unknown }>();
87
+
88
+ const pill = computed(() => props.variant === 'pill');
89
+
90
+ const listClass = computed(() =>
91
+ pill.value
92
+ ? 'flex flex-wrap gap-1'
93
+ : 'no-scrollbar flex gap-0.5 -my-1 overflow-x-auto px-2.5 py-1',
94
+ );
95
+
96
+ /**
97
+ * The control-state recipe's focus ring, whole: full strength, 2px, and a 2px gap of
98
+ * `--background`. `--ring` and `--primary` are one colour in five of six theme/mode pairs,
99
+ * so on an active pill (a `--primary` edge) a ring without the gap measures 1.00 against it.
100
+ */
101
+ const FOCUS_RING =
102
+ 'outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background';
103
+
104
+ const triggerClass = computed(() =>
105
+ cn(
106
+ FOCUS_RING,
107
+ 'inline-flex items-center gap-1.5 whitespace-nowrap',
108
+ pill.value
109
+ ? 'border-border text-muted-foreground hover:text-foreground data-[state=active]:border-primary data-[state=active]:bg-accent-tint data-[state=active]:text-primary-on-wash rounded-full border px-2.5 py-0.5 text-[11.5px] font-semibold'
110
+ : 'text-muted-foreground hover:text-foreground data-[state=active]:text-primary-on-wash data-[state=active]:border-b-primary border-b-2 border-transparent px-2.5 py-2 text-[12.5px] font-semibold data-[state=active]:font-bold',
111
+ ),
112
+ );
113
+
114
+ /** On a pill the wash is the selected state, so the count needs its own ground. */
115
+ const countClass = computed(() =>
116
+ pill.value
117
+ ? 'bg-background text-primary-on-wash rounded-full px-1.5 text-[10px] leading-4 font-extrabold'
118
+ : 'bg-accent-tint text-primary-on-wash rounded-full px-1.5 text-[10px] leading-4 font-extrabold',
119
+ );
120
+ </script>
121
+
122
+ <template>
123
+ <TabsRoot
124
+ :model-value="props.modelValue"
125
+ :class="cn('flex flex-col', props.class)"
126
+ @update:model-value="(v) => $emit('update:modelValue', String(v))"
127
+ >
128
+ <div :class="pill ? undefined : 'border-border border-b'">
129
+ <TabsList
130
+ data-slot="tabs-list"
131
+ :data-variant="pill ? 'pill' : 'underline'"
132
+ :aria-label="props.listLabel"
133
+ :class="listClass"
134
+ >
135
+ <TabsTrigger
136
+ v-for="item in props.items"
137
+ :key="item.value"
138
+ :value="item.value"
139
+ data-slot="tabs-trigger"
140
+ :data-testid="`tab-${item.value}`"
141
+ :class="triggerClass"
142
+ >
143
+ <Badge
144
+ v-if="item.tag"
145
+ :data-testid="`tab-tag-${item.value}`"
146
+ tone="teal"
147
+ class="rounded px-1 py-0 text-[9px]"
148
+ >{{ item.tag }}</Badge
149
+ >
150
+ <span>{{ item.label }}</span>
151
+ <span
152
+ v-if="(item.count ?? 0) > 0"
153
+ :data-testid="`tab-count-${item.value}`"
154
+ :class="countClass"
155
+ >{{ item.count }}</span
156
+ >
157
+ </TabsTrigger>
158
+ </TabsList>
159
+ </div>
160
+
161
+ <TabsContent
162
+ v-for="item in props.items"
163
+ :key="item.value"
164
+ :value="item.value"
165
+ :data-testid="`tabpanel-${item.value}`"
166
+ :force-mount="props.forceMount ? true : undefined"
167
+ v-bind="props.forceMount && item.value !== props.modelValue ? { hidden: true } : {}"
168
+ :class="FOCUS_RING"
169
+ >
170
+ <slot :name="item.value" />
171
+ </TabsContent>
172
+ </TabsRoot>
173
+ </template>
@@ -0,0 +1,2 @@
1
+ export { default as Tabs } from './Tabs.vue';
2
+ export type { TabItem } from './tabItem';
@@ -0,0 +1,12 @@
1
+ export interface TabItem {
2
+ /** Stable identity: the model value, the slot name and part of the panel id. */
3
+ value: string;
4
+ label: string;
5
+ /**
6
+ * Rendered beside the label when greater than zero. A zero is left out on purpose —
7
+ * "Dateien 0" tells the reader nothing that "Dateien" does not.
8
+ */
9
+ count?: number;
10
+ /** A short marker before the label, e.g. "KI" on a tab that holds AI output. */
11
+ tag?: string;
12
+ }
@@ -0,0 +1,81 @@
1
+ <script setup lang="ts">
2
+ import { computed, useAttrs, useId } from 'vue';
3
+ import { cn } from '../../lib/cn';
4
+ import Textarea from './Textarea.vue';
5
+ import TextLimitCounter from './TextLimitCounter.vue';
6
+ import { textLength, textLimitFieldClass, textLimitState } from './textLimit';
7
+
8
+ /**
9
+ * A `Textarea` with a limit it shows but does not enforce: the value stays whole past the
10
+ * limit, so a pasted text is never silently cut, and the field says how far over it is.
11
+ * Attributes land on the textarea; the counter is wired to it as its description, so the
12
+ * limit is read when the field is focused rather than only when it is crossed.
13
+ */
14
+ defineOptions({ inheritAttrs: false });
15
+
16
+ const props = defineProps<{
17
+ modelValue?: string | number;
18
+ limit: number | null;
19
+ /** Overrides the label contract's `textLimitReached`. */
20
+ reachedText?: string;
21
+ /** Overrides the label contract's `textLimitOver`; receives the excess. */
22
+ overText?: (excess: number) => string;
23
+ /** The locale the count is grouped in. Left out, the runtime's own locale is used. */
24
+ locale?: string;
25
+ }>();
26
+
27
+ const emit = defineEmits<{
28
+ (e: 'update:modelValue', payload: string | number): void;
29
+ }>();
30
+
31
+ const attrs = useAttrs();
32
+ const counterId = useId();
33
+
34
+ // Trimmed, as the server trims before it measures.
35
+ const count = computed(() => textLength(String(props.modelValue ?? '').trim()));
36
+ const state = computed(() => textLimitState(count.value, props.limit));
37
+ // Merged into `class` so the host's own classes still win.
38
+ const fieldClass = computed(() => cn(textLimitFieldClass(state.value), attrs.class as string));
39
+ // The host's description first, the counter after it; there is no counter without a limit.
40
+ const describedBy = computed(
41
+ () =>
42
+ [attrs['aria-describedby'], props.limit === null ? undefined : counterId]
43
+ .filter(Boolean)
44
+ .join(' ') || undefined,
45
+ );
46
+ // An explicit host value wins, `false` included. Over the limit the value cannot be saved,
47
+ // and unlike an announcement the attribute is still there when someone tabs back.
48
+ const ariaInvalid = computed(
49
+ () => attrs['aria-invalid'] ?? (state.value === 'over' ? 'true' : undefined),
50
+ );
51
+ // Tells the base field its resting fill does not apply: the state's wash replaces it.
52
+ const limitState = computed(() =>
53
+ state.value === 'reached' || state.value === 'over' ? state.value : undefined,
54
+ );
55
+ </script>
56
+
57
+ <template>
58
+ <div class="min-w-0">
59
+ <!-- min-w-0: the textarea sizes to its content, so one long word would widen a grid parent. -->
60
+ <Textarea
61
+ v-bind="{
62
+ ...attrs,
63
+ class: undefined,
64
+ 'aria-describedby': describedBy,
65
+ 'aria-invalid': ariaInvalid,
66
+ 'data-limit-state': limitState,
67
+ }"
68
+ :class="fieldClass"
69
+ :model-value="modelValue"
70
+ @update:model-value="(v) => emit('update:modelValue', v)"
71
+ />
72
+ <TextLimitCounter
73
+ :id="counterId"
74
+ :count="count"
75
+ :limit="limit"
76
+ :reached-text="reachedText"
77
+ :over-text="overText"
78
+ :locale="locale"
79
+ />
80
+ </div>
81
+ </template>
@@ -0,0 +1,107 @@
1
+ <script setup lang="ts">
2
+ import { formatLabel, useUiLabels } from '@noix-dev/brix-core';
3
+ import { computed, onBeforeUnmount, ref, watch } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { textLimitState } from './textLimit';
6
+
7
+ /**
8
+ * The count under a limited field, and what it says at the limit and over it.
9
+ *
10
+ * What a screen reader hears is deliberately not what the page shows. The visible message
11
+ * follows the count: over the limit it names the excess and changes with every keystroke.
12
+ * That is right to look at and wrong to announce, so the message itself is not a live
13
+ * region. A second, visually hidden one speaks only when the state CROSSES a threshold —
14
+ * reaching the limit, going over it — says what the visible message says at that moment,
15
+ * and is emptied again after a few seconds so that nobody browsing the page later finds a
16
+ * stale excess there. A field that mounts already at its limit announces nothing.
17
+ */
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ count: number;
21
+ limit: number | null;
22
+ /** Overrides the label contract's `textLimitReached`. */
23
+ reachedText?: string;
24
+ /** Overrides the label contract's `textLimitOver`; receives the excess. */
25
+ overText?: (excess: number) => string;
26
+ /**
27
+ * The locale the numbers are grouped in. Left out, `Intl.NumberFormat` takes the
28
+ * runtime's own locale — deliberately, and not `'en-US'`: this is the family that
29
+ * exists to prove the label contract works, and a consumer who supplies the German
30
+ * catalogue should not get German words beside American digit grouping. A caller who
31
+ * wants a fixed grouping names it here.
32
+ */
33
+ locale?: string;
34
+ }>(),
35
+ {
36
+ reachedText: undefined,
37
+ overText: undefined,
38
+ },
39
+ );
40
+
41
+ const labels = useUiLabels();
42
+ const state = computed(() => textLimitState(props.count, props.limit));
43
+ const format = (n: number) => new Intl.NumberFormat(props.locale).format(n);
44
+
45
+ const message = computed(() => {
46
+ if (state.value === 'reached') {
47
+ return props.reachedText ?? labels.value.textLimitReached;
48
+ }
49
+ if (state.value === 'over' && props.limit !== null) {
50
+ const excess = props.count - props.limit;
51
+ return props.overText
52
+ ? props.overText(excess)
53
+ : formatLabel(labels.value.textLimitOver, { excess: format(excess) });
54
+ }
55
+ return '';
56
+ });
57
+
58
+ /** How long a spoken message stays in the live region before it is emptied. */
59
+ const ANNOUNCEMENT_MS = 4000;
60
+ const announcement = ref('');
61
+ let clearTimer: ReturnType<typeof setTimeout> | undefined;
62
+
63
+ watch(state, (next) => {
64
+ clearTimeout(clearTimer);
65
+ if (next === 'reached' || next === 'over') {
66
+ announcement.value = message.value;
67
+ clearTimer = setTimeout(() => {
68
+ announcement.value = '';
69
+ }, ANNOUNCEMENT_MS);
70
+ } else {
71
+ announcement.value = '';
72
+ }
73
+ });
74
+
75
+ onBeforeUnmount(() => clearTimeout(clearTimer));
76
+ </script>
77
+
78
+ <template>
79
+ <div
80
+ v-if="limit !== null"
81
+ data-testid="text-limit-counter"
82
+ :data-state="state"
83
+ class="mt-1 flex justify-between gap-2 text-xs text-muted-foreground"
84
+ >
85
+ <span
86
+ data-testid="text-limit-message"
87
+ :class="
88
+ cn(
89
+ state === 'reached' && 'text-warning-on-wash',
90
+ state === 'over' && 'text-destructive-on-wash',
91
+ )
92
+ "
93
+ >{{ message }}</span
94
+ >
95
+ <span class="sr-only" aria-live="polite" aria-atomic="true">{{ announcement }}</span>
96
+ <span
97
+ :class="
98
+ cn(
99
+ 'ml-auto shrink-0 whitespace-nowrap tabular-nums',
100
+ state === 'reached' && 'font-semibold text-warning-on-wash',
101
+ state === 'over' && 'font-semibold text-destructive-on-wash',
102
+ )
103
+ "
104
+ >{{ format(count) }} / {{ format(limit) }}</span
105
+ >
106
+ </div>
107
+ </template>
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { useVModel } from '@vueuse/core';
4
+ import { cn } from '../../lib/cn';
5
+
6
+ const props = defineProps<{
7
+ class?: HTMLAttributes['class'];
8
+ defaultValue?: string | number;
9
+ modelValue?: string | number;
10
+ }>();
11
+
12
+ const emits = defineEmits<{
13
+ (e: 'update:modelValue', payload: string | number): void;
14
+ }>();
15
+
16
+ const modelValue = useVModel(props, 'modelValue', emits, {
17
+ passive: true,
18
+ defaultValue: props.defaultValue,
19
+ });
20
+ </script>
21
+
22
+ <template>
23
+ <!-- The resting dark fill is the one `Input` has, but it applies only while the field has
24
+ no limit state (`data-limit-state`, set by `LimitedTextarea`): a `dark:` background
25
+ would otherwise out-rank the state's plain `bg-warning/10` and erase the wash.
26
+
27
+ `data-slot="textarea"` is forward-looking: it is the one field slot
28
+ `packages/tokens/src/density.css` does not name, because a textarea's height comes
29
+ from its content (`field-sizing-content`) rather than from a row height the density
30
+ axes set. The hook is here so a later rule — padding, or the font size the compact
31
+ and dense axes give the fields beside it — has something to address. -->
32
+ <textarea
33
+ v-model="modelValue"
34
+ data-slot="textarea"
35
+ :class="
36
+ cn(
37
+ 'border-muted-foreground dark:not-data-[limit-state]:bg-input/30 focus-visible:border-ring focus-visible:ring-ring aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background aria-invalid:ring-3 md:text-sm flex field-sizing-content min-h-16 w-full outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',
38
+ props.class,
39
+ )
40
+ "
41
+ />
42
+ </template>
@@ -0,0 +1,4 @@
1
+ export { default as Textarea } from './Textarea.vue';
2
+ export { default as LimitedTextarea } from './LimitedTextarea.vue';
3
+ export { default as TextLimitCounter } from './TextLimitCounter.vue';
4
+ export { textLength, textLimitFieldClass, textLimitState, type TextLimitState } from './textLimit';
@@ -0,0 +1,43 @@
1
+ export type TextLimitState = 'none' | 'ok' | 'reached' | 'over';
2
+
3
+ /**
4
+ * Length as a server counts it. Most backends measure code points (PHP's `mb_strlen`, for
5
+ * one), so an emoji is one character and `String#length`, which counts UTF-16 units, would
6
+ * be off.
7
+ */
8
+ export function textLength(text: string): number {
9
+ return [...text].length;
10
+ }
11
+
12
+ export function textLimitState(count: number, limit: number | null): TextLimitState {
13
+ if (limit === null) {
14
+ return 'none';
15
+ }
16
+ if (count > limit) {
17
+ return 'over';
18
+ }
19
+ return count === limit ? 'reached' : 'ok';
20
+ }
21
+
22
+ /**
23
+ * Classes that colour a field by its limit state. Its one host is `LimitedTextarea`.
24
+ *
25
+ * Both states carry meaning, so both name a role: the warning wash and edge at the limit,
26
+ * and the same wash with the destructive edge over it. The roles flip with the mode on
27
+ * their own, which is why there is no `dark:` twin here, and `bg-warning/10` is exactly the
28
+ * wash `--warning-on-wash` is measured against.
29
+ *
30
+ * The base field's `aria-invalid:` classes carry a variant, so they out-rank these plain
31
+ * border classes and a server-side error still reads as an error. The `focus-visible:`
32
+ * ones replace the base field's focus border: a field that has just been pasted into still
33
+ * has focus and must show its state.
34
+ */
35
+ export function textLimitFieldClass(state: TextLimitState): string {
36
+ if (state === 'reached') {
37
+ return 'bg-warning/10 border-warning focus-visible:border-warning';
38
+ }
39
+ if (state === 'over') {
40
+ return 'bg-warning/10 border-destructive focus-visible:border-destructive';
41
+ }
42
+ return '';
43
+ }