@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,502 @@
1
+ <script setup lang="ts">
2
+ import type { AppearanceAlign, AppearanceGroup, AppearanceLayout } from '.';
3
+ import type { PageDensity, TableDensity, ThemePreference } from '@noix-dev/brix-core';
4
+ import type { ComponentPublicInstance, HTMLAttributes } from 'vue';
5
+ import {
6
+ applyTableDensity,
7
+ applyPageDensity,
8
+ applyTheme,
9
+ applyThemeName,
10
+ asPageDensity,
11
+ asTableDensity,
12
+ asThemePreference,
13
+ formatLabel,
14
+ subscribeAppearance,
15
+ useUiLabels,
16
+ } from '@noix-dev/brix-core';
17
+ import { computed, onBeforeUnmount, onMounted, onUnmounted, ref, watch } from 'vue';
18
+ import { cn } from '../../lib/cn';
19
+ import { Button } from '../button';
20
+ import AppearanceSegment from './AppearanceSegment.vue';
21
+
22
+ /**
23
+ * Lets a person change the four things the appearance of an application is made of: the
24
+ * named theme, the colour mode, and the table and page density axes.
25
+ *
26
+ * It has no emits and no model. A pick is applied to the document root and written to
27
+ * `localStorage` by `@noix-dev/brix-core` on the spot, under the keys `initAppearance` reads
28
+ * back on the next load — so a consumer mounts it and is done. The two storage keys
29
+ * cross over, which is worth saying once: the theme's NAME lives under
30
+ * `<prefix>.theme`, and the light/dark/system MODE under `<prefix>.mode`.
31
+ *
32
+ * The theme names are the consumer's data, not wording: `themes` lists them, their
33
+ * display name is derived from the name itself, and the label contract — which cannot
34
+ * know them — is not asked.
35
+ *
36
+ * What it shows is read from the document, and the two density axes read their attribute
37
+ * only — no storage fallback, because an absent attribute IS 'normal'. So on a page where
38
+ * `initAppearance` has not run, the two densities show 'normal' whatever is stored, while
39
+ * the theme and the mode do fall back to storage: there a stored value is the only
40
+ * evidence of a choice, since neither has an "absent means this" state.
41
+ *
42
+ * ONE LIMIT, and it is the kind that reads as a dead control rather than as a bug: in the
43
+ * `popover` layout the panel is positioned `absolute` inside this component and is NOT
44
+ * teleported to the body, so ANY ancestor with `overflow: hidden` clips it. `Card` is one
45
+ * — it carries `overflow-hidden` in its base classes — so a picker dropped into a card
46
+ * opens a panel that is cut off a few pixels below the trigger, and pressing the trigger
47
+ * looks like nothing happening. Two ways out:
48
+ *
49
+ * - pass `overflow-visible` on the ancestor. A consumer class really does win here:
50
+ * both are in tailwind-merge's `overflow` group, so `cn` drops the component's own.
51
+ * - use `layout="rows"`, which has no panel and nothing to clip.
52
+ *
53
+ * Teleporting the panel to the body, with the positioning that then has to be computed
54
+ * rather than inherited, is the real fix and is deliberately not in this version.
55
+ */
56
+ const props = withDefaults(
57
+ defineProps<{
58
+ /** The theme names on offer, in order. A name is a `data-brix-theme` value. */
59
+ themes: string[];
60
+ /** Prefix of the four storage keys, as handed to `initAppearance`. */
61
+ storagePrefix: string;
62
+ layout?: AppearanceLayout;
63
+ /**
64
+ * Which edge of the trigger the `popover` panel lines up with. `end` is what a
65
+ * trigger at the right-hand end of a header wants; the default keeps every
66
+ * existing mounting exactly where it is. Ignored by the `rows` layout.
67
+ */
68
+ align?: AppearanceAlign;
69
+ class?: HTMLAttributes['class'];
70
+ }>(),
71
+ { layout: 'rows', align: 'start', class: undefined },
72
+ );
73
+
74
+ const labels = useUiLabels();
75
+
76
+ /**
77
+ * The names actually worth offering: trimmed, blanks dropped, each one once. A blank entry
78
+ * would render an option that shows as checked and then does nothing, because
79
+ * `applyThemeName` refuses it; a repeated entry would render two controls with the same
80
+ * `data-testid` and make Vue warn about a duplicate key.
81
+ */
82
+ const offeredThemes = computed(() => [
83
+ ...new Set(props.themes.map((name) => name.trim()).filter((name) => name !== '')),
84
+ ]);
85
+
86
+ // Glyphs, as the `d` of each path of a 24×24 stroke icon. They are data rather than
87
+ // markup so that an option carries its own glyph and the segment stays one loop.
88
+
89
+ const SUN = [
90
+ 'M12 8a4 4 0 1 0 0 8 4 4 0 1 0 0-8',
91
+ 'M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4',
92
+ ];
93
+ const MOON = ['M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z'];
94
+ const SCREEN = [
95
+ 'M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z',
96
+ 'M8 20h8M12 16v4',
97
+ ];
98
+ // The three density steps are the same three lines with shrinking gaps, so the control
99
+ // shows what it does. Only the rows layout draws them: see `glyphs` on AppearanceSegment
100
+ // for why the panel spends that width on the words instead.
101
+ const LINES_NORMAL = ['M5 7h14', 'M5 12h14', 'M5 17h14'];
102
+ const LINES_COMPACT = ['M5 8.5h14', 'M5 12h14', 'M5 15.5h14'];
103
+ const LINES_DENSE = ['M5 9.5h14', 'M5 12h14', 'M5 14.5h14'];
104
+ const SLIDERS = [
105
+ 'M4 7h9M17 7h3M4 17h3M11 17h9',
106
+ 'M13 7a2 2 0 1 0 4 0 2 2 0 1 0-4 0',
107
+ 'M7 17a2 2 0 1 0 4 0 2 2 0 1 0-4 0',
108
+ ];
109
+ const CHEVRON = ['m6 9 6 6 6-6'];
110
+
111
+ // What is in force, read from the document and from storage — not from a default. A
112
+ // picker on a page that `initAppearance` already configured must show the state that is
113
+ // actually applied, and must keep showing it: `subscribeAppearance` below re-reads
114
+ // whenever anything else applies a change, which is what keeps two pickers on one page
115
+ // (a popover in the chrome, a rows card on a settings page) telling the same story.
116
+
117
+ const theme = ref('');
118
+ const mode = ref<ThemePreference>('light');
119
+ const density = ref<TableDensity>('normal');
120
+ const pageDensity = ref<PageDensity>('normal');
121
+
122
+ /** Storage throws in private mode and with site data blocked; an unreadable key is absent. */
123
+ function readStored(key: string): string | null {
124
+ try {
125
+ return localStorage.getItem(key);
126
+ } catch {
127
+ return null;
128
+ }
129
+ }
130
+
131
+ function readLiveState(): void {
132
+ // Server-rendered: nothing is applied yet, so show the first theme on offer and the
133
+ // defaults core itself falls back to. The client re-runs this at setup.
134
+ if (typeof document === 'undefined') {
135
+ theme.value = offeredThemes.value[0] ?? '';
136
+
137
+ return;
138
+ }
139
+ const root = document.documentElement;
140
+
141
+ // The attribute is the theme in force. Only if nothing is applied does the stored
142
+ // name decide, and only if nothing is stored either does the first offer — which is
143
+ // a guess, deliberately not written anywhere.
144
+ const applied = root.dataset.brixTheme?.trim() ?? '';
145
+ const stored = readStored(`${props.storagePrefix}.theme`)?.trim() ?? '';
146
+ theme.value =
147
+ applied !== '' ? applied : stored !== '' ? stored : (offeredThemes.value[0] ?? '');
148
+
149
+ // The `dark` class cannot tell 'system' from the colour it resolves to, so the
150
+ // preference can only come from storage. With nothing stored — or something
151
+ // unrecognised — the class is the honest answer: it is what is in force, and it is
152
+ // also what core's own `initTheme` would have applied.
153
+ const storedMode = readStored(`${props.storagePrefix}.mode`);
154
+ const preference = asThemePreference(storedMode);
155
+ mode.value =
156
+ storedMode !== null && preference === storedMode
157
+ ? preference
158
+ : root.classList.contains('dark')
159
+ ? 'dark'
160
+ : 'light';
161
+
162
+ // Both axes write 'normal' as a missing attribute, so the attribute is the whole
163
+ // truth and storage is not consulted.
164
+ density.value = asTableDensity(root.dataset.brixTableDensity);
165
+ pageDensity.value = asPageDensity(root.dataset.brixPageDensity);
166
+ }
167
+
168
+ readLiveState();
169
+
170
+ // Writing. Each pick updates what the control shows and hands core the value with the
171
+ // key it belongs under; core applies it to the document root and persists it.
172
+
173
+ function chooseTheme(name: string): void {
174
+ theme.value = name;
175
+ applyThemeName(name, `${props.storagePrefix}.theme`);
176
+ }
177
+
178
+ function chooseMode(value: string): void {
179
+ const picked = asThemePreference(value);
180
+ mode.value = picked;
181
+ applyTheme(picked, `${props.storagePrefix}.mode`);
182
+ }
183
+
184
+ function chooseDensity(value: string): void {
185
+ const picked = asTableDensity(value);
186
+ density.value = picked;
187
+ applyTableDensity(picked, `${props.storagePrefix}.tableDensity`);
188
+ }
189
+
190
+ function choosePageDensity(value: string): void {
191
+ const picked = asPageDensity(value);
192
+ pageDensity.value = picked;
193
+ applyPageDensity(picked, `${props.storagePrefix}.pageDensity`);
194
+ }
195
+
196
+ /** A theme's display name: its own name, capitalised. See the note on the props. */
197
+ function themeName(name: string): string {
198
+ return name.charAt(0).toUpperCase() + name.slice(1);
199
+ }
200
+
201
+ const themeGroup = computed<AppearanceGroup>(() => ({
202
+ name: 'theme',
203
+ title: labels.value.appearanceTheme,
204
+ text: labels.value.appearanceThemeText,
205
+ options: offeredThemes.value.map((name) => ({
206
+ value: name,
207
+ label: themeName(name),
208
+ swatch: true,
209
+ })),
210
+ selected: theme.value,
211
+ choose: chooseTheme,
212
+ }));
213
+
214
+ const modeGroup = computed<AppearanceGroup>(() => ({
215
+ name: 'mode',
216
+ title: labels.value.appearanceMode,
217
+ text: labels.value.appearanceModeText,
218
+ options: [
219
+ { value: 'light', label: labels.value.appearanceModeLight, glyph: SUN },
220
+ { value: 'dark', label: labels.value.appearanceModeDark, glyph: MOON },
221
+ { value: 'system', label: labels.value.appearanceModeSystem, glyph: SCREEN },
222
+ ],
223
+ selected: mode.value,
224
+ choose: chooseMode,
225
+ }));
226
+
227
+ /** The three steps both density axes offer, each with the glyph of its own line spacing. */
228
+ function densityOptions() {
229
+ return [
230
+ { value: 'normal', label: labels.value.appearanceDensityNormal, glyph: LINES_NORMAL },
231
+ { value: 'compact', label: labels.value.appearanceDensityCompact, glyph: LINES_COMPACT },
232
+ { value: 'dense', label: labels.value.appearanceDensityDense, glyph: LINES_DENSE },
233
+ ];
234
+ }
235
+
236
+ const densityGroup = computed<AppearanceGroup>(() => ({
237
+ name: 'density',
238
+ title: labels.value.appearanceTableDensity,
239
+ text: labels.value.appearanceTableDensityText,
240
+ options: densityOptions(),
241
+ selected: density.value,
242
+ choose: chooseDensity,
243
+ }));
244
+
245
+ const pageDensityGroup = computed<AppearanceGroup>(() => ({
246
+ name: 'page-density',
247
+ title: labels.value.appearancePageDensity,
248
+ text: labels.value.appearancePageDensityText,
249
+ options: densityOptions(),
250
+ selected: pageDensity.value,
251
+ choose: choosePageDensity,
252
+ }));
253
+
254
+ /**
255
+ * A group with no options is left out of both layouts, rather than rendered as a
256
+ * `radiogroup` owning no `radio` — which is an ARIA violation, and a heading over nothing.
257
+ * Only the theme group can end up empty: the other three carry fixed option lists.
258
+ */
259
+ const offeredGroups = (...given: AppearanceGroup[]): AppearanceGroup[] =>
260
+ given.filter((group) => group.options.length > 0);
261
+
262
+ /** The rows layout: one row per group, in this order. */
263
+ const groups = computed(() =>
264
+ offeredGroups(themeGroup.value, modeGroup.value, densityGroup.value, pageDensityGroup.value),
265
+ );
266
+
267
+ /** The popover layout: theme and mode stand alone, the two density axes share a heading. */
268
+ const singleGroups = computed(() => offeredGroups(themeGroup.value, modeGroup.value));
269
+ const densityAxes = computed(() => [
270
+ { label: labels.value.appearanceDensityTables, group: densityGroup.value },
271
+ { label: labels.value.appearanceDensityPages, group: pageDensityGroup.value },
272
+ ]);
273
+
274
+ /**
275
+ * The trigger's visible text, and its accessible name — which has to contain that text
276
+ * (WCAG 2.5.3), hence the `{theme}` template. With no theme to name, the trigger says what
277
+ * the panel is called and carries no `aria-label` at all, so its name is that same word
278
+ * rather than a label ending in a stranded colon.
279
+ */
280
+ const triggerText = computed(() =>
281
+ theme.value === '' ? labels.value.appearanceTitle : themeName(theme.value),
282
+ );
283
+ const triggerLabel = computed(() =>
284
+ theme.value === ''
285
+ ? undefined
286
+ : formatLabel(labels.value.appearanceOpen, { theme: triggerText.value }),
287
+ );
288
+
289
+ // The popover. Only the `popover` layout renders a trigger, but the state is declared
290
+ // unconditionally: a conditional `ref` is not a thing, and an unopened panel costs
291
+ // nothing.
292
+
293
+ const open = ref(false);
294
+ const wrap = ref<HTMLElement | null>(null);
295
+ const trigger = ref<ComponentPublicInstance | null>(null);
296
+
297
+ function focusTrigger(): void {
298
+ const element: unknown = trigger.value?.$el;
299
+ if (element instanceof HTMLElement) element.focus();
300
+ }
301
+
302
+ /**
303
+ * Closing returns focus to the trigger, so Escape cannot drop focus into nowhere. The
304
+ * exception is a pointer press outside the panel that lands on something focusable:
305
+ * focus has already moved there with the press, and pulling it back to the trigger would
306
+ * take it off whatever the person just aimed at.
307
+ */
308
+ function close(restoreFocus = true): void {
309
+ if (!open.value) return;
310
+ open.value = false;
311
+ if (restoreFocus) focusTrigger();
312
+ }
313
+
314
+ function toggle(): void {
315
+ if (open.value) close();
316
+ else open.value = true;
317
+ }
318
+
319
+ /**
320
+ * An Escape that closed this panel is spent: letting it travel on would also close the
321
+ * dialog or drawer the picker happens to sit in. An Escape on a closed picker is not this
322
+ * component's business, so it is left alone — a closed picker that swallowed Escape would
323
+ * be the same bug pointing the other way.
324
+ */
325
+ function onEscape(event: KeyboardEvent): void {
326
+ if (!open.value) return;
327
+ event.stopPropagation();
328
+ close();
329
+ }
330
+
331
+ function onPointerDown(event: Event): void {
332
+ if (event.target instanceof Node && wrap.value?.contains(event.target)) return;
333
+ // Focus still inside the panel means the press landed on something that does not
334
+ // take focus, and the panel is about to be removed from under it.
335
+ const inside =
336
+ document.activeElement instanceof Node && wrap.value?.contains(document.activeElement);
337
+ close(inside === true);
338
+ }
339
+
340
+ // Listening only while open, in the capture phase so that a handler which stops
341
+ // propagation cannot leave the panel stuck open.
342
+ watch(open, (isOpen) => {
343
+ if (isOpen) document.addEventListener('pointerdown', onPointerDown, true);
344
+ else document.removeEventListener('pointerdown', onPointerDown, true);
345
+ });
346
+
347
+ onBeforeUnmount(() => document.removeEventListener('pointerdown', onPointerDown, true));
348
+
349
+ // Two pickers can be on one page — a popover in the chrome and a rows card on a settings
350
+ // page — and in a single-page application neither remounts when the other writes. Core
351
+ // announces every change it applies, including the `dark` class flipping under 'system',
352
+ // so following it is one subscription and a re-read; watching the DOM instead would be
353
+ // guessing at an event that already exists.
354
+ let unsubscribe: (() => void) | null = null;
355
+ onMounted(() => {
356
+ unsubscribe = subscribeAppearance(readLiveState);
357
+ });
358
+ onUnmounted(() => {
359
+ unsubscribe?.();
360
+ unsubscribe = null;
361
+ });
362
+ </script>
363
+
364
+ <!-- The two layouts are the only root nodes on purpose: a comment between them would
365
+ make the root a fragment, and a fragment root silently drops everything a consumer
366
+ passes through — an `id`, an `aria-describedby`, a utility class. The notes on the
367
+ two shapes are therefore inside them. -->
368
+ <template>
369
+ <div
370
+ v-if="layout === 'rows'"
371
+ data-slot="appearance-picker"
372
+ data-layout="rows"
373
+ :class="
374
+ cn(
375
+ 'bg-card text-card-foreground ring-foreground/10 divide-border divide-y overflow-hidden rounded-xl text-sm ring-1',
376
+ props.class,
377
+ )
378
+ "
379
+ >
380
+ <!-- The settings-page shape: one card, one row per setting, hairlines between. -->
381
+ <div
382
+ v-for="group in groups"
383
+ :key="group.name"
384
+ class="grid gap-3 px-6 py-4 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center"
385
+ >
386
+ <div>
387
+ <h3 class="font-semibold">{{ group.title }}</h3>
388
+ <p class="text-muted-foreground mt-0.5 text-xs">{{ group.text }}</p>
389
+ </div>
390
+ <AppearanceSegment :group="group" />
391
+ </div>
392
+ </div>
393
+
394
+ <div
395
+ v-else
396
+ ref="wrap"
397
+ data-slot="appearance-picker"
398
+ data-layout="popover"
399
+ :class="cn('relative inline-block', props.class)"
400
+ @keydown.escape="onEscape"
401
+ >
402
+ <!-- The application-chrome shape: one trigger, one panel below it.
403
+
404
+ The `aria-expanded:` pair is a **deviation from the control-state recipe**, named as
405
+ one in CLAUDE.md's recipe section, and it is allowed because it is not a focus
406
+ indication: focus still comes from `Button`'s own recipe ring, which this class
407
+ string does not touch. What it does is say "the panel below me is open" by lifting
408
+ the trigger's resting edge — `--border`, which measures 1.26-1.57:1 against the
409
+ page in the six theme/mode pairs — to `--ring` at 3.28-13.38:1 against the page and
410
+ 3.28-12.11:1 against a card. So it strengthens an edge rather than standing in for
411
+ a ring, which is why it has no offset and only 1px: an outset gap here would read
412
+ as a second focus ring beside the real one. -->
413
+ <Button
414
+ ref="trigger"
415
+ type="button"
416
+ variant="outline"
417
+ size="lg"
418
+ aria-haspopup="dialog"
419
+ :aria-expanded="open"
420
+ :aria-label="triggerLabel"
421
+ data-testid="appearance-trigger"
422
+ class="aria-expanded:border-ring aria-expanded:ring-ring aria-expanded:ring-1"
423
+ @click="toggle"
424
+ >
425
+ <svg
426
+ viewBox="0 0 24 24"
427
+ fill="none"
428
+ stroke="currentColor"
429
+ stroke-width="2"
430
+ stroke-linecap="round"
431
+ stroke-linejoin="round"
432
+ aria-hidden="true"
433
+ >
434
+ <path v-for="d in SLIDERS" :key="d" :d="d" />
435
+ </svg>
436
+ <span>{{ triggerText }}</span>
437
+ <svg
438
+ class="text-muted-foreground size-3.5"
439
+ viewBox="0 0 24 24"
440
+ fill="none"
441
+ stroke="currentColor"
442
+ stroke-width="2"
443
+ stroke-linecap="round"
444
+ stroke-linejoin="round"
445
+ aria-hidden="true"
446
+ >
447
+ <path v-for="d in CHEVRON" :key="d" :d="d" />
448
+ </svg>
449
+ </Button>
450
+ <!-- The width cap below is `2rem`, not `3rem`, and the difference is a phone. At
451
+ 375px a `3rem` cap holds the panel to 327px instead of the 340 it is asking
452
+ for, and a group splits whatever it gets into equal thirds — so that cap, and
453
+ nothing else, was what left the longest theme name a pixel short of its box
454
+ there. A pixel is not a pixel on screen: the ellipsis needs room of its own,
455
+ so one pixel of overflow costs three characters. At `2rem` a phone renders the
456
+ same 340-wide panel a desktop does, where every label already fits, and it
457
+ still sits inside the `px-4` of the header it hangs from. Buying those pixels
458
+ out of the option padding instead would have fitted this one name and left the
459
+ next slightly longer one to find the same wall. -->
460
+ <div
461
+ v-if="open"
462
+ role="dialog"
463
+ :aria-label="labels.appearanceTitle"
464
+ data-testid="appearance-panel"
465
+ :data-align="align"
466
+ :class="
467
+ cn(
468
+ 'border-border bg-popover text-popover-foreground absolute top-full z-20 mt-2 grid w-85 max-w-[calc(100vw-2rem)] gap-4 rounded-xl border p-4 text-sm shadow-[0_12px_32px_color-mix(in_oklab,var(--foreground)_16%,transparent)]',
469
+ align === 'end' ? 'right-0' : 'left-0',
470
+ )
471
+ "
472
+ >
473
+ <div v-for="group in singleGroups" :key="group.name">
474
+ <div
475
+ class="text-muted-foreground mb-2 text-xs font-semibold tracking-wide uppercase"
476
+ >
477
+ {{ group.title }}
478
+ </div>
479
+ <!-- No check on the selected theme here: the filled segment and
480
+ `aria-checked` already say which one it is, and the 18 pixels it cost
481
+ are what the theme names need to be read in full. -->
482
+ <AppearanceSegment :group="group" full :checks="false" />
483
+ </div>
484
+ <div>
485
+ <div class="text-muted-foreground text-xs font-semibold tracking-wide uppercase">
486
+ {{ labels.appearanceDensity }}
487
+ </div>
488
+ <!-- A 2.5rem column, not 3.5rem: "Tables" and "Pages" need about 38px at
489
+ this size, and the 16 pixels that buys go to the three density
490
+ labels, which are what the panel was cutting off. -->
491
+ <div
492
+ v-for="axis in densityAxes"
493
+ :key="axis.group.name"
494
+ class="mt-2 grid grid-cols-[2.5rem_minmax(0,1fr)] items-center gap-2"
495
+ >
496
+ <span class="text-muted-foreground text-xs">{{ axis.label }}</span>
497
+ <AppearanceSegment :group="axis.group" full :glyphs="false" />
498
+ </div>
499
+ </div>
500
+ </div>
501
+ </div>
502
+ </template>
@@ -0,0 +1,175 @@
1
+ <script setup lang="ts">
2
+ import type { AppearanceGroup, AppearanceOption } from '.';
3
+ import { computed } from 'vue';
4
+ import { cn } from '../../lib/cn';
5
+ import { Button } from '../button';
6
+
7
+ /**
8
+ * One segmented control: a `radiogroup` whose options are `radio`s, drawn as a row of
9
+ * buttons on a muted track with the selected one filled. Private to the appearance
10
+ * picker, which owns the state; this file owns the semantics, the keyboard and the
11
+ * `data-testid`s.
12
+ */
13
+ const props = withDefaults(
14
+ defineProps<{
15
+ group: AppearanceGroup;
16
+ full?: boolean;
17
+ /**
18
+ * Whether an option's glyph is drawn. The popover panel turns it off for the two
19
+ * density rows: a `full` group splits its row evenly, so every option gets the
20
+ * same width whatever its label needs, and a glyph plus its gap costs 18 of the
21
+ * 73 pixels an option has there — which was enough to cut "Compact" to "Comp…" at
22
+ * every window size. The three density glyphs are also the least load-bearing of
23
+ * the set (the same three lines with shrinking gaps, drawn twice in one panel),
24
+ * so they are what gives way to the words. A theme's swatch is not a glyph and is
25
+ * never dropped.
26
+ */
27
+ glyphs?: boolean;
28
+ /**
29
+ * Whether the selected theme option gets a check beside its name. The popover
30
+ * panel turns it off for the same reason it turns the density glyphs off: an
31
+ * even split leaves a theme option 97 pixels, and a check plus its gap costs 18
32
+ * of them — enough to render "Kingfisher" as "Kingfi…".
33
+ *
34
+ * It is the cheapest of the three signals to lose. The selected segment is
35
+ * already filled with `bg-primary text-primary-foreground`, which is how the
36
+ * design says "selected" everywhere else in this control, and `aria-checked`
37
+ * says it to assistive technology — so the check was a third telling of the same
38
+ * thing. The rows layout keeps it: there an option is narrow next to its label,
39
+ * and the room is not contested.
40
+ */
41
+ checks?: boolean;
42
+ }>(),
43
+ { full: false, glyphs: true, checks: true },
44
+ );
45
+
46
+ /** The `d` of the check that marks the selected theme, as in the approved design. */
47
+ const CHECK = 'm5 12 5 5 9-10';
48
+
49
+ /**
50
+ * A radiogroup is one tab stop, not one per option: the checked option is the stop and
51
+ * the arrow keys move from there. When the value in force is not on offer — a theme
52
+ * applied to the document that this picker does not list — the first option is the stop,
53
+ * so the group never drops out of the tab order entirely.
54
+ */
55
+ const tabStop = computed(() => {
56
+ const checked = props.group.options.findIndex(
57
+ (option) => option.value === props.group.selected,
58
+ );
59
+
60
+ return checked === -1 ? 0 : checked;
61
+ });
62
+
63
+ const STEP: Record<string, number> = {
64
+ ArrowRight: 1,
65
+ ArrowDown: 1,
66
+ ArrowLeft: -1,
67
+ ArrowUp: -1,
68
+ };
69
+
70
+ /** Arrow keys wrap around, Home and End jump to the ends; each move also selects. */
71
+ function move(event: KeyboardEvent): void {
72
+ const options = props.group.options;
73
+ if (options.length === 0) return;
74
+
75
+ const step = STEP[event.key];
76
+ const to =
77
+ step !== undefined
78
+ ? (tabStop.value + step + options.length) % options.length
79
+ : event.key === 'Home'
80
+ ? 0
81
+ : event.key === 'End'
82
+ ? options.length - 1
83
+ : -1;
84
+ if (to === -1) return;
85
+
86
+ event.preventDefault();
87
+ props.group.choose(options[to]!.value);
88
+ // Focus follows the selection, which is what makes the group one tab stop: the next
89
+ // Tab leaves the group rather than walking the rest of the options.
90
+ if (event.currentTarget instanceof HTMLElement) {
91
+ event.currentTarget.querySelectorAll<HTMLElement>('[role="radio"]')[to]?.focus();
92
+ }
93
+ }
94
+
95
+ /** The selected option is the filled one; the rest read as muted until hovered. */
96
+ function optionClass(option: AppearanceOption): string {
97
+ return cn(
98
+ option.value === props.group.selected ? 'font-semibold' : 'text-muted-foreground',
99
+ // A full-width group shares the row evenly and takes the smaller type, which is
100
+ // what lets three options fit the popover's panel.
101
+ props.full && 'min-w-0 flex-1 px-2 text-xs',
102
+ );
103
+ }
104
+ </script>
105
+
106
+ <template>
107
+ <div
108
+ role="radiogroup"
109
+ :aria-label="group.title"
110
+ :data-testid="`appearance-${group.name}`"
111
+ :class="
112
+ cn(
113
+ // `flex-wrap` costs nothing where there is room and is what keeps a group
114
+ // that does not fit from pushing the page sideways instead: in the `rows`
115
+ // layout the options are their natural width, and on a 375px screen three
116
+ // theme names are wider than the card, so the settings page gained a
117
+ // horizontal scrollbar. Wrapping is the honest answer there — the labels
118
+ // stay whole.
119
+ 'border-border bg-muted flex flex-wrap gap-0.5 rounded-lg border p-0.5',
120
+ !full && 'w-fit',
121
+ )
122
+ "
123
+ @keydown="move"
124
+ >
125
+ <Button
126
+ v-for="(option, index) in group.options"
127
+ :key="option.value"
128
+ type="button"
129
+ role="radio"
130
+ :aria-checked="option.value === group.selected"
131
+ :tabindex="index === tabStop ? 0 : -1"
132
+ :variant="option.value === group.selected ? 'default' : 'ghost'"
133
+ :size="full ? 'sm' : 'default'"
134
+ :class="optionClass(option)"
135
+ :data-testid="`appearance-${group.name}-${option.value}`"
136
+ @click="group.choose(option.value)"
137
+ >
138
+ <!-- The swatch carries the theme it offers, so `var(--primary)` resolves to
139
+ that theme's own hue, in whatever mode is current. Nothing here knows a
140
+ palette. -->
141
+ <span
142
+ v-if="option.swatch"
143
+ :data-brix-theme="option.value"
144
+ aria-hidden="true"
145
+ class="ring-foreground/25 group-aria-checked/button:ring-primary-foreground size-3.5 shrink-0 rounded-full bg-[var(--primary)] ring-1 group-aria-checked/button:ring-2"
146
+ />
147
+ <svg
148
+ v-else-if="option.glyph && glyphs"
149
+ viewBox="0 0 24 24"
150
+ fill="none"
151
+ stroke="currentColor"
152
+ stroke-width="2"
153
+ stroke-linecap="round"
154
+ stroke-linejoin="round"
155
+ aria-hidden="true"
156
+ >
157
+ <path v-for="d in option.glyph" :key="d" :d="d" />
158
+ </svg>
159
+ <span class="truncate">{{ option.label }}</span>
160
+ <svg
161
+ v-if="option.swatch && checks"
162
+ class="hidden size-3.5 group-aria-checked/button:block"
163
+ viewBox="0 0 24 24"
164
+ fill="none"
165
+ stroke="currentColor"
166
+ stroke-width="3"
167
+ stroke-linecap="round"
168
+ stroke-linejoin="round"
169
+ aria-hidden="true"
170
+ >
171
+ <path :d="CHECK" />
172
+ </svg>
173
+ </Button>
174
+ </div>
175
+ </template>