UNPKG

@wordpress/editor

Version:
57 lines (56 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _compose = require("@wordpress/compose"); var _components = require("@wordpress/components"); var _plugins = require("@wordpress/plugins"); var _interface = require("@wordpress/interface"); /** * WordPress dependencies */ /** * Renders a menu item in the Preview dropdown, which can be used as a button or link depending on the props provided. * The text within the component appears as the menu item label. * * @param {Object} props Component properties. * @param {string} [props.href] When `href` is provided, the menu item is rendered as an anchor instead of a button. It corresponds to the `href` attribute of the anchor. * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The icon to be rendered to the left of the menu item label. Can be a Dashicon slug or an SVG WP element. * @param {Function} [props.onClick] The callback function to be executed when the user clicks the menu item. * @param {...*} [props.other] Any additional props are passed through to the underlying MenuItem component. * * @example * ```jsx * import { __ } from '@wordpress/i18n'; * import { PluginPreviewMenuItem } from '@wordpress/editor'; * import { external } from '@wordpress/icons'; * * function onPreviewClick() { * // Handle preview action * } * * const ExternalPreviewMenuItem = () => ( * <PreviewDropdownMenuItem * icon={ external } * onClick={ onPreviewClick } * > * { __( 'Preview in new tab' ) } * </PreviewDropdownMenuItem> * ); * registerPlugin( 'external-preview-menu-item', { * render: ExternalPreviewMenuItem, * } ); * ``` * * @return {Component} The rendered menu item component. */ var _default = exports.default = (0, _compose.compose)((0, _plugins.withPluginContext)((context, ownProps) => { var _ownProps$as; return { as: (_ownProps$as = ownProps.as) !== null && _ownProps$as !== void 0 ? _ownProps$as : _components.MenuItem, icon: ownProps.icon || context.icon, name: 'core/plugin-preview-menu' }; }))(_interface.ActionItem); //# sourceMappingURL=index.js.map