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

Expose BlockPreview component #16834

Merged
merged 4 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ Undocumented declaration.

Undocumented declaration.

<a name="BlockPreview" href="#BlockPreview">#</a> **BlockPreview**

BlockPreview renders a preview given an array of blocks.

_Parameters_

- _props_ `Object`: Component props.

_Returns_

- `WPElement`: Rendered element.

<a name="BlockSelectionClearer" href="#BlockSelectionClearer">#</a> **BlockSelectionClearer**

Undocumented declaration.
Expand Down
29 changes: 29 additions & 0 deletions packages/block-editor/src/components/block-preview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BlockPreview
============

`<BlockPreview />` allows you to preview blocks.

## Usage

Render the component passing in the required props:

```jsx
<BlockPreview
blocks={ blocks }
isScaled={ false }
/>
```

## Props

### `blocks`
* **Type:** `array|object`
* **Default:** `undefined`

A block instance (object) or a blocks array you would like to render a preview.

### `isScaled`
* **Type:** `Boolean`
* **Default:** `false`

Use this if you need to render previews in smaller areas, like block thumbnails.
16 changes: 8 additions & 8 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ import { withSelect } from '@wordpress/data';
import BlockEditorProvider from '../provider';
import BlockList from '../block-list';

/**
* Block Preview Component: It renders a preview given a block name and attributes.
*
* @param {Object} props Component props.
*
* @return {WPElement} Rendered element.
*/
function BlockPreview( { blocks, settings, className, isScaled } ) {
export function BlockPreview( { blocks, settings, className, isScaled } ) {
if ( ! blocks ) {
return null;
}
Expand Down Expand Up @@ -51,6 +44,13 @@ function BlockPreview( { blocks, settings, className, isScaled } ) {
);
}

/**
* BlockPreview renders a preview given an array of blocks.
*
* @param {Object} props Component props.
*
* @return {WPElement} Rendered element.
*/
export default withSelect( ( select ) => {
return {
settings: select( 'core/block-editor' ).getSettings(),
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export { default as BlockEditorKeyboardShortcuts } from './block-editor-keyboard
export { default as BlockInspector } from './block-inspector';
export { default as BlockList } from './block-list';
export { default as BlockMover } from './block-mover';
export { default as BlockPreview } from './block-preview';
export { default as BlockSelectionClearer } from './block-selection-clearer';
export { default as BlockSettingsMenu } from './block-settings-menu';
export { default as BlockTitle } from './block-title';
Expand Down