Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example usage for MediaPlaceholder #13389

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions packages/editor/src/components/media-placeholder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,31 @@ MediaPlaceholder

`MediaPlaceholder` is a React component used to render either the media associated with a block, or an editing interface to replace the media for a block.

## Setup
## Usage

An example usage which sets the URL of the selected image to `theImage` attributes.

```
const { MediaPlaceholder } = wp.editor;

...

edit: ( { attributes, setAttributes } ) {
const mediaPlaceholder = <MediaPlaceholder
onSelect = {
( el ) => {
setAttributes( { theImage: el.url } );
}
}
allowedTypes = { [ 'image' ] }
multiple = { false }
labels = { { title: 'The Image' } }
/>;
...
}
```

## Extend

It includes a `wp.hooks` filter `editor.MediaPlaceholder` that enables developers to replace or extend it.

Expand All @@ -12,18 +36,18 @@ _Example:_
Replace implementation of the placeholder:

```js
function replaceMediaPlaceholder() {
return function() {
return wp.element.createElement(
'div',
{},
'The replacement contents or components.'
);
}
}

wp.hooks.addFilter(
'editor.MediaPlaceholder',
function replaceMediaPlaceholder() {
return function() {
return wp.element.createElement(
'div',
{},
'The replacement contents or components.'
);
}
}

wp.hooks.addFilter(
'editor.MediaPlaceholder',
'my-plugin/replace-media-placeholder',
replaceMediaPlaceholder
);
Expand Down