@domicile-desktop/component-library 0.0.0-alpha-e496597a53df → 0.0.0-alpha-b318faf96469

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/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "dependencies": {
3
3
  "@base-ui/react": "^1.8.0",
4
4
  "@cprussin/option-result": "^2.0.1",
5
- "@domicile-desktop/sdk": "0.0.0-alpha-e496597a53df",
6
- "@domicile-desktop/system-apps": "0.0.0-alpha-e496597a53df",
5
+ "@domicile-desktop/sdk": "0.0.0-alpha-b318faf96469",
6
+ "@domicile-desktop/system-apps": "0.0.0-alpha-b318faf96469",
7
7
  "@pandacss/dev": "^1.12.1",
8
8
  "@phosphor-icons/react": "^2.1.10"
9
9
  },
@@ -92,6 +92,7 @@
92
92
  "./list-walk": "./src/list-walk.ts",
93
93
  "./Marked": "./src/ResultList/Marked.tsx",
94
94
  "./Menu": "./src/Menu/Menu.tsx",
95
+ "./MenuBar": "./src/MenuBar/MenuBar.tsx",
95
96
  "./ModalDialog": "./src/ModalDialog/ModalDialog.tsx",
96
97
  "./media-theme-source": "./src/ThemeSwitch/media-theme-source.ts",
97
98
  "./Notice": "./src/Notice/Notice.tsx",
@@ -166,5 +167,5 @@
166
167
  "test:unit": "bun test"
167
168
  },
168
169
  "type": "module",
169
- "version": "0.0.0-alpha-e496597a53df"
170
+ "version": "0.0.0-alpha-b318faf96469"
170
171
  }
@@ -361,7 +361,7 @@ const mnemonicKey = (
361
361
  * instead of base-ui's type-ahead. A key from a submenu bubbles here through
362
362
  * React's tree; that submenu's popup is not inside this one, so it is skipped.
363
363
  */
364
- const chooseByMnemonic = (
364
+ export const chooseByMnemonic = (
365
365
  event: BaseUIEvent<KeyboardEvent<HTMLDivElement>>,
366
366
  ) => {
367
367
  const item = mnemonicItem(event);
@@ -0,0 +1,136 @@
1
+ import { Menu as BaseMenu } from "@base-ui/react/menu";
2
+ import { Menubar as BaseMenubar } from "@base-ui/react/menubar";
3
+ import type { ReactNode } from "react";
4
+ import { css } from "../../styled-system/css";
5
+ import { ContextMenu, chooseByMnemonic } from "../ContextMenu/ContextMenu";
6
+ import { popupStyles, positionerStyles } from "../ContextMenu/menu-popup";
7
+ import type { ExtendProps } from "../extend-props";
8
+ import { usePopupBoundary } from "../PopupBoundary/PopupBoundary";
9
+ import "../stylesheet";
10
+
11
+ type Props = ExtendProps<
12
+ typeof BaseMenubar,
13
+ {
14
+ /** Its menus, each a `MenuBar.Menu`. */
15
+ children: ReactNode;
16
+ /** What the bar is called, to assistive technology. */
17
+ label: string;
18
+ }
19
+ >;
20
+
21
+ /**
22
+ * A row of menus across the top of a window (File, Edit, View, ...), as an
23
+ * app's menu bar. Arrow keys move between them, and pointing at another one
24
+ * while one is open opens it instead.
25
+ */
26
+ const MenuBarComponent = ({ children, label, ...barProps }: Props) => (
27
+ <BaseMenubar aria-label={label} className={barStyles} {...barProps}>
28
+ {children}
29
+ </BaseMenubar>
30
+ );
31
+
32
+ type MenuProps = ExtendProps<
33
+ typeof BaseMenu.Root,
34
+ {
35
+ /** Its items: `ContextMenu`'s. */
36
+ children: ReactNode;
37
+ disabled?: boolean | undefined;
38
+ /** Its name on the bar. */
39
+ label: string;
40
+ /**
41
+ * Where in `label` the access key is. It is underlined, and Alt with it
42
+ * opens the menu where the caller binds that.
43
+ */
44
+ mnemonic?: number | undefined;
45
+ }
46
+ >;
47
+
48
+ /** One menu on the bar: its name, and the items under it when open. */
49
+ const Menu = ({
50
+ children,
51
+ disabled,
52
+ label,
53
+ mnemonic,
54
+ ...rootProps
55
+ }: MenuProps) => {
56
+ const { boundary } = usePopupBoundary(false);
57
+ return (
58
+ <BaseMenu.Root {...rootProps}>
59
+ {/* Named outright: the mnemonic's span splits the text for some readers. */}
60
+ <BaseMenu.Trigger
61
+ aria-label={label}
62
+ className={triggerStyles}
63
+ disabled={disabled}
64
+ >
65
+ {mnemonic === undefined ? (
66
+ label
67
+ ) : (
68
+ <>
69
+ {label.slice(0, mnemonic)}
70
+ <span className={mnemonicStyles}>{label.charAt(mnemonic)}</span>
71
+ {label.slice(mnemonic + 1)}
72
+ </>
73
+ )}
74
+ </BaseMenu.Trigger>
75
+ <BaseMenu.Portal>
76
+ <BaseMenu.Positioner
77
+ align="start"
78
+ className={positionerStyles}
79
+ collisionBoundary={boundary}
80
+ sideOffset={2}
81
+ >
82
+ <BaseMenu.Popup
83
+ aria-label={label}
84
+ className={popupStyles}
85
+ onKeyDown={chooseByMnemonic}
86
+ >
87
+ {children}
88
+ </BaseMenu.Popup>
89
+ </BaseMenu.Positioner>
90
+ </BaseMenu.Portal>
91
+ </BaseMenu.Root>
92
+ );
93
+ };
94
+
95
+ export const MenuBar = Object.assign(MenuBarComponent, {
96
+ CheckboxItem: ContextMenu.CheckboxItem,
97
+ Item: ContextMenu.Item,
98
+ Menu,
99
+ RadioGroup: ContextMenu.RadioGroup,
100
+ RadioItem: ContextMenu.RadioItem,
101
+ Separator: ContextMenu.Separator,
102
+ Submenu: ContextMenu.Submenu,
103
+ });
104
+
105
+ const barStyles = css({
106
+ alignItems: "center",
107
+ borderBlockEnd: "1px solid {colors.border}",
108
+ display: "flex",
109
+ gap: 0.5,
110
+ paddingBlock: 0.5,
111
+ paddingInline: 1.5,
112
+ });
113
+
114
+ // The highlight is `ContextMenu`'s item's, so the bar and its menus match.
115
+ const triggerStyles = css({
116
+ "&:focus-visible, &[data-popup-open], &:hover:not([data-disabled])": {
117
+ backgroundColor: "color-mix(in oklab, {colors.foreground} 8%, transparent)",
118
+ },
119
+ "&[data-disabled]": {
120
+ color: "muted",
121
+ opacity: "disabled",
122
+ },
123
+ backgroundColor: "transparent",
124
+ border: "none",
125
+ borderRadius: "sm",
126
+ color: "foreground",
127
+ cursor: { _disabled: "not-allowed", base: "pointer" },
128
+ fontFamily: "inherit",
129
+ fontSize: "sm",
130
+ outlineStyle: "none",
131
+ paddingBlock: 0.5,
132
+ paddingInline: 2,
133
+ userSelect: "none",
134
+ });
135
+
136
+ const mnemonicStyles = css({ textDecoration: "underline" });