Skip to content

Commit

Permalink
Filter DropZone and MediaPlaceholder components (#11184)
Browse files Browse the repository at this point in the history
* Export Media Placeholder withFilters

* Export Block Drop Zone withFilters

* Update test snapshots

* Appropriately name DropZone filter

* Add super-simple README files

* Move withFilters call into the compose function

* Update README.md

* Update README.md
  • Loading branch information
mikeselander authored and gziolo committed Oct 30, 2018
1 parent cc53d7c commit fe51bd0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
30 changes: 30 additions & 0 deletions packages/editor/src/components/block-drop-zone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BlockDropZone
===========

`BlockDropZone` is a React component that renders a container which allows a user to drag media into the editor and immediately place it.

## Setup

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

_Example:_

Replace implementation of the drop zone:

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

wp.hooks.addFilter(
'editor.BlockDropZone',
'my-plugin/replace-block-drop-zone',
replaceBlockDropZone
);
```
8 changes: 6 additions & 2 deletions packages/editor/src/components/block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { DropZone } from '@wordpress/components';
import {
DropZone,
withFilters,
} from '@wordpress/components';
import {
rawHandler,
getBlockTransforms,
Expand Down Expand Up @@ -149,5 +152,6 @@ export default compose(
isLocked: !! getTemplateLock( rootClientId ),
getClientIdsOfDescendants,
};
} )
} ),
withFilters( 'editor.BlockDropZone' )
)( BlockDropZone );
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
className="wp-block editor-default-block-appender"
data-root-client-id=""
>
<WithDispatch(WithSelect(BlockDropZone)) />
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<input
aria-label="Add block"
className="editor-default-block-appender__content"
Expand Down Expand Up @@ -34,7 +34,7 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
className="wp-block editor-default-block-appender"
data-root-client-id=""
>
<WithDispatch(WithSelect(BlockDropZone)) />
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<input
aria-label="Add block"
className="editor-default-block-appender__content"
Expand All @@ -56,7 +56,7 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = `
className="wp-block editor-default-block-appender"
data-root-client-id=""
>
<WithDispatch(WithSelect(BlockDropZone)) />
<WithDispatch(WithSelect(WithFilters(BlockDropZone))) />
<input
aria-label="Add block"
className="editor-default-block-appender__content"
Expand Down
30 changes: 30 additions & 0 deletions packages/editor/src/components/media-placeholder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

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

_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',
'my-plugin/replace-media-placeholder',
replaceMediaPlaceholder
);
```
3 changes: 2 additions & 1 deletion packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Placeholder,
DropZone,
IconButton,
withFilters,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
Expand Down Expand Up @@ -233,4 +234,4 @@ class MediaPlaceholder extends Component {
}
}

export default MediaPlaceholder;
export default withFilters( 'editor.MediaPlaceholder' )( MediaPlaceholder );

0 comments on commit fe51bd0

Please sign in to comment.