@funstack/ui 0.1.0-alpha.0 → 0.1.0-alpha.2
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/combobox/combobox-clear.d.mts +34 -0
- package/dist/combobox/combobox-clear.d.mts.map +1 -0
- package/dist/combobox/combobox-clear.mjs +58 -0
- package/dist/combobox/combobox-clear.mjs.map +1 -0
- package/dist/combobox/combobox-context.mjs +23 -0
- package/dist/combobox/combobox-context.mjs.map +1 -0
- package/dist/combobox/combobox-group.d.mts +72 -0
- package/dist/combobox/combobox-group.d.mts.map +1 -0
- package/dist/combobox/combobox-group.mjs +104 -0
- package/dist/combobox/combobox-group.mjs.map +1 -0
- package/dist/combobox/combobox-input.d.mts +40 -0
- package/dist/combobox/combobox-input.d.mts.map +1 -0
- package/dist/combobox/combobox-input.mjs +88 -0
- package/dist/combobox/combobox-input.mjs.map +1 -0
- package/dist/combobox/combobox-label.d.mts +22 -0
- package/dist/combobox/combobox-label.d.mts.map +1 -0
- package/dist/combobox/combobox-label.mjs +32 -0
- package/dist/combobox/combobox-label.mjs.map +1 -0
- package/dist/combobox/combobox-list.d.mts +37 -0
- package/dist/combobox/combobox-list.d.mts.map +1 -0
- package/dist/combobox/combobox-list.mjs +70 -0
- package/dist/combobox/combobox-list.mjs.map +1 -0
- package/dist/combobox/combobox-option.d.mts +45 -0
- package/dist/combobox/combobox-option.d.mts.map +1 -0
- package/dist/combobox/combobox-option.mjs +88 -0
- package/dist/combobox/combobox-option.mjs.map +1 -0
- package/dist/combobox/combobox-popup.d.mts +49 -0
- package/dist/combobox/combobox-popup.d.mts.map +1 -0
- package/dist/combobox/combobox-popup.mjs +86 -0
- package/dist/combobox/combobox-popup.mjs.map +1 -0
- package/dist/combobox/combobox-root.d.mts +135 -0
- package/dist/combobox/combobox-root.d.mts.map +1 -0
- package/dist/combobox/combobox-root.mjs +508 -0
- package/dist/combobox/combobox-root.mjs.map +1 -0
- package/dist/combobox/combobox-trigger.d.mts +36 -0
- package/dist/combobox/combobox-trigger.d.mts.map +1 -0
- package/dist/combobox/combobox-trigger.mjs +92 -0
- package/dist/combobox/combobox-trigger.mjs.map +1 -0
- package/dist/combobox/index.d.mts +36 -0
- package/dist/combobox/index.d.mts.map +1 -0
- package/dist/combobox/index.mjs +36 -0
- package/dist/combobox/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 +42 -2
- package/dist/index.mjs +6 -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 +18 -1
- 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/types.d.mts +8 -0
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +58 -0
- package/dist/internal/use-action-trigger.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +5 -1
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- 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-form-reset.mjs +5 -1
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-hydrated-mount.mjs +21 -0
- package/dist/internal/use-hydrated-mount.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-native-select-value.mjs +182 -0
- package/dist/internal/use-native-select-value.mjs.map +1 -0
- 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/select/index.d.mts +30 -0
- package/dist/select/index.d.mts.map +1 -0
- package/dist/select/index.mjs +30 -0
- package/dist/select/index.mjs.map +1 -0
- package/dist/select/select-context.mjs +13 -0
- package/dist/select/select-context.mjs.map +1 -0
- package/dist/select/select-dom.mjs +44 -0
- package/dist/select/select-dom.mjs.map +1 -0
- package/dist/select/select-group-label.d.mts +22 -0
- package/dist/select/select-group-label.d.mts.map +1 -0
- package/dist/select/select-group-label.mjs +39 -0
- package/dist/select/select-group-label.mjs.map +1 -0
- package/dist/select/select-group.d.mts +28 -0
- package/dist/select/select-group.d.mts.map +1 -0
- package/dist/select/select-group.mjs +45 -0
- package/dist/select/select-group.mjs.map +1 -0
- package/dist/select/select-option.d.mts +42 -0
- package/dist/select/select-option.d.mts.map +1 -0
- package/dist/select/select-option.mjs +65 -0
- package/dist/select/select-option.mjs.map +1 -0
- package/dist/select/select-root.d.mts +66 -0
- package/dist/select/select-root.d.mts.map +1 -0
- package/dist/select/select-root.mjs +94 -0
- package/dist/select/select-root.mjs.map +1 -0
- package/dist/select/select-separator.d.mts +20 -0
- package/dist/select/select-separator.d.mts.map +1 -0
- package/dist/select/select-separator.mjs +30 -0
- package/dist/select/select-separator.mjs.map +1 -0
- package/dist/select/select-trigger.d.mts +29 -0
- package/dist/select/select-trigger.d.mts.map +1 -0
- package/dist/select/select-trigger.mjs +48 -0
- package/dist/select/select-trigger.mjs.map +1 -0
- package/dist/select/select-value.d.mts +31 -0
- package/dist/select/select-value.d.mts.map +1 -0
- package/dist/select/select-value.mjs +101 -0
- package/dist/select/select-value.mjs.map +1 -0
- 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 +6 -1
|
@@ -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"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { resolveStateValue } from "../internal/use-render.mjs";
|
|
3
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
|
+
import { useDelayedPair } from "../internal/use-delayed-pair.mjs";
|
|
5
|
+
import { usePopoverRoot } from "../internal/use-popover-root.mjs";
|
|
6
|
+
import { MenuContext, MenuListContext } from "./menu-context.mjs";
|
|
7
|
+
import { use, useCallback, useMemo, useRef } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
//#region src/menu/menu-root.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`
|
|
12
|
+
* rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an
|
|
13
|
+
* item of the parent menu) and its Popup opens beside that item.
|
|
14
|
+
*
|
|
15
|
+
* A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a
|
|
16
|
+
* part asks for are transitions (pending Trigger, items render from committed state,
|
|
17
|
+
* `showPopover()` / `hidePopover()` once the change has committed); dismissals are the
|
|
18
|
+
* browser's and `openChangeAction(false)` is a notification.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_FOCUS = {
|
|
21
|
+
cause: "first",
|
|
22
|
+
pointer: false
|
|
23
|
+
};
|
|
24
|
+
function MenuRoot({ open, defaultOpen, openChangeAction, loop = true, delay, closeDelay, children }) {
|
|
25
|
+
const parent = use(MenuContext);
|
|
26
|
+
const list = use(MenuListContext);
|
|
27
|
+
const parentMenu = list !== null ? list.menu : null;
|
|
28
|
+
const submenu = parentMenu !== null;
|
|
29
|
+
useDevWarning(!submenu && (delay !== void 0 || closeDelay !== void 0), "Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a Menu.Popup); a top-level menu does not open on hover.");
|
|
30
|
+
useDevWarning(parent !== null && !submenu, "Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root goes inside the parent's Menu.Popup.");
|
|
31
|
+
const timers = useDelayedPair();
|
|
32
|
+
const nextCause = useRef(null);
|
|
33
|
+
const openCause = useRef(null);
|
|
34
|
+
const popover = usePopoverRoot({
|
|
35
|
+
component: "menu",
|
|
36
|
+
part: "Menu.Root",
|
|
37
|
+
mode: "library",
|
|
38
|
+
open,
|
|
39
|
+
defaultOpen,
|
|
40
|
+
openChangeAction,
|
|
41
|
+
onDispatch: (next) => {
|
|
42
|
+
timers.cancel();
|
|
43
|
+
if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;
|
|
44
|
+
nextCause.current = null;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const setOpenCause = useCallback((cause, pointer = false) => {
|
|
48
|
+
nextCause.current = {
|
|
49
|
+
cause,
|
|
50
|
+
pointer
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
const takeOpenCause = useCallback(() => {
|
|
54
|
+
const cause = openCause.current ?? DEFAULT_FOCUS;
|
|
55
|
+
openCause.current = null;
|
|
56
|
+
return cause;
|
|
57
|
+
}, []);
|
|
58
|
+
const resolvedDelay = delay ?? 100;
|
|
59
|
+
const resolvedCloseDelay = closeDelay ?? 150;
|
|
60
|
+
const value = useMemo(() => {
|
|
61
|
+
const self = {
|
|
62
|
+
popover,
|
|
63
|
+
submenu,
|
|
64
|
+
get root() {
|
|
65
|
+
return parentMenu?.root ?? self;
|
|
66
|
+
},
|
|
67
|
+
parent: parentMenu,
|
|
68
|
+
loop,
|
|
69
|
+
delay: resolvedDelay,
|
|
70
|
+
closeDelay: resolvedCloseDelay,
|
|
71
|
+
triggerId: `${popover.ids.popup}-trigger`,
|
|
72
|
+
setOpenCause,
|
|
73
|
+
takeOpenCause,
|
|
74
|
+
timers
|
|
75
|
+
};
|
|
76
|
+
return self;
|
|
77
|
+
}, [
|
|
78
|
+
popover,
|
|
79
|
+
submenu,
|
|
80
|
+
parentMenu,
|
|
81
|
+
loop,
|
|
82
|
+
resolvedDelay,
|
|
83
|
+
resolvedCloseDelay,
|
|
84
|
+
setOpenCause,
|
|
85
|
+
takeOpenCause,
|
|
86
|
+
timers
|
|
87
|
+
]);
|
|
88
|
+
const state = {
|
|
89
|
+
open: popover.optimistic,
|
|
90
|
+
pending: popover.pending,
|
|
91
|
+
submenu
|
|
92
|
+
};
|
|
93
|
+
return /* @__PURE__ */ jsx(MenuContext, {
|
|
94
|
+
value,
|
|
95
|
+
children: resolveStateValue(children, state)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
MenuRoot.displayName = "MenuRoot";
|
|
99
|
+
//#endregion
|
|
100
|
+
export { MenuRoot };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=menu-root.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-root.mjs","names":[],"sources":["../../src/menu/menu-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useMemo, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { ActionDetails, ChangeAction, ChangeReason, StateValue } from \"../internal/types.js\";\nimport { useDelayedPair } from \"../internal/use-delayed-pair.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverRoot } from \"../internal/use-popover-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { MenuContext, MenuListContext } from \"./menu-context.js\";\nimport type { MenuContextValue, MenuOpenFocus } from \"./menu-context.js\";\n\n/** Details passed as the second argument of `Menu.Root`'s `openChangeAction`. */\nexport interface MenuOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: the Trigger or SubmenuTrigger (click, Enter / Space,\n * arrow keys), an item's activation (the close after its action), ArrowLeft in a submenu, or a\n * foreign invoker.\n * `\"dismiss\"`: Escape, a click outside, Tab or focus leaving the menu, the pointer leaving a\n * hover-opened submenu, the parent menu closing (a submenu when the whole stack closes), script.\n * `\"platform\"`: the menu was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n}\n\nexport interface MenuRootState {\n /** Optimistic open state. Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An open or close of this Root is in flight (its `openChangeAction`). */\n readonly pending: boolean;\n /** This Root is a submenu (rendered inside a `Menu.Popup`). */\n readonly submenu: boolean;\n}\n\nexport interface MenuRootProps {\n /** Controlled open state. `undefined` means uncontrolled. */\n open?: boolean;\n /** Initial open state when uncontrolled. Opens after hydration. */\n defaultOpen?: boolean;\n /**\n * Awaited for `true` (the menu opens when it resolves and the items have rendered) and for the\n * closes the user asks a part for (Trigger toggle, an item's activation, ArrowLeft in a\n * submenu); a notification for dismissals (Escape, a click outside, Tab, the parent menu\n * closing). May be a Server Function. A `setState` placed after your own `await` needs\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, MenuOpenChangeDetails>;\n /** Arrow keys wrap from the last item to the first and back. Default `true`. */\n loop?: boolean;\n /** Submenu only: milliseconds from hovering the SubmenuTrigger to the open. Default 100. */\n delay?: number;\n /**\n * Submenu only: milliseconds from the pointer leaving the SubmenuTrigger and the submenu to the\n * close. Default 150.\n */\n closeDelay?: number;\n children?: StateValue<ReactNode, MenuRootState>;\n}\n\n/**\n * Owns the ids, the open state and the context of one menu level. Renders no DOM. A `Menu.Root`\n * rendered inside a `Menu.Popup` is a **submenu**: its Trigger is a `Menu.SubmenuTrigger` (an\n * item of the parent menu) and its Popup opens beside that item.\n *\n * A menu is always in library mode (design/components/menu.md 2.1): opening and the closes a\n * part asks for are transitions (pending Trigger, items render from committed state,\n * `showPopover()` / `hidePopover()` once the change has committed); dismissals are the\n * browser's and `openChangeAction(false)` is a notification.\n */\nconst DEFAULT_FOCUS: MenuOpenFocus = { cause: \"first\", pointer: false };\n\nexport function MenuRoot({\n open,\n defaultOpen,\n openChangeAction,\n loop = true,\n delay,\n closeDelay,\n children,\n}: MenuRootProps) {\n const parent = use(MenuContext);\n const list = use(MenuListContext);\n // A Root inside a Popup's content is a submenu (design 1); the enclosing menu is the Popup's.\n const parentMenu = list !== null ? list.menu : null;\n const submenu = parentMenu !== null;\n\n useDevWarning(\n !submenu && (delay !== undefined || closeDelay !== undefined),\n \"Menu.Root: `delay` and `closeDelay` only apply to a submenu (a Menu.Root inside a \" +\n \"Menu.Popup); a top-level menu does not open on hover.\",\n );\n useDevWarning(\n parent !== null && !submenu,\n \"Menu.Root: rendered inside another Menu.Root but outside its Menu.Popup. A submenu's Root \" +\n \"goes inside the parent's Menu.Popup.\",\n );\n\n const timers = useDelayedPair();\n // The cause recorded by the part about to dispatch an open, and the cause of the open being\n // shown (design 14, \"Open cause\").\n const nextCause = useRef<MenuOpenFocus | null>(null);\n const openCause = useRef<MenuOpenFocus | null>(null);\n\n const popover = usePopoverRoot<MenuOpenChangeDetails>({\n component: \"menu\",\n part: \"Menu.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onDispatch: (next) => {\n // Any dispatch cancels hover intent (walkthrough 9).\n timers.cancel();\n if (next) openCause.current = nextCause.current ?? DEFAULT_FOCUS;\n nextCause.current = null;\n },\n });\n\n const setOpenCause = useCallback((cause: MenuOpenFocus[\"cause\"], pointer = false) => {\n nextCause.current = { cause, pointer };\n }, []);\n const takeOpenCause = useCallback(() => {\n const cause = openCause.current ?? DEFAULT_FOCUS;\n openCause.current = null;\n return cause;\n }, []);\n\n const resolvedDelay = delay ?? 100;\n const resolvedCloseDelay = closeDelay ?? 150;\n // Note: `popover` is a new object on every render (the shared `usePopoverRoot` is not memoised:\n // its `dispatch` closes over the render's state), so today this recomputes on every render of\n // the Root and the parts re-render with it, as Popover's do. The other members are stable; the\n // memo starts to hit without further change once that hook returns a stable value.\n const value = useMemo<MenuContextValue>(() => {\n const self: MenuContextValue = {\n popover,\n submenu,\n // The top-level menu: this one, or the parent's root (design 2.2).\n get root() {\n return parentMenu?.root ?? self;\n },\n parent: parentMenu,\n loop,\n delay: resolvedDelay,\n closeDelay: resolvedCloseDelay,\n triggerId: `${popover.ids.popup}-trigger`,\n setOpenCause,\n takeOpenCause,\n timers,\n };\n return self;\n }, [\n popover,\n submenu,\n parentMenu,\n loop,\n resolvedDelay,\n resolvedCloseDelay,\n setOpenCause,\n takeOpenCause,\n timers,\n ]);\n\n const state: MenuRootState = {\n open: popover.optimistic,\n pending: popover.pending,\n submenu,\n };\n\n return <MenuContext value={value}>{resolveStateValue(children, state)}</MenuContext>;\n}\n\nMenuRoot.displayName = \"MenuRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqEA,MAAM,gBAA+B;CAAE,OAAO;CAAS,SAAS;AAAM;AAEtE,SAAgB,SAAS,EACvB,MACA,aACA,kBACA,OAAO,MACP,OACA,YACA,YACgB;CAChB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,OAAO,IAAI,eAAe;CAEhC,MAAM,aAAa,SAAS,OAAO,KAAK,OAAO;CAC/C,MAAM,UAAU,eAAe;CAE/B,cACE,CAAC,YAAY,UAAU,KAAA,KAAa,eAAe,KAAA,IACnD,yIAEF;CACA,cACE,WAAW,QAAQ,CAAC,SACpB,gIAEF;CAEA,MAAM,SAAS,eAAe;CAG9B,MAAM,YAAY,OAA6B,IAAI;CACnD,MAAM,YAAY,OAA6B,IAAI;CAEnD,MAAM,UAAU,eAAsC;EACpD,WAAW;EACX,MAAM;EACN,MAAM;EACN;EACA;EACA;EACA,aAAa,SAAS;GAEpB,OAAO,OAAO;GACd,IAAI,MAAM,UAAU,UAAU,UAAU,WAAW;GACnD,UAAU,UAAU;EACtB;CACF,CAAC;CAED,MAAM,eAAe,aAAa,OAA+B,UAAU,UAAU;EACnF,UAAU,UAAU;GAAE;GAAO;EAAQ;CACvC,GAAG,CAAC,CAAC;CACL,MAAM,gBAAgB,kBAAkB;EACtC,MAAM,QAAQ,UAAU,WAAW;EACnC,UAAU,UAAU;EACpB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,SAAS;CAC/B,MAAM,qBAAqB,cAAc;CAKzC,MAAM,QAAQ,cAAgC;EAC5C,MAAM,OAAyB;GAC7B;GACA;GAEA,IAAI,OAAO;IACT,OAAO,YAAY,QAAQ;GAC7B;GACA,QAAQ;GACR;GACA,OAAO;GACP,YAAY;GACZ,WAAW,GAAG,QAAQ,IAAI,MAAM;GAChC;GACA;GACA;EACF;EACA,OAAO;CACT,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,MAAM,QAAQ;EACd,SAAS,QAAQ;EACjB;CACF;CAEA,OAAO,oBAAC,aAAD;EAAoB;EAAQ,UAAA,kBAAkB,UAAU,KAAK;CAAe,CAAA;AACrF;AAEA,SAAS,cAAc"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import { MenuItemProps } from "./menu-item.mjs";
|
|
3
|
+
import { MenuTriggerState } from "./menu-trigger.mjs";
|
|
4
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
|
+
//#region src/menu/menu-submenu-trigger.d.ts
|
|
6
|
+
export type MenuSubmenuTriggerState = MenuTriggerState;
|
|
7
|
+
export interface MenuSubmenuTriggerProps extends Omit<MenuItemProps, "action" | "closeOnActivate" | "aria-expanded" | "aria-haspopup" | "onPointerEnter" | "onPointerLeave" | "className" | "style" | "children" | "render"> {
|
|
8
|
+
className?: StateValue<string | undefined, MenuSubmenuTriggerState>;
|
|
9
|
+
style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;
|
|
10
|
+
/** Rendered from optimistic state; must not suspend. */
|
|
11
|
+
children?: StateValue<ReactNode, MenuSubmenuTriggerState>;
|
|
12
|
+
render?: RenderProp<ComponentPropsWithRef<"button">, MenuSubmenuTriggerState>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The item that opens a submenu: an item of the parent menu (`role="menuitem"`, roving
|
|
16
|
+
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`commandfor`,
|
|
17
|
+
* `command="toggle-popover"`, `aria-haspopup="menu"`, `aria-expanded`). ArrowRight (ArrowLeft in
|
|
18
|
+
* RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens
|
|
19
|
+
* the submenu after the Root's `delay` and leaves focus where it is.
|
|
20
|
+
*
|
|
21
|
+
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `commandfor`, `command`,
|
|
22
|
+
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`) and the item's (`role`,
|
|
23
|
+
* `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,
|
|
24
|
+
* `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function MenuSubmenuTrigger({ disabled, label, className, style, children, render, ...rest }: MenuSubmenuTriggerProps): ReactNode;
|
|
27
|
+
export declare namespace MenuSubmenuTrigger {
|
|
28
|
+
var displayName: string;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=menu-submenu-trigger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-submenu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"mappings":";;;;;YAoBY,0BAA0B;iBAErB,gCAAgC,KAC/C;EAYA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,qBACd,UACA,OACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBARV"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
|
+
import { usePopoverTrigger } from "../internal/use-popover-trigger.mjs";
|
|
5
|
+
import { useMenuContext } from "./menu-context.mjs";
|
|
6
|
+
import { hasModifier, isRtl } from "./menu-dom.mjs";
|
|
7
|
+
import { useMenuItem } from "./use-menu-item.mjs";
|
|
8
|
+
import { scheduleHoverClose } from "./menu-hover.mjs";
|
|
9
|
+
import { openMenuWithFocus } from "./menu-trigger.mjs";
|
|
10
|
+
//#region src/menu/menu-submenu-trigger.tsx
|
|
11
|
+
/**
|
|
12
|
+
* The item that opens a submenu: an item of the parent menu (`role="menuitem"`, roving
|
|
13
|
+
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`commandfor`,
|
|
14
|
+
* `command="toggle-popover"`, `aria-haspopup="menu"`, `aria-expanded`). ArrowRight (ArrowLeft in
|
|
15
|
+
* RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens
|
|
16
|
+
* the submenu after the Root's `delay` and leaves focus where it is.
|
|
17
|
+
*
|
|
18
|
+
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `commandfor`, `command`,
|
|
19
|
+
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`) and the item's (`role`,
|
|
20
|
+
* `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,
|
|
21
|
+
* `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).
|
|
22
|
+
*/
|
|
23
|
+
function MenuSubmenuTrigger({ disabled = false, label, className, style, children, render, ...rest }) {
|
|
24
|
+
const menu = useMenuContext("Menu.SubmenuTrigger");
|
|
25
|
+
useDevWarning(!menu.submenu, "Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root inside the parent's Menu.Popup.");
|
|
26
|
+
const open = (event) => openMenuWithFocus(menu, event, "first");
|
|
27
|
+
const item = useMenuItem({
|
|
28
|
+
part: "Menu.SubmenuTrigger",
|
|
29
|
+
role: "menuitem",
|
|
30
|
+
disabled,
|
|
31
|
+
label,
|
|
32
|
+
activate: open
|
|
33
|
+
});
|
|
34
|
+
const onKeyDown = (event) => {
|
|
35
|
+
if (event.defaultPrevented || hasModifier(event) || disabled) return;
|
|
36
|
+
const parentPopup = event.currentTarget.closest("[role=\"menu\"]");
|
|
37
|
+
const forward = parentPopup !== null && isRtl(parentPopup) ? "ArrowLeft" : "ArrowRight";
|
|
38
|
+
if (event.key !== forward) return;
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
open(event.nativeEvent);
|
|
41
|
+
};
|
|
42
|
+
const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {
|
|
43
|
+
part: "Menu.SubmenuTrigger",
|
|
44
|
+
disabled,
|
|
45
|
+
render,
|
|
46
|
+
disabledAs: "aria",
|
|
47
|
+
handlers: {
|
|
48
|
+
onKeyDown: (event) => {
|
|
49
|
+
item.libraryProps.onKeyDown(event);
|
|
50
|
+
onKeyDown(event);
|
|
51
|
+
},
|
|
52
|
+
onPointerMove: item.libraryProps.onPointerMove,
|
|
53
|
+
onPointerEnter: (event) => {
|
|
54
|
+
if (disabled || event.pointerType === "touch") return;
|
|
55
|
+
const native = event.nativeEvent;
|
|
56
|
+
menu.timers.open(menu.delay, () => {
|
|
57
|
+
menu.setOpenCause("none");
|
|
58
|
+
menu.popover.requestOpen(native, "activate");
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
onPointerLeave: (event) => {
|
|
62
|
+
if (event.pointerType === "touch") return;
|
|
63
|
+
if (menu.popover.intended()) scheduleHoverClose(menu, event.nativeEvent);
|
|
64
|
+
else menu.timers.cancel();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
activate: (event) => open(event.nativeEvent)
|
|
68
|
+
});
|
|
69
|
+
return useRender({
|
|
70
|
+
defaultElement: "button",
|
|
71
|
+
render,
|
|
72
|
+
state,
|
|
73
|
+
className,
|
|
74
|
+
style,
|
|
75
|
+
children,
|
|
76
|
+
props: rest,
|
|
77
|
+
libraryProps: {
|
|
78
|
+
...libraryProps,
|
|
79
|
+
role: item.libraryProps.role,
|
|
80
|
+
tabIndex: item.libraryProps.tabIndex,
|
|
81
|
+
"data-typeahead": item.libraryProps["data-typeahead"],
|
|
82
|
+
id: menu.triggerId,
|
|
83
|
+
"aria-haspopup": "menu"
|
|
84
|
+
},
|
|
85
|
+
ref
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
MenuSubmenuTrigger.displayName = "MenuSubmenuTrigger";
|
|
89
|
+
//#endregion
|
|
90
|
+
export { MenuSubmenuTrigger };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=menu-submenu-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`commandfor`,\n * `command=\"toggle-popover\"`, `aria-haspopup=\"menu\"`, `aria-expanded`). ArrowRight (ArrowLeft in\n * RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens\n * the submenu after the Root's `delay` and leaves focus where it is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `commandfor`, `command`,\n * `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`) and the item's (`role`,\n * `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,\n * `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below).\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n activate: open,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n disabledAs: \"aria\",\n // Item first (Enter / Space activation, pointer focus), then the submenu keys.\n handlers: {\n onKeyDown: (event) => {\n item.libraryProps.onKeyDown(event);\n onKeyDown(event);\n },\n onPointerMove: item.libraryProps.onPointerMove,\n onPointerEnter: (event: PointerEvent<HTMLButtonElement>) => {\n if (disabled || event.pointerType === \"touch\") return;\n const native = event.nativeEvent;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n },\n onPointerLeave: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType === \"touch\") return;\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, event.nativeEvent);\n else menu.timers.cancel();\n },\n },\n // A click opens (or moves focus into the open submenu); it never closes.\n activate: (event) => open(event.nativeEvent),\n });\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n role: item.libraryProps.role,\n tabIndex: item.libraryProps.tabIndex,\n \"data-typeahead\": item.libraryProps[\"data-typeahead\"],\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuSubmenuTrigger.displayName = \"MenuSubmenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,mBAAmB,EACjC,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAAe,qBAAqB;CACjD,cACE,CAAC,KAAK,SACN,4HAEF;CAEA,MAAM,QAAQ,UAAiB,kBAAkB,MAAM,OAAO,OAAO;CAIrE,MAAM,OAAO,YAAY;EACvB,MAAM;EACN,MAAM;EACN;EACA;EACA,UAAU;CACZ,CAAC;CAED,MAAM,aAAa,UAA4C;EAC7D,IAAI,MAAM,oBAAoB,YAAY,KAAK,KAAK,UAAU;EAC9D,MAAM,cAAc,MAAM,cAAc,QAAQ,iBAAe;EAC/D,MAAM,UAAU,gBAAgB,QAAQ,MAAM,WAAW,IAAI,cAAc;EAC3E,IAAI,MAAM,QAAQ,SAAS;EAC3B,MAAM,eAAe;EACrB,KAAK,MAAM,WAAW;CACxB;CAEA,MAAM,EAAE,OAAO,cAAc,QAAQ,kBAAkB,KAAK,SAAS;EACnE,MAAM;EACN;EACA;EACA,YAAY;EAEZ,UAAU;GACR,YAAY,UAAU;IACpB,KAAK,aAAa,UAAU,KAAK;IACjC,UAAU,KAAK;GACjB;GACA,eAAe,KAAK,aAAa;GACjC,iBAAiB,UAA2C;IAC1D,IAAI,YAAY,MAAM,gBAAgB,SAAS;IAC/C,MAAM,SAAS,MAAM;IACrB,KAAK,OAAO,KAAK,KAAK,aAAa;KACjC,KAAK,aAAa,MAAM;KACxB,KAAK,QAAQ,YAAY,QAAQ,UAAU;IAC7C,CAAC;GACH;GACA,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS;IAGnC,IAAI,KAAK,QAAQ,SAAS,GAAG,mBAAmB,MAAM,MAAM,WAAW;SAClE,KAAK,OAAO,OAAO;GAC1B;EACF;EAEA,WAAW,UAAU,KAAK,MAAM,WAAW;CAC7C,CAAC;CAED,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,MAAM,KAAK,aAAa;GACxB,UAAU,KAAK,aAAa;GAC5B,kBAAkB,KAAK,aAAa;GACpC,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
+
import "./menu-context.mjs";
|
|
3
|
+
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
4
|
+
//#region src/menu/menu-trigger.d.ts
|
|
5
|
+
export interface MenuTriggerState {
|
|
6
|
+
/** Optimistic open state. */
|
|
7
|
+
readonly open: boolean;
|
|
8
|
+
/** The Root's transition is pending (an open, a part-initiated close or a dismissal notification). */
|
|
9
|
+
readonly pending: boolean;
|
|
10
|
+
readonly disabled: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface MenuTriggerProps extends Omit<ComponentPropsWithRef<"button">, "onClick" | "onKeyDown" | "aria-expanded" | "aria-haspopup" | "className" | "style" | "children"> {
|
|
13
|
+
/** Native `disabled`: the menu cannot be opened from this button. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
className?: StateValue<string | undefined, MenuTriggerState>;
|
|
16
|
+
style?: StateValue<CSSProperties | undefined, MenuTriggerState>;
|
|
17
|
+
/** Rendered from optimistic state; must not suspend. */
|
|
18
|
+
children?: StateValue<ReactNode, MenuTriggerState>;
|
|
19
|
+
/** Should render a `<button>` (the command path before hydration). */
|
|
20
|
+
render?: RenderProp<ComponentPropsWithRef<"button">, MenuTriggerState>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The menu button: `<button type="button" commandfor command="toggle-popover"
|
|
24
|
+
* aria-haspopup="menu" aria-expanded>`. A click (Enter, Space) toggles the menu through the
|
|
25
|
+
* Root's transition; ArrowDown / ArrowUp open it with the first / last item focused.
|
|
26
|
+
*
|
|
27
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `commandfor`,
|
|
28
|
+
* `command`, `aria-haspopup`, `aria-expanded`, `onClick`, `onKeyDown`, `data-open`,
|
|
29
|
+
* `data-pending`, `data-disabled`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function MenuTrigger({ disabled, className, style, children, render, ...rest }: MenuTriggerProps): ReactNode;
|
|
32
|
+
export declare namespace MenuTrigger {
|
|
33
|
+
var displayName: string;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//# sourceMappingURL=menu-trigger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"mappings":";;;;iBAUiB;;WAEN;;WAEA;WACA;;iBAGM,yBAAyB,KACxC;;EAIA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;wBAuCvC,cACd,UACA,WACA,OACA,UACA,WACG,QACF,mBAAgB;yBAPH"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
4
|
+
import { usePopoverTrigger } from "../internal/use-popover-trigger.mjs";
|
|
5
|
+
import { useMenuContext } from "./menu-context.mjs";
|
|
6
|
+
import { edgeItem, focusItem, hasModifier } from "./menu-dom.mjs";
|
|
7
|
+
//#region src/menu/menu-trigger.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Opens with the first (`"first"`) or last (`"last"`) item focused, or focuses that item when the
|
|
10
|
+
* menu is already open (a pre-hydration open, walkthrough 10). Shared with SubmenuTrigger.
|
|
11
|
+
*/
|
|
12
|
+
function openMenuWithFocus(menu, event, which) {
|
|
13
|
+
const { popover } = menu;
|
|
14
|
+
if (popover.intended()) {
|
|
15
|
+
const popup = popover.popupRef.current;
|
|
16
|
+
if (popup !== null && popup.matches(":popover-open")) {
|
|
17
|
+
const item = edgeItem(popup, which);
|
|
18
|
+
if (item !== null) focusItem(item);
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
menu.setOpenCause(which, isPointerClick(event));
|
|
23
|
+
popover.requestOpen(event, "activate");
|
|
24
|
+
}
|
|
25
|
+
/** A click from a pointing device (`detail` counts clicks; keyboard and `click()` give 0). */
|
|
26
|
+
function isPointerClick(event) {
|
|
27
|
+
return event.type === "click" && event.detail > 0;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The menu button: `<button type="button" commandfor command="toggle-popover"
|
|
31
|
+
* aria-haspopup="menu" aria-expanded>`. A click (Enter, Space) toggles the menu through the
|
|
32
|
+
* Root's transition; ArrowDown / ArrowUp open it with the first / last item focused.
|
|
33
|
+
*
|
|
34
|
+
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `commandfor`,
|
|
35
|
+
* `command`, `aria-haspopup`, `aria-expanded`, `onClick`, `onKeyDown`, `data-open`,
|
|
36
|
+
* `data-pending`, `data-disabled`.
|
|
37
|
+
*/
|
|
38
|
+
function MenuTrigger({ disabled = false, className, style, children, render, ...rest }) {
|
|
39
|
+
const menu = useMenuContext("Menu.Trigger");
|
|
40
|
+
useDevWarning(menu.submenu, "Menu.Trigger: rendered in a submenu. Use Menu.SubmenuTrigger, which is also an item of the parent menu.");
|
|
41
|
+
const onKeyDown = (event) => {
|
|
42
|
+
if (disabled || hasModifier(event)) return;
|
|
43
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
openMenuWithFocus(menu, event.nativeEvent, event.key === "ArrowDown" ? "first" : "last");
|
|
46
|
+
};
|
|
47
|
+
const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {
|
|
48
|
+
part: "Menu.Trigger",
|
|
49
|
+
disabled,
|
|
50
|
+
render,
|
|
51
|
+
handlers: { onKeyDown },
|
|
52
|
+
activate: (event) => {
|
|
53
|
+
const native = event.nativeEvent;
|
|
54
|
+
if (menu.popover.intended()) menu.popover.requestClose(native, "activate");
|
|
55
|
+
else {
|
|
56
|
+
menu.setOpenCause("first", isPointerClick(native));
|
|
57
|
+
menu.popover.requestOpen(native, "activate");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return useRender({
|
|
62
|
+
defaultElement: "button",
|
|
63
|
+
render,
|
|
64
|
+
state,
|
|
65
|
+
className,
|
|
66
|
+
style,
|
|
67
|
+
children,
|
|
68
|
+
props: rest,
|
|
69
|
+
libraryProps: {
|
|
70
|
+
...libraryProps,
|
|
71
|
+
id: menu.triggerId,
|
|
72
|
+
"aria-haspopup": "menu"
|
|
73
|
+
},
|
|
74
|
+
ref
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
MenuTrigger.displayName = "MenuTrigger";
|
|
78
|
+
//#endregion
|
|
79
|
+
export { MenuTrigger, isPointerClick, openMenuWithFocus };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=menu-trigger.mjs.map
|