Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zoom Out toggle to editor header when experiment enabled #65183

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/editor/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PostPublishButtonOrToggle from '../post-publish-button/post-publish-butto
import PostSavedState from '../post-saved-state';
import PostViewLink from '../post-view-link';
import PreviewDropdown from '../preview-dropdown';
import ZoomOutToggle from '../zoom-out-toggle';
import { store as editorStore } from '../../store';

const toolbarVariations = {
Expand All @@ -48,6 +49,9 @@ function Header( {
title,
icon,
} ) {
const zoomOutExperimentEnabled =
window.__experimentalEnableZoomOutExperiment;

const isWideViewport = useViewportMatch( 'large' );
const isLargeViewport = useViewportMatch( 'medium' );
const isTooNarrowForDocumentBar = useMediaQuery( '(max-width: 403px)' );
Expand Down Expand Up @@ -142,9 +146,13 @@ function Header( {
forceIsAutosaveable={ forceIsDirty }
/>
<PostViewLink />

{ zoomOutExperimentEnabled && <ZoomOutToggle /> }

{ ( isWideViewport || ! showIconLabels ) && (
<PinnedItems.Slot scope="core" />
) }
Comment on lines +150 to 154
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will currently appear across all editors.

If instead we only want it on the Site Editor then we can use the <PinnedItems.Slot scope="core" /> to add the Toggle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, it's still behind the flag.


{ ! customSaveButton && (
<PostPublishButtonOrToggle
forceIsDirty={ forceIsDirty }
Expand All @@ -153,6 +161,7 @@ function Header( {
}
/>
) }

{ customSaveButton }
<MoreMenu />
</motion.div>
Expand Down
34 changes: 34 additions & 0 deletions packages/editor/src/components/zoom-out-toggle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

import { useDispatch, useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { square as zoomOutIcon } from '@wordpress/icons';

const ZoomOutToggle = () => {
const { isZoomOutMode } = useSelect( ( select ) => ( {
isZoomOutMode:
select( blockEditorStore ).__unstableGetEditorMode() === 'zoom-out',
} ) );

const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const handleZoomOut = () => {
__unstableSetEditorMode( isZoomOutMode ? 'edit' : 'zoom-out' );
};

return (
<Button
onClick={ handleZoomOut }
icon={ zoomOutIcon }
label={ __( 'Toggle Zoom Out' ) }
isPressed={ isZoomOutMode }
size="compact"
/>
);
};

export default ZoomOutToggle;
1 change: 1 addition & 0 deletions packages/icons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export { default as store } from './library/store';
export { default as stretchFullWidth } from './library/stretch-full-width';
export { default as styles } from './library/styles';
export { default as shipping } from './library/shipping';
export { default as square } from './library/square';
export { default as stretchWide } from './library/stretch-wide';
export { default as subscript } from './library/subscript';
export { default as superscript } from './library/superscript';
Expand Down
18 changes: 18 additions & 0 deletions packages/icons/src/library/square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* WordPress dependencies
*/
import { SVG, Path } from '@wordpress/primitives';

const square = (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
<Path
fill="none"
d="M5.75 12.75V18.25H11.25M12.75 5.75H18.25V11.25"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="square"
/>
</SVG>
);

export default square;
Loading