-
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.
Zoom out: Invoke zoom out mode when opening the patterns tab, and mov…
…e the code to do so to a shared hook (#59775) * Invoke zoomed out when using the patterns tab, and create a hook * Update packages/block-editor/README.md Co-authored-by: Andrei Draganescu <[email protected]> * update docs * enter zoom out on category select --------- Co-authored-by: Andrei Draganescu <[email protected]> Co-authored-by: Andrei Draganescu <[email protected]>
- Loading branch information
1 parent
46a67d5
commit 2b085de
Showing
7 changed files
with
63 additions
and
35 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useEffect, useRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../store'; | ||
|
||
/** | ||
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode. | ||
*/ | ||
export function useZoomOut() { | ||
const { __unstableSetEditorMode } = useDispatch( blockEditorStore ); | ||
const { mode } = useSelect( ( select ) => { | ||
return { | ||
mode: select( blockEditorStore ).__unstableGetEditorMode(), | ||
}; | ||
}, [] ); | ||
|
||
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 ] ); | ||
|
||
// Intentionality left without any dependency. | ||
// This effect should only run the first time the component is rendered. | ||
// The effect opens the zoom-out view if it is not open before when applying a style variation. | ||
useEffect( () => { | ||
if ( mode !== 'zoom-out' ) { | ||
__unstableSetEditorMode( 'zoom-out' ); | ||
shouldRevertInitialMode.current = true; | ||
return () => { | ||
// if there were not mode changes revert to the initial mode when unmounting. | ||
if ( shouldRevertInitialMode.current ) { | ||
__unstableSetEditorMode( mode ); | ||
} | ||
}; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [] ); | ||
} |
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