-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/interface/src/components/plugin-preview-menu/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill, MenuItem } from '@wordpress/components'; | ||
|
||
export const { Fill, Slot } = createSlotFill( 'PluginPreviewMenu' ); | ||
|
||
/** | ||
* Defines an extensibility slot for the device preview dropdown. | ||
* | ||
* The `title` and `icon` are used to populate the Preview menu item. | ||
* | ||
* @param {Object} props Component properties. | ||
* @param {string} props.name A unique name of the custom preview. Prefix with plugin name. | ||
* @param {Function} props.onClick Menu item click handler | ||
* @param {string} props.title Menu item title. | ||
*/ | ||
const PluginPreviewMenu = ( { name, onClick, title, ...props } ) => ( | ||
<Fill> | ||
<MenuItem | ||
className="block-editor-post-preview__button-resize" | ||
onClick={ ( ...args ) => { | ||
if ( onClick ) { | ||
onClick( ...args ); | ||
} | ||
} } | ||
{ ...props } | ||
> | ||
{ title } | ||
</MenuItem> | ||
</Fill> | ||
); | ||
|
||
PluginPreviewMenu.Slot = Slot; | ||
|
||
/** | ||
* Renders items in the devide preview dropdown within the editor header. | ||
* | ||
* @example | ||
* ```jsx | ||
* // Using ESNext syntax | ||
* import { PluginPreviewMenu } from '@wordpress/interface'; | ||
* import { registerPlugin } from '@wordpress/plugins'; | ||
* | ||
* const MyPreviewMenu = () => ( | ||
* <PluginPreviewMenu | ||
* name="MyPreview" | ||
* onClick={ () => {} } | ||
* title="My preview" | ||
* /> | ||
* ); | ||
* | ||
* registerPlugin( 'my-preview-menu', { render: MyPreviewMenu } ); | ||
* ``` | ||
* | ||
* @return {WPComponent} The component to be rendered. | ||
*/ | ||
export default PluginPreviewMenu; |