Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove top and bottom margin from block inside preview
  • Loading branch information
noisysocks committed Dec 4, 2022
commit 071f55c4b03265213e5a489c8c74e6ce29325c63
17 changes: 17 additions & 0 deletions packages/block-editor/src/components/block-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ Set `viewportWidth` to `0` to make the viewport the same width as the container.
- **Default** `undefined`

Padding for the preview container body.

### `__experimentalStyles`

List of additional editor styles to load into the preview iframe. Each object
should contain a `css` attribute. See `EditorStyles` for more info.

```jsx
<BlockPreview
blocks={ blocks }
__experimentalStyles={ [
{ css: '.wp-block { margin: 16px; }' },
] }
/>
```

- **Type** `Int`
- **Default** `[]`
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function ScaledBlockPreview( {
containerWidth,
__experimentalPadding,
__experimentalMinHeight,
__experimentalStyles,
} ) {
if ( ! viewportWidth ) {
viewportWidth = containerWidth;
Expand All @@ -46,6 +47,7 @@ function ScaledBlockPreview( {
if ( styles ) {
return [
...styles,
...__experimentalStyles,
{
css: 'body{height:auto;overflow:hidden;}',
__unstableType: 'presets',
Expand All @@ -54,7 +56,7 @@ function ScaledBlockPreview( {
}

return styles;
}, [ styles ] );
}, [ styles, __experimentalStyles ] );

const svgFilters = useMemo( () => {
return [ ...( duotone?.default ?? [] ), ...( duotone?.theme ?? [] ) ];
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function BlockPreview( {
__experimentalPadding = 0,
viewportWidth = 1200,
__experimentalMinHeight,
__experimentalStyles = [],
} ) {
const originalSettings = useSelect(
( select ) => select( blockEditorStore ).getSettings(),
Expand All @@ -45,6 +46,7 @@ export function BlockPreview( {
viewportWidth={ viewportWidth }
__experimentalPadding={ __experimentalPadding }
__experimentalMinHeight={ __experimentalMinHeight }
__experimentalStyles={ __experimentalStyles }
/>
</BlockEditorProvider>
);
Expand Down
12 changes: 11 additions & 1 deletion packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ function Example( { title, blocks, isSelected, onClick } ) {
>
<h3 className="edit-site-style-book__example-title">{ title }</h3>
<div className="edit-site-style-book__example-preview">
<BlockPreview blocks={ blocks } viewportWidth={ 0 } />
<BlockPreview
blocks={ blocks }
viewportWidth={ 0 }
__experimentalStyles={ [
{
css:
'.wp-block:first-child { margin-top: 0; }' +
'.wp-block:last-child { margin-bottom: 0; }',
},
] }
/>
</div>
</button>
);
Expand Down
1 change: 0 additions & 1 deletion packages/edit-site/src/components/style-book/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
text-align: left;

.edit-site-style-book.is-wide & {
margin-top: $grid-unit-40;
text-align: right;
width: 120px;
}
Expand Down