Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Aug 2, 2018
1 parent b68b316 commit d51b5ee
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,88 @@ Refer to [the plugins module documentation](../plugins/) for more information.
The following components can be used with the `registerPlugin` ([see documentation](../packages/plugins)) API.
They can be found in the global variable `wp.editPost` when defining `wp-edit-post` as a script dependency.

### `PluginBlockSettingsMenuItem`

Renders a new item in the block settings menu.

Example:

{% codetabs %}

{% ES5 %}
```js
var __ = wp.i18n.__;
var PluginBlockSettingsMenuItem = wp.editPost.PluginBlockSettingsMenuItem;

function doOnClick(){
// To be called when the user clicks the menu item.
}

function MyPluginBlockSettingsMenuItem() {
return el(
PluginBlockSettingsMenuItem,
{
allowedBlockNames: [ 'core/paragraph' ],
icon: 'dashicon-name',
label: __( 'Menu item text' ),
onClick: doOnClick,
}
);
}
```

{% ESNext %}
```jsx
import { __ } from wp.i18n;
import { PluginBlockSettingsMenuItem } from wp.editPost;

const doOnClick = ( ) => {
// To be called when the user clicks the menu item.
};

const MyPluginBlockSettingsMenuItem = () => (
<PluginBlockSettingsMenuItem
allowedBlockNames=[ 'core/paragraph' ]
icon='dashicon-name'
label=__( 'Menu item text' )
onClick={ doOnClick } />
);
```

{% end %}

#### Props

##### allowedBlockNames

An array containing a whitelist of block names for which the item should be shown. If this prop is not present the item will be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the whitelist.

- Type: `Array`
- Required: No
- Default: Menu item is shown for any block

##### icon

The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered to the left of the menu item label.

- Type: `String` | `Element`
- Required: No
- Default: Menu item wil be rendered without icon

##### label

A string containing the menu item text.

- Type: `String`
- Required: Yes

##### onClick

The callback function to be executed when the user clicks the menu item.

- Type: `function`
- Required: Yes

### `PluginSidebar`

Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content within the sidebar.
Expand Down

0 comments on commit d51b5ee

Please sign in to comment.