UNPKG

@wordpress/components

Version:
50 lines (47 loc) 1.54 kB
/** * WordPress dependencies */ import { forwardRef, useContext } from '@wordpress/element'; /** * Internal dependencies */ import * as Styled from './styles'; import { Context } from './context'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export const Item = forwardRef(function Item({ prefix, suffix, children, disabled = false, hideOnClick = true, store, ...props }, ref) { const menuContext = useContext(Context); if (!menuContext?.store) { throw new Error('Menu.Item can only be rendered inside a Menu component'); } // In most cases, the menu store will be retrieved from context (ie. the store // created by the top-level menu component). But in rare cases (ie. // `Menu.SubmenuTriggerItem`), the context store wouldn't be correct. This is // why the component accepts a `store` prop to override the context store. const computedStore = store !== null && store !== void 0 ? store : menuContext.store; return /*#__PURE__*/_jsxs(Styled.Item, { ref: ref, ...props, accessibleWhenDisabled: true, disabled: disabled, hideOnClick: hideOnClick, store: computedStore, children: [/*#__PURE__*/_jsx(Styled.ItemPrefixWrapper, { children: prefix }), /*#__PURE__*/_jsxs(Styled.ItemContentWrapper, { children: [/*#__PURE__*/_jsx(Styled.ItemChildrenWrapper, { children: children }), suffix && /*#__PURE__*/_jsx(Styled.ItemSuffixWrapper, { children: suffix })] })] }); }); //# sourceMappingURL=item.js.map