UNPKG

@wordpress/components

Version:
50 lines (47 loc) 1.57 kB
/** * External dependencies */ import * as Ariakit from '@ariakit/react'; /** * WordPress dependencies */ import { forwardRef, useContext } from '@wordpress/element'; import { chevronRightSmall } from '@wordpress/icons'; /** * Internal dependencies */ import { Context } from './context'; import { Item } from './item'; import * as Styled from './styles'; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; export const SubmenuTriggerItem = forwardRef(function SubmenuTriggerItem({ suffix, ...otherProps }, ref) { const menuContext = useContext(Context); if (!menuContext?.store.parent) { throw new Error('Menu.SubmenuTriggerItem can only be rendered inside a nested Menu component'); } return /*#__PURE__*/_jsx(Ariakit.MenuButton, { ref: ref, accessibleWhenDisabled: true, store: menuContext.store, render: /*#__PURE__*/_jsx(Item, { ...otherProps, // The menu item needs to register and be part of the parent menu. // Without specifying the store explicitly, the `Item` component // would otherwise read the store via context and pick up the one from // the sub-menu `Menu` component. store: menuContext.store.parent, suffix: /*#__PURE__*/_jsxs(_Fragment, { children: [suffix, /*#__PURE__*/_jsx(Styled.SubmenuChevronIcon, { "aria-hidden": "true", icon: chevronRightSmall, size: 24, preserveAspectRatio: "xMidYMid slice" })] }) }) }); }); //# sourceMappingURL=submenu-trigger-item.js.map