How to use the @wordpress/plugins.withPluginContext function in @wordpress/plugins

To help you get started, we’ve selected a few @wordpress/plugins examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / edit-post / src / components / sidebar / plugin-document-setting-panel / index.js View on Github external
* const { registerPlugin } = wp.plugins;
 * const { PluginDocumentSettingPanel } = wp.editPost;
 *
 * const MyDocumentSettingTest = () => (
 * 		
 *			<p>My Document Setting Panel</p>
 *		
 *	);
 *
 *  registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );
 * ```
 *
 * @return {WPElement} The WPElement to be rendered.
 */
const PluginDocumentSettingPanel = compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			panelName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { panelName } ) =&gt; {
		return (
			{
				opened: select( 'core/edit-post' ).isEditorPanelOpened( panelName ),
				isEnabled: select( 'core/edit-post' ).isEditorPanelEnabled( panelName ),
			}
		);
	} ),
	withDispatch( ( dispatch, { panelName } ) =&gt; ( {
		onToggle() {
			return dispatch( 'core/edit-post' ).toggleEditorPanelOpened( panelName );
github WordPress / gutenberg / edit-post / components / sidebar / plugin-sidebar / index.js View on Github external
onClick={ togglePin }
							isToggled={ isPinned }
							aria-expanded={ isPinned }
						/&gt;
					) }
				
				
					{ children }
				
			
		
	);
}

export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
			isPluginItemPinned,
		} = select( 'core/edit-post' );

		return {
			isActive: getActiveGeneralSidebarName() === sidebarName,
			isPinned: isPluginItemPinned( sidebarName ),
		};
	} ),
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / plugin-sidebar / index.js View on Github external
* 	
 * 		
 * 			{ __( 'My sidebar content' ) }
 * 		
 * 	
 * );
 * ```
 *
 * @return {WPComponent} Plugin sidebar component.
 */
export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
			isPluginItemPinned,
		} = select( 'core/edit-post' );

		return {
			isActive: getActiveGeneralSidebarName() === sidebarName,
			isPinned: isPluginItemPinned( sidebarName ),
		};
	} ),
github WordPress / gutenberg / edit-post / components / header / plugin-sidebar-more-menu-item / index.js View on Github external
const PluginSidebarMoreMenuItem = ( { children, icon, isSelected, onClick } ) =&gt; (
	
		{ ( fillProps ) =&gt; (
			<menuitem>
				{ children }
			</menuitem>
		) }
	
);

export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.target }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
		} = select( 'core/edit-post' );

		return {
			isSelected: getActiveGeneralSidebarName() === sidebarName,
		};
	} ),
	withDispatch( ( dispatch, { isSelected, sidebarName } ) =&gt; {
		const {
github WordPress / gutenberg / packages / edit-post / src / components / header / plugin-more-menu-item / index.js View on Github external
* }
 *
 * const MyButtonMoreMenuItem = () =&gt; (
 * 	
 * 		{ __( 'My button title' ) }
 * 	
 * );
 * ```
 *
 * @return {WPElement} The element to be rendered.
 */
export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
		};
	} ),
)( PluginMoreMenuItem );
github WordPress / gutenberg / packages / edit-post / src / components / header / plugin-sidebar-more-menu-item / index.js View on Github external
* const { PluginSidebarMoreMenuItem } = wp.editPost;
 *
 * const MySidebarMoreMenuItem = () =&gt; (
 * 	
 * 		{ __( 'My sidebar title' ) }
 * 	
 * );
 * ```
 *
 * @return {WPElement} The element to be rendered.
 */
export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.target }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
		} = select( 'core/edit-post' );

		return {
			isSelected: getActiveGeneralSidebarName() === sidebarName,
		};
	} ),
	withDispatch( ( dispatch, { isSelected, sidebarName } ) =&gt; {
		const {
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / plugin-sidebar / index.js View on Github external
* 	
 * 		
 * 			{ __( 'My sidebar content' ) }
 * 		
 * 	
 * );
 * ```
 *
 * @return {WPElement} Plugin sidebar component.
 */
export default compose(
	withPluginContext( ( context, ownProps ) =&gt; {
		return {
			icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) =&gt; {
		const {
			getActiveGeneralSidebarName,
			isPluginItemPinned,
		} = select( 'core/edit-post' );

		return {
			isActive: getActiveGeneralSidebarName() === sidebarName,
			isPinned: isPluginItemPinned( sidebarName ),
		};
	} ),

@wordpress/plugins

Plugins module for WordPress.

GPL-2.0-or-later
Latest version published 12 days ago

Package Health Score

95 / 100
Full package analysis