-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Invoke zoom out view when navigating on inserter pattern tabs.
- Loading branch information
1 parent
c4b5770
commit a9375c6
Showing
3 changed files
with
65 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
packages/edit-site/src/components/block-editor/use-open-zoom-out-on-patterns.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,34 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useCallback, useRef, useEffect } from '@wordpress/element'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
export default function useOpenZoomOutOnPatterns() { | ||
const { mode } = useSelect( ( select ) => { | ||
return { | ||
mode: select( blockEditorStore ).__unstableGetEditorMode(), | ||
}; | ||
}, [] ); | ||
const { __unstableSetEditorMode } = useDispatch( blockEditorStore ); | ||
const shouldRevertInitialMode = useRef( null ); | ||
useEffect( () => { | ||
// ignore changes to zoom-out mode as we explictily change to it on mount. | ||
if ( mode !== 'zoom-out' ) { | ||
shouldRevertInitialMode.current = false; | ||
} | ||
}, [ mode ] ); | ||
return [ | ||
useCallback( () => { | ||
__unstableSetEditorMode( 'zoom-out' ); | ||
shouldRevertInitialMode.current = true; | ||
}, [] ), | ||
useCallback( () => { | ||
// if there were not mode changes revert to the initial mode when unmounting. | ||
if ( shouldRevertInitialMode.current ) { | ||
__unstableSetEditorMode( mode ); | ||
} | ||
}, [] ), | ||
]; | ||
} |