@funstack/ui 0.1.0-alpha.0 → 0.1.0-alpha.1
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/README.md +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs +24 -0
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-item.d.mts +55 -0
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -0
- package/dist/checkbox-group/checkbox-group-item.mjs +90 -0
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-label.d.mts +21 -0
- package/dist/checkbox-group/checkbox-group-label.d.mts.map +1 -0
- package/dist/checkbox-group/checkbox-group-label.mjs +30 -0
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.d.mts +68 -0
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +145 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-root.d.mts +100 -0
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -0
- package/dist/checkbox-group/checkbox-group-root.mjs +291 -0
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -0
- package/dist/checkbox-group/index.d.mts +23 -0
- package/dist/checkbox-group/index.d.mts.map +1 -0
- package/dist/checkbox-group/index.mjs +23 -0
- package/dist/checkbox-group/index.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +4 -4
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-popup.mjs +1 -0
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.mjs +9 -1
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/index.d.mts +23 -1
- package/dist/index.mjs +4 -1
- package/dist/internal/anchor-position.d.mts +7 -0
- package/dist/internal/anchor-position.d.mts.map +1 -0
- package/dist/internal/anchor-position.mjs +16 -0
- package/dist/internal/anchor-position.mjs.map +1 -0
- package/dist/internal/platform-attributes.d.mts +6 -0
- package/dist/internal/platform-attributes.d.mts.map +1 -1
- package/dist/internal/sync-presence.mjs +19 -0
- package/dist/internal/sync-presence.mjs.map +1 -0
- package/dist/internal/use-action-trigger.mjs +58 -0
- package/dist/internal/use-action-trigger.mjs.map +1 -0
- package/dist/internal/use-delayed-pair.mjs +40 -0
- package/dist/internal/use-delayed-pair.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +55 -0
- package/dist/internal/use-exit-animation.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs +2 -2
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-popover-popup.mjs +274 -0
- package/dist/internal/use-popover-popup.mjs.map +1 -0
- package/dist/internal/use-popover-root.d.mts +2 -0
- package/dist/internal/use-popover-root.mjs +112 -0
- package/dist/internal/use-popover-root.mjs.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +86 -0
- package/dist/internal/use-popover-trigger.mjs.map +1 -0
- package/dist/menu/index.d.mts +34 -0
- package/dist/menu/index.d.mts.map +1 -0
- package/dist/menu/index.mjs +34 -0
- package/dist/menu/index.mjs.map +1 -0
- package/dist/menu/menu-checkbox-item.d.mts +42 -0
- package/dist/menu/menu-checkbox-item.d.mts.map +1 -0
- package/dist/menu/menu-checkbox-item.mjs +71 -0
- package/dist/menu/menu-checkbox-item.mjs.map +1 -0
- package/dist/menu/menu-context.d.mts +1 -0
- package/dist/menu/menu-context.mjs +28 -0
- package/dist/menu/menu-context.mjs.map +1 -0
- package/dist/menu/menu-dom.mjs +37 -0
- package/dist/menu/menu-dom.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts +48 -0
- package/dist/menu/menu-group.d.mts.map +1 -0
- package/dist/menu/menu-group.mjs +69 -0
- package/dist/menu/menu-group.mjs.map +1 -0
- package/dist/menu/menu-hover.mjs +29 -0
- package/dist/menu/menu-hover.mjs.map +1 -0
- package/dist/menu/menu-item.d.mts +45 -0
- package/dist/menu/menu-item.d.mts.map +1 -0
- package/dist/menu/menu-item.mjs +54 -0
- package/dist/menu/menu-item.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +69 -0
- package/dist/menu/menu-popup.d.mts.map +1 -0
- package/dist/menu/menu-popup.mjs +207 -0
- package/dist/menu/menu-popup.mjs.map +1 -0
- package/dist/menu/menu-radio-group.d.mts +37 -0
- package/dist/menu/menu-radio-group.d.mts.map +1 -0
- package/dist/menu/menu-radio-group.mjs +72 -0
- package/dist/menu/menu-radio-group.mjs.map +1 -0
- package/dist/menu/menu-radio-item.d.mts +33 -0
- package/dist/menu/menu-radio-item.d.mts.map +1 -0
- package/dist/menu/menu-radio-item.mjs +62 -0
- package/dist/menu/menu-radio-item.mjs.map +1 -0
- package/dist/menu/menu-root.d.mts +54 -0
- package/dist/menu/menu-root.d.mts.map +1 -0
- package/dist/menu/menu-root.mjs +102 -0
- package/dist/menu/menu-root.mjs.map +1 -0
- package/dist/menu/menu-submenu-trigger.d.mts +31 -0
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -0
- package/dist/menu/menu-submenu-trigger.mjs +92 -0
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -0
- package/dist/menu/menu-trigger.d.mts +36 -0
- package/dist/menu/menu-trigger.d.mts.map +1 -0
- package/dist/menu/menu-trigger.mjs +81 -0
- package/dist/menu/menu-trigger.mjs.map +1 -0
- package/dist/menu/use-menu-item.mjs +54 -0
- package/dist/menu/use-menu-item.mjs.map +1 -0
- package/dist/popover/index.d.mts +28 -0
- package/dist/popover/index.d.mts.map +1 -0
- package/dist/popover/index.mjs +28 -0
- package/dist/popover/index.mjs.map +1 -0
- package/dist/popover/popover-close.d.mts +41 -0
- package/dist/popover/popover-close.d.mts.map +1 -0
- package/dist/popover/popover-close.mjs +90 -0
- package/dist/popover/popover-close.mjs.map +1 -0
- package/dist/popover/popover-context.mjs +26 -0
- package/dist/popover/popover-context.mjs.map +1 -0
- package/dist/popover/popover-description.d.mts +22 -0
- package/dist/popover/popover-description.d.mts.map +1 -0
- package/dist/popover/popover-description.mjs +28 -0
- package/dist/popover/popover-description.mjs.map +1 -0
- package/dist/popover/popover-popup.d.mts +82 -0
- package/dist/popover/popover-popup.d.mts.map +1 -0
- package/dist/popover/popover-popup.mjs +93 -0
- package/dist/popover/popover-popup.mjs.map +1 -0
- package/dist/popover/popover-root.d.mts +64 -0
- package/dist/popover/popover-root.d.mts.map +1 -0
- package/dist/popover/popover-root.mjs +39 -0
- package/dist/popover/popover-root.mjs.map +1 -0
- package/dist/popover/popover-title.d.mts +23 -0
- package/dist/popover/popover-title.d.mts.map +1 -0
- package/dist/popover/popover-title.mjs +28 -0
- package/dist/popover/popover-title.mjs.map +1 -0
- package/dist/popover/popover-trigger.d.mts +37 -0
- package/dist/popover/popover-trigger.d.mts.map +1 -0
- package/dist/popover/popover-trigger.mjs +40 -0
- package/dist/popover/popover-trigger.mjs.map +1 -0
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +1 -6
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/tabs/tabs-context.mjs +2 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +17 -9
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +1 -1
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs +6 -3
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +2 -7
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +5 -17
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
|
|
4
|
+
//#region src/menu/menu-popup.d.ts
|
|
5
|
+
export type MenuSide = AnchorSide;
|
|
6
|
+
export type MenuAlign = AnchorAlign;
|
|
7
|
+
export interface MenuPopupState {
|
|
8
|
+
/** Committed open state. Read `:popover-open` for the DOM truth. */
|
|
9
|
+
readonly open: boolean;
|
|
10
|
+
readonly side: MenuSide | null;
|
|
11
|
+
readonly align: MenuAlign;
|
|
12
|
+
/** This popup belongs to a submenu. */
|
|
13
|
+
readonly submenu: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface MenuPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "role" | "aria-labelledby" | "onKeyDown" | "onFocus" | "onBlur" | "onMouseDown" | "onPointerEnter" | "onPointerLeave" | "onToggle" | "onBeforeToggle" | "className" | "style" | "children"> {
|
|
16
|
+
/**
|
|
17
|
+
* Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`
|
|
18
|
+
* flipping it when it does not fit. Default `"bottom"` for a top-level menu, `"right"` for a
|
|
19
|
+
* submenu (whose fallback is `flip-inline` only). `null` emits no inline positioning (and no
|
|
20
|
+
* `data-side` / `data-align`): the stylesheet owns placement.
|
|
21
|
+
*/
|
|
22
|
+
side?: MenuSide | null;
|
|
23
|
+
/** Alignment along the side. Default `"start"`. Ignored when `side` is `null`. */
|
|
24
|
+
align?: MenuAlign;
|
|
25
|
+
/**
|
|
26
|
+
* `false` (default): the items are not rendered while the menu is closed; mounting them is part
|
|
27
|
+
* of the opening transition, so items that suspend hold the open (and the Trigger pending)
|
|
28
|
+
* until they are ready. `true`: they stay mounted inside `<Activity mode="hidden">`.
|
|
29
|
+
*/
|
|
30
|
+
keepMounted?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Experimental (Chromium 150+). Renders `focusgroup="menu wrap|nowrap"` and, where the engine
|
|
33
|
+
* implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then
|
|
34
|
+
* render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,
|
|
35
|
+
* submenu keys and Tab stay in JS. No effect in other engines. Default `false`.
|
|
36
|
+
*/
|
|
37
|
+
experimental_focusgroup?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening
|
|
40
|
+
* commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover
|
|
41
|
+
* leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click
|
|
42
|
+
* outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.
|
|
43
|
+
*/
|
|
44
|
+
transition?: ViewTransitionClass;
|
|
45
|
+
className?: StateValue<string | undefined, MenuPopupState>;
|
|
46
|
+
style?: StateValue<CSSProperties | undefined, MenuPopupState>;
|
|
47
|
+
children?: StateValue<ReactNode, MenuPopupState>;
|
|
48
|
+
/** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */
|
|
49
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, MenuPopupState>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The menu itself: `<div popover="auto" role="menu" aria-labelledby={trigger} tabindex="-1">`,
|
|
53
|
+
* placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):
|
|
54
|
+
* ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
|
|
55
|
+
* `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
|
|
56
|
+
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).
|
|
57
|
+
* Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
|
|
58
|
+
*
|
|
59
|
+
* Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),
|
|
60
|
+
* `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on
|
|
61
|
+
* non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and
|
|
62
|
+
* `data-side` / `data-align` unless `side` is `null`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function MenuPopup({ side: sideProp, align, keepMounted, experimental_focusgroup, transition, className, style, children, render, ...rest }: MenuPopupProps): ReactNode;
|
|
65
|
+
export declare namespace MenuPopup {
|
|
66
|
+
var displayName: string;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//# sourceMappingURL=menu-popup.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;YAiCY,WAAW;YACX,YAAY;iBAEP;;WAEN;WACA,MAAM;WACN,OAAO;;WAEP;;iBAGM,uBAAuB,KACtC;;;;;;;EAuBA,OAAO;;EAEP,QAAQ;;;;;;EAMR;;;;;;;EAOA;;;;;;;EAOA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBA4BpC,YACd,MAAM,UACN,OACA,aACA,yBACA,YACA,WACA,OACA,UACA,WACG,QACF,iBAAc;yBAXD"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
|
|
3
|
+
import { mergeRefs } from "../internal/merge-props.mjs";
|
|
4
|
+
import { resolveStateValue, useRender } from "../internal/use-render.mjs";
|
|
5
|
+
import { POSITION_TRY_FALLBACKS, positionArea } from "../internal/anchor-position.mjs";
|
|
6
|
+
import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
|
|
7
|
+
import { MenuListContext, useMenuContext } from "./menu-context.mjs";
|
|
8
|
+
import { edgeItem, focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from "./menu-dom.mjs";
|
|
9
|
+
import { scheduleHoverClose } from "./menu-hover.mjs";
|
|
10
|
+
import { Activity, useCallback, useMemo, useRef, useSyncExternalStore } from "react";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
//#region src/menu/menu-popup.tsx
|
|
13
|
+
/** Engine capabilities never change while the page lives. */
|
|
14
|
+
const subscribeNever = () => () => {};
|
|
15
|
+
/** Typeahead buffer lifetime after the last keystroke (design 5.1). */
|
|
16
|
+
const TYPEAHEAD_RESET_MS = 500;
|
|
17
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
18
|
+
/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */
|
|
19
|
+
const FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])";
|
|
20
|
+
/**
|
|
21
|
+
* The menu itself: `<div popover="auto" role="menu" aria-labelledby={trigger} tabindex="-1">`,
|
|
22
|
+
* placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):
|
|
23
|
+
* ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
|
|
24
|
+
* `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
|
|
25
|
+
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).
|
|
26
|
+
* Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.
|
|
27
|
+
*
|
|
28
|
+
* Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),
|
|
29
|
+
* `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on
|
|
30
|
+
* non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and
|
|
31
|
+
* `data-side` / `data-align` unless `side` is `null`.
|
|
32
|
+
*/
|
|
33
|
+
function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_focusgroup = false, transition, className, style, children, render, ...rest }) {
|
|
34
|
+
const menu = useMenuContext("Menu.Popup");
|
|
35
|
+
const { popover, submenu, loop } = menu;
|
|
36
|
+
const side = sideProp === void 0 ? submenu ? "right" : "bottom" : sideProp;
|
|
37
|
+
const nativeFocusgroup = useSyncExternalStore(subscribeNever, () => experimental_focusgroup && "focusGroup" in HTMLElement.prototype, () => false);
|
|
38
|
+
const typeahead = useRef({
|
|
39
|
+
text: "",
|
|
40
|
+
at: 0
|
|
41
|
+
});
|
|
42
|
+
const typingAhead = useCallback(() => {
|
|
43
|
+
const { text, at } = typeahead.current;
|
|
44
|
+
return text !== "" && Date.now() - at <= TYPEAHEAD_RESET_MS;
|
|
45
|
+
}, []);
|
|
46
|
+
const { setElement, visible, wrapContent } = usePopoverPopup(popover, {
|
|
47
|
+
part: "Menu.Popup",
|
|
48
|
+
initialFocus: void 0,
|
|
49
|
+
resolveInitialFocus: (popup) => {
|
|
50
|
+
const { cause, pointer } = menu.takeOpenCause();
|
|
51
|
+
if (cause === "none") return null;
|
|
52
|
+
const element = edgeItem(popup, cause) ?? popup;
|
|
53
|
+
return pointer ? {
|
|
54
|
+
element,
|
|
55
|
+
focusVisible: false
|
|
56
|
+
} : element;
|
|
57
|
+
},
|
|
58
|
+
keepMounted,
|
|
59
|
+
transition
|
|
60
|
+
});
|
|
61
|
+
const devRef = useCallback((element) => {
|
|
62
|
+
if (isDev && element.tagName === "DIALOG") console.error("Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog focusing steps, which fight the menu's item focus.");
|
|
63
|
+
return () => {};
|
|
64
|
+
}, []);
|
|
65
|
+
const ref = useMemo(() => mergeRefs(setElement, devRef), [setElement, devRef]);
|
|
66
|
+
const listContext = useMemo(() => ({
|
|
67
|
+
menu,
|
|
68
|
+
nativeFocusgroup,
|
|
69
|
+
typingAhead
|
|
70
|
+
}), [
|
|
71
|
+
menu,
|
|
72
|
+
nativeFocusgroup,
|
|
73
|
+
typingAhead
|
|
74
|
+
]);
|
|
75
|
+
const state = {
|
|
76
|
+
open: popover.committed,
|
|
77
|
+
side,
|
|
78
|
+
align,
|
|
79
|
+
submenu
|
|
80
|
+
};
|
|
81
|
+
const runTypeahead = (popup, current, key) => {
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const buffer = typeahead.current;
|
|
84
|
+
if (buffer.text === "" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = "";
|
|
85
|
+
if (key === " " && buffer.text === "") return false;
|
|
86
|
+
buffer.text += key.toLowerCase();
|
|
87
|
+
buffer.at = now;
|
|
88
|
+
const items = menuItems(popup);
|
|
89
|
+
if (items.length === 0) return true;
|
|
90
|
+
const repeated = [...buffer.text].every((c) => c === buffer.text[0]);
|
|
91
|
+
const search = repeated ? buffer.text[0] : buffer.text;
|
|
92
|
+
const index = current === null ? -1 : items.indexOf(current);
|
|
93
|
+
const start = repeated || index < 0 ? index + 1 : index;
|
|
94
|
+
for (let i = 0; i < items.length; i++) {
|
|
95
|
+
const item = items[(start + i) % items.length];
|
|
96
|
+
if (typeaheadText(item).startsWith(search)) {
|
|
97
|
+
if (item !== current) focusItem(item);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
const onKeyDown = (event) => {
|
|
104
|
+
if (event.defaultPrevented || hasModifier(event)) return;
|
|
105
|
+
const popup = event.currentTarget;
|
|
106
|
+
const target = event.target;
|
|
107
|
+
const onItem = isMenuItem(target, popup);
|
|
108
|
+
if (!onItem && target !== popup) return;
|
|
109
|
+
const key = event.key;
|
|
110
|
+
if (submenu && key === (isRtl(popup) ? "ArrowRight" : "ArrowLeft")) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
popover.requestClose(event.nativeEvent, "activate");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (key === "ArrowDown" || key === "ArrowUp" || key === "Home" || key === "End") {
|
|
116
|
+
if (!onItem) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
const items = menuItems(popup);
|
|
119
|
+
const item = key === "ArrowDown" || key === "Home" ? items[0] : items.at(-1);
|
|
120
|
+
if (item !== void 0) focusItem(item);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (nativeFocusgroup) return;
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
const items = menuItems(popup);
|
|
126
|
+
const index = items.indexOf(target);
|
|
127
|
+
const last = items.length - 1;
|
|
128
|
+
let next;
|
|
129
|
+
if (key === "Home") next = 0;
|
|
130
|
+
else if (key === "End") next = last;
|
|
131
|
+
else if (key === "ArrowDown") next = index >= last ? loop ? 0 : last : index + 1;
|
|
132
|
+
else next = index <= 0 ? loop ? last : 0 : index - 1;
|
|
133
|
+
const item = items[next];
|
|
134
|
+
if (item !== void 0 && item !== target) focusItem(item);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) event.preventDefault();
|
|
138
|
+
};
|
|
139
|
+
const onBlur = (event) => {
|
|
140
|
+
if (submenu) return;
|
|
141
|
+
const popup = event.currentTarget;
|
|
142
|
+
const next = event.relatedTarget;
|
|
143
|
+
if (!(next instanceof Node) || popup.contains(next)) return;
|
|
144
|
+
if (popup.matches(":popover-open")) popup.hidePopover();
|
|
145
|
+
};
|
|
146
|
+
const onMouseDown = (event) => {
|
|
147
|
+
if (event.button !== 0) return;
|
|
148
|
+
const focusable = event.target.closest(FOCUSABLE_SELECTOR);
|
|
149
|
+
if (focusable === null || focusable.getAttribute("role") === "menu") event.preventDefault();
|
|
150
|
+
};
|
|
151
|
+
const libraryProps = {
|
|
152
|
+
id: popover.ids.popup,
|
|
153
|
+
popover: "auto",
|
|
154
|
+
role: "menu",
|
|
155
|
+
"aria-labelledby": menu.triggerId,
|
|
156
|
+
tabIndex: -1,
|
|
157
|
+
...experimental_focusgroup && { focusgroup: `menu ${loop ? "wrap" : "nowrap"}` },
|
|
158
|
+
onKeyDown,
|
|
159
|
+
onBlur,
|
|
160
|
+
onMouseDown,
|
|
161
|
+
...submenu && {
|
|
162
|
+
onPointerEnter: (event) => {
|
|
163
|
+
if (event.pointerType !== "touch") menu.timers.cancelClose();
|
|
164
|
+
},
|
|
165
|
+
onPointerLeave: (event) => {
|
|
166
|
+
if (event.pointerType !== "touch") scheduleHoverClose(menu, event.nativeEvent);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
...side !== null && {
|
|
170
|
+
"data-side": side,
|
|
171
|
+
"data-align": align
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const content = (s) => {
|
|
175
|
+
let node;
|
|
176
|
+
if (keepMounted === true) node = /* @__PURE__ */ jsx(Activity, {
|
|
177
|
+
mode: visible ? "visible" : "hidden",
|
|
178
|
+
children: wrapContent(resolveStateValue(children, s))
|
|
179
|
+
});
|
|
180
|
+
else node = visible ? wrapContent(resolveStateValue(children, s)) : null;
|
|
181
|
+
return /* @__PURE__ */ jsx(MenuListContext, {
|
|
182
|
+
value: listContext,
|
|
183
|
+
children: node
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
const element = useRender({
|
|
187
|
+
defaultElement: "div",
|
|
188
|
+
render,
|
|
189
|
+
state,
|
|
190
|
+
className,
|
|
191
|
+
style: side === null ? style : (s) => ({
|
|
192
|
+
positionArea: positionArea(side, align),
|
|
193
|
+
positionTryFallbacks: submenu ? "flip-inline" : POSITION_TRY_FALLBACKS,
|
|
194
|
+
...resolveStateValue(style, s)
|
|
195
|
+
}),
|
|
196
|
+
children: content,
|
|
197
|
+
props: rest,
|
|
198
|
+
libraryProps,
|
|
199
|
+
ref
|
|
200
|
+
});
|
|
201
|
+
return useTransitionBoundary("Menu.Popup", transition, element);
|
|
202
|
+
}
|
|
203
|
+
MenuPopup.displayName = "MenuPopup";
|
|
204
|
+
//#endregion
|
|
205
|
+
export { MenuPopup };
|
|
206
|
+
|
|
207
|
+
//# sourceMappingURL=menu-popup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { Activity, useCallback, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { POSITION_TRY_FALLBACKS, positionArea } from \"../internal/anchor-position.js\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { mergeRefs } from \"../internal/merge-props.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport {\n edgeItem,\n focusItem,\n hasModifier,\n isMenuItem,\n isRtl,\n menuItems,\n typeaheadText,\n} from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\n\nexport type MenuSide = AnchorSide;\nexport type MenuAlign = AnchorAlign;\n\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n readonly side: MenuSide | null;\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n}\n\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. Default `\"bottom\"` for a top-level menu, `\"right\"` for a\n * submenu (whose fallback is `flip-inline` only). `null` emits no inline positioning (and no\n * `data-side` / `data-align`): the stylesheet owns placement.\n */\n side?: MenuSide | null;\n /** Alignment along the side. Default `\"start\"`. Ignored when `side` is `null`. */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines. Default `false`.\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, MenuPopupState>;\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** Engine capabilities never change while the page lives. */\nconst subscribeNever = () => () => {};\n\n/** Typeahead buffer lifetime after the last keystroke (design 5.1). */\nconst TYPEAHEAD_RESET_MS = 500;\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onPointerEnter` / `onPointerLeave`, and\n * `data-side` / `data-align` unless `side` is `null`.\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const side = sideProp === undefined ? (submenu ? \"right\" : \"bottom\") : sideProp;\n\n // As Tabs.List (#43): detected only with the flag, never during SSR or hydration.\n const nativeFocusgroup = useSyncExternalStore(\n subscribeNever,\n () => experimental_focusgroup && \"focusGroup\" in HTMLElement.prototype,\n () => false,\n );\n\n const typeahead = useRef({ text: \"\", at: 0 });\n const typingAhead = useCallback(() => {\n const { text, at } = typeahead.current;\n return text !== \"\" && Date.now() - at <= TYPEAHEAD_RESET_MS;\n }, []);\n\n const { setElement, visible, wrapContent } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n initialFocus: undefined,\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so (H1).\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n });\n\n const devRef = useCallback((element: HTMLElement) => {\n if (isDev && element.tagName === \"DIALOG\") {\n console.error(\n \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\",\n );\n }\n return () => {};\n }, []);\n const ref = useMemo(() => mergeRefs(setElement, devRef), [setElement, devRef]);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = { open: popover.committed, side, align, submenu };\n\n const runTypeahead = (popup: HTMLElement, current: HTMLElement | null, key: string): boolean => {\n const now = Date.now();\n const buffer = typeahead.current;\n if (buffer.text === \"\" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = \"\";\n if (key === \" \" && buffer.text === \"\") return false;\n buffer.text += key.toLowerCase();\n buffer.at = now;\n const items = menuItems(popup);\n if (items.length === 0) return true;\n // A repeated single character cycles through the items starting with it; a longer buffer\n // keeps the current item while it still matches (design 5.1).\n const repeated = [...buffer.text].every((c) => c === buffer.text[0]);\n const search = repeated ? buffer.text[0]! : buffer.text;\n const index = current === null ? -1 : items.indexOf(current);\n const start = repeated || index < 0 ? index + 1 : index;\n for (let i = 0; i < items.length; i++) {\n const item = items[(start + i) % items.length]!;\n if (typeaheadText(item).startsWith(search)) {\n if (item !== current) focusItem(item);\n break;\n }\n }\n return true;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || hasModifier(event)) return;\n const popup = event.currentTarget;\n const target = event.target as HTMLElement;\n const onItem = isMenuItem(target, popup);\n if (!onItem && target !== popup) return;\n const key = event.key;\n\n // ArrowLeft (ArrowRight in RTL) closes a submenu; focus returns to its SubmenuTrigger\n // through the popover hook's nested focus rule (design 6.3).\n if (submenu && key === (isRtl(popup) ? \"ArrowRight\" : \"ArrowLeft\")) {\n event.preventDefault();\n popover.requestClose(event.nativeEvent, \"activate\");\n return;\n }\n\n if (key === \"ArrowDown\" || key === \"ArrowUp\" || key === \"Home\" || key === \"End\") {\n if (!onItem) {\n // The popup itself has focus (no items at open, or focus landed on it some other way):\n // into the list from its edge (review M1).\n event.preventDefault();\n const items = menuItems(popup);\n const item = key === \"ArrowDown\" || key === \"Home\" ? items[0] : items.at(-1);\n if (item !== undefined) focusItem(item);\n return;\n }\n // The browser moves focus itself where `focusgroup` is implemented.\n if (nativeFocusgroup) return;\n event.preventDefault();\n const items = menuItems(popup);\n const index = items.indexOf(target);\n const last = items.length - 1;\n let next: number;\n if (key === \"Home\") next = 0;\n else if (key === \"End\") next = last;\n else if (key === \"ArrowDown\") next = index >= last ? (loop ? 0 : last) : index + 1;\n else next = index <= 0 ? (loop ? last : 0) : index - 1;\n const item = items[next];\n if (item !== undefined && item !== target) focusItem(item);\n return;\n }\n\n if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) {\n event.preventDefault();\n }\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (popup.matches(\":popover-open\")) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (review M1, the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...(side !== null && { \"data-side\": side, \"data-align\": align }),\n };\n\n const content = (s: MenuPopupState): ReactNode => {\n let node: ReactNode;\n if (keepMounted === true) {\n node = (\n <Activity mode={visible ? \"visible\" : \"hidden\"}>\n {wrapContent(resolveStateValue(children, s))}\n </Activity>\n );\n } else {\n node = visible ? wrapContent(resolveStateValue(children, s)) : null;\n }\n return <MenuListContext value={listContext}>{node}</MenuListContext>;\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n side === null\n ? style\n : (s) => ({\n positionArea: positionArea(side, align),\n positionTryFallbacks: submenu ? \"flip-inline\" : POSITION_TRY_FALLBACKS,\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":"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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ChangeAction, RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
//#region src/menu/menu-radio-group.d.ts
|
|
4
|
+
export interface MenuRadioGroupState {
|
|
5
|
+
/** Optimistic value; `null` when no item is selected. */
|
|
6
|
+
readonly value: string | null;
|
|
7
|
+
/** `valueChangeAction` is in flight. */
|
|
8
|
+
readonly pending: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface MenuRadioGroupProps extends Omit<ComponentPropsWithRef<"div">, "role" | "defaultValue" | "className" | "style" | "children"> {
|
|
11
|
+
/** Controlled value; `null` selects nothing, `undefined` means uncontrolled. */
|
|
12
|
+
value?: string | null;
|
|
13
|
+
/** Initial value when uncontrolled. Default `null`. */
|
|
14
|
+
defaultValue?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Receives the chosen item's `value`, awaited inside the group's transition; the items'
|
|
17
|
+
* `aria-checked` follow at once and roll back on rejection. Re-activating the selected item
|
|
18
|
+
* dispatches nothing. May be a Server Function.
|
|
19
|
+
*/
|
|
20
|
+
valueChangeAction?: ChangeAction<string>;
|
|
21
|
+
className?: StateValue<string | undefined, MenuRadioGroupState>;
|
|
22
|
+
style?: StateValue<CSSProperties | undefined, MenuRadioGroupState>;
|
|
23
|
+
children?: StateValue<ReactNode, MenuRadioGroupState>;
|
|
24
|
+
render?: RenderProp<ComponentPropsWithRef<"div">, MenuRadioGroupState>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The state owner of a set of `Menu.RadioItem`s: `<div role="group" aria-labelledby>` (named by
|
|
28
|
+
* a `Menu.GroupLabel` inside it). Emits `data-pending` while `valueChangeAction` runs.
|
|
29
|
+
*
|
|
30
|
+
* Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged), `data-pending`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function MenuRadioGroup({ value, defaultValue, valueChangeAction, className, style, children, render, ...rest }: MenuRadioGroupProps): import("react").JSX.Element;
|
|
33
|
+
export declare namespace MenuRadioGroup {
|
|
34
|
+
var displayName: string;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//# sourceMappingURL=menu-radio-group.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-radio-group.d.mts","names":[],"sources":["../../src/menu/menu-radio-group.tsx"],"mappings":";;;iBAYiB;;WAEN;;WAEA;;iBAGM,4BAA4B,KAC3C;;EAIA;;EAEA;;;;;;EAMA,oBAAoB;EACpB,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,8BAA8B;;;;;;;;wBASpC,iBACd,OACA,cACA,mBACA,WACA,OACA,UACA,WACG,QACF,sCAAmB,IAAA;yBATN"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createActionDetails } from "../internal/action-details.mjs";
|
|
3
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
+
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
5
|
+
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
6
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
7
|
+
import { MenuGroupContext, MenuRadioGroupContext } from "./menu-context.mjs";
|
|
8
|
+
import { useId, useRef } from "react";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
//#region src/menu/menu-radio-group.tsx
|
|
11
|
+
/**
|
|
12
|
+
* The state owner of a set of `Menu.RadioItem`s: `<div role="group" aria-labelledby>` (named by
|
|
13
|
+
* a `Menu.GroupLabel` inside it). Emits `data-pending` while `valueChangeAction` runs.
|
|
14
|
+
*
|
|
15
|
+
* Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged), `data-pending`.
|
|
16
|
+
*/
|
|
17
|
+
function MenuRadioGroup({ value, defaultValue, valueChangeAction, className, style, children, render, ...rest }) {
|
|
18
|
+
const labelId = `${useId()}-label`;
|
|
19
|
+
const after = useRef(/* @__PURE__ */ new WeakMap());
|
|
20
|
+
const { optimistic, pending, dispatch } = useControllableAction({
|
|
21
|
+
controlled: value,
|
|
22
|
+
defaultValue,
|
|
23
|
+
initialValue: null,
|
|
24
|
+
action: async (next, details) => {
|
|
25
|
+
if (next !== null) await valueChangeAction?.(next, details);
|
|
26
|
+
after.current.get(details)?.();
|
|
27
|
+
},
|
|
28
|
+
transitionTypes: () => transitionTypes("menu", "select"),
|
|
29
|
+
warn: {
|
|
30
|
+
component: "Menu.RadioGroup",
|
|
31
|
+
prop: "value"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const context = {
|
|
35
|
+
value: optimistic,
|
|
36
|
+
pending,
|
|
37
|
+
select: (next, event, then) => {
|
|
38
|
+
const details = createActionDetails(event, {});
|
|
39
|
+
if (then !== void 0) after.current.set(details, then);
|
|
40
|
+
dispatch(next, details);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const element = useRender({
|
|
44
|
+
defaultElement: "div",
|
|
45
|
+
render,
|
|
46
|
+
state: {
|
|
47
|
+
value: optimistic,
|
|
48
|
+
pending
|
|
49
|
+
},
|
|
50
|
+
className,
|
|
51
|
+
style,
|
|
52
|
+
children,
|
|
53
|
+
props: rest,
|
|
54
|
+
libraryProps: {
|
|
55
|
+
role: "group",
|
|
56
|
+
"aria-labelledby": labelId,
|
|
57
|
+
"data-pending": dataAttr(pending)
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsx(MenuGroupContext, {
|
|
61
|
+
value: { labelId },
|
|
62
|
+
children: /* @__PURE__ */ jsx(MenuRadioGroupContext, {
|
|
63
|
+
value: context,
|
|
64
|
+
children: element
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
MenuRadioGroup.displayName = "MenuRadioGroup";
|
|
69
|
+
//#endregion
|
|
70
|
+
export { MenuRadioGroup };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=menu-radio-group.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-radio-group.mjs","names":[],"sources":["../../src/menu/menu-radio-group.tsx"],"sourcesContent":["\"use client\";\nimport { useId, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ActionDetails, ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { MenuGroupContext, MenuRadioGroupContext } from \"./menu-context.js\";\nimport type { MenuRadioGroupContextValue } from \"./menu-context.js\";\n\nexport interface MenuRadioGroupState {\n /** Optimistic value; `null` when no item is selected. */\n readonly value: string | null;\n /** `valueChangeAction` is in flight. */\n readonly pending: boolean;\n}\n\nexport interface MenuRadioGroupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"defaultValue\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` selects nothing, `undefined` means uncontrolled. */\n value?: string | null;\n /** Initial value when uncontrolled. Default `null`. */\n defaultValue?: string | null;\n /**\n * Receives the chosen item's `value`, awaited inside the group's transition; the items'\n * `aria-checked` follow at once and roll back on rejection. Re-activating the selected item\n * dispatches nothing. May be a Server Function.\n */\n valueChangeAction?: ChangeAction<string>;\n className?: StateValue<string | undefined, MenuRadioGroupState>;\n style?: StateValue<CSSProperties | undefined, MenuRadioGroupState>;\n children?: StateValue<ReactNode, MenuRadioGroupState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>;\n}\n\n/**\n * The state owner of a set of `Menu.RadioItem`s: `<div role=\"group\" aria-labelledby>` (named by\n * a `Menu.GroupLabel` inside it). Emits `data-pending` while `valueChangeAction` runs.\n *\n * Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged), `data-pending`.\n */\nexport function MenuRadioGroup({\n value,\n defaultValue,\n valueChangeAction,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuRadioGroupProps) {\n const labelId = `${useId()}-label`;\n // The work to run after a dispatch's action resolved (an item's `closeOnActivate`), keyed by\n // the dispatch's details object.\n const after = useRef(new WeakMap<object, () => void>());\n\n const { optimistic, pending, dispatch } = useControllableAction<string | null>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: async (next, details) => {\n if (next !== null) await valueChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: () => transitionTypes(\"menu\", \"select\"),\n warn: { component: \"Menu.RadioGroup\", prop: \"value\" },\n });\n\n const context: MenuRadioGroupContextValue = {\n value: optimistic,\n pending,\n select: (next, event, then) => {\n const details = createActionDetails(event, {}) as ActionDetails;\n if (then !== undefined) after.current.set(details, then);\n dispatch(next, details);\n },\n };\n\n const state: MenuRadioGroupState = { value: optimistic, pending };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuRadioGroupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n role: \"group\",\n \"aria-labelledby\": labelId,\n \"data-pending\": dataAttr(pending),\n },\n });\n\n return (\n <MenuGroupContext value={{ labelId }}>\n <MenuRadioGroupContext value={context}>{element}</MenuRadioGroupContext>\n </MenuGroupContext>\n );\n}\n\nMenuRadioGroup.displayName = \"MenuRadioGroup\";\n"],"mappings":";;;;;;;;;;;;;;;;AA6CA,SAAgB,eAAe,EAC7B,OACA,cACA,mBACA,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,UAAU,GAAG,MAAM,EAAE;CAG3B,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CAEtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAAqC;EAC7E,YAAY;EACZ;EACA,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,IAAI,SAAS,MAAM,MAAM,oBAAoB,MAAM,OAAO;GAC1D,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,uBAAuB,gBAAgB,QAAQ,QAAQ;EACvD,MAAM;GAAE,WAAW;GAAmB,MAAM;EAAQ;CACtD,CAAC;CAED,MAAM,UAAsC;EAC1C,OAAO;EACP;EACA,SAAS,MAAM,OAAO,SAAS;GAC7B,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,SAAS,KAAA,GAAW,MAAM,QAAQ,IAAI,SAAS,IAAI;GACvD,SAAS,MAAM,OAAO;EACxB;CACF;CAIA,MAAM,UAAU,UAA6D;EAC3E,gBAAgB;EAChB;EACA,OAAA;GALmC,OAAO;GAAY;EAKlD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,MAAM;GACN,mBAAmB;GACnB,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;CAED,OACE,oBAAC,kBAAD;EAAkB,OAAO,EAAE,QAAQ;EACjC,UAAA,oBAAC,uBAAD;GAAuB,OAAO;GAAU,UAAA;EAA+B,CAAA;CACvD,CAAA;AAEtB;AAEA,eAAe,cAAc"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { MenuCheckboxItemProps } from "./menu-checkbox-item.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
4
|
+
//#region src/menu/menu-radio-item.d.ts
|
|
5
|
+
export interface MenuRadioItemState {
|
|
6
|
+
/** This item is the group's optimistic value (`aria-checked`). */
|
|
7
|
+
readonly checked: boolean;
|
|
8
|
+
/** The group's change to this item is in flight. */
|
|
9
|
+
readonly pending: boolean;
|
|
10
|
+
readonly disabled: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface MenuRadioItemProps extends Omit<MenuCheckboxItemProps, "checked" | "defaultChecked" | "checkedChangeAction" | "className" | "style" | "children" | "render"> {
|
|
13
|
+
/** The value the group's `valueChangeAction` receives when this item is chosen. */
|
|
14
|
+
value: string;
|
|
15
|
+
className?: StateValue<string | undefined, MenuRadioItemState>;
|
|
16
|
+
style?: StateValue<CSSProperties | undefined, MenuRadioItemState>;
|
|
17
|
+
children?: StateValue<ReactNode, MenuRadioItemState>;
|
|
18
|
+
render?: RenderProp<ComponentPropsWithRef<"button">, MenuRadioItemState>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One option of a `Menu.RadioGroup`: `<button type="button" role="menuitemradio" aria-checked>`.
|
|
22
|
+
* Activation selects it through the group's transition (nothing is dispatched when it is already
|
|
23
|
+
* selected); the menu stays open unless `closeOnActivate`.
|
|
24
|
+
*
|
|
25
|
+
* Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked`, `data-checked`, and
|
|
26
|
+
* `value` (not rendered: a menu item is not a form control).
|
|
27
|
+
*/
|
|
28
|
+
export declare function MenuRadioItem({ value, closeOnActivate, disabled, label, className, style, children, render, ...rest }: MenuRadioItemProps): ReactNode;
|
|
29
|
+
export declare namespace MenuRadioItem {
|
|
30
|
+
var displayName: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=menu-radio-item.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-radio-item.d.mts","names":[],"sources":["../../src/menu/menu-radio-item.tsx"],"mappings":";;;;iBAUiB;;WAEN;;WAEA;WACA;;iBAGM,2BAA2B,KAC1C;;EAUA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;wBAWvC,gBACd,OACA,iBACA,UACA,OACA,WACA,OACA,UACA,WACG,QACF,qBAAkB;yBAVL"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { dataAttr } from "../internal/data-attr.mjs";
|
|
3
|
+
import { rendersButton, useRender } from "../internal/use-render.mjs";
|
|
4
|
+
import { MenuRadioGroupContext, closeStackLater, useMenuContext } from "./menu-context.mjs";
|
|
5
|
+
import { useMenuItem } from "./use-menu-item.mjs";
|
|
6
|
+
import { use } from "react";
|
|
7
|
+
//#region src/menu/menu-radio-item.tsx
|
|
8
|
+
/**
|
|
9
|
+
* One option of a `Menu.RadioGroup`: `<button type="button" role="menuitemradio" aria-checked>`.
|
|
10
|
+
* Activation selects it through the group's transition (nothing is dispatched when it is already
|
|
11
|
+
* selected); the menu stays open unless `closeOnActivate`.
|
|
12
|
+
*
|
|
13
|
+
* Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked`, `data-checked`, and
|
|
14
|
+
* `value` (not rendered: a menu item is not a form control).
|
|
15
|
+
*/
|
|
16
|
+
function MenuRadioItem({ value, closeOnActivate = false, disabled = false, label, className, style, children, render, ...rest }) {
|
|
17
|
+
const menu = useMenuContext("Menu.RadioItem");
|
|
18
|
+
const group = use(MenuRadioGroupContext);
|
|
19
|
+
if (group === null) throw new Error("Menu.RadioItem must be rendered inside a Menu.RadioGroup.");
|
|
20
|
+
const checked = group.value === value;
|
|
21
|
+
const pending = group.pending && checked;
|
|
22
|
+
const { libraryProps } = useMenuItem({
|
|
23
|
+
part: "Menu.RadioItem",
|
|
24
|
+
role: "menuitemradio",
|
|
25
|
+
disabled,
|
|
26
|
+
label,
|
|
27
|
+
activate: (event) => {
|
|
28
|
+
const close = closeOnActivate ? closeStackLater(menu, event) : void 0;
|
|
29
|
+
if (checked) {
|
|
30
|
+
close?.();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
group.select(value, event, close);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return useRender({
|
|
37
|
+
defaultElement: "button",
|
|
38
|
+
render,
|
|
39
|
+
state: {
|
|
40
|
+
checked,
|
|
41
|
+
pending,
|
|
42
|
+
disabled
|
|
43
|
+
},
|
|
44
|
+
className,
|
|
45
|
+
style,
|
|
46
|
+
children,
|
|
47
|
+
props: rest,
|
|
48
|
+
libraryProps: {
|
|
49
|
+
...rendersButton(render) && { type: "button" },
|
|
50
|
+
...libraryProps,
|
|
51
|
+
value: void 0,
|
|
52
|
+
"aria-checked": checked,
|
|
53
|
+
"data-checked": dataAttr(checked),
|
|
54
|
+
"data-pending": dataAttr(pending)
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
MenuRadioItem.displayName = "MenuRadioItem";
|
|
59
|
+
//#endregion
|
|
60
|
+
export { MenuRadioItem };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=menu-radio-item.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-radio-item.mjs","names":[],"sources":["../../src/menu/menu-radio-item.tsx"],"sourcesContent":["\"use client\";\nimport { use } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { MenuCheckboxItemProps } from \"./menu-checkbox-item.js\";\nimport { closeStackLater, MenuRadioGroupContext, useMenuContext } from \"./menu-context.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nexport interface MenuRadioItemState {\n /** This item is the group's optimistic value (`aria-checked`). */\n readonly checked: boolean;\n /** The group's change to this item is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface MenuRadioItemProps extends Omit<\n MenuCheckboxItemProps,\n | \"checked\"\n | \"defaultChecked\"\n | \"checkedChangeAction\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n /** The value the group's `valueChangeAction` receives when this item is chosen. */\n value: string;\n className?: StateValue<string | undefined, MenuRadioItemState>;\n style?: StateValue<CSSProperties | undefined, MenuRadioItemState>;\n children?: StateValue<ReactNode, MenuRadioItemState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuRadioItemState>;\n}\n\n/**\n * One option of a `Menu.RadioGroup`: `<button type=\"button\" role=\"menuitemradio\" aria-checked>`.\n * Activation selects it through the group's transition (nothing is dispatched when it is already\n * selected); the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked`, `data-checked`, and\n * `value` (not rendered: a menu item is not a form control).\n */\nexport function MenuRadioItem({\n value,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuRadioItemProps) {\n const menu = useMenuContext(\"Menu.RadioItem\");\n const group = use(MenuRadioGroupContext);\n if (group === null) throw new Error(\"Menu.RadioItem must be rendered inside a Menu.RadioGroup.\");\n\n const checked = group.value === value;\n const pending = group.pending && checked;\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.RadioItem\",\n role: \"menuitemradio\",\n disabled,\n label,\n activate: (event) => {\n const close = closeOnActivate ? closeStackLater(menu, event) : undefined;\n // Re-activating the selected item changes nothing (conventions 2.3 item 8); with\n // `closeOnActivate` it still closes the menu, as any activation does.\n if (checked) {\n close?.();\n return;\n }\n group.select(value, event, close);\n },\n });\n\n const state: MenuRadioItemState = { checked, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuRadioItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n value: undefined,\n \"aria-checked\": checked,\n \"data-checked\": dataAttr(checked),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuRadioItem.displayName = \"MenuRadioItem\";\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,SAAgB,cAAc,EAC5B,OACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,OAAO,eAAe,gBAAgB;CAC5C,MAAM,QAAQ,IAAI,qBAAqB;CACvC,IAAI,UAAU,MAAM,MAAM,IAAI,MAAM,2DAA2D;CAE/F,MAAM,UAAU,MAAM,UAAU;CAChC,MAAM,UAAU,MAAM,WAAW;CAEjC,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,QAAQ,kBAAkB,gBAAgB,MAAM,KAAK,IAAI,KAAA;GAG/D,IAAI,SAAS;IACX,QAAQ;IACR;GACF;GACA,MAAM,OAAO,OAAO,OAAO,KAAK;EAClC;CACF,CAAC;CAID,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA,OAAA;GALkC;GAAS;GAAS;EAKhD;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,OAAO,KAAA;GACP,gBAAgB;GAChB,gBAAgB,SAAS,OAAO;GAChC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,cAAc,cAAc"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ActionDetails, ChangeAction, ChangeReason, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/menu/menu-root.d.ts
|
|
4
|
+
/** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */
|
|
5
|
+
export interface MenuOpenChangeDetails extends ActionDetails {
|
|
6
|
+
/**
|
|
7
|
+
* `"activate"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,
|
|
8
|
+
* arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a
|
|
9
|
+
* foreign invoker.
|
|
10
|
+
* `"dismiss"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a
|
|
11
|
+
* hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.
|
|
12
|
+
* `"platform"`: the menu was found open on mount (opened before hydration); `event` is
|
|
13
|
+
* `undefined`.
|
|
14
|
+
*/
|
|
15
|
+
readonly reason: ChangeReason;
|
|
16
|
+
}
|
|
17
|
+
export interface MenuRootState {
|
|
18
|
+
/** Optimistic open state. Content rendered from it must not suspend. */
|
|
19
|
+
readonly open: boolean;
|
|
20
|
+
/** An open or close of this Root is in flight (its `openChangeAction`). */
|
|
21
|
+
readonly pending: boolean;
|
|
22
|
+
/** This Root is a submenu (rendered inside a `Menu.Popup`). */
|
|
23
|
+
readonly submenu: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface MenuRootProps {
|
|
26
|
+
/** Controlled open state. `undefined` means uncontrolled. */
|
|
27
|
+
open?: boolean;
|
|
28
|
+
/** Initial open state when uncontrolled. Opens after hydration. */
|
|
29
|
+
defaultOpen?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the
|
|
32
|
+
* closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a
|
|
33
|
+
* submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu
|
|
34
|
+
* closing). May be a Server Function. A `setState` placed after your own `await` needs
|
|
35
|
+
* `startTransition` (React limitation).
|
|
36
|
+
*/
|
|
37
|
+
openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;
|
|
38
|
+
/** Arrow keys wrap from the last item to the first and back. Default `true`. */
|
|
39
|
+
loop?: boolean;
|
|
40
|
+
/** Submenu only: milliseconds from hovering the SubmenuTrigger to the open. Default 100. */
|
|
41
|
+
delay?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the
|
|
44
|
+
* close. Default 150.
|
|
45
|
+
*/
|
|
46
|
+
closeDelay?: number;
|
|
47
|
+
children?: StateValue<ReactNode, MenuRootState>;
|
|
48
|
+
}
|
|
49
|
+
export declare function MenuRoot({ open, defaultOpen, openChangeAction, loop, delay, closeDelay, children }: MenuRootProps): import("react").JSX.Element;
|
|
50
|
+
export declare namespace MenuRoot {
|
|
51
|
+
var displayName: string;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//# sourceMappingURL=menu-root.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-root.d.mts","names":[],"sources":["../../src/menu/menu-root.tsx"],"mappings":";;;;iBAYiB,8BAA8B;;;;;;;;;;WAUpC,QAAQ;;iBAGF;;WAEN;;WAEA;;WAEA;;iBAGM;;EAEf;;EAEA;;;;;;;;EAQA,mBAAmB,sBAAsB;;EAEzC;;EAEA;;;;;EAKA;EACA,WAAW,WAAW,WAAW;;wBAenB,WACd,MACA,aACA,kBACA,MACA,OACA,YACA,YACC,gCAAa,IAAA;yBARA"}
|