@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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PopoverContentProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { PopoverAnchor, PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui';
|
|
5
|
+
import { cn } from '../../lib/cn';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The panel a picker field hangs its content on. A family renders its field into `trigger` and
|
|
9
|
+
* its content into `panel`, and never imports reka-ui itself: this component is the whole of its
|
|
10
|
+
* contact with the popover engine.
|
|
11
|
+
*
|
|
12
|
+
* `trigger` must have ONE root element. It is the popover's anchor and its trigger at once, so
|
|
13
|
+
* that element receives `aria-expanded`, `data-state` and the click handler, and (from reka-ui
|
|
14
|
+
* 2.12) an `aria-controls` that names the panel only while the panel is rendered and is absent
|
|
15
|
+
* otherwise, instead of dangling at nothing.
|
|
16
|
+
*
|
|
17
|
+
* DO NOT WRITE `aria-expanded`, `aria-controls` OR `data-state` ON THAT ELEMENT YOURSELF, and
|
|
18
|
+
* this is the half of `as-child` nobody guesses. The trigger is rendered `as-child`, so reka
|
|
19
|
+
* merges with `mergeProps(shell, child)` and the CHILD WINS: an attribute of one of those three
|
|
20
|
+
* names, passed in on the element in `trigger` or forwarded onto it by a consuming family,
|
|
21
|
+
* **replaces** the one the popover engine writes. The result is a trigger that says
|
|
22
|
+
* `aria-expanded="false"` while its panel stands open — a screen reader is told the thing is
|
|
23
|
+
* shut, and nothing in the repository objects. A notification bell that wires its own
|
|
24
|
+
* `aria-expanded` onto its own button is the first way in. Four shipped families forward a
|
|
25
|
+
* consumer's attributes onto this trigger (`ColourPicker`, `TimePicker`, `IconPicker`,
|
|
26
|
+
* `FilterCheckMenu`), so a consumer meets the rule through them too.
|
|
27
|
+
*
|
|
28
|
+
* **Reserving those three names here is the fix that is owed** — the shell keeping the engine's
|
|
29
|
+
* value whatever a consumer passes, rather than every consumer defending itself and the next
|
|
30
|
+
* family finding this again. It changes the behaviour of a shipped family with four in-house
|
|
31
|
+
* callers, so it is a slice of its own and not a line in this one. Until it lands this is a
|
|
32
|
+
* rule and not a guard, written here and on this family's own page, and parked in `CLAUDE.md`.
|
|
33
|
+
*
|
|
34
|
+
* WHAT THE PANEL IS: a non-modal dialog (`role="dialog"`, no `aria-modal`), NAMED BY ITS TRIGGER
|
|
35
|
+
* (`aria-labelledby` points at it), so the trigger's own label ("Choose a colour") is the panel's
|
|
36
|
+
* name. There is deliberately no label prop. reka merges its own `role` and `aria-labelledby`
|
|
37
|
+
* AFTER any attribute a consumer passes, and `aria-labelledby` outranks `aria-label`, so a label
|
|
38
|
+
* passed here could never take effect. Name the trigger instead. Do not patch the attributes
|
|
39
|
+
* from outside either: `role="region"` would add a landmark per open picker.
|
|
40
|
+
*
|
|
41
|
+
* WHERE THE PANEL GOES, and it is three declared props rather than three attributes that happen
|
|
42
|
+
* to fall through: `side` (default `bottom`), `align` (default `start`, where the engine's own
|
|
43
|
+
* default is `center`) and `side-offset` (default `4`). An end-aligned bell panel is
|
|
44
|
+
* `align="end"`, and a caller reading this docblock can see that it is possible. Everything else
|
|
45
|
+
* the engine offers — `collision-padding`, `avoid-collisions`, `@open-auto-focus`, which two
|
|
46
|
+
* in-house callers use to take the first focus themselves — still falls through `$attrs` onto
|
|
47
|
+
* the panel, and `PopoverPanel.test.ts` holds that it reaches it.
|
|
48
|
+
*
|
|
49
|
+
* `class` REPLACES what it collides with rather than landing beside it: the panel's own string
|
|
50
|
+
* goes through `cn`, so `p-0` on a notification list unpads the panel and a `max-w-*` of your
|
|
51
|
+
* own widens it, the way `MenuContent` answers the same question for the menu family.
|
|
52
|
+
*
|
|
53
|
+
* Behaviour the shell owns:
|
|
54
|
+
*
|
|
55
|
+
* - Non-modal. There is no backdrop, so two pickers opened in turn never leave a stack of
|
|
56
|
+
* overlays swallowing each other's clicks; a click outside closes the panel and reaches
|
|
57
|
+
* whatever it landed on.
|
|
58
|
+
* - No tab stop of its own, and no focus trap. Whatever the family puts in `panel` decides how
|
|
59
|
+
* many stops there are: a grid keeps one (a roving tabindex, `tabindex="-1"` on all but the
|
|
60
|
+
* current cell), and Tab then leaves it.
|
|
61
|
+
* - Escape closes it and focus returns to the trigger. `disabled` keeps it shut however the
|
|
62
|
+
* open state is driven.
|
|
63
|
+
*
|
|
64
|
+
* The panel is portalled to `document.body`, the one place the playground's contrast walk can
|
|
65
|
+
* see it, and it lands four pixels off its trigger. `--popover` ground, `--border` edge and
|
|
66
|
+
* `--radius` are role tokens, so every theme and mode restyles it with no rule of its own.
|
|
67
|
+
*/
|
|
68
|
+
defineOptions({ inheritAttrs: false });
|
|
69
|
+
|
|
70
|
+
const props = withDefaults(
|
|
71
|
+
defineProps<{
|
|
72
|
+
disabled?: boolean;
|
|
73
|
+
/** Replaces the panel's own padding, radius and caps, through `tailwind-merge`. */
|
|
74
|
+
class?: HTMLAttributes['class'];
|
|
75
|
+
/** Which side of the trigger the panel takes. */
|
|
76
|
+
side?: PopoverContentProps['side'];
|
|
77
|
+
/** How the panel lines up with the trigger along that side. */
|
|
78
|
+
align?: PopoverContentProps['align'];
|
|
79
|
+
/** The gap between the trigger and the panel, in pixels. */
|
|
80
|
+
sideOffset?: PopoverContentProps['sideOffset'];
|
|
81
|
+
}>(),
|
|
82
|
+
{ side: 'bottom', align: 'start', sideOffset: 4 },
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const open = defineModel<boolean>('open', { default: false });
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The panel's own look and size. A consumer `class` is merged over this with `cn`, so a class
|
|
89
|
+
* in any of these groups replaces the one written here instead of fighting it in the cascade.
|
|
90
|
+
*/
|
|
91
|
+
const PANEL =
|
|
92
|
+
'z-50 max-h-(--reka-popover-content-available-height) max-w-(--reka-popover-content-available-width) overflow-y-auto rounded-[var(--radius)] border border-border bg-popover p-2 text-popover-foreground shadow-[0_12px_32px_color-mix(in_oklab,var(--foreground)_16%,transparent)] outline-none';
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<PopoverRoot :open="open && !disabled" @update:open="(next) => (open = next)">
|
|
97
|
+
<PopoverAnchor as-child>
|
|
98
|
+
<PopoverTrigger as-child :disabled="disabled">
|
|
99
|
+
<slot name="trigger" />
|
|
100
|
+
</PopoverTrigger>
|
|
101
|
+
</PopoverAnchor>
|
|
102
|
+
<PopoverPortal>
|
|
103
|
+
<PopoverContent
|
|
104
|
+
data-slot="popover-panel"
|
|
105
|
+
:side="side"
|
|
106
|
+
:align="align"
|
|
107
|
+
:side-offset="sideOffset"
|
|
108
|
+
v-bind="$attrs"
|
|
109
|
+
:class="cn(PANEL, props.class)"
|
|
110
|
+
>
|
|
111
|
+
<slot name="panel" />
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</PopoverPortal>
|
|
114
|
+
</PopoverRoot>
|
|
115
|
+
</template>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The shell a trigger and a panel hang on: the colour, icon and time pickers, the filter menu and
|
|
2
|
+
// the data table's column menu compose it as `../popover-panel`, and a consumer's own dropdown
|
|
3
|
+
// does the same from the package barrel. It owns the popover engine, so nothing that composes it
|
|
4
|
+
// imports reka-ui.
|
|
5
|
+
export { default as PopoverPanel } from './PopoverPanel.vue';
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { cn } from '../../lib/cn';
|
|
4
|
+
import { StarIcon } from '../icon';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A row of stars: one to `stars` given, or none yet. Editable it is a single tab stop, a
|
|
8
|
+
* `role="slider"`; the arrow keys step it, Home and End jump to the ends, and the stars
|
|
9
|
+
* inside are for the pointer only (`tabindex="-1"`). `readonly` swaps it for a static
|
|
10
|
+
* `role="img"` with no tab stop and no key handler.
|
|
11
|
+
*
|
|
12
|
+
* Everything a screen reader hears comes from the root. The star buttons inside carry
|
|
13
|
+
* `aria-hidden="true"`, because ARIA 1.2 marks `slider` *Children Presentational: True* and a
|
|
14
|
+
* conforming reader prunes them anyway; the chosen star's wording reaches a listener through
|
|
15
|
+
* the root's `aria-valuetext`, which `starLabel` supplies.
|
|
16
|
+
*
|
|
17
|
+
* A given star is `brand-alt` and a star not yet given is `muted-foreground`, and the two also
|
|
18
|
+
* differ in shape (filled against outline), so the state does not rest on colour alone.
|
|
19
|
+
* "None" is a real state: the value is `null` and the slider reports it as 0 of a 0-to-`stars`
|
|
20
|
+
* range, with `aria-valuetext` "Not rated". It is reachable both ways. Keyboard: ArrowLeft or
|
|
21
|
+
* ArrowDown at one star, Home, Backspace and Delete all clear it (Home is the slider's minimum).
|
|
22
|
+
* Pointer: clicking the star that is already chosen clears it, the usual toggle idiom. Clearing
|
|
23
|
+
* emits `null`.
|
|
24
|
+
*
|
|
25
|
+
* The glyph is the `icon` slot, drawn once per star and told `{ value, filled }`.
|
|
26
|
+
*/
|
|
27
|
+
const props = withDefaults(
|
|
28
|
+
defineProps<{
|
|
29
|
+
modelValue: number | null;
|
|
30
|
+
stars?: number;
|
|
31
|
+
readonly?: boolean;
|
|
32
|
+
label?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Overrides the group name; a static `label` still wins. By default the editable slider
|
|
35
|
+
* is named just "Rating" (its score is in `aria-valuetext`) and the read-only image
|
|
36
|
+
* "Rating {current} of {stars}". A name that includes the score makes a screen reader
|
|
37
|
+
* say it twice on the slider.
|
|
38
|
+
*/
|
|
39
|
+
groupLabel?: (current: number, stars: number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Overrides the slider's `aria-valuetext`: "Not rated", or "{current} of {stars}".
|
|
42
|
+
* Wins over `starLabel`, which the chosen star's wording otherwise comes from.
|
|
43
|
+
*/
|
|
44
|
+
valueText?: (current: number | null, stars: number) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Overrides the "{value} of {stars}" wording of a star.
|
|
47
|
+
*
|
|
48
|
+
* It reaches a listener through the root's `aria-valuetext`, which is built from it
|
|
49
|
+
* for the chosen star. The `aria-label` it also puts on each star button is a DOM
|
|
50
|
+
* hook and nothing more: ARIA 1.2 marks `slider` *Children Presentational: True*, so
|
|
51
|
+
* a conforming screen reader prunes those buttons and never reads their names. The
|
|
52
|
+
* pruning is what this component wants — one tab stop, one announced value — and
|
|
53
|
+
* `aria-hidden="true"` on the buttons says so out loud rather than relying on it.
|
|
54
|
+
*/
|
|
55
|
+
starLabel?: (value: number, stars: number) => string;
|
|
56
|
+
class?: string;
|
|
57
|
+
}>(),
|
|
58
|
+
{ stars: 10, readonly: false },
|
|
59
|
+
);
|
|
60
|
+
const emits = defineEmits<{ (e: 'update:modelValue', value: number | null): void }>();
|
|
61
|
+
|
|
62
|
+
defineSlots<{
|
|
63
|
+
/** The star glyph. Replaces the internal star, for a filled and for an empty star alike. */
|
|
64
|
+
icon?: (props: { value: number; filled: boolean }) => unknown;
|
|
65
|
+
}>();
|
|
66
|
+
|
|
67
|
+
const current = computed(() => props.modelValue ?? 0);
|
|
68
|
+
|
|
69
|
+
const defaultGroupLabel = (value: number, stars: number): string =>
|
|
70
|
+
props.readonly ? `Rating ${value} of ${stars}` : 'Rating';
|
|
71
|
+
const defaultValueText = (value: number | null, stars: number): string =>
|
|
72
|
+
value === null || value === 0 ? 'Not rated' : `${value} of ${stars}`;
|
|
73
|
+
|
|
74
|
+
const defaultStarLabel = (value: number, stars: number): string => `${value} of ${stars}`;
|
|
75
|
+
|
|
76
|
+
function starAriaLabel(value: number): string {
|
|
77
|
+
return (props.starLabel ?? defaultStarLabel)(value, props.stars);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* What a screen reader actually says, and the only place a star's wording reaches one: the
|
|
82
|
+
* star buttons are pruned (see `starLabel`), so the chosen star's text is routed here. The
|
|
83
|
+
* `valueText` prop still wins, and "none" keeps its own wording rather than asking
|
|
84
|
+
* `starLabel` for a nought.
|
|
85
|
+
*/
|
|
86
|
+
const valueText = computed(() => {
|
|
87
|
+
if (props.valueText) {
|
|
88
|
+
return props.valueText(props.modelValue ?? null, props.stars);
|
|
89
|
+
}
|
|
90
|
+
return current.value === 0 ? defaultValueText(null, props.stars) : starAriaLabel(current.value);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const ariaLabel = computed(
|
|
94
|
+
() => props.label ?? (props.groupLabel ?? defaultGroupLabel)(current.value, props.stars),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/** Choosing the star that is already chosen takes the rating back to none. */
|
|
98
|
+
function choose(value: number): void {
|
|
99
|
+
if (props.readonly) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const clamped = Math.min(Math.max(value, 1), props.stars);
|
|
103
|
+
emits('update:modelValue', clamped === current.value ? null : clamped);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Steps run from 0 (none) to `stars`. A key that would leave the value where it is says
|
|
108
|
+
* nothing, so walking left on an unrated control stays unrated.
|
|
109
|
+
*/
|
|
110
|
+
function onKeydown(event: KeyboardEvent): void {
|
|
111
|
+
if (event.altKey || event.ctrlKey || event.metaKey) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let next: number | null = null;
|
|
115
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowUp') {
|
|
116
|
+
next = current.value + 1;
|
|
117
|
+
} else if (event.key === 'ArrowLeft' || event.key === 'ArrowDown') {
|
|
118
|
+
next = current.value - 1;
|
|
119
|
+
} else if (event.key === 'Home' || event.key === 'Backspace' || event.key === 'Delete') {
|
|
120
|
+
next = 0;
|
|
121
|
+
} else if (event.key === 'End') {
|
|
122
|
+
next = props.stars;
|
|
123
|
+
}
|
|
124
|
+
if (next === null) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const target = Math.min(Math.max(next, 0), props.stars);
|
|
129
|
+
if (target !== current.value) {
|
|
130
|
+
emits('update:modelValue', target === 0 ? null : target);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<template>
|
|
136
|
+
<!-- Readonly: static stars, no interaction. -->
|
|
137
|
+
<div
|
|
138
|
+
v-if="readonly"
|
|
139
|
+
role="img"
|
|
140
|
+
:aria-label="ariaLabel"
|
|
141
|
+
:class="cn('inline-flex items-center gap-0.5', props.class)"
|
|
142
|
+
>
|
|
143
|
+
<span
|
|
144
|
+
v-for="i in stars"
|
|
145
|
+
:key="i"
|
|
146
|
+
:data-star="i"
|
|
147
|
+
:data-filled="i <= current ? 'true' : 'false'"
|
|
148
|
+
class="inline-flex"
|
|
149
|
+
:class="i <= current ? 'text-brand-alt' : 'text-muted-foreground'"
|
|
150
|
+
>
|
|
151
|
+
<slot name="icon" :value="i" :filled="i <= current">
|
|
152
|
+
<StarIcon class="size-3.5" :fill="i <= current ? 'currentColor' : 'none'" />
|
|
153
|
+
</slot>
|
|
154
|
+
</span>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<!-- Editable: focusable slider + clickable star buttons. -->
|
|
158
|
+
<div
|
|
159
|
+
v-else
|
|
160
|
+
role="slider"
|
|
161
|
+
tabindex="0"
|
|
162
|
+
:aria-valuenow="current"
|
|
163
|
+
:aria-valuetext="valueText"
|
|
164
|
+
aria-valuemin="0"
|
|
165
|
+
:aria-valuemax="stars"
|
|
166
|
+
:aria-label="ariaLabel"
|
|
167
|
+
:class="
|
|
168
|
+
cn(
|
|
169
|
+
'inline-flex items-center rounded-md',
|
|
170
|
+
'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none',
|
|
171
|
+
props.class,
|
|
172
|
+
)
|
|
173
|
+
"
|
|
174
|
+
@keydown="onKeydown"
|
|
175
|
+
>
|
|
176
|
+
<!-- Hidden on purpose, and not as a shortcut. ARIA 1.2 marks `slider` *Children
|
|
177
|
+
Presentational: True*, so a conforming screen reader prunes these buttons and
|
|
178
|
+
ignores their names whatever this component does; `aria-hidden` makes the pruning
|
|
179
|
+
explicit instead of leaning on it, and the chosen star's wording reaches a
|
|
180
|
+
listener through the root's `aria-valuetext`. `tabindex="-1"` keeps them out of
|
|
181
|
+
the tab order, so nothing focusable is hidden. The `aria-label` stays as a DOM
|
|
182
|
+
hook. -->
|
|
183
|
+
<button
|
|
184
|
+
v-for="i in stars"
|
|
185
|
+
:key="i"
|
|
186
|
+
type="button"
|
|
187
|
+
:data-star="i"
|
|
188
|
+
:data-filled="i <= current ? 'true' : 'false'"
|
|
189
|
+
:aria-label="starAriaLabel(i)"
|
|
190
|
+
aria-hidden="true"
|
|
191
|
+
tabindex="-1"
|
|
192
|
+
class="hover:text-brand-alt inline-flex cursor-pointer p-0.5 transition-colors"
|
|
193
|
+
:class="i <= current ? 'text-brand-alt' : 'text-muted-foreground'"
|
|
194
|
+
@click="choose(i)"
|
|
195
|
+
>
|
|
196
|
+
<slot name="icon" :value="i" :filled="i <= current">
|
|
197
|
+
<StarIcon :fill="i <= current ? 'currentColor' : 'none'" />
|
|
198
|
+
</slot>
|
|
199
|
+
</button>
|
|
200
|
+
</div>
|
|
201
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Rating } from './Rating.vue';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { cn } from '../../lib/cn';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The square that opens a record's page: its picture, or its initials on a wash of the
|
|
7
|
+
* theme's two accents when it has none. Presentational: it takes no focus and no input.
|
|
8
|
+
*
|
|
9
|
+
* Square and `rounded-xl`, not a circle: a circle reads as "a person's account" and this
|
|
10
|
+
* stands for a record, which is as often a customer, a repair job or an invoice. 44px is the
|
|
11
|
+
* page head's height anchor, so it sets the eyebrow-plus-title block beside it.
|
|
12
|
+
*
|
|
13
|
+
* THE ONE EXCEPTION is named rather than assumed: `shape="round"` draws the circle. It is for
|
|
14
|
+
* the case the argument above describes, an avatar that stands for a *person's account*, which
|
|
15
|
+
* is what the user menu's identity is. It is a prop and not a `rounded-full` class from the
|
|
16
|
+
* caller so that the exception sits in the one place that holds the reason for the rule; a
|
|
17
|
+
* class string would hide a deliberate departure inside a consumer. The default is `square`,
|
|
18
|
+
* so nothing that draws a record changes.
|
|
19
|
+
*
|
|
20
|
+
* The gradient runs from `--primary` towards `--brand-alt` and stops short of it: the full
|
|
21
|
+
* accent would put the primary ink at 2.3:1 under the initials in the dark mode of the
|
|
22
|
+
* violet theme, and the 65/35 mix keeps them at 4.5:1 or better in all six theme and mode
|
|
23
|
+
* pairs. The gradient stays behind the picture rather than being swapped out for it, so an
|
|
24
|
+
* image that fails to load leaves a coloured square instead of a broken frame.
|
|
25
|
+
*/
|
|
26
|
+
const props = defineProps<{
|
|
27
|
+
/** The record's picture. Null, undefined or empty all mean "no picture". */
|
|
28
|
+
src?: string | null;
|
|
29
|
+
/** Shown when there is no picture. One or two letters; the caller derives them. */
|
|
30
|
+
initials: string;
|
|
31
|
+
/**
|
|
32
|
+
* Describes the picture. Leave it out when the name is already next to the square, which
|
|
33
|
+
* is the normal case in a page head: repeating it makes a screen reader read the record
|
|
34
|
+
* twice.
|
|
35
|
+
*/
|
|
36
|
+
alt?: string;
|
|
37
|
+
/**
|
|
38
|
+
* `square` (default) stands for a record. `round` is for a person's account only: see the
|
|
39
|
+
* note above on why it is a named exception.
|
|
40
|
+
*/
|
|
41
|
+
shape?: 'square' | 'round';
|
|
42
|
+
class?: string;
|
|
43
|
+
}>();
|
|
44
|
+
|
|
45
|
+
const picture = computed(() =>
|
|
46
|
+
props.src !== null && props.src !== undefined && props.src !== '' ? props.src : null,
|
|
47
|
+
);
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div
|
|
52
|
+
data-testid="record-avatar"
|
|
53
|
+
data-slot="record-avatar"
|
|
54
|
+
:class="
|
|
55
|
+
cn(
|
|
56
|
+
'text-primary-foreground flex h-11 w-11 shrink-0 items-center justify-center overflow-hidden text-sm font-bold',
|
|
57
|
+
props.shape === 'round' ? 'rounded-full' : 'rounded-xl',
|
|
58
|
+
props.class,
|
|
59
|
+
)
|
|
60
|
+
"
|
|
61
|
+
style="
|
|
62
|
+
background: linear-gradient(
|
|
63
|
+
135deg,
|
|
64
|
+
var(--primary),
|
|
65
|
+
color-mix(in oklab, var(--primary) 65%, var(--brand-alt))
|
|
66
|
+
);
|
|
67
|
+
"
|
|
68
|
+
>
|
|
69
|
+
<img
|
|
70
|
+
v-if="picture"
|
|
71
|
+
:src="picture"
|
|
72
|
+
:alt="alt ?? ''"
|
|
73
|
+
class="h-full w-full object-cover"
|
|
74
|
+
/><template v-else>{{ initials }}</template>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as RecordAvatar } from './RecordAvatar.vue';
|