-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add zoom-in/zoom-out to the template level
- Loading branch information
1 parent
fef2cae
commit 7d58ed5
Showing
5 changed files
with
128 additions
and
13 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
36 changes: 36 additions & 0 deletions
36
packages/edit-post/src/components/header/template-zoom-toggle/index.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,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { stack } from '@wordpress/icons'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
|
||
function TemplateZoomToggle( { ...props } ) { | ||
const isActive = useSelect( | ||
( select ) => | ||
select( 'core/edit-post' ).isFeatureActive( 'templateZoomOut' ), | ||
[] | ||
); | ||
const { toggleFeature } = useDispatch( 'core/edit-post' ); | ||
|
||
return ( | ||
<Button | ||
isPressed={ isActive } | ||
onClick={ () => { | ||
toggleFeature( 'templateZoomOut' ); | ||
} } | ||
icon={ stack } | ||
/* translators: button label text should, if possible, be under 16 | ||
characters. */ | ||
label={ | ||
isActive | ||
? __( 'Zoom in to the post content' ) | ||
: __( 'Zoom out to the template' ) | ||
} | ||
{ ...props } | ||
/> | ||
); | ||
} | ||
|
||
export default TemplateZoomToggle; |
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,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Browser dependencies | ||
*/ | ||
const { fetch } = window; | ||
|
||
/** | ||
* Find the template for a given page path. | ||
* | ||
* @param {string} path The page path. | ||
* @param {Function} getEntityRecords The promise-returning `getEntityRecords` selector to use. | ||
* | ||
* @return {number} The found template ID. | ||
*/ | ||
export default async function findTemplate( path, getEntityRecords ) { | ||
const { data } = await fetch( | ||
addQueryArgs( findTemplate.siteUrl + path, { | ||
'_wp-find-template': true, | ||
} ) | ||
).then( ( res ) => res.json() ); | ||
|
||
let newTemplate = data; | ||
if ( newTemplate === null ) { | ||
newTemplate = ( | ||
await getEntityRecords( 'postType', 'wp_template', { | ||
resolved: true, | ||
slug: data.post_name, | ||
} ) | ||
)[ 0 ]; | ||
} | ||
|
||
return newTemplate; | ||
} | ||
|
||
findTemplate.siteUrl = ''; |