@motifx-community/ui 0.1.0-beta.10 → 0.1.0-beta.11
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/CHANGELOG.md +10 -0
- package/dist/components/toolbar/Toolbar.d.ts +2 -2
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/docs/accordion.md +1 -1
- package/docs/actionsheet.md +1 -1
- package/docs/appbar.md +1 -1
- package/docs/appmenu-api.md +1 -1
- package/docs/appmenu-programmatic.md +1 -1
- package/docs/appmenu-search.md +1 -1
- package/docs/appmenu.md +1 -1
- package/docs/avatar.md +1 -1
- package/docs/badge.md +1 -1
- package/docs/bar-gauge-angles.md +1 -1
- package/docs/bar-gauge-data.md +1 -1
- package/docs/bar-gauge-labels.md +1 -1
- package/docs/bar-gauge.md +1 -1
- package/docs/barcode.md +1 -1
- package/docs/bottomnavigation.md +1 -1
- package/docs/bottomsheet.md +1 -1
- package/docs/breadcrumb.md +1 -1
- package/docs/button.md +2 -2
- package/docs/buttongroup.md +1 -1
- package/docs/buttons.md +3 -5
- package/docs/calendar.md +1 -1
- package/docs/card.md +1 -1
- package/docs/chart-bars.md +1 -1
- package/docs/chart-candles.md +1 -1
- package/docs/chart-funnel.md +1 -1
- package/docs/chart-heatmap.md +1 -1
- package/docs/chart-lines.md +1 -1
- package/docs/chart-live.md +1 -1
- package/docs/chart-pie.md +1 -1
- package/docs/chart-radar.md +1 -1
- package/docs/chart-ranges.md +1 -1
- package/docs/chart-references.md +1 -1
- package/docs/chart-scatter.md +1 -1
- package/docs/chart-waterfall.md +1 -1
- package/docs/chart-zoom.md +1 -1
- package/docs/chart.md +1 -1
- package/docs/checkbox.md +1 -1
- package/docs/chip.md +1 -1
- package/docs/choice.md +1 -1
- package/docs/colorbox.md +1 -1
- package/docs/combobox.md +1 -1
- package/docs/commands.md +126 -0
- package/docs/control.md +1 -1
- package/docs/data.md +1 -1
- package/docs/datagrid-api.md +3 -3
- package/docs/datagrid-bands.md +1 -1
- package/docs/datagrid-drag-select.md +1 -1
- package/docs/datagrid-drag.md +1 -1
- package/docs/datagrid-editing.md +107 -1
- package/docs/datagrid-filtering.md +11 -3
- package/docs/datagrid-forms.md +1 -1
- package/docs/datagrid-grouping.md +1 -1
- package/docs/datagrid-layout.md +2 -2
- package/docs/datagrid-lookups.md +1 -1
- package/docs/datagrid-master-detail.md +1 -1
- package/docs/datagrid-scrolling.md +1 -1
- package/docs/datagrid-selection.md +1 -1
- package/docs/datagrid.md +1 -1
- package/docs/datebox.md +1 -1
- package/docs/daterangebox.md +1 -1
- package/docs/display.md +1 -1
- package/docs/draggable.md +1 -1
- package/docs/drawer.md +1 -1
- package/docs/dropdown.md +1 -1
- package/docs/editors.md +3 -1
- package/docs/feedback.md +1 -1
- package/docs/fileuploader.md +1 -1
- package/docs/filterbuilder.md +1 -1
- package/docs/formlayout.md +1 -1
- package/docs/foundations.md +1 -1
- package/docs/gallery.md +1 -1
- package/docs/gauge-base.md +1 -1
- package/docs/gauge-circular.md +1 -1
- package/docs/gauge-dashboards.md +1 -1
- package/docs/gauge-linear.md +1 -1
- package/docs/gauge-markers.md +1 -1
- package/docs/gauge-marks.md +1 -1
- package/docs/gauge-ranges.md +1 -1
- package/docs/gauge-scales.md +1 -1
- package/docs/gauge.md +1 -1
- package/docs/home.md +2 -2
- package/docs/keyboard.md +5 -3
- package/docs/language.md +2 -2
- package/docs/layout.md +1 -1
- package/docs/listbox.md +1 -1
- package/docs/loadpanel.md +2 -2
- package/docs/lookup.md +1 -1
- package/docs/menus-api.md +142 -0
- package/docs/menus-context.md +126 -0
- package/docs/menus-customization.md +138 -0
- package/docs/menus-merging.md +208 -0
- package/docs/menus-programmatic.md +74 -0
- package/docs/menus.md +22 -179
- package/docs/multiview.md +1 -1
- package/docs/navigation.md +7 -2
- package/docs/numberbox.md +3 -3
- package/docs/otpinput.md +1 -1
- package/docs/pagination.md +1 -1
- package/docs/popover.md +1 -1
- package/docs/progress.md +3 -3
- package/docs/qrcode.md +1 -1
- package/docs/radiogroup.md +1 -1
- package/docs/rating.md +1 -1
- package/docs/resizable.md +1 -1
- package/docs/ribbonmenu-api.md +1 -1
- package/docs/ribbonmenu-commands.md +1 -1
- package/docs/ribbonmenu-customization.md +1 -1
- package/docs/ribbonmenu-display.md +1 -1
- package/docs/ribbonmenu-layouts.md +1 -1
- package/docs/ribbonmenu-programmatic.md +1 -1
- package/docs/ribbonmenu.md +1 -1
- package/docs/scheduler-agenda.md +1 -1
- package/docs/scheduler-big-data.md +1 -1
- package/docs/scheduler-editing.md +1 -1
- package/docs/scheduler-form.md +1 -1
- package/docs/scheduler-icalendar.md +1 -1
- package/docs/scheduler-mobile.md +1 -1
- package/docs/scheduler-recurrence.md +1 -1
- package/docs/scheduler-resources.md +1 -1
- package/docs/scheduler-timeline.md +1 -1
- package/docs/scheduler.md +1 -1
- package/docs/scrollview.md +1 -1
- package/docs/shortcuteditor.md +248 -0
- package/docs/showcase-home.md +1 -1
- package/docs/showcase.md +1 -1
- package/docs/signature.md +1 -1
- package/docs/skeleton.md +1 -1
- package/docs/slider.md +3 -3
- package/docs/sortable.md +1 -1
- package/docs/sparkline.md +1 -1
- package/docs/speeddial.md +1 -1
- package/docs/splitter.md +1 -1
- package/docs/stepper.md +1 -1
- package/docs/switch.md +1 -1
- package/docs/tabdocs-dock.md +1 -1
- package/docs/tabdocs-drag.md +1 -1
- package/docs/tabdocs-menus.md +1 -1
- package/docs/tabdocs-mobile.md +1 -1
- package/docs/tabdocs-tabs.md +1 -1
- package/docs/tabdocs-windows.md +1 -1
- package/docs/tabdocs-workspace.md +1 -1
- package/docs/tabdocs.md +1 -1
- package/docs/tabs.md +1 -1
- package/docs/tagbox.md +1 -1
- package/docs/textarea.md +1 -1
- package/docs/textbox.md +1 -1
- package/docs/tileview.md +1 -1
- package/docs/timeline.md +1 -1
- package/docs/toast.md +1 -1
- package/docs/tokens.md +13 -1
- package/docs/toolbar.md +1 -1
- package/docs/tooltip.md +1 -1
- package/docs/treeview.md +1 -1
- package/docs/validationsummary.md +1 -1
- package/docs/window.md +1 -1
- package/docs/wizard.md +1 -1
- package/llms-full.txt +3774 -2692
- package/llms.txt +16 -6
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# MenuBar: API reference
|
|
2
|
+
|
|
3
|
+
> MenuBar · @motifx-community/ui 0.1.0-beta.10
|
|
4
|
+
|
|
5
|
+
Every prop, property, method and event of `MenuBar` and `ContextMenu`, the fields of a menu item, and the styling hooks and tokens.
|
|
6
|
+
|
|
7
|
+
## MenuBar props
|
|
8
|
+
|
|
9
|
+
| Prop | Type | Default | Description |
|
|
10
|
+
| --- | --- | --- | --- |
|
|
11
|
+
| `items` | `Bind<readonly MenuItem[]>` | `[]` | The top-level items, whose `items` define the menus they open. A top-level item without `items` runs its `click`. |
|
|
12
|
+
| `label` | `Bind<string>` | `''` | The accessible name of the bar. This is the same property as `text`. |
|
|
13
|
+
| `focusOnF10` | `Bind<boolean>` | `false` | F10 moves focus to the bar from anywhere on the page. This is off by default because browsers use F10. |
|
|
14
|
+
| `openOnHover` | `Bind<boolean>` | `true` | While a menu is open, hovering another top-level item opens its menu, and hovering an item opens its submenu. |
|
|
15
|
+
| `customizable` | `Bind<boolean>` | `false` | The user can hide and move items from the menu of a right-click or Shift+F10. Each item can say otherwise. |
|
|
16
|
+
| `customization` | `Bind<MenuBarCustomization \| null>` | `null` | What the user changed, as `onCustomized` reported it, to restore. |
|
|
17
|
+
| `commands` | `Bind<readonly MenuItem[]>` | The app’s commands | The commands the user can add in the customizer, each with a `key`. |
|
|
18
|
+
| `customizer` | `Bind<boolean>` | `true` | The menu of a right-click offers the customizer when `customizable` is on. |
|
|
19
|
+
| `customizerKeyboard` | `Bind<boolean>` | `true` | The customizer has a Keyboard page ([ShortcutEditor](shortcuteditor.md)). |
|
|
20
|
+
| `mergeHost` | `Bind<boolean>` | `false` | The app’s bar: other bars merge their items into it. |
|
|
21
|
+
| `mergeName` | `Bind<string>` | `'main'` | The name of the app’s bar, when there are several. |
|
|
22
|
+
| `mergeInto` | `Bind<string \| MenuBar \| null>` | `null` | The app’s bar to merge into: its name or the bar itself. |
|
|
23
|
+
| `mergeWhen` | `Bind<'shown' \| 'focus' \| 'manual'>` | `'shown'` | When the bar merges. |
|
|
24
|
+
| `mergeScope` | `Bind<ComponentBase \| null>` | Its parent | The place whose being shown or focused merges the bar. |
|
|
25
|
+
| `hideWhenMerged` | `Bind<boolean>` | `true` | The bar is hidden while it is merged. |
|
|
26
|
+
| `enabled / disabled, visible, tabStop, tabIndex` | see Control | | Properties shared by all controls. |
|
|
27
|
+
|
|
28
|
+
## ContextMenu props
|
|
29
|
+
|
|
30
|
+
| Prop | Type | Default | Description |
|
|
31
|
+
| --- | --- | --- | --- |
|
|
32
|
+
| `items` | `Bind<readonly MenuItem[]>` | `[]` | The commands. `onOpening` can provide different ones for each component. |
|
|
33
|
+
| `target` | `Bind<Component \| null>` | Its parent | The component the menu belongs to. If not set, this is the component the `ContextMenu` is placed in. |
|
|
34
|
+
| `label` | `Bind<string>` | `''` | The accessible name of the menu. |
|
|
35
|
+
| `keyboard` | `Bind<boolean>` | `true` | The Menu key and Shift+F10 open the menu at the focused element. |
|
|
36
|
+
| `closeOnScroll` | `Bind<boolean>` | `true` | Scrolling the element out of view closes the menu. Until then, the menu follows the element. |
|
|
37
|
+
| `openOnHover` | `Bind<boolean>` | `true` | Hovering an item opens its submenu. |
|
|
38
|
+
| `enabled` | `Bind<boolean>` | `true` | `false` shows the browser’s own menu. |
|
|
39
|
+
|
|
40
|
+
## MenuItem
|
|
41
|
+
|
|
42
|
+
| Field | Type | Description |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| `key` | `string \| number` | Names the item in paths (`file/save`), in what the user changed and in merging. Without it, an item is named by its position. |
|
|
45
|
+
| `text` | `Bind<string>` | The label. `&Copy` makes C select the item while the menu is open (Alt+C on a top-level menu bar item). |
|
|
46
|
+
| `command` | `string` | The key of an app command (`commands`). What the item is not given, such as its text, icon, keys, state and action, comes from the command. |
|
|
47
|
+
| `icon, hint` | `Bind<…>` | An icon at the start, and a tooltip. |
|
|
48
|
+
| `shortcut` | `Bind<string>` | A key combination displayed at the end (`Ctrl+S`). It is for display only: register the key with `addShortcut`, or name a command, whose keys are shown and run. |
|
|
49
|
+
| `description` | `Bind<string>` | A second, dimmer text after the label that distinguishes the item, such as a folder name. It is part of the item’s name and never a key. |
|
|
50
|
+
| `items` | `Bind<readonly MenuItem[]>` | A submenu that opens at the side. |
|
|
51
|
+
| `checked` | `Bind<boolean>` | A check item (`menuitemcheckbox`). |
|
|
52
|
+
| `group` | `Bind<string>` | With `checked`, one choice in a group (`menuitemradio`), shown with a dot. |
|
|
53
|
+
| `enabled, visible` | `Bind<boolean>` | Dims the item so it cannot be selected, or removes it. |
|
|
54
|
+
| `beginGroup` | `Bind<boolean>` | Draws a separator before the item. |
|
|
55
|
+
| `tone` | `Bind<'standard' \| 'accent' \| 'success' \| 'caution' \| 'danger'>` | Colors the item with a kit tone (`danger` for destructive actions). A toolbar button moved into the overflow menu keeps its tone. |
|
|
56
|
+
| `customizable` | `Bind<boolean>` | `false` keeps the item shown and in its place in a customizable bar; nothing moves past it. |
|
|
57
|
+
| `merge` | `Bind<'auto' \| 'add' \| 'replace' \| 'remove' \| 'none'>` | In a bar merged into another: what the item does there. The default is `auto`. |
|
|
58
|
+
| `mergeAt` | `Bind<number \| { before } \| { after }>` | In a bar merged into another: where the item stands there. The default is the end. |
|
|
59
|
+
| `click` | `(e) => void` | Occurs when the item is selected, after the menu closes. `e`: `{ item, source, event }`. |
|
|
60
|
+
| `data` | `unknown` | A custom value. |
|
|
61
|
+
|
|
62
|
+
## Properties
|
|
63
|
+
|
|
64
|
+
| Property | Access | Description |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `MenuBar.openItem` | read-only, reactive | The top-level item whose menu is open. |
|
|
67
|
+
| `MenuBar.mergedBars` | read-only | On the app’s bar: the bars merged into it, in the order they came. |
|
|
68
|
+
| `MenuBar.mergedInto` | read-only | On a bar that merges: the app’s bar it is merged into, or `null`. |
|
|
69
|
+
| `MenuBar.mergedItems` | read-only | The top-level items as drawn now, the merged bars’ included. |
|
|
70
|
+
| `ContextMenu.opened` | read-only, reactive | Indicates whether it is open. |
|
|
71
|
+
| `ContextMenu.targetPart` | read-only, reactive | The component the menu was last opened on. |
|
|
72
|
+
| `ContextMenu.target` | read/write, reactive | The component the menu listens on. |
|
|
73
|
+
|
|
74
|
+
## Methods
|
|
75
|
+
|
|
76
|
+
| Method | Returns | Description |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `MenuBar.open(item \| index \| key)` | `boolean` | Opens a top-level item’s menu with focus on its first item. |
|
|
79
|
+
| `MenuBar.close()` | `void` | Closes the open menu. |
|
|
80
|
+
| `MenuBar.findItem(path)` | `MenuItem \| null` | The item at the path, as it is now. |
|
|
81
|
+
| `MenuBar.addItem(parentPath, item, index?)` | `boolean` | Adds an item to the menu at `parentPath` (the bar when empty). |
|
|
82
|
+
| `MenuBar.removeItem(path)` | `boolean` | Removes the item with its menu. |
|
|
83
|
+
| `MenuBar.moveItem(path, index, toParent?)` | `boolean` | Moves the item in its menu or into another one. |
|
|
84
|
+
| `MenuBar.updateItem(path, changes)` | `boolean` | Changes fields of the item. |
|
|
85
|
+
| `MenuBar.beginUpdate(), endUpdate()` | `void` | Applies the changes made between them at once. |
|
|
86
|
+
| `MenuBar.openCustomizer()` | `boolean` | Opens the customizer window. Returns `false` when it is already open. |
|
|
87
|
+
| `MenuBar.merge(), unmerge()` | `boolean` | Merges the bar into the app’s bar, or takes its items back. |
|
|
88
|
+
| `MenuBar.refresh(), ContextMenu.refresh()` | `void` | Reads items changed in place again. The bar, the open menu and its submenus update. |
|
|
89
|
+
| `ContextMenu.open(at, target?)` | `boolean` | Opens the menu programmatically, at `{ x, y }` or at a component. |
|
|
90
|
+
| `ContextMenu.close()` | `void` | Closes it. |
|
|
91
|
+
| `attachContextMenu(target, items)` | `() => void` | Attaches a menu to a component. `items` can be a function of the opening event (`e.part`). Returns a function that removes the menu. |
|
|
92
|
+
|
|
93
|
+
## Events
|
|
94
|
+
|
|
95
|
+
| Event | When |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `onItemClick(e)` | On both components, occurs when an item is selected, after its own `click`. `e`: `{ item, source, event }`. |
|
|
98
|
+
| `MenuBar.onCustomized(e)` | The user changed the bar. `e`: `{ customization, source }`, everything changed so far. |
|
|
99
|
+
| `MenuBar.onCustomMenuOpening(e)` | Before the menu of a right-click opens. `e`: `{ item, path, items, cancel, byKeyboard, event, source }`. |
|
|
100
|
+
| `MenuBar.onItemsChanged(e)` | After a change by path. `e`: `{ items, source }`, the new list to keep. |
|
|
101
|
+
| `MenuBar.onMerged(e), onUnmerged(e)` | On the app’s bar: a bar merged into it or left it. `e`: `{ bar, source }`. |
|
|
102
|
+
| `ContextMenu.onOpening(e)` | Occurs before the menu opens. `e`: `{ part, items, cancel, byKeyboard, event, source }`. Set `e.items` for the component `part`, or set `e.cancel = true`. |
|
|
103
|
+
| `ContextMenu.onClosed(reason)` | `escape`, `outside`, `focus` or `code`. |
|
|
104
|
+
|
|
105
|
+
## Keyboard
|
|
106
|
+
|
|
107
|
+
| Key | Description |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `Tab` | Moves focus into the menu bar (one Tab stop) and out of it. |
|
|
110
|
+
| `Left / Right` | On the bar, moves to the previous or next top-level item. In a menu, moves to the adjacent menu or closes a submenu (Right opens one). These keys are mirrored on right-to-left pages. |
|
|
111
|
+
| `Down, Enter, Space` | On the bar, opens the menu on its first item. Up opens it on the last item. |
|
|
112
|
+
| `Up / Down, Home / End` | In a menu, moves between items and wraps at the ends. |
|
|
113
|
+
| `A letter` | Moves to the next item that starts with that letter. An item’s `&` key selects it. |
|
|
114
|
+
| `Alt + key` | Opens the top-level item with that `&` key (Control + Option on Apple platforms). |
|
|
115
|
+
| `Escape` | Closes a submenu, then the menu, and returns to where it opened. |
|
|
116
|
+
| `F10` | Moves focus to the menu bar when `focusOnF10` is set. |
|
|
117
|
+
| `Menu key, Shift+F10` | Opens a context menu at the focused element; on a customizable bar, the menu of the focused item. |
|
|
118
|
+
|
|
119
|
+
## Styling
|
|
120
|
+
|
|
121
|
+
| Hook | Description |
|
|
122
|
+
| --- | --- |
|
|
123
|
+
| `.mx-menubar, .mx-menubar__bar, .mx-menubar__item` | The menu bar, its row and a top-level item (`aria-expanded="true"` while open). |
|
|
124
|
+
| `.mx-context-menu, .mx-context-menu__anchor` | The context menu, which has no box of its own, and the point it opens at. |
|
|
125
|
+
| `.mx-menu, .mx-menu__item, .mx-menu__separator` | A menu (shared with Button), an item and a separator. |
|
|
126
|
+
| `.mx-menu__check, .mx-menu__icon, .mx-menu__label, .mx-menu__description, .mx-menu__shortcut, .mx-menu__arrow` | The parts of an item. |
|
|
127
|
+
| `.mx-customizer__pages, .mx-customizer__tree, .mx-customizer__commands` | The customizer window: its pages, the tree of items and the list of commands. |
|
|
128
|
+
|
|
129
|
+
### Component tokens
|
|
130
|
+
|
|
131
|
+
| Token | Description |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `menubar.height, menubar.item-height` | The height of the bar and of a top-level item. |
|
|
134
|
+
| `menubar.bar, menubar.item, menubar.icon, menubar.mnemonic` | Units: the bar, a top-level item with its box per state (`hover`, `pressed`, `open`, `disabled`, `focus`), its icon, and its access key indicator (`shown`). |
|
|
135
|
+
| `menu.item, menu.item-height, menu.item-white-space` | Menu items, shared with the Button menu: the item unit in each state (`highlight`, `pressed`, `focus`, `checked`, `disabled`, `first`, `last`, each tone and `<tone>-highlight`), the row height, and text wrapping. |
|
|
136
|
+
| `menu.panel, menu.check, menu.icon, menu.check-mark, menu.radio-mark, menu.separator` | Units: the item column, the leading indicator and icon, the check and radio marks, and the separator between groups. |
|
|
137
|
+
| `menu.label, menu.description, menu.shortcut, menu.arrow` | Units: the item text, its description, the shortcut and the submenu arrow. |
|
|
138
|
+
| `customizer.page, .buttons, .footer` | Units: the gaps of a customizer page, of the buttons of its forms and of its footer. |
|
|
139
|
+
|
|
140
|
+
## Feedback
|
|
141
|
+
|
|
142
|
+
Loading issues…
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# MenuBar: ContextMenu
|
|
2
|
+
|
|
3
|
+
> MenuBar · @motifx-community/ui 0.1.0-beta.10
|
|
4
|
+
|
|
5
|
+
The menu of an element: it opens on a right-click at the pointer, and with the Menu key or Shift+F10 at the focused element. Its items are the same as those of a menu bar.
|
|
6
|
+
|
|
7
|
+
## A menu for each row
|
|
8
|
+
|
|
9
|
+
A `ContextMenu` placed in an element belongs to it (`target` can name another). `onOpening` builds the items for the component under the pointer, in this case a row in a list: a locked file cannot be renamed. Setting `e.cancel = true` outside a row leaves the browser’s own menu.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { reactive, type Component, type ComponentBase } from '@motifx/core';
|
|
13
|
+
import { ContextMenu, type MenuItem } from '@motifx-community/ui';
|
|
14
|
+
|
|
15
|
+
interface FileRow {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string;
|
|
18
|
+
locked: boolean;
|
|
19
|
+
starred: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const BOX = 'inline-size: 100%; margin: 0; list-style: none; padding: var(--mx-space-4); background: var(--mx-color-bg-card); border: var(--mx-border-width-1) solid var(--mx-color-stroke-card); border-radius: var(--mx-radius-lg)';
|
|
23
|
+
|
|
24
|
+
/** A context menu whose items `onOpening` builds for the row of a list it opens on. */
|
|
25
|
+
export default function FileList() {
|
|
26
|
+
const s = reactive({
|
|
27
|
+
log: 'Nothing chosen yet.',
|
|
28
|
+
files: [
|
|
29
|
+
{ id: 1, name: 'report.docx', locked: false, starred: true },
|
|
30
|
+
{ id: 2, name: 'budget.xlsx', locked: true, starred: false },
|
|
31
|
+
{ id: 3, name: 'photo.png', locked: false, starred: false },
|
|
32
|
+
] as FileRow[],
|
|
33
|
+
});
|
|
34
|
+
let renamed = 0;
|
|
35
|
+
let list: Component<HTMLUListElement> | null = null;
|
|
36
|
+
|
|
37
|
+
const did = (what: string) => (s.log = what);
|
|
38
|
+
const rename = (row: FileRow) => {
|
|
39
|
+
row.name = `copy-${++renamed}-${row.name}`;
|
|
40
|
+
did(`Renamed to ${row.name}`);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const rowItems = (row: FileRow): MenuItem[] => [
|
|
44
|
+
{ text: '&Open', click: () => did(`Open ${row.name}`) },
|
|
45
|
+
{ text: '&Rename', enabled: !row.locked, click: () => rename(row) },
|
|
46
|
+
{ text: '&Star', checked: row.starred, click: () => (row.starred = !row.starred) },
|
|
47
|
+
{ text: '&Move to', items: ['Documents', 'Pictures', 'Archive'].map((folder) => ({ text: folder, click: () => did(`Move ${row.name} to ${folder}`) })) },
|
|
48
|
+
{ text: '&Delete', shortcut: 'Del', beginGroup: true, enabled: !row.locked, click: () => (s.files = s.files.filter((f) => f !== row)) },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const rowOf = (part: ComponentBase) => {
|
|
52
|
+
let id: string | null = null;
|
|
53
|
+
for (let at: ComponentBase | null = part; at && !id; at = at.parent) id = at.attr.get('data-id');
|
|
54
|
+
return s.files.find((f) => f.id === Number(id));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<ul class="cm-list" aria-label="Files" ref={(c: Component<HTMLUListElement>) => (list = c)} style={BOX}>
|
|
60
|
+
{s.files.map((file) => (
|
|
61
|
+
<li key={file.id} data-id={String(file.id)} tabindex="0" style="padding-block: var(--mx-space-2)">
|
|
62
|
+
{() => `${file.starred ? '★ ' : ''}${file.name}${file.locked ? ' (locked)' : ''}`}
|
|
63
|
+
</li>
|
|
64
|
+
))}
|
|
65
|
+
</ul>
|
|
66
|
+
<ContextMenu
|
|
67
|
+
target={() => list}
|
|
68
|
+
label="File"
|
|
69
|
+
onOpening={(e) => {
|
|
70
|
+
const row = rowOf(e.part);
|
|
71
|
+
if (row) e.items = rowItems(row);
|
|
72
|
+
else e.cancel = true;
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
<output class="cm-log">{() => s.log}</output>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## attachContextMenu
|
|
82
|
+
|
|
83
|
+
`attachContextMenu(target, items)` attaches a menu to a component without placing another one. `items` can be a function of the opening event. It returns a function that removes the menu.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { reactive, type Component } from '@motifx/core';
|
|
87
|
+
import { attachContextMenu } from '@motifx-community/ui';
|
|
88
|
+
|
|
89
|
+
const START = 'Right-click here, or focus me and press the Menu key.';
|
|
90
|
+
const BOX = 'padding: var(--mx-space-4); background: var(--mx-color-bg-card); border: var(--mx-border-width-1) solid var(--mx-color-stroke-card); border-radius: var(--mx-radius-lg)';
|
|
91
|
+
|
|
92
|
+
/** A menu given to a component with `attachContextMenu`, its items built from the opening. */
|
|
93
|
+
export default function AttachedMenu() {
|
|
94
|
+
const s = reactive({ zone: START });
|
|
95
|
+
|
|
96
|
+
const attach = (c: Component<HTMLDivElement>) => {
|
|
97
|
+
const remove = attachContextMenu(c, (e) => [
|
|
98
|
+
{ text: '&Say where', click: () => (s.zone = `Opened ${e.byKeyboard ? 'from the keyboard' : 'with the pointer'} on ${e.part === c ? 'the zone' : 'its content'}.`) },
|
|
99
|
+
{ text: '&Reset', click: () => (s.zone = START) },
|
|
100
|
+
]);
|
|
101
|
+
c.motif.setDisposable(remove);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div class="cm-zone" tabindex="0" style={BOX} onBuilt={attach}>
|
|
106
|
+
{() => s.zone}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Behavior
|
|
113
|
+
|
|
114
|
+
| Topic | Details |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `Opening` | A right-click opens the menu at the pointer; the Menu key and Shift+F10 open it at the focused element, on its first item. |
|
|
117
|
+
| `Items per element` | `onOpening` receives the component under the pointer or the focus (`e.part`) and sets `e.items` for it, or `e.cancel = true` to leave the browser’s own menu. |
|
|
118
|
+
| `Closing` | Escape, a click outside or choosing an item closes the menu; focus returns to the element it opened on. |
|
|
119
|
+
| `Scrolling` | The menu follows the element it opened on while the page scrolls, and closes once the element is out of view (`closeOnScroll`). |
|
|
120
|
+
| `Room` | A menu taller than the window scrolls inside and keeps its scroll position. |
|
|
121
|
+
|
|
122
|
+
The props, properties and events of `ContextMenu` are in the [API reference](menus-api.md).
|
|
123
|
+
|
|
124
|
+
## Feedback
|
|
125
|
+
|
|
126
|
+
Loading issues…
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# MenuBar: Customization
|
|
2
|
+
|
|
3
|
+
> MenuBar · @motifx-community/ui 0.1.0-beta.10
|
|
4
|
+
|
|
5
|
+
With `customizable`, the user arranges the bar: hides and moves items, renames them, adds commands and menus, and changes keyboard shortcuts. The items you give stay as they are; what the user changed is one object for the app to save.
|
|
6
|
+
|
|
7
|
+
## Changes by the user
|
|
8
|
+
|
|
9
|
+
The user right-clicks an item, or presses Shift+F10 on it, to hide it or move it along the bar or up and down its menu. An item with `customizable: false` stays shown and in its place, and nothing moves past it. “Customize…” in that menu, or `openCustomizer()`, opens the customizer window. On a touch screen the window takes the whole screen; `customizer: false` leaves the command out of the menu.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { reactive } from '@motifx/core';
|
|
13
|
+
import { Button, MenuBar, Stack, type MenuBarCustomization, type MenuItem } from '@motifx-community/ui';
|
|
14
|
+
|
|
15
|
+
const MENUS: MenuItem[] = [
|
|
16
|
+
{
|
|
17
|
+
key: 'file',
|
|
18
|
+
text: '&File',
|
|
19
|
+
items: [
|
|
20
|
+
{ key: 'new', text: '&New', shortcut: 'Ctrl+N' },
|
|
21
|
+
{ key: 'open', text: '&Open…', shortcut: 'Ctrl+O' },
|
|
22
|
+
{ key: 'save', text: '&Save', shortcut: 'Ctrl+S', beginGroup: true },
|
|
23
|
+
{ key: 'export', text: '&Export', items: [{ key: 'pdf', text: 'PDF' }, { key: 'html', text: 'HTML' }] },
|
|
24
|
+
{ key: 'exit', text: 'E&xit', beginGroup: true, customizable: false },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{ key: 'edit', text: '&Edit', items: [{ key: 'undo', text: '&Undo' }, { key: 'redo', text: '&Redo' }, { key: 'find', text: '&Find' }] },
|
|
28
|
+
{ key: 'view', text: '&View', items: [{ key: 'zoom', text: '&Zoom' }, { key: 'full', text: '&Full screen' }] },
|
|
29
|
+
{ key: 'help', text: '&Help', customizable: false, items: [{ key: 'about', text: '&About' }] },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// Commands the user can add from the customizer.
|
|
33
|
+
const COMMANDS: MenuItem[] = [
|
|
34
|
+
{ key: 'print', text: '&Print', shortcut: 'Ctrl+P' },
|
|
35
|
+
{ key: 'share', text: 'S&hare' },
|
|
36
|
+
{ key: 'spelling', text: 'Check &spelling', shortcut: 'F7' },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/** Right-click an item, or press Shift+F10 on it, to hide or move it; what the user changed is one object to save. */
|
|
40
|
+
export default function CustomizableMenu() {
|
|
41
|
+
const s = reactive({ saved: null as MenuBarCustomization | null, told: 'Nothing yet.' });
|
|
42
|
+
let bar!: MenuBar;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Stack gap="md">
|
|
46
|
+
<MenuBar
|
|
47
|
+
ref={(b: MenuBar) => (bar = b)}
|
|
48
|
+
label="Editor"
|
|
49
|
+
items={MENUS}
|
|
50
|
+
customizable
|
|
51
|
+
commands={COMMANDS}
|
|
52
|
+
onCustomized={(e) => (s.saved = e.customization)}
|
|
53
|
+
onCustomMenuOpening={(e) => {
|
|
54
|
+
if (e.path) e.items.push({ text: 'Show the path', beginGroup: true, click: () => (s.told = `Path: ${e.path}`) });
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
<output class="mb-custom-told">{() => s.told}</output>
|
|
58
|
+
<pre class="mb-custom-saved">{() => JSON.stringify(s.saved ?? {}, null, 2)}</pre>
|
|
59
|
+
<Stack orientation="horizontal" gap="sm" wrap>
|
|
60
|
+
<Button text="Customize…" variant="outline" onclick={() => bar.openCustomizer()} />
|
|
61
|
+
<Button text="Forget the changes" variant="outline" onclick={() => (bar.customization = null)} />
|
|
62
|
+
<Button text="Restore the saved changes" variant="outline" onclick={() => (bar.customization = s.saved)} />
|
|
63
|
+
</Stack>
|
|
64
|
+
</Stack>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Page of the window | Content |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `Menus` | Every item in a tree. Its check box shows or hides it; the toolbar adds a menu of the user’s own, renames, deletes what the user added, moves items up, down or into another menu, and resets. Alt with an arrow moves the selected item, F2 renames it, Delete deletes it. |
|
|
72
|
+
| `Commands` | The commands given as `commands`, or the app’s commands (`commands.add`) when none are given, to add one to a menu. |
|
|
73
|
+
| `Keyboard` | A [ShortcutEditor](shortcuteditor.md): the app’s keyboard shortcuts, to assign other keys. `customizerKeyboard: false` leaves the page out. |
|
|
74
|
+
|
|
75
|
+
## Saving the changes
|
|
76
|
+
|
|
77
|
+
`onCustomized` reports everything the user changed so far as one plain object; assigning it to `customization` restores the changes, and `null` forgets them. An item of the app is named by its path in the items given and keeps that name wherever the user moves it, so a saved object still applies after the app adds items. How the object is stored is up to the app.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
bar.customization = JSON.parse(localStorage.getItem('menu') ?? 'null');
|
|
81
|
+
bar.onCustomized((e) => localStorage.setItem('menu', JSON.stringify(e.customization)));
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Field | Type | Description |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `hidden` | `string[]` | The items the user hid. |
|
|
87
|
+
| `order` | `Record<string, string[]>` | The order the user gave: the bar’s items under `''`, a menu’s items under the name of the menu. |
|
|
88
|
+
| `moves` | `Record<string, string>` | The items the user moved to another menu, and the menu each went to. |
|
|
89
|
+
| `texts` | `Record<string, string>` | The names the user gave to items. |
|
|
90
|
+
| `added` | `MenuBarAddedItem[]` | The commands and menus the user added, each with its `id` (`user:1`). |
|
|
91
|
+
|
|
92
|
+
## Commands of your own in the menu
|
|
93
|
+
|
|
94
|
+
`onCustomMenuOpening` occurs before the menu of a right-click opens, with the item, its path and the commands about to be shown: add commands of your own, leave some out, or set `cancel`. It occurs without `customizable` too, with no commands of the bar, so a bar can have a right-click menu of the app’s own.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { reactive } from '@motifx/core';
|
|
98
|
+
import { MenuBar, Stack, type MenuItem } from '@motifx-community/ui';
|
|
99
|
+
|
|
100
|
+
const MENUS: MenuItem[] = [
|
|
101
|
+
{ key: 'file', text: '&File', items: [{ key: 'new', text: '&New' }, { key: 'open', text: '&Open…' }] },
|
|
102
|
+
{ key: 'edit', text: '&Edit', items: [{ key: 'undo', text: '&Undo' }, { key: 'redo', text: '&Redo' }] },
|
|
103
|
+
{ key: 'help', text: '&Help', items: [{ key: 'about', text: '&About' }] },
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The menu a right-click opens on the bar, with commands of the app's own: the bar is not `customizable`, so they are
|
|
108
|
+
* the only ones. Help opens no menu at all.
|
|
109
|
+
*/
|
|
110
|
+
export default function CustomMenuCommands() {
|
|
111
|
+
const s = reactive({ told: 'Nothing yet.' });
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Stack gap="md">
|
|
115
|
+
<MenuBar
|
|
116
|
+
label="Own commands"
|
|
117
|
+
items={MENUS}
|
|
118
|
+
onCustomMenuOpening={(e) => {
|
|
119
|
+
if (e.path === 'help') {
|
|
120
|
+
e.cancel = true;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const name = e.item ? String(e.item.text).replace('&', '') : 'the bar';
|
|
124
|
+
e.items.push(
|
|
125
|
+
{ text: `Copy the path of ${name}`, click: () => (s.told = `Path: ${e.path ?? '(none)'}`) },
|
|
126
|
+
{ text: 'Show all menus', beginGroup: true, click: () => (s.told = 'Every menu is shown.') },
|
|
127
|
+
);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
<output class="mb-own-told">{() => s.told}</output>
|
|
131
|
+
</Stack>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Feedback
|
|
137
|
+
|
|
138
|
+
Loading issues…
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# MenuBar: Merging menus
|
|
2
|
+
|
|
3
|
+
> MenuBar · @motifx-community/ui 0.1.0-beta.10
|
|
4
|
+
|
|
5
|
+
A page can have several bars: the app’s bar, and the bars of documents, windows and tabs. The bar of the document in use shows its items in the app’s bar, so the user always finds the commands in one place.
|
|
6
|
+
|
|
7
|
+
## Merging into the app’s bar
|
|
8
|
+
|
|
9
|
+
The app’s bar is marked `mergeHost`; a page with several such bars names them with `mergeName` (`'main'` by default). The bar of a document names the app’s bar with `mergeInto`, by name or as the bar itself; the two can be anywhere in the component tree. While it is merged, its items are shown in the app’s bar and it hides itself (`hideWhenMerged`).
|
|
10
|
+
|
|
11
|
+
`mergeAt` places an item: an index, or `{ before: key }` or `{ after: key }`. A merged item’s action, `onItemClick` and the user’s changes stay with its own bar, and it takes another access key when the app’s bar already uses its letter.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { reactive } from '@motifx/core';
|
|
15
|
+
import { MenuBar, Stack, Tab, Tabs, type MenuItem, type MenuItemClickEventArgs } from '@motifx-community/ui';
|
|
16
|
+
|
|
17
|
+
/** The app's bar, and a bar in each document: the bar of the document shown merges into the app's. */
|
|
18
|
+
export default function MergedMenus() {
|
|
19
|
+
const s = reactive({ told: 'Nothing yet.' });
|
|
20
|
+
const tell = (e: MenuItemClickEventArgs) => (s.told = `${String(e.item.text).replace('&', '')} in ${(e.source as MenuBar).label}`);
|
|
21
|
+
|
|
22
|
+
const app: MenuItem[] = [
|
|
23
|
+
{ key: 'file', text: '&File', items: [{ key: 'new', text: '&New' }, { key: 'open', text: '&Open…' }, { key: 'exit', text: 'E&xit', beginGroup: true }] },
|
|
24
|
+
{ key: 'edit', text: '&Edit', items: [{ key: 'undo', text: '&Undo' }, { key: 'redo', text: '&Redo' }] },
|
|
25
|
+
{ key: 'window', text: '&Window', items: [{ key: 'split', text: '&Split' }] },
|
|
26
|
+
{ key: 'help', text: '&Help', items: [{ key: 'about', text: '&About' }] },
|
|
27
|
+
];
|
|
28
|
+
const report: MenuItem[] = [
|
|
29
|
+
{ key: 'file', text: '&File', items: [{ key: 'export', text: 'Export as &PDF', mergeAt: { after: 'open' } }] },
|
|
30
|
+
{ key: 'format', text: 'F&ormat', mergeAt: { before: 'window' }, items: [{ key: 'bold', text: '&Bold' }, { key: 'italic', text: '&Italic' }] },
|
|
31
|
+
];
|
|
32
|
+
const sheet: MenuItem[] = [
|
|
33
|
+
{ key: 'edit', text: '&Edit', items: [{ key: 'fill', text: '&Fill down', beginGroup: true }] },
|
|
34
|
+
{ key: 'data', text: '&Data', mergeAt: { before: 'window' }, items: [{ key: 'sort', text: '&Sort' }, { key: 'filter', text: 'F&ilter' }] },
|
|
35
|
+
{ key: 'window', merge: 'remove', text: 'Window' },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Stack gap="md">
|
|
40
|
+
<MenuBar label="App" items={app} mergeHost mergeName="docs-demo" onItemClick={tell} />
|
|
41
|
+
<Tabs label="Documents">
|
|
42
|
+
<Tab key="report" title="Report.docx">
|
|
43
|
+
<MenuBar class="mb-merge-report" label="Report" items={report} mergeInto="docs-demo" onItemClick={tell} />
|
|
44
|
+
<p>The report’s own commands are in the app’s bar while this document is shown.</p>
|
|
45
|
+
</Tab>
|
|
46
|
+
<Tab key="sheet" title="Budget.xlsx">
|
|
47
|
+
<MenuBar class="mb-merge-sheet" label="Budget" items={sheet} mergeInto="docs-demo" onItemClick={tell} />
|
|
48
|
+
<p>The budget adds Data, joins Edit and takes Window away.</p>
|
|
49
|
+
</Tab>
|
|
50
|
+
</Tabs>
|
|
51
|
+
<output class="mb-merge-told">{() => s.told}</output>
|
|
52
|
+
</Stack>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| merge | What the item does in the app’s bar |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `auto` | The default. An item with a menu joins the app’s item with the same key; any other item is added. |
|
|
60
|
+
| `add` | Always added beside the app’s items, even when one has the same key. |
|
|
61
|
+
| `replace` | Takes the place of the app’s item with the same key. |
|
|
62
|
+
| `remove` | Takes the app’s item with the same key away while the bar is merged. |
|
|
63
|
+
| `none` | Stays out of the app’s bar. |
|
|
64
|
+
|
|
65
|
+
## When a bar merges
|
|
66
|
+
|
|
67
|
+
| mergeWhen | Merged |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `shown` | The default. Merged while the bar’s place (`mergeScope`, its parent by default) is shown: the tab or the document shown. |
|
|
70
|
+
| `focus` | Merged while focus is in its place, such as a window that is not modal. |
|
|
71
|
+
| `manual` | Merged only by `merge()` and unmerged by `unmerge()`. |
|
|
72
|
+
|
|
73
|
+
The app’s bar reports the bars that come and go with `onMerged` and `onUnmerged`; `mergedBars`, `mergedInto` and `mergedItems` tell what is merged now. A bar that waits for an app’s bar not yet created merges when it comes.
|
|
74
|
+
|
|
75
|
+
## Documents of a TabDocumentManager
|
|
76
|
+
|
|
77
|
+
Each document has a bar in its content; the bar of the active document is the one shown, so its menus are in the app’s bar. A document moved into a browser window of its own is shown there too: its menus stay in the app’s bar of the main window, beside those of the document shown in the main window, until the window closes.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { reactive } from '@motifx/core';
|
|
81
|
+
import { Button, MenuBar, Stack, Switch, TabDocument, TabDocumentManager, TextBox, type MenuItem, type MenuItemClickEventArgs } from '@motifx-community/ui';
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Documents of a TabDocumentManager, each with its own bar: the menus of the active document are shown in the app's
|
|
85
|
+
* bar, also while the document is in a browser window of its own. The switch merges a bar only while focus is in its
|
|
86
|
+
* document.
|
|
87
|
+
*/
|
|
88
|
+
export default function MergedDocuments() {
|
|
89
|
+
const s = reactive({ told: 'Nothing yet.', focus: false });
|
|
90
|
+
const tell = (e: MenuItemClickEventArgs) => (s.told = `${String(e.item.text).replace('&', '')} in ${(e.source as MenuBar).label}`);
|
|
91
|
+
|
|
92
|
+
const app: MenuItem[] = [
|
|
93
|
+
{ key: 'file', text: '&File', items: [{ key: 'new', text: '&New' }, { key: 'open', text: '&Open…' }, { key: 'close', text: '&Close', beginGroup: true }] },
|
|
94
|
+
{ key: 'view', text: '&View', items: [{ key: 'zoom', text: '&Zoom' }] },
|
|
95
|
+
{ key: 'help', text: '&Help', items: [{ key: 'about', text: '&About' }] },
|
|
96
|
+
];
|
|
97
|
+
const documentOf = (title: string, items: MenuItem[], text: string) => () => (
|
|
98
|
+
<div class="mb-doc">
|
|
99
|
+
<MenuBar label={title} items={items} mergeInto="docs-documents" mergeWhen={() => (s.focus ? 'focus' : 'shown')} onItemClick={tell} />
|
|
100
|
+
<p>{text}</p>
|
|
101
|
+
<TextBox label={`${title} notes`} />
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const docs = new TabDocumentManager({ label: 'Documents with menus' });
|
|
106
|
+
docs.element.style.cssText = 'block-size: 18rem; inline-size: 100%';
|
|
107
|
+
docs.open(
|
|
108
|
+
new TabDocument({
|
|
109
|
+
id: 'letter',
|
|
110
|
+
title: 'Letter',
|
|
111
|
+
content: documentOf('Letter', [{ key: 'format', text: 'F&ormat', mergeAt: { before: 'help' }, items: [{ key: 'bold', text: '&Bold' }, { key: 'italic', text: '&Italic' }] }], 'The letter adds Format.'),
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
docs.open(
|
|
115
|
+
new TabDocument({
|
|
116
|
+
id: 'photo',
|
|
117
|
+
title: 'Photo',
|
|
118
|
+
content: documentOf(
|
|
119
|
+
'Photo',
|
|
120
|
+
[
|
|
121
|
+
{ key: 'image', text: '&Image', mergeAt: { before: 'help' }, items: [{ key: 'crop', text: '&Crop' }, { key: 'rotate', text: '&Rotate' }] },
|
|
122
|
+
{ key: 'view', text: '&View', items: [{ key: 'actual', text: '&Actual size' }] },
|
|
123
|
+
],
|
|
124
|
+
'The photo adds Image and joins View.',
|
|
125
|
+
),
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<>
|
|
131
|
+
<MenuBar label="Studio" items={app} mergeHost mergeName="docs-documents" onItemClick={tell} />
|
|
132
|
+
<Stack orientation="horizontal" wrap align="center">
|
|
133
|
+
<Switch label="Merge only while focus is in the document" x-model={() => s.focus} />
|
|
134
|
+
<Button
|
|
135
|
+
text="Move the active document into a new window"
|
|
136
|
+
variant="outline"
|
|
137
|
+
enabled={() => !!docs.activeDocument && !docs.activeDocument.browserWindow}
|
|
138
|
+
onclick={() => docs.moveToNewWindow(docs.activeDocument!)}
|
|
139
|
+
/>
|
|
140
|
+
<Button text="Bring it back" variant="outline" enabled={() => docs.browserWindows.length > 0} onclick={() => docs.browserWindows.forEach((w) => w.moveToMainWindow())} />
|
|
141
|
+
</Stack>
|
|
142
|
+
{docs}
|
|
143
|
+
<output class="mb-docs-told">{() => s.told}</output>
|
|
144
|
+
</>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## A window
|
|
150
|
+
|
|
151
|
+
A window that is not modal stays open while the user works elsewhere, so its bar merges while focus is in it (`mergeWhen: 'focus'`).
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import type { Component } from '@motifx/core';
|
|
155
|
+
import { reactive } from '@motifx/core';
|
|
156
|
+
import { Button, MenuBar, MxForm, Stack, TextBox, type MenuItem, type MenuItemClickEventArgs } from '@motifx-community/ui';
|
|
157
|
+
|
|
158
|
+
/** A window with its own bar that merges while focus is in the window (`mergeWhen: 'focus'`). */
|
|
159
|
+
export default function MergedWindow() {
|
|
160
|
+
const s = reactive({ told: 'Nothing yet.' });
|
|
161
|
+
const tell = (e: MenuItemClickEventArgs) => (s.told = `${String(e.item.text).replace('&', '')} in ${(e.source as MenuBar).label}`);
|
|
162
|
+
let host: Component<HTMLDivElement> | null = null;
|
|
163
|
+
let form: MxForm | null = null;
|
|
164
|
+
|
|
165
|
+
const app: MenuItem[] = [
|
|
166
|
+
{ key: 'file', text: '&File', items: [{ key: 'new', text: '&New' }, { key: 'exit', text: 'E&xit', beginGroup: true }] },
|
|
167
|
+
{ key: 'help', text: '&Help', items: [{ key: 'about', text: '&About' }] },
|
|
168
|
+
];
|
|
169
|
+
const notes: MenuItem[] = [
|
|
170
|
+
{ key: 'file', text: '&File', items: [{ key: 'save', text: '&Save note', mergeAt: { after: 'new' } }] },
|
|
171
|
+
{ key: 'insert', text: '&Insert', mergeAt: { before: 'help' }, items: [{ key: 'date', text: '&Date' }, { key: 'list', text: '&List' }] },
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const open = () => {
|
|
175
|
+
if (form && !form.isDisposed) {
|
|
176
|
+
form.focus();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
form = new MxForm({
|
|
180
|
+
title: 'Note',
|
|
181
|
+
startPosition: 'manual',
|
|
182
|
+
left: 120,
|
|
183
|
+
top: 160,
|
|
184
|
+
width: '22rem',
|
|
185
|
+
content: (
|
|
186
|
+
<div class="mb-window-note">
|
|
187
|
+
<MenuBar label="Note" items={notes} mergeInto="docs-window" mergeWhen="focus" onItemClick={tell} />
|
|
188
|
+
<TextBox label="Title" />
|
|
189
|
+
</div>
|
|
190
|
+
),
|
|
191
|
+
});
|
|
192
|
+
form.show(host!);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<Stack gap="md" ref={(c: Stack) => (host = c)}>
|
|
197
|
+
<MenuBar label="Desk" items={app} mergeHost mergeName="docs-window" onItemClick={tell} />
|
|
198
|
+
<Button text="Open the note window" variant="outline" onclick={open} />
|
|
199
|
+
<p tabIndex={0} class="mb-window-page">Focus in the window shows its menus in the bar above; click here and they go back.</p>
|
|
200
|
+
<output class="mb-window-told">{() => s.told}</output>
|
|
201
|
+
</Stack>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Feedback
|
|
207
|
+
|
|
208
|
+
Loading issues…
|