Skip to content

Commit

Permalink
Fix/plugin document setting panel name (#22763)
Browse files Browse the repository at this point in the history
* Cleaner logic to determine which name to use

* Adding trailing comma

* Adding a warning to the slotfill and update docs.

* Adding missing period.

* Update docs/designers-developers/developers/slotfills/plugin-document-setting-panel.md

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>

* Update docs/designers-developers/developers/slotfills/plugin-document-setting-panel.md

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>

* Re-add file removed in error

* Correct logic checking for missing name prop.

* Update docs to use correct function name.

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
  • Loading branch information
Ryan Welcher and gziolo authored Jun 17, 2020
1 parent f932b9a commit 1894d4b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ registerPlugin( 'plugin-document-setting-panel-demo', {
icon: 'palmtree',
} );
```
## Accessing a panel programmatically

Custom panels are namespaced with the plugin name that was passed to `registerPlugin`.
In order to access the panels using function such as `wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelOpened` or `wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelEnabled` be sure to prepend the namepace.

To programmatically toggle the custom panel added in the example above, use the following:

```js
wp.data.dispatch( 'core/edit-post' ).toggleEditorPanelOpened( 'plugin-document-setting-panel-demo/custom-panel' );
```
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/edit-post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@wordpress/primitives": "file:../primitives",
"@wordpress/url": "file:../url",
"@wordpress/viewport": "file:../viewport",
"@wordpress/warning": "file:../warning",
"classnames": "^2.2.5",
"lodash": "^4.17.15",
"memize": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createSlotFill, PanelBody } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { withDispatch, withSelect } from '@wordpress/data';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand Down Expand Up @@ -104,6 +105,9 @@ const PluginDocumentSettingFill = ( {
*/
const PluginDocumentSettingPanel = compose(
withPluginContext( ( context, ownProps ) => {
if ( undefined === ownProps.name ) {
warning( 'PluginDocumentSettingPanel requires a name property.' );
}
return {
icon: ownProps.icon || context.icon,
panelName: `${ context.name }/${ ownProps.name }`,
Expand Down

0 comments on commit 1894d4b

Please sign in to comment.