-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
use-zoom-out.js
43 lines (38 loc) · 979 Bytes
/
use-zoom-out.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
38
39
40
41
42
43
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';
/**
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
*
* @param {boolean} zoomOut If we should enter into zoomOut mode or not
*/
export function useZoomOut( zoomOut = true ) {
const { setZoomLevel, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );
useEffect( () => {
const isZoomOutOnMount = isZoomOut();
return () => {
if ( isZoomOutOnMount ) {
setZoomLevel( 50 );
} else {
resetZoomLevel();
}
};
}, [] );
useEffect( () => {
if ( zoomOut ) {
setZoomLevel( 50 );
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );
}