@wordpress/components
Version:
UI components for WordPress.
168 lines (167 loc) • 7.22 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let _ariakit_react = require("@ariakit/react");
_ariakit_react = __toESM(_ariakit_react);
let _wordpress_element = require("@wordpress/element");
let _wordpress_i18n = require("@wordpress/i18n");
let ___context_index_ts = require("../context/index.cjs");
let __context_tsx = require("./context.cjs");
let __item_tsx = require("./item.cjs");
let __checkbox_item_tsx = require("./checkbox-item.cjs");
let __radio_item_tsx = require("./radio-item.cjs");
let __group_tsx = require("./group.cjs");
let __group_label_tsx = require("./group-label.cjs");
let __separator_tsx = require("./separator.cjs");
let __item_label_tsx = require("./item-label.cjs");
let __item_help_text_tsx = require("./item-help-text.cjs");
let __trigger_button_tsx = require("./trigger-button.cjs");
let __submenu_trigger_item_tsx = require("./submenu-trigger-item.cjs");
let __popover_tsx = require("./popover.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/menu/index.tsx
const UnconnectedMenu = (props) => {
const { children, defaultOpen = false, open, onOpenChange, placement, variant } = (0, ___context_index_ts.useContextSystem)(props, "Menu");
const parentContext = (0, _wordpress_element.useContext)(__context_tsx.Context);
const rtl = (0, _wordpress_i18n.isRTL)();
let computedPlacement = placement ?? (parentContext?.store ? "right-start" : "bottom-start");
if (rtl) {
if (/right/.test(computedPlacement)) computedPlacement = computedPlacement.replace("right", "left");
else if (/left/.test(computedPlacement)) computedPlacement = computedPlacement.replace("left", "right");
}
const menuStore = _ariakit_react.useMenuStore({
parent: parentContext?.store,
open,
defaultOpen,
placement: computedPlacement,
focusLoop: true,
setOpen(willBeOpen) {
onOpenChange?.(willBeOpen);
},
rtl
});
const contextValue = (0, _wordpress_element.useMemo)(() => ({
store: menuStore,
variant
}), [menuStore, variant]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__context_tsx.Context.Provider, {
value: contextValue,
children
});
};
/**
* Menu is a collection of React components that combine to render
* ARIA-compliant [menu](https://www.w3.org/WAI/ARIA/apg/patterns/menu/) and
* [menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menubutton/) patterns.
*
* `Menu` itself is a wrapper component and context provider.
* It is responsible for managing the state of the menu and its items, and for
* rendering the `Menu.TriggerButton` (or the `Menu.SubmenuTriggerItem`)
* component, and the `Menu.Popover` component.
*
* This component is deprecated. When building for the Gutenberg repo, use `Menu` from `@wordpress/ui` instead. Otherwise, continue using `DropdownMenu` for now.
*
* @deprecated
*/
const Menu = Object.assign((0, ___context_index_ts.contextConnectWithoutRef)(UnconnectedMenu, "Menu"), {
Context: Object.assign(__context_tsx.Context, { displayName: "Menu.Context" }),
/**
* Renders a menu item inside the `Menu.Popover` or `Menu.Group` components.
*
* It can optionally contain one instance of the `Menu.ItemLabel` component
* and one instance of the `Menu.ItemHelpText` component.
*/
Item: Object.assign(__item_tsx.Item, { displayName: "Menu.Item" }),
/**
* Renders a radio menu item inside the `Menu.Popover` or `Menu.Group`
* components.
*
* It can optionally contain one instance of the `Menu.ItemLabel` component
* and one instance of the `Menu.ItemHelpText` component.
*/
RadioItem: Object.assign(__radio_item_tsx.RadioItem, { displayName: "Menu.RadioItem" }),
/**
* Renders a checkbox menu item inside the `Menu.Popover` or `Menu.Group`
* components.
*
* It can optionally contain one instance of the `Menu.ItemLabel` component
* and one instance of the `Menu.ItemHelpText` component.
*/
CheckboxItem: Object.assign(__checkbox_item_tsx.CheckboxItem, { displayName: "Menu.CheckboxItem" }),
/**
* Renders a group for menu items.
*
* It should contain one instance of `Menu.GroupLabel` and one or more
* instances of `Menu.Item`, `Menu.RadioItem`, or `Menu.CheckboxItem`.
*/
Group: Object.assign(__group_tsx.Group, { displayName: "Menu.Group" }),
/**
* Renders a label in a menu group.
*
* This component should be wrapped with `Menu.Group` so the
* `aria-labelledby` is correctly set on the group element.
*/
GroupLabel: Object.assign(__group_label_tsx.GroupLabel, { displayName: "Menu.GroupLabel" }),
/**
* Renders a divider between menu items or menu groups.
*/
Separator: Object.assign(__separator_tsx.Separator, { displayName: "Menu.Separator" }),
/**
* Renders a menu item's label text. It should be wrapped with `Menu.Item`,
* `Menu.RadioItem`, or `Menu.CheckboxItem`.
*/
ItemLabel: Object.assign(__item_label_tsx.ItemLabel, { displayName: "Menu.ItemLabel" }),
/**
* Renders a menu item's help text. It should be wrapped with `Menu.Item`,
* `Menu.RadioItem`, or `Menu.CheckboxItem`.
*/
ItemHelpText: Object.assign(__item_help_text_tsx.ItemHelpText, { displayName: "Menu.ItemHelpText" }),
/**
* Renders a dropdown menu element that's controlled by a sibling
* `Menu.TriggerButton` component. It renders a popover and automatically
* focuses on items when the menu is shown.
*
* The only valid children of `Menu.Popover` are `Menu.Item`,
* `Menu.RadioItem`, `Menu.CheckboxItem`, `Menu.Group`, `Menu.Separator`,
* and `Menu` (for nested dropdown menus).
*/
Popover: Object.assign(__popover_tsx.Popover, { displayName: "Menu.Popover" }),
/**
* Renders a menu button that toggles the visibility of a sibling
* `Menu.Popover` component when clicked or when using arrow keys.
*/
TriggerButton: Object.assign(__trigger_button_tsx.TriggerButton, { displayName: "Menu.TriggerButton" }),
/**
* Renders a menu item that toggles the visibility of a sibling
* `Menu.Popover` component when clicked or when using arrow keys.
*
* This component is used to create a nested dropdown menu.
*/
SubmenuTriggerItem: Object.assign(__submenu_trigger_item_tsx.SubmenuTriggerItem, { displayName: "Menu.SubmenuTriggerItem" })
});
exports.Menu = Menu;
exports.default = Menu;
//# sourceMappingURL=index.cjs.map