UNPKG

@wordpress/interface

Version:

Interface module for WordPress. The package contains shared functionality across the modern JavaScript-based WordPress screens.

84 lines (81 loc) 2.31 kB
/* wp:polyfill */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _components = require("@wordpress/components"); var _element = require("@wordpress/element"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ const noop = () => {}; function ActionItemSlot({ name, as: Component = _components.ButtonGroup, fillProps = {}, bubblesVirtually, ...props }) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Slot, { name: name, bubblesVirtually: bubblesVirtually, fillProps: fillProps, children: fills => { if (!_element.Children.toArray(fills).length) { return null; } // Special handling exists for backward compatibility. // It ensures that menu items created by plugin authors aren't // duplicated with automatically injected menu items coming // from pinnable plugin sidebars. // @see https://github.com/WordPress/gutenberg/issues/14457 const initializedByPlugins = []; _element.Children.forEach(fills, ({ props: { __unstableExplicitMenuItem, __unstableTarget } }) => { if (__unstableTarget && __unstableExplicitMenuItem) { initializedByPlugins.push(__unstableTarget); } }); const children = _element.Children.map(fills, child => { if (!child.props.__unstableExplicitMenuItem && initializedByPlugins.includes(child.props.__unstableTarget)) { return null; } return child; }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, { ...props, children: children }); } }); } function ActionItem({ name, as: Component = _components.Button, onClick, ...props }) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Fill, { name: name, children: ({ onClick: fpOnClick }) => { return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, { onClick: onClick || fpOnClick ? (...args) => { (onClick || noop)(...args); (fpOnClick || noop)(...args); } : undefined, ...props }); } }); } ActionItem.Slot = ActionItemSlot; var _default = exports.default = ActionItem; //# sourceMappingURL=index.js.map