@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.
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/package.json +117 -3
- package/src/components/address-field/AddressField.vue +337 -0
- package/src/components/address-field/index.ts +1 -0
- package/src/components/appearance-picker/AppearancePicker.vue +502 -0
- package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
- package/src/components/appearance-picker/index.ts +44 -0
- package/src/components/autofill/AutoFillDialog.vue +264 -0
- package/src/components/autofill/index.ts +1 -0
- package/src/components/badge/Badge.vue +23 -0
- package/src/components/badge/index.ts +106 -0
- package/src/components/build-stamp/BuildStamp.vue +62 -0
- package/src/components/build-stamp/index.ts +1 -0
- package/src/components/button/Button.vue +31 -0
- package/src/components/button/index.ts +122 -0
- package/src/components/card/Card.vue +29 -0
- package/src/components/card/CardAction.vue +17 -0
- package/src/components/card/CardContent.vue +14 -0
- package/src/components/card/CardDescription.vue +14 -0
- package/src/components/card/CardFooter.vue +22 -0
- package/src/components/card/CardHeader.vue +22 -0
- package/src/components/card/CardTitle.vue +29 -0
- package/src/components/card/index.ts +47 -0
- package/src/components/chart/BarChart.vue +123 -0
- package/src/components/chart/StackedBarChart.vue +149 -0
- package/src/components/chart/appearanceRevision.ts +22 -0
- package/src/components/chart/chartColor.ts +59 -0
- package/src/components/chart/index.ts +6 -0
- package/src/components/checkbox/Checkbox.vue +61 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/code-editor/CodeEditor.vue +352 -0
- package/src/components/code-editor/index.ts +9 -0
- package/src/components/code-editor/syntaxTheme.ts +110 -0
- package/src/components/colour-picker/ColourPicker.vue +421 -0
- package/src/components/colour-picker/index.ts +1 -0
- package/src/components/combobox/Combobox.vue +337 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/comments/CommentComposer.vue +302 -0
- package/src/components/comments/CommentMessage.vue +259 -0
- package/src/components/comments/CommentThread.vue +250 -0
- package/src/components/comments/commentBody.ts +185 -0
- package/src/components/comments/commentLevels.ts +139 -0
- package/src/components/comments/commentNode.ts +35 -0
- package/src/components/comments/composer.ts +20 -0
- package/src/components/comments/index.ts +29 -0
- package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/containers/Box.vue +42 -0
- package/src/components/containers/Section.vue +88 -0
- package/src/components/containers/SectionAction.vue +17 -0
- package/src/components/containers/SectionContent.vue +14 -0
- package/src/components/containers/SectionDescription.vue +14 -0
- package/src/components/containers/SectionHeader.vue +22 -0
- package/src/components/containers/SectionTitle.vue +17 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/data-table/ColumnMenu.vue +241 -0
- package/src/components/data-table/DataTable.vue +447 -0
- package/src/components/data-table/ExpandCaret.vue +34 -0
- package/src/components/data-table/SortableHead.vue +184 -0
- package/src/components/data-table/TableLoadingRow.vue +13 -0
- package/src/components/data-table/TableProgressRow.vue +26 -0
- package/src/components/data-table/columns.ts +13 -0
- package/src/components/data-table/index.ts +3 -0
- package/src/components/data-table/pinned.ts +19 -0
- package/src/components/data-table/rowActivation.ts +14 -0
- package/src/components/data-table/sort.ts +13 -0
- package/src/components/data-table/types.ts +23 -0
- package/src/components/date-picker/CalendarPanel.vue +432 -0
- package/src/components/date-picker/DateField.vue +293 -0
- package/src/components/date-picker/DatePicker.vue +147 -0
- package/src/components/date-picker/UntilDatePicker.vue +96 -0
- package/src/components/date-picker/dateFieldGuard.ts +87 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/useDateField.ts +37 -0
- package/src/components/date-range-picker/DateRangePicker.vue +247 -0
- package/src/components/date-range-picker/index.ts +1 -0
- package/src/components/date-time-picker/DateTimePicker.vue +291 -0
- package/src/components/date-time-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +250 -0
- package/src/components/dialog/DialogSurface.vue +214 -0
- package/src/components/dialog/dialogEdges.ts +65 -0
- package/src/components/dialog/dialogSizes.ts +35 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dialog/toastHost.ts +18 -0
- package/src/components/dropdown/Dropdown.vue +101 -0
- package/src/components/dropdown/DropdownItems.vue +154 -0
- package/src/components/dropdown/dropdown.ts +64 -0
- package/src/components/dropdown/index.ts +2 -0
- package/src/components/file-preview/FilePreview.vue +78 -0
- package/src/components/file-preview/index.ts +1 -0
- package/src/components/file-upload/FileUpload.vue +234 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
- package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
- package/src/components/filter-check-menu/index.ts +2 -0
- package/src/components/form-field/FormField.vue +74 -0
- package/src/components/form-field/index.ts +2 -0
- package/src/components/form-field/types.ts +5 -0
- package/src/components/frames/FrameCentred.vue +137 -0
- package/src/components/frames/FrameSidebar.vue +113 -0
- package/src/components/frames/FrameSplit.vue +109 -0
- package/src/components/frames/index.ts +3 -0
- package/src/components/icon/BellIcon.vue +27 -0
- package/src/components/icon/BoldIcon.vue +31 -0
- package/src/components/icon/CalendarDaysIcon.vue +33 -0
- package/src/components/icon/CheckIcon.vue +31 -0
- package/src/components/icon/ChevronDownIcon.vue +30 -0
- package/src/components/icon/ChevronLeftIcon.vue +31 -0
- package/src/components/icon/ChevronRightIcon.vue +31 -0
- package/src/components/icon/ChevronUpIcon.vue +30 -0
- package/src/components/icon/CircleAlertIcon.vue +29 -0
- package/src/components/icon/ClockIcon.vue +31 -0
- package/src/components/icon/Columns3Icon.vue +32 -0
- package/src/components/icon/FlipHorizontalIcon.vue +29 -0
- package/src/components/icon/ItalicIcon.vue +28 -0
- package/src/components/icon/LinkIcon.vue +27 -0
- package/src/components/icon/ListIcon.vue +29 -0
- package/src/components/icon/ListOrderedIcon.vue +28 -0
- package/src/components/icon/PenLineIcon.vue +31 -0
- package/src/components/icon/PlusIcon.vue +28 -0
- package/src/components/icon/RotateCcwIcon.vue +28 -0
- package/src/components/icon/RotateCwIcon.vue +28 -0
- package/src/components/icon/SearchIcon.vue +31 -0
- package/src/components/icon/StarIcon.vue +29 -0
- package/src/components/icon/TriangleAlertIcon.vue +29 -0
- package/src/components/icon/UnderlineIcon.vue +27 -0
- package/src/components/icon/Undo2Icon.vue +28 -0
- package/src/components/icon/XIcon.vue +31 -0
- package/src/components/icon/ZoomInIcon.vue +30 -0
- package/src/components/icon/ZoomOutIcon.vue +29 -0
- package/src/components/icon/index.ts +37 -0
- package/src/components/icon-picker/IconPicker.vue +560 -0
- package/src/components/icon-picker/index.ts +1 -0
- package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
- package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
- package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
- package/src/components/image-crop-dialog/index.ts +16 -0
- package/src/components/image-upload/ImageUpload.vue +345 -0
- package/src/components/image-upload/index.ts +2 -0
- package/src/components/input/Input.vue +48 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/keycap/Keycap.vue +49 -0
- package/src/components/keycap/index.ts +1 -0
- package/src/components/label/Label.vue +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/menu/MenuCheckboxItem.vue +63 -0
- package/src/components/menu/MenuContent.vue +45 -0
- package/src/components/menu/MenuGroup.vue +22 -0
- package/src/components/menu/MenuItem.vue +34 -0
- package/src/components/menu/MenuLabel.vue +22 -0
- package/src/components/menu/MenuRadioGroup.vue +22 -0
- package/src/components/menu/MenuRadioItem.vue +50 -0
- package/src/components/menu/MenuRoot.vue +25 -0
- package/src/components/menu/MenuSeparator.vue +27 -0
- package/src/components/menu/MenuSub.vue +29 -0
- package/src/components/menu/MenuSubContent.vue +48 -0
- package/src/components/menu/MenuSubTrigger.vue +49 -0
- package/src/components/menu/MenuTrigger.vue +22 -0
- package/src/components/menu/index.ts +20 -0
- package/src/components/menu/menuClasses.ts +74 -0
- package/src/components/morph-select/MorphSelect.vue +150 -0
- package/src/components/morph-select/index.ts +1 -0
- package/src/components/nav/NavFlyout.vue +343 -0
- package/src/components/nav/NavGroup.vue +306 -0
- package/src/components/nav/NavItem.vue +243 -0
- package/src/components/nav/NavNodes.ts +66 -0
- package/src/components/nav/NavSection.vue +105 -0
- package/src/components/nav/NavSidebar.vue +137 -0
- package/src/components/nav/index.ts +5 -0
- package/src/components/nav/navChain.ts +112 -0
- package/src/components/nav/navClasses.ts +229 -0
- package/src/components/nav/navNode.ts +10 -0
- package/src/components/nav/navRegistry.ts +24 -0
- package/src/components/notification-list/NotificationList.vue +314 -0
- package/src/components/notification-list/index.ts +2 -0
- package/src/components/notification-list/notifications.ts +21 -0
- package/src/components/pagination/Pagination.vue +296 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pin-field/PinField.vue +332 -0
- package/src/components/pin-field/index.ts +1 -0
- package/src/components/popover-panel/PopoverPanel.vue +115 -0
- package/src/components/popover-panel/index.ts +5 -0
- package/src/components/rating/Rating.vue +201 -0
- package/src/components/rating/index.ts +1 -0
- package/src/components/record-avatar/RecordAvatar.vue +76 -0
- package/src/components/record-avatar/index.ts +1 -0
- package/src/components/result-window/ResultWindow.vue +399 -0
- package/src/components/result-window/index.ts +2 -0
- package/src/components/result-window/results.ts +75 -0
- package/src/components/rich-editor/RichEditor.vue +370 -0
- package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
- package/src/components/rich-editor/index.ts +8 -0
- package/src/components/row-actions/RowActions.vue +262 -0
- package/src/components/row-actions/index.ts +2 -0
- package/src/components/row-actions/rowActions.ts +44 -0
- package/src/components/search-select/SearchSelect.vue +599 -0
- package/src/components/search-select/index.ts +2 -0
- package/src/components/search-select/types.ts +14 -0
- package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
- package/src/components/segmented-choice/index.ts +2 -0
- package/src/components/segmented-choice/segmentedOption.ts +6 -0
- package/src/components/select/Select.vue +18 -0
- package/src/components/select/SelectContent.vue +73 -0
- package/src/components/select/SelectGroup.vue +21 -0
- package/src/components/select/SelectItem.vue +47 -0
- package/src/components/select/SelectItemText.vue +12 -0
- package/src/components/select/SelectLabel.vue +17 -0
- package/src/components/select/SelectScrollDownButton.vue +36 -0
- package/src/components/select/SelectScrollUpButton.vue +36 -0
- package/src/components/select/SelectSeparator.vue +19 -0
- package/src/components/select/SelectTrigger.vue +52 -0
- package/src/components/select/SelectValue.vue +12 -0
- package/src/components/select/index.ts +11 -0
- package/src/components/session/IdleTimer.vue +71 -0
- package/src/components/session/SessionDialogs.vue +177 -0
- package/src/components/session/index.ts +2 -0
- package/src/components/split-button/SplitButton.vue +122 -0
- package/src/components/split-button/index.ts +2 -0
- package/src/components/split-button/splitButtonItem.ts +7 -0
- package/src/components/switch/Switch.vue +60 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.vue +51 -0
- package/src/components/table/TableBody.vue +14 -0
- package/src/components/table/TableCaption.vue +17 -0
- package/src/components/table/TableCell.vue +22 -0
- package/src/components/table/TableEmpty.vue +72 -0
- package/src/components/table/TableFooter.vue +17 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeader.vue +14 -0
- package/src/components/table/TableRow.vue +22 -0
- package/src/components/table/index.ts +9 -0
- package/src/components/tabs/Tabs.vue +173 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tabItem.ts +12 -0
- package/src/components/textarea/LimitedTextarea.vue +81 -0
- package/src/components/textarea/TextLimitCounter.vue +107 -0
- package/src/components/textarea/Textarea.vue +42 -0
- package/src/components/textarea/index.ts +4 -0
- package/src/components/textarea/textLimit.ts +43 -0
- package/src/components/time-picker/TimePicker.vue +522 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/toast/ToastHost.vue +276 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/update-notice/UpdateNotice.vue +103 -0
- package/src/components/update-notice/index.ts +1 -0
- package/src/components/user-menu/UserMenu.vue +154 -0
- package/src/components/user-menu/index.ts +1 -0
- package/src/index.ts +182 -0
- package/src/lib/cn.ts +21 -0
- package/src/lib/panelFocus.ts +65 -0
- package/src/lib/sessionMonitor.ts +390 -0
- package/src/lib/slotContent.ts +17 -0
- package/src/lib/updateCheck.ts +133 -0
- package/src/styles.css +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NoiX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @noix-dev/brix-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Vue components of Brix, a small design system for Vue 3 and Tailwind CSS 4
|
|
4
|
+
applications: button, card, badge, input and an appearance picker, each written
|
|
5
|
+
against the token roles rather than against colours, so a theme, a colour mode
|
|
6
|
+
and a section accent can all change the same utility at runtime.
|
|
7
|
+
|
|
8
|
+
Shipped as single-file components, not as a build: your bundler compiles them
|
|
9
|
+
and your Tailwind compiles their classes.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @noix-dev/brix-vue @noix-dev/brix-core @noix-dev/brix-tokens
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
All three: the components are drawn with the roles `@noix-dev/brix-tokens` binds and
|
|
18
|
+
use `@noix-dev/brix-core` for appearance and labels.
|
|
19
|
+
|
|
20
|
+
## Use
|
|
21
|
+
|
|
22
|
+
**The stylesheet first, and all three lines in ONE CSS file.** This is the step
|
|
23
|
+
that fails silently when it is done differently:
|
|
24
|
+
|
|
25
|
+
```css
|
|
26
|
+
/* src/app.css — one file, imported once from your entry point */
|
|
27
|
+
@import '@noix-dev/brix-tokens';
|
|
28
|
+
@import '@noix-dev/brix-tokens/themes/kingfisher.css';
|
|
29
|
+
@import '@noix-dev/brix-vue/styles.css';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The third line is what makes the components' classes compile. Tailwind scans the
|
|
33
|
+
application it runs in and stops there, so a class only a Brix component uses
|
|
34
|
+
would never reach your stylesheet. `@noix-dev/brix-vue/styles.css` carries no
|
|
35
|
+
`@import 'tailwindcss'` of its own — it only tells Tailwind where the components
|
|
36
|
+
are, and it can only tell the Tailwind root it is imported into. Import these
|
|
37
|
+
files separately from your JavaScript entry point and each becomes its own root:
|
|
38
|
+
the colours still load, the page still looks themed, and every component class
|
|
39
|
+
is dropped, with nothing in the build output to say so.
|
|
40
|
+
|
|
41
|
+
Then the components:
|
|
42
|
+
|
|
43
|
+
```vue
|
|
44
|
+
<script setup lang="ts">
|
|
45
|
+
import { Button, Badge, Card, CardHeader, CardTitle, CardContent } from '@noix-dev/brix-vue';
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<Card>
|
|
50
|
+
<CardHeader>
|
|
51
|
+
<CardTitle>Workshop</CardTitle>
|
|
52
|
+
</CardHeader>
|
|
53
|
+
<CardContent class="flex items-center gap-2">
|
|
54
|
+
<Badge tone="teal">open</Badge>
|
|
55
|
+
<Button variant="brand" size="xl">Sign in</Button>
|
|
56
|
+
</CardContent>
|
|
57
|
+
</Card>
|
|
58
|
+
</template>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`AppearancePicker` is the ready-made control for theme, mode and density; give
|
|
62
|
+
it the themes your application imports and the storage prefix you passed to
|
|
63
|
+
`initAppearance`:
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<AppearancePicker :themes="['kingfisher', 'graphite', 'noix']" storage-prefix="myapp" />
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Its panel is positioned inside the component rather than teleported, so an
|
|
70
|
+
ancestor with `overflow: hidden` clips it — `Card` is one. Pass
|
|
71
|
+
`overflow-visible` on the ancestor, or use `layout="rows"`, which has no panel.
|
|
72
|
+
|
|
73
|
+
## Repository
|
|
74
|
+
|
|
75
|
+
<https://github.com/NoiXdev/noix-brix> — MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,120 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noix-dev/brix-vue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Brix components: Vue 3 single-file components built on the token contract, shipped as source with their Tailwind source declaration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"**/*.css"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts",
|
|
12
|
+
"./chart": "./src/components/chart/index.ts",
|
|
13
|
+
"./code-editor": "./src/components/code-editor/index.ts",
|
|
14
|
+
"./comment-composer": "./src/components/comments/composer.ts",
|
|
15
|
+
"./date-picker": "./src/components/date-picker/index.ts",
|
|
16
|
+
"./date-range-picker": "./src/components/date-range-picker/index.ts",
|
|
17
|
+
"./date-time-picker": "./src/components/date-time-picker/index.ts",
|
|
18
|
+
"./image-crop-dialog": "./src/components/image-crop-dialog/index.ts",
|
|
19
|
+
"./image-upload": "./src/components/image-upload/index.ts",
|
|
20
|
+
"./rich-editor": "./src/components/rich-editor/index.ts",
|
|
21
|
+
"./styles.css": "./src/styles.css",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"!src/**/*.test.ts"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@vueuse/core": "^14.4.0",
|
|
30
|
+
"class-variance-authority": "^0.7.1",
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
|
+
"reka-ui": "^2.12.0",
|
|
33
|
+
"tailwind-merge": "^3.7.0",
|
|
34
|
+
"@noix-dev/brix-core": "0.2.0",
|
|
35
|
+
"@noix-dev/brix-tokens": "0.2.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@codemirror/lang-html": "^6.4.12",
|
|
39
|
+
"@codemirror/language": "^6.13.1",
|
|
40
|
+
"@codemirror/state": "^6.7.6",
|
|
41
|
+
"@codemirror/view": "^6.44.2",
|
|
42
|
+
"@internationalized/date": "^3.12.4",
|
|
43
|
+
"@lezer/highlight": "^1.2.5",
|
|
44
|
+
"@tiptap/extension-link": "^3.35.1",
|
|
45
|
+
"@tiptap/starter-kit": "^3.35.1",
|
|
46
|
+
"@tiptap/vue-3": "^3.35.1",
|
|
47
|
+
"@types/node": "^26.6.6",
|
|
48
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
49
|
+
"@vue/test-utils": "^2.6.0",
|
|
50
|
+
"chart.js": "^4.6.1",
|
|
51
|
+
"codemirror": "^6.0.2",
|
|
52
|
+
"cropperjs": "^2.3.1",
|
|
53
|
+
"jsdom": "^27.0.0",
|
|
54
|
+
"typescript": "~5.8.3",
|
|
55
|
+
"vite": "^7.3.7",
|
|
56
|
+
"vitest": "^4.1.12",
|
|
57
|
+
"vue": "^3.5.44",
|
|
58
|
+
"vue-chartjs": "^5.3.4",
|
|
59
|
+
"vue-tsc": "^3.3.14"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@codemirror/language": "^6.13.1",
|
|
63
|
+
"@codemirror/state": "^6.7.6",
|
|
64
|
+
"@codemirror/view": "^6.44.2",
|
|
65
|
+
"@internationalized/date": "^3.12.4",
|
|
66
|
+
"@lezer/highlight": "^1.2.5",
|
|
67
|
+
"@tiptap/extension-link": "^3.35.1",
|
|
68
|
+
"@tiptap/starter-kit": "^3.35.1",
|
|
69
|
+
"@tiptap/vue-3": "^3.35.1",
|
|
70
|
+
"chart.js": "^4.6.1",
|
|
71
|
+
"codemirror": "^6.0.2",
|
|
72
|
+
"cropperjs": "^2.3.1",
|
|
73
|
+
"typescript": "^5.8.3",
|
|
74
|
+
"vue": "^3.5.44",
|
|
75
|
+
"vue-chartjs": "^5.3.4"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@codemirror/language": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@codemirror/state": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@codemirror/view": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@internationalized/date": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@lezer/highlight": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@tiptap/extension-link": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@tiptap/starter-kit": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"@tiptap/vue-3": {
|
|
100
|
+
"optional": true
|
|
101
|
+
},
|
|
102
|
+
"chart.js": {
|
|
103
|
+
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"codemirror": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"cropperjs": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"vue-chartjs": {
|
|
112
|
+
"optional": true
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"scripts": {
|
|
116
|
+
"lint": "eslint . --max-warnings 0",
|
|
117
|
+
"typecheck": "vue-tsc -p tsconfig.json --noEmit",
|
|
118
|
+
"test": "vitest run"
|
|
119
|
+
}
|
|
6
120
|
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
addressPart,
|
|
4
|
+
blankAddress,
|
|
5
|
+
isEmptyAddress,
|
|
6
|
+
joinAddress,
|
|
7
|
+
POSTAL_ADDRESS_PARTS,
|
|
8
|
+
useUiLabels,
|
|
9
|
+
} from '@noix-dev/brix-core';
|
|
10
|
+
import type { PostalAddress, PostalAddressPart } from '@noix-dev/brix-core';
|
|
11
|
+
import type { HTMLAttributes } from 'vue';
|
|
12
|
+
import { computed, ref, useId, watch } from 'vue';
|
|
13
|
+
import { cn } from '../../lib/cn';
|
|
14
|
+
import { Button } from '../button';
|
|
15
|
+
import { Dialog } from '../dialog';
|
|
16
|
+
import { FormField } from '../form-field';
|
|
17
|
+
import { PenLineIcon } from '../icon';
|
|
18
|
+
import { Input } from '../input';
|
|
19
|
+
import { Label } from '../label';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A postal address as one field. READING IS THE NORMAL STATE: the address is drawn as lines in
|
|
23
|
+
* a summary box with one button, and the parts are edited in brix's own `Dialog`, which brings
|
|
24
|
+
* the focus trap, the dismiss behaviour and the close button. Six inputs sitting open in a form
|
|
25
|
+
* are six inputs of noise for a value that changes once a year.
|
|
26
|
+
*
|
|
27
|
+
* THE MODEL is a `PostalAddress` (five strings) or `null`. Saving emits one value: every part a
|
|
28
|
+
* string, trimmed, or `null` when nothing is left in any of them. It is the field's own shape and
|
|
29
|
+
* only that: a design system cannot know a consumer's request body, so a host that writes
|
|
30
|
+
* `house_number` maps it itself, once, where it builds the request.
|
|
31
|
+
*
|
|
32
|
+
* THE SUMMARY. `summary` is the address as the consumer already rendered it, one line per line
|
|
33
|
+
* of text, for a server that formats addresses and wants the field and its other renderings to
|
|
34
|
+
* agree. When it is given it is what is read, even where it disagrees with the parts, because
|
|
35
|
+
* the consumer is the one who knows. It is not trusted past an edit: once a person saves, it
|
|
36
|
+
* describes the old address, so the field reads the parts again until the consumer hands in a
|
|
37
|
+
* new `summary`. Without a summary (or with one that is only whitespace) the parts are joined
|
|
38
|
+
* locally: street and number, postcode and city, country, a missing part leaving no gap.
|
|
39
|
+
*
|
|
40
|
+
* A VALUE THE FIELD WOULD NOT ITSELF HAVE PRODUCED is read as far as it goes and left alone
|
|
41
|
+
* until a person acts. Parts missing or not strings read as empty; an address with nothing in
|
|
42
|
+
* it reads as no address, and so does `null`. Nothing is rewritten on mount. Saving an address
|
|
43
|
+
* that came out the same as it went in emits nothing, so opening the dialog and pressing Save
|
|
44
|
+
* does not make a form dirty or turn a partial stored value into a whole one; once a part
|
|
45
|
+
* changes, the whole value is emitted. Clearing every part emits `null`, so a stored address
|
|
46
|
+
* can be removed. A `summary` with no parts behind it is shown and offers Edit, the dialog
|
|
47
|
+
* opening on empty parts.
|
|
48
|
+
*
|
|
49
|
+
* THE GLYPH on the edit button is the `edit-icon` slot (ADR 0013).
|
|
50
|
+
*
|
|
51
|
+
* THE COUNTRY is a text input on purpose. A country list is locale-dependent consumer data running
|
|
52
|
+
* to a couple of hundred entries, which a design system should neither own nor ship in everyone's
|
|
53
|
+
* bundle; a consumer who wants a picker builds it from their own list.
|
|
54
|
+
*
|
|
55
|
+
* ERRORS. `fieldErrors` is keyed by part and each message sits beside its own input in the
|
|
56
|
+
* dialog. Saving closes the dialog before a host can validate, so by the time a rejection comes
|
|
57
|
+
* back the red input is behind a dialog nobody has reason to reopen: while the dialog is closed
|
|
58
|
+
* the rejected parts are summarised under the field, by the label the input carries, and `error`
|
|
59
|
+
* (the address as a whole) stands with them. While the dialog is open the parts are beside their
|
|
60
|
+
* inputs and `error` is shown in the dialog, so each message is said once.
|
|
61
|
+
*
|
|
62
|
+
* THE FIELD OWNS NO ERROR STATE, so after a save the closed field keeps showing the previous value's
|
|
63
|
+
* `fieldErrors` and `error` until the consumer clears them (and cancelling the dialog brings
|
|
64
|
+
* them back, correctly): clear both when you receive a new value.
|
|
65
|
+
*
|
|
66
|
+
* `disabled` opens nothing; a dialog that is open when it turns on closes without handing
|
|
67
|
+
* anything back. The wording is the labels contract's (`addressField*`, with `cancel` for the
|
|
68
|
+
* dialog's other button), and `labels` overrides it member by member. `labels` has no `cancel`: the dialog's Cancel is the
|
|
69
|
+
* contract's own `cancel`, so it changes only through a provided contract, not through this prop.
|
|
70
|
+
*
|
|
71
|
+
* Attributes land on the outer element. The inputs are `Input` and carry the `input` slot; the
|
|
72
|
+
* parts sit in `FormField`, so a page's density settings reach them as they reach every field.
|
|
73
|
+
*/
|
|
74
|
+
defineOptions({ inheritAttrs: true });
|
|
75
|
+
|
|
76
|
+
interface AddressFieldLabels {
|
|
77
|
+
addressFieldTitle: string;
|
|
78
|
+
addressFieldEmpty: string;
|
|
79
|
+
addressFieldEdit: string;
|
|
80
|
+
addressFieldAdd: string;
|
|
81
|
+
addressFieldStreet: string;
|
|
82
|
+
addressFieldHouseNumber: string;
|
|
83
|
+
addressFieldPostalCode: string;
|
|
84
|
+
addressFieldCity: string;
|
|
85
|
+
addressFieldCountry: string;
|
|
86
|
+
addressFieldSave: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const props = withDefaults(
|
|
90
|
+
defineProps<{
|
|
91
|
+
/** The address, or `null` for none. */
|
|
92
|
+
modelValue?: PostalAddress | null;
|
|
93
|
+
/** The address as the consumer rendered it, one line per line of text. It wins while given. */
|
|
94
|
+
summary?: string | null;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
/** The refusal of the address as a whole. */
|
|
97
|
+
error?: string;
|
|
98
|
+
/** The refusal of single parts, each shown beside its own input. */
|
|
99
|
+
fieldErrors?: Partial<Record<PostalAddressPart, string>>;
|
|
100
|
+
/** The field's heading and its dialog's title; the contract's `addressFieldTitle` when not given. */
|
|
101
|
+
label?: string;
|
|
102
|
+
/** Overrides the contract's wording member by member; the rest keep the contract's. */
|
|
103
|
+
labels?: Partial<AddressFieldLabels>;
|
|
104
|
+
class?: HTMLAttributes['class'];
|
|
105
|
+
}>(),
|
|
106
|
+
{
|
|
107
|
+
modelValue: null,
|
|
108
|
+
summary: undefined,
|
|
109
|
+
disabled: false,
|
|
110
|
+
error: undefined,
|
|
111
|
+
fieldErrors: undefined,
|
|
112
|
+
label: undefined,
|
|
113
|
+
labels: undefined,
|
|
114
|
+
class: undefined,
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const emit = defineEmits<{
|
|
119
|
+
(e: 'update:modelValue', value: PostalAddress | null): void;
|
|
120
|
+
}>();
|
|
121
|
+
|
|
122
|
+
const contract = useUiLabels();
|
|
123
|
+
|
|
124
|
+
const text = computed<AddressFieldLabels>(() => ({
|
|
125
|
+
addressFieldTitle: contract.value.addressFieldTitle,
|
|
126
|
+
addressFieldEmpty: contract.value.addressFieldEmpty,
|
|
127
|
+
addressFieldEdit: contract.value.addressFieldEdit,
|
|
128
|
+
addressFieldAdd: contract.value.addressFieldAdd,
|
|
129
|
+
addressFieldStreet: contract.value.addressFieldStreet,
|
|
130
|
+
addressFieldHouseNumber: contract.value.addressFieldHouseNumber,
|
|
131
|
+
addressFieldPostalCode: contract.value.addressFieldPostalCode,
|
|
132
|
+
addressFieldCity: contract.value.addressFieldCity,
|
|
133
|
+
addressFieldCountry: contract.value.addressFieldCountry,
|
|
134
|
+
addressFieldSave: contract.value.addressFieldSave,
|
|
135
|
+
// Members given as `undefined` are dropped, not spread: they would blank the contract's word.
|
|
136
|
+
...Object.fromEntries(Object.entries(props.labels ?? {}).filter(([, v]) => v !== undefined)),
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
const heading = computed(() => props.label ?? text.value.addressFieldTitle);
|
|
140
|
+
const headingId = useId();
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* One row per part: its label, the grid span the approved layout gives it, and where it lives in
|
|
144
|
+
* the contract. Six columns, so a row sets its own proportions: a street name is long and a
|
|
145
|
+
* house number short, a postcode is five digits and a town name is not. The first draft had the
|
|
146
|
+
* postcode in the wide cell and the town in the narrow one, which is backwards, and the owner
|
|
147
|
+
* swapped them: 4 + 2, then 2 + 4, then the country across. `AddressField.test.ts` asserts the
|
|
148
|
+
* span each part carries, since a proportion nobody asserts is one that regresses.
|
|
149
|
+
*/
|
|
150
|
+
const GRID: Record<PostalAddressPart, { span: string; label: keyof AddressFieldLabels }> = {
|
|
151
|
+
street: { span: 'col-span-4', label: 'addressFieldStreet' },
|
|
152
|
+
houseNumber: { span: 'col-span-2', label: 'addressFieldHouseNumber' },
|
|
153
|
+
postalCode: { span: 'col-span-2', label: 'addressFieldPostalCode' },
|
|
154
|
+
city: { span: 'col-span-4', label: 'addressFieldCity' },
|
|
155
|
+
country: { span: 'col-span-full', label: 'addressFieldCountry' },
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// --- Reading. ---
|
|
159
|
+
|
|
160
|
+
/** True once a person has saved an address and the consumer has not yet sent a summary for it. */
|
|
161
|
+
const summaryOutdated = ref(false);
|
|
162
|
+
watch(
|
|
163
|
+
() => props.summary,
|
|
164
|
+
() => {
|
|
165
|
+
summaryOutdated.value = false;
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const lines = computed<string[]>(() => {
|
|
170
|
+
const given = summaryOutdated.value ? '' : (props.summary ?? '');
|
|
171
|
+
const fromSummary = given
|
|
172
|
+
.split('\n')
|
|
173
|
+
// The trim also takes the carriage return off a CRLF break.
|
|
174
|
+
.map((line) => line.trim())
|
|
175
|
+
.filter((line) => line !== '');
|
|
176
|
+
return fromSummary.length > 0 ? fromSummary : joinAddress(props.modelValue);
|
|
177
|
+
});
|
|
178
|
+
const hasAddress = computed(() => lines.value.length > 0);
|
|
179
|
+
|
|
180
|
+
const buttonText = computed(() =>
|
|
181
|
+
hasAddress.value ? text.value.addressFieldEdit : text.value.addressFieldAdd,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// --- Errors. ---
|
|
185
|
+
|
|
186
|
+
const partErrors = computed(() =>
|
|
187
|
+
POSTAL_ADDRESS_PARTS.map((name) => ({
|
|
188
|
+
name,
|
|
189
|
+
label: text.value[GRID[name].label],
|
|
190
|
+
message: props.fieldErrors?.[name],
|
|
191
|
+
})).filter((entry): entry is typeof entry & { message: string } => !!entry.message),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// --- The dialog. ---
|
|
195
|
+
|
|
196
|
+
const open = ref(false);
|
|
197
|
+
const draft = ref<PostalAddress>(blankAddress());
|
|
198
|
+
const editButton = ref<InstanceType<typeof Button> | null>(null);
|
|
199
|
+
|
|
200
|
+
function seed(): PostalAddress {
|
|
201
|
+
const seeded = blankAddress();
|
|
202
|
+
for (const name of POSTAL_ADDRESS_PARTS) {
|
|
203
|
+
const raw: unknown = props.modelValue?.[name];
|
|
204
|
+
seeded[name] = typeof raw === 'string' ? raw : '';
|
|
205
|
+
}
|
|
206
|
+
return seeded;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function openDialog(): void {
|
|
210
|
+
if (props.disabled) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
draft.value = seed();
|
|
214
|
+
open.value = true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
watch(
|
|
218
|
+
() => props.disabled,
|
|
219
|
+
(disabled) => {
|
|
220
|
+
if (disabled) {
|
|
221
|
+
open.value = false;
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
function save(): void {
|
|
227
|
+
const next = blankAddress();
|
|
228
|
+
for (const name of POSTAL_ADDRESS_PARTS) {
|
|
229
|
+
next[name] = draft.value[name].trim();
|
|
230
|
+
}
|
|
231
|
+
const unchanged = isEmptyAddress(next)
|
|
232
|
+
? isEmptyAddress(props.modelValue)
|
|
233
|
+
: POSTAL_ADDRESS_PARTS.every((name) => addressPart(props.modelValue, name) === next[name]);
|
|
234
|
+
open.value = false;
|
|
235
|
+
if (unchanged) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
summaryOutdated.value = true;
|
|
239
|
+
emit('update:modelValue', isEmptyAddress(next) ? null : next);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function onEnter(event: KeyboardEvent): void {
|
|
243
|
+
// Enter that confirms an input-method choice is not a request to save.
|
|
244
|
+
if (!event.isComposing) {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
save();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The dialog has no trigger of its own for reka to return the focus to, so it would fall to
|
|
252
|
+
* the page; it goes back to the button that opened it. (Reka itself cancels its own return when
|
|
253
|
+
* it has no trigger, so there is nothing to prevent here.)
|
|
254
|
+
*/
|
|
255
|
+
function returnFocus(): void {
|
|
256
|
+
(editButton.value?.$el as HTMLElement | undefined)?.focus();
|
|
257
|
+
}
|
|
258
|
+
</script>
|
|
259
|
+
|
|
260
|
+
<template>
|
|
261
|
+
<div :class="cn('grid gap-1.5', props.class)">
|
|
262
|
+
<Label :id="headingId" as="span">{{ heading }}</Label>
|
|
263
|
+
<!-- The lines are a group named by the heading, so a screen reader announces them as the
|
|
264
|
+
address and not as loose text. -->
|
|
265
|
+
<div
|
|
266
|
+
role="group"
|
|
267
|
+
:aria-labelledby="headingId"
|
|
268
|
+
class="border-border bg-background flex items-start gap-3 rounded-lg border p-3"
|
|
269
|
+
>
|
|
270
|
+
<div class="min-w-0 text-sm leading-snug">
|
|
271
|
+
<template v-if="hasAddress">
|
|
272
|
+
<p v-for="(line, index) in lines" :key="index" data-testid="address-line">
|
|
273
|
+
{{ line }}
|
|
274
|
+
</p>
|
|
275
|
+
</template>
|
|
276
|
+
<p v-else class="text-muted-foreground">{{ text.addressFieldEmpty }}</p>
|
|
277
|
+
</div>
|
|
278
|
+
<Button
|
|
279
|
+
ref="editButton"
|
|
280
|
+
type="button"
|
|
281
|
+
variant="outline"
|
|
282
|
+
size="sm"
|
|
283
|
+
class="ml-auto"
|
|
284
|
+
data-testid="address-edit"
|
|
285
|
+
:disabled="disabled"
|
|
286
|
+
:aria-label="`${buttonText}, ${heading}`"
|
|
287
|
+
@click="openDialog"
|
|
288
|
+
>
|
|
289
|
+
<slot name="edit-icon"><PenLineIcon /></slot>
|
|
290
|
+
{{ buttonText }}
|
|
291
|
+
</Button>
|
|
292
|
+
</div>
|
|
293
|
+
<!-- One alert for the whole refusal. It leaves while the dialog is open, where the same
|
|
294
|
+
messages stand beside their inputs. -->
|
|
295
|
+
<div
|
|
296
|
+
v-if="!open && (error || partErrors.length > 0)"
|
|
297
|
+
role="alert"
|
|
298
|
+
class="text-destructive grid gap-0.5 text-sm"
|
|
299
|
+
>
|
|
300
|
+
<p v-if="error">{{ error }}</p>
|
|
301
|
+
<p v-for="entry in partErrors" :key="entry.name">
|
|
302
|
+
{{ entry.label }}: {{ entry.message }}
|
|
303
|
+
</p>
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
<Dialog v-model:open="open" :title="heading" size="md" @close-auto-focus="returnFocus">
|
|
307
|
+
<p v-if="error" role="alert" class="text-destructive mb-3 text-sm">{{ error }}</p>
|
|
308
|
+
<div class="grid grid-cols-6 gap-3">
|
|
309
|
+
<FormField
|
|
310
|
+
v-for="name in POSTAL_ADDRESS_PARTS"
|
|
311
|
+
:key="name"
|
|
312
|
+
:label="text[GRID[name].label]"
|
|
313
|
+
:error="fieldErrors?.[name]"
|
|
314
|
+
:data-part="name"
|
|
315
|
+
:class="GRID[name].span"
|
|
316
|
+
>
|
|
317
|
+
<template #default="{ id, describedBy }">
|
|
318
|
+
<Input
|
|
319
|
+
:id="id"
|
|
320
|
+
:model-value="draft[name]"
|
|
321
|
+
:aria-describedby="describedBy"
|
|
322
|
+
:aria-invalid="fieldErrors?.[name] ? 'true' : undefined"
|
|
323
|
+
@update:model-value="draft[name] = String($event)"
|
|
324
|
+
@keydown.enter="onEnter"
|
|
325
|
+
/>
|
|
326
|
+
</template>
|
|
327
|
+
</FormField>
|
|
328
|
+
</div>
|
|
329
|
+
<template #footer>
|
|
330
|
+
<Button type="button" variant="outline" @click="open = false">
|
|
331
|
+
{{ contract.cancel }}
|
|
332
|
+
</Button>
|
|
333
|
+
<Button type="button" @click="save">{{ text.addressFieldSave }}</Button>
|
|
334
|
+
</template>
|
|
335
|
+
</Dialog>
|
|
336
|
+
</div>
|
|
337
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as AddressField } from './AddressField.vue';
|