Skip to content

Commit

Permalink
Avoid zooming out when browsing styles if the preview mode is active
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Nov 21, 2024
1 parent b7d989e commit 98f6feb
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* WordPress dependencies
*/
import {
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { Card, CardBody } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { useDispatch } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { useEffect } from '@wordpress/element';

Expand All @@ -19,10 +22,13 @@ const { useZoomOut } = unlock( blockEditorPrivateApis );

function ScreenStyleVariations() {
// Style Variations should only be previewed in with
// - a "zoomed out" editor
// - a "zoomed out" editor (but not when in preview mode)
// - "Desktop" device preview
const isPreviewMode = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().isPreviewMode;
}, [] );
const { setDeviceType } = useDispatch( editorStore );
useZoomOut();
useZoomOut( ! isPreviewMode );
useEffect( () => {
setDeviceType( 'desktop' );
}, [ setDeviceType ] );
Expand Down

0 comments on commit 98f6feb

Please sign in to comment.