@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,262 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import { computed, onBeforeUnmount, ref, useId, watch } from 'vue';
|
|
4
|
+
import { MenuContent, MenuItem, MenuRoot, MenuTrigger, menuItemHintClass } from '../menu';
|
|
5
|
+
import { claimRowMenu, type RowAction } from './rowActions';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One row of a listing, with its actions. Every listing row exposes them twice and from the
|
|
9
|
+
* same `actions` array: a right-click anywhere on the row opens the menu at the cursor, and a
|
|
10
|
+
* visible kebab at the row's end opens it under itself, for the pointer that does not
|
|
11
|
+
* right-click and for the keyboard.
|
|
12
|
+
*
|
|
13
|
+
* **It composes the package's `menu/` family**, which the split button and the
|
|
14
|
+
* pager already use, and builds no positioning of its own. The source drew a `position: fixed`
|
|
15
|
+
* panel and did its own edge arithmetic; the open menu here is the family's `MenuRoot`,
|
|
16
|
+
* controlled, with one difference between the two paths: a right-click hands the panel a
|
|
17
|
+
* virtual reference (a zero-size rectangle at the cursor) through reka's `reference` prop, the
|
|
18
|
+
* kebab path leaves the panel anchored to the kebab. Both then take the same floating-ui
|
|
19
|
+
* collision logic, which flips a panel that would leave the window and shifts one that is too
|
|
20
|
+
* wide. That covers *where* the panel goes and nothing about how tall it is: flip and shift
|
|
21
|
+
* move a panel, and neither can make one shorter than its rows, so a menu with more actions
|
|
22
|
+
* than the window has room for is capped by `menu/menuClasses.ts` and scrolls — not by this
|
|
23
|
+
* file, but not by collision handling either. An earlier revision of this paragraph claimed
|
|
24
|
+
* height was covered too, and that sentence is why a panel with no cap at all shipped.
|
|
25
|
+
* (`ContextMenuRoot` would also open at a cursor, but it is a second root with a second set of
|
|
26
|
+
* items; one root and one `actions` loop is what makes the two paths the same menu.)
|
|
27
|
+
*
|
|
28
|
+
* KEYBOARD. The kebab is a tab stop; ArrowDown, Enter or Space opens the menu with focus on
|
|
29
|
+
* the first enabled action; the arrow keys move between actions and **stop at the ends** (the
|
|
30
|
+
* source wrapped, but a menu is the listbox shape in CLAUDE.md's "Keyboard ends" and this
|
|
31
|
+
* package's other menus clamp; wrapping is not kept by being asked for by nobody); Enter or
|
|
32
|
+
* Space chooses; Escape closes and returns focus to the kebab. No action is a tab stop (every
|
|
33
|
+
* row is `tabindex=-1`) and Tab is held inside the open menu, which is reka's modal menu, so
|
|
34
|
+
* the arrow keys are the only way between rows. A disabled action stays on the page, for its
|
|
35
|
+
* hint, and is never focused.
|
|
36
|
+
*
|
|
37
|
+
* THE HINT is drawn on the row, beside the label, and referenced by `aria-describedby`. It was
|
|
38
|
+
* a `title` attribute, and a `title` on a row reka marks `aria-disabled` and skips in arrow
|
|
39
|
+
* navigation is a reason only a pointer can read — on exactly the rows whose reason matters
|
|
40
|
+
* most, since `rowActions.ts` documents the hint as saying *why* an action is disabled. That is
|
|
41
|
+
* the same defect as the two unnamed pager arrows this family's slice found: information
|
|
42
|
+
* present for one input modality only.
|
|
43
|
+
*
|
|
44
|
+
* KNOWN DEPARTURE: with a menu open, a right-click on another row only closes it (the modal
|
|
45
|
+
* menu sets `pointer-events: none` on the body, so the row never sees the event); the source
|
|
46
|
+
* switched in one gesture. Changing the `modal` setting is standing in the fix's way: see
|
|
47
|
+
* `docs/design/README.md`, "Row actions".
|
|
48
|
+
*
|
|
49
|
+
* Opening one row's menu closes any other row's. Scrolling closes it: the panel is fixed to
|
|
50
|
+
* the window and would stay where it opened while its row moved away under it. The one
|
|
51
|
+
* exception is the panel's own scroll, which is how a capped long menu is read at all.
|
|
52
|
+
*
|
|
53
|
+
* COLOUR. The panel is `--popover`, the same as the other menus. `danger` is the destructive
|
|
54
|
+
* ink (`menu/menuClasses.ts` holds the rest), where the source named a fixed red. A highlighted
|
|
55
|
+
* danger row takes the ordinary highlighted ink, because the destructive one measures 4.495 on
|
|
56
|
+
* the highlight wash in kingfisher light. The kebab is
|
|
57
|
+
* `muted-foreground` at rest and carries the control-state recipe's focus ring.
|
|
58
|
+
*
|
|
59
|
+
* The kebab's glyph is the character the source drew. The package has no glyph of its own for
|
|
60
|
+
* it and a character is faithful, but the site is a named slot, `kebab-icon`, so a consumer
|
|
61
|
+
* can replace it. Its accessible name is `menuLabel`, falling back to the contract's
|
|
62
|
+
* `moreActions`.
|
|
63
|
+
*
|
|
64
|
+
* The row itself carries `data-slot="row-actions"` and the kebab is its direct child button,
|
|
65
|
+
* which are the hooks `density.css` reaches for inside a table cell.
|
|
66
|
+
*/
|
|
67
|
+
const props = withDefaults(
|
|
68
|
+
defineProps<{
|
|
69
|
+
actions: RowAction[];
|
|
70
|
+
/** The kebab's `data-testid`. */
|
|
71
|
+
kebabTestid?: string;
|
|
72
|
+
/** Accessible name of the kebab, which has no text of its own. Defaults to the contract's `moreActions`. */
|
|
73
|
+
menuLabel?: string;
|
|
74
|
+
}>(),
|
|
75
|
+
{ kebabTestid: 'kebab', menuLabel: undefined },
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
defineSlots<{
|
|
79
|
+
/** The row's own content, at the left of the kebab. */
|
|
80
|
+
default?: () => unknown;
|
|
81
|
+
/** The character on the kebab. Defaults to `⋮`. */
|
|
82
|
+
'kebab-icon'?: () => unknown;
|
|
83
|
+
}>();
|
|
84
|
+
|
|
85
|
+
const labels = useUiLabels();
|
|
86
|
+
|
|
87
|
+
const open = ref(false);
|
|
88
|
+
/** Where a right-click happened; `null` when the menu belongs to the kebab. */
|
|
89
|
+
const point = ref<{ x: number; y: number } | null>(null);
|
|
90
|
+
/** This instance's prefix for hint ids, so two rows on a page never share one. */
|
|
91
|
+
const uid = useId();
|
|
92
|
+
|
|
93
|
+
// A zero-size rectangle at the cursor, which is all floating-ui asks of a reference.
|
|
94
|
+
const reference = computed(() => {
|
|
95
|
+
const at = point.value;
|
|
96
|
+
if (at === null) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
getBoundingClientRect: () =>
|
|
101
|
+
({
|
|
102
|
+
x: at.x,
|
|
103
|
+
y: at.y,
|
|
104
|
+
left: at.x,
|
|
105
|
+
right: at.x,
|
|
106
|
+
top: at.y,
|
|
107
|
+
bottom: at.y,
|
|
108
|
+
width: 0,
|
|
109
|
+
height: 0,
|
|
110
|
+
toJSON: () => ({}),
|
|
111
|
+
}) as DOMRect,
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
function openAtPointer(event: MouseEvent): void {
|
|
116
|
+
point.value = { x: event.clientX, y: event.clientY };
|
|
117
|
+
open.value = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Reka's own toggles (the kebab, Escape, an outside press, a chosen row) come through here,
|
|
121
|
+
// and none of them has a cursor.
|
|
122
|
+
function onUpdateOpen(next: boolean): void {
|
|
123
|
+
if (next) {
|
|
124
|
+
point.value = null;
|
|
125
|
+
}
|
|
126
|
+
open.value = next;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Reka's default focuses the panel itself on a pointer open and the first row on a key open.
|
|
130
|
+
// The source put focus on the first action either way, and a right-click that leaves nothing
|
|
131
|
+
// focused is a menu a keyboard user has to find first.
|
|
132
|
+
function focusFirstAction(event: Event): void {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
const panel = event.target as HTMLElement | null;
|
|
135
|
+
const first = panel?.querySelector<HTMLElement>('[role="menuitem"]:not([data-disabled])');
|
|
136
|
+
(first ?? panel)?.focus({ preventScroll: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function closeMenu(): void {
|
|
140
|
+
open.value = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A scroll anywhere but inside the panel closes the menu, because the panel is fixed to the
|
|
145
|
+
* window and its row would move away under it. The panel's **own** scroll is the exception and
|
|
146
|
+
* not a nicety: a menu longer than the window caps its height and scrolls inside that cap
|
|
147
|
+
* (`menu/menuClasses.ts`), and the capture listener below sees that scroll like any other — so
|
|
148
|
+
* without this guard the first ArrowDown past the cap closes the menu, and the rows the cap
|
|
149
|
+
* exists to reach are unreachable again by a second route. Measured in a browser: a 24-action
|
|
150
|
+
* menu in a 520px window scrolls 842px of rows inside a 245px panel, and every scroll of it
|
|
151
|
+
* dismissed the menu until this check was added.
|
|
152
|
+
*/
|
|
153
|
+
function onScrollAnywhere(event: Event): void {
|
|
154
|
+
const target = event.target;
|
|
155
|
+
if (target instanceof Element && target.closest('[data-slot="menu-content"]') !== null) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
closeMenu();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let release: (() => void) | undefined;
|
|
162
|
+
watch(open, (isOpen) => {
|
|
163
|
+
release?.();
|
|
164
|
+
release = undefined;
|
|
165
|
+
if (isOpen) {
|
|
166
|
+
release = claimRowMenu(closeMenu);
|
|
167
|
+
// Capture: a scroll inside any box (a table's own) does not bubble.
|
|
168
|
+
window.addEventListener('scroll', onScrollAnywhere, true);
|
|
169
|
+
} else {
|
|
170
|
+
window.removeEventListener('scroll', onScrollAnywhere, true);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
onBeforeUnmount(() => {
|
|
175
|
+
release?.();
|
|
176
|
+
window.removeEventListener('scroll', onScrollAnywhere, true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
function itemClass(action: RowAction): string | undefined {
|
|
180
|
+
if (action.disabled === true) {
|
|
181
|
+
// Nothing. A disabled row is the shared recipe's `opacity-50` over
|
|
182
|
+
// `--popover-foreground` and no more: an earlier revision added `text-muted-foreground`
|
|
183
|
+
// on top of that opacity, which halved the label against the panel — 1.96-2.92 where the
|
|
184
|
+
// shared form reads 3.33-5.12, in the six theme/mode pairs. Both are WCAG-exempt, so no
|
|
185
|
+
// gate saw it, and `portability.test.ts` cannot: it checks the opacity token, not an ink
|
|
186
|
+
// change. A disabled row in one menu reading as a different kind of unavailable from a
|
|
187
|
+
// disabled row in the next is exactly what the recipe exists to prevent.
|
|
188
|
+
//
|
|
189
|
+
// `cursor-not-allowed` and `data-disabled:pointer-events-auto` went with it: both were
|
|
190
|
+
// there so a `title` tooltip could be hovered, and the reason is now on the row itself.
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
// The destructive ink is the row's resting ink only. Highlighted, the row takes the shared
|
|
194
|
+
// `accent-foreground` (12.80 to 16.42): `--destructive` on the `--accent` wash is **4.495**
|
|
195
|
+
// in kingfisher light, under the 4.5 a 12.5px label needs (it is 4.64 to 5.76 in the other
|
|
196
|
+
// five pairs, and 4.90 to 6.86 on the popover at rest).
|
|
197
|
+
return action.danger === true ? 'text-destructive' : undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The quiet text beside a label, for an action that carries a hint. On an enabled row it is the
|
|
202
|
+
* package's hint ink. On a **disabled** row it is the row's own ink at the row's own fade and
|
|
203
|
+
* nothing more, for the reason the disabled row above takes no ink of its own: the row is
|
|
204
|
+
* already at `opacity-50`, and the quiet ink underneath that fade measures 1.96-2.92 against the
|
|
205
|
+
* panel where the row's own reads 3.33-5.12. The reason an action is unavailable is the last
|
|
206
|
+
* thing to dim twice.
|
|
207
|
+
*/
|
|
208
|
+
function hintClass(action: RowAction): string {
|
|
209
|
+
return action.disabled === true ? 'text-[11px]' : menuItemHintClass;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** A hint's own id, so the row can point `aria-describedby` at it. */
|
|
213
|
+
function hintId(index: number): string {
|
|
214
|
+
return `${uid}-hint-${index}`;
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
<template>
|
|
219
|
+
<div
|
|
220
|
+
data-slot="row-actions"
|
|
221
|
+
class="border-border relative flex items-center gap-3 border-b py-2.5 last:border-b-0"
|
|
222
|
+
@contextmenu.prevent="openAtPointer"
|
|
223
|
+
>
|
|
224
|
+
<slot />
|
|
225
|
+
<MenuRoot :open="open" @update:open="onUpdateOpen">
|
|
226
|
+
<MenuTrigger as-child>
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
:data-testid="props.kebabTestid"
|
|
230
|
+
:aria-label="props.menuLabel ?? labels.moreActions"
|
|
231
|
+
class="text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background ml-auto rounded-md px-1.5 py-0.5 text-lg leading-none transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2"
|
|
232
|
+
>
|
|
233
|
+
<slot name="kebab-icon">⋮</slot>
|
|
234
|
+
</button>
|
|
235
|
+
</MenuTrigger>
|
|
236
|
+
<MenuContent
|
|
237
|
+
:reference="reference"
|
|
238
|
+
:align="reference === undefined ? 'end' : 'start'"
|
|
239
|
+
class="min-w-36"
|
|
240
|
+
@open-auto-focus="focusFirstAction"
|
|
241
|
+
>
|
|
242
|
+
<MenuItem
|
|
243
|
+
v-for="(action, index) in props.actions"
|
|
244
|
+
:key="action.testid ?? index"
|
|
245
|
+
:data-testid="action.testid"
|
|
246
|
+
:disabled="action.disabled === true"
|
|
247
|
+
:aria-describedby="action.hint === undefined ? undefined : hintId(index)"
|
|
248
|
+
:class="itemClass(action)"
|
|
249
|
+
@select="action.handler()"
|
|
250
|
+
>
|
|
251
|
+
<span>{{ action.label }}</span>
|
|
252
|
+
<span
|
|
253
|
+
v-if="action.hint !== undefined"
|
|
254
|
+
:id="hintId(index)"
|
|
255
|
+
:class="hintClass(action)"
|
|
256
|
+
>{{ action.hint }}</span
|
|
257
|
+
>
|
|
258
|
+
</MenuItem>
|
|
259
|
+
</MenuContent>
|
|
260
|
+
</MenuRoot>
|
|
261
|
+
</div>
|
|
262
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface RowAction {
|
|
2
|
+
label: string;
|
|
3
|
+
handler: () => void;
|
|
4
|
+
/** Draws the row in the destructive ink: a delete, a revoke. */
|
|
5
|
+
danger?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Stable `data-testid` for the menu item, for tests that can't rely on label text. It is
|
|
8
|
+
* also the row's render key where it is given, which is the one reason to set it on a row
|
|
9
|
+
* no test names: two rows labelled the same — an ordinary "Delete" in two groups — would
|
|
10
|
+
* otherwise collide and let Vue reuse the wrong node, moving the danger ink, the disabled
|
|
11
|
+
* state and the hint onto a neighbour. Without it the key falls back to the index.
|
|
12
|
+
*/
|
|
13
|
+
testid?: string;
|
|
14
|
+
/** Renders the item greyed out and non-interactive; its `handler` is never invoked. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A short reason drawn on the row beside its label, typically explaining why the action is
|
|
18
|
+
* disabled, and referenced by the row's `aria-describedby`. It is not a tooltip: a disabled
|
|
19
|
+
* row is never focusable, so a `title` on it reaches a pointer and nobody else.
|
|
20
|
+
*/
|
|
21
|
+
hint?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Only one row menu may be open at a time across ALL instances. Reka's modal menu already
|
|
25
|
+
// dismisses an open one on any pointer press outside it, but a right-click on a second row is
|
|
26
|
+
// swallowed by that dismissal, and an open driven from code (a test, a page) presses nothing;
|
|
27
|
+
// this registry is what closes the first in every case.
|
|
28
|
+
let closeActive: (() => void) | null = null;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Claims the one open slot for a menu, closing whichever menu held it. Returns the release a
|
|
32
|
+
* menu calls when it has closed itself.
|
|
33
|
+
*/
|
|
34
|
+
export function claimRowMenu(close: () => void): () => void {
|
|
35
|
+
if (closeActive !== null && closeActive !== close) {
|
|
36
|
+
closeActive();
|
|
37
|
+
}
|
|
38
|
+
closeActive = close;
|
|
39
|
+
return () => {
|
|
40
|
+
if (closeActive === close) {
|
|
41
|
+
closeActive = null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|