forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block preview component in global styles (WordPress#45719)
* add block preview in global styles panel update viewport widths for few blocks add border to preview block and convert viewport width to scale fix border radius and address minor review comments address review comments * revert scale * revert defaultPadding and alignment APIs * remove dropcap for paragraph
- Loading branch information
1 parent
f7addb9
commit 37bd47d
Showing
10 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ export { metadata, name }; | |
|
||
export const settings = { | ||
icon, | ||
example: {}, | ||
edit, | ||
transforms, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ export const settings = { | |
}, | ||
], | ||
}, | ||
viewportWidth: 450, | ||
}, | ||
transforms, | ||
edit, | ||
|
29 changes: 29 additions & 0 deletions
29
packages/edit-site/src/components/global-styles/block-preview-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockPreview } from '@wordpress/block-editor'; | ||
import { getBlockType, getBlockFromExample } from '@wordpress/blocks'; | ||
import { useResizeObserver } from '@wordpress/compose'; | ||
|
||
const BlockPreviewPanel = ( { name } ) => { | ||
const blockExample = getBlockType( name )?.example; | ||
const [ | ||
containerResizeListener, | ||
{ width: containerWidth, height: containerHeight }, | ||
] = useResizeObserver(); | ||
const viewportWidth = blockExample?.viewportWidth || containerWidth; | ||
|
||
return ! blockExample ? null : ( | ||
<div className="edit-site-global-styles__block-preview-panel"> | ||
{ containerResizeListener } | ||
|
||
<BlockPreview | ||
viewportWidth={ viewportWidth } | ||
__experimentalMinHeight={ containerHeight } | ||
blocks={ getBlockFromExample( name, blockExample ) } | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BlockPreviewPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters