Skip to content

Commit

Permalink
block-preview: set onReady as experimental prop
Browse files Browse the repository at this point in the history
  • Loading branch information
retrofox committed Sep 4, 2019
1 parent d96f345 commit a71db9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Width of the preview container in pixels. Controls at what size the blocks will

`viewportWidth` can be used to simulate how blocks look on different device sizes or to make sure make sure multiple previews will be rendered with the same scale, regardless of their content.

### `onReady`
### `__experimentalOnReady`
* **Type** `Function`
* **Default:** `noop`

Expand All @@ -39,7 +39,7 @@ Use this callback as an opportunity to know when the preview is ready. The callb
```es6

<BlockPreview
onReady={ ( { scale } ) => console.log( `Current preview scale: ${ scale }` )
__experimentalOnReady={ ( { scale } ) => console.log( `Current preview scale: ${ scale }` )
blocks={ blocks }
/>
```
10 changes: 5 additions & 5 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import BlockEditorProvider from '../provider';
import BlockList from '../block-list';
import { getBlockPreviewContainerDOMNode } from '../../utils/dom';

function ScaledBlockPreview( { blocks, viewportWidth, onReady } ) {
function ScaledBlockPreview( { blocks, viewportWidth, __experimentalOnReady } ) {
const previewRef = useRef( null );

const [ isReady, setIsReady ] = useState( false );
Expand Down Expand Up @@ -56,7 +56,7 @@ function ScaledBlockPreview( { blocks, viewportWidth, onReady } ) {
// Hack: we need to reset the scaled elements margins
previewElement.style.marginTop = '0';

onReady( {
__experimentalOnReady( {
scale,
position: { x: offsetX * scale, y: offsetY },
ref: previewRef,
Expand All @@ -65,7 +65,7 @@ function ScaledBlockPreview( { blocks, viewportWidth, onReady } ) {
const containerElementRect = containerElement.getBoundingClientRect();
const scale = containerElementRect.width / viewportWidth;
setPreviewScale( scale );
onReady( { scale, ref: previewRef } );
__experimentalOnReady( { scale, ref: previewRef } );
}

setIsReady( true );
Expand Down Expand Up @@ -106,7 +106,7 @@ function ScaledBlockPreview( { blocks, viewportWidth, onReady } ) {
);
}

export function BlockPreview( { blocks, viewportWidth = 700, settings, onReady = noop } ) {
export function BlockPreview( { blocks, viewportWidth = 700, settings, __experimentalOnReady = noop } ) {
const renderedBlocks = useMemo( () => castArray( blocks ), [ blocks ] );
const [ recompute, triggerRecompute ] = useReducer( ( state ) => state + 1, 0 );
useLayoutEffect( triggerRecompute, [ blocks ] );
Expand All @@ -126,7 +126,7 @@ export function BlockPreview( { blocks, viewportWidth = 700, settings, onReady =
key={ recompute }
blocks={ renderedBlocks }
viewportWidth={ viewportWidth }
onReady={ onReady }
__experimentalOnReady={ __experimentalOnReady }
/>
</BlockEditorProvider>
);
Expand Down

0 comments on commit a71db9a

Please sign in to comment.