-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathpreview-panel.js
37 lines (34 loc) · 971 Bytes
/
preview-panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* WordPress dependencies
*/
import { getBlockType } from '@wordpress/blocks';
import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import InserterPreviewPanel from '../inserter/preview-panel';
import { replaceActiveStyle } from './utils';
export default function BlockStylesPreviewPanel( {
genericPreviewBlock,
style,
className,
activeStyle,
} ) {
const example = getBlockType( genericPreviewBlock.name )?.example;
const styleClassName = replaceActiveStyle( className, activeStyle, style );
const previewBlocks = useMemo( () => {
return {
...genericPreviewBlock,
title: style.label || style.name,
description: style.description,
initialAttributes: {
...genericPreviewBlock.attributes,
className:
styleClassName +
' block-editor-block-styles__block-preview-container',
},
example,
};
}, [ genericPreviewBlock, styleClassName ] );
return <InserterPreviewPanel item={ previewBlocks } />;
}