Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion packages/editor/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
}
}

.editor-zoom-control {
width: 50px;
}

.editor-editor-interface.is-distraction-free {
.interface-interface-skeleton__header {
border-bottom: none;
Expand All @@ -258,7 +262,8 @@
& > .editor-header__toolbar .editor-document-tools__document-overview-toggle,
& > .editor-header__settings > .editor-preview-dropdown,
& > .editor-header__settings > .interface-pinned-items,
& > .editor-header__settings > .editor-zoom-out-toggle {
& > .editor-header__settings > .editor-zoom-out-toggle
& > .editor-header__settings > .editor-zoom-control {
display: none;
}

Expand Down
58 changes: 40 additions & 18 deletions packages/editor/src/components/zoom-out-toggle/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { Button, RangeControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { square as zoomOutIcon } from '@wordpress/icons';
Expand All @@ -20,6 +20,8 @@ import { isAppleOS } from '@wordpress/keycodes';
import { unlock } from '../../lock-unlock';

const ZoomOutToggle = ( { disabled } ) => {
const [ zoomValue, setZoomValue ] = useState( 0.45 );

const { isZoomOut, showIconLabels, isDistractionFree } = useSelect(
( select ) => ( {
isZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),
Expand Down Expand Up @@ -61,11 +63,7 @@ const ZoomOutToggle = ( { disabled } ) => {
useShortcut(
'core/editor/zoom',
() => {
if ( isZoomOut ) {
resetZoomLevel();
} else {
setZoomLevel( 'auto-scaled' );
}
handleZoomOut();
},
{
isDisabled: isDistractionFree,
Expand All @@ -77,21 +75,45 @@ const ZoomOutToggle = ( { disabled } ) => {
resetZoomLevel();
} else {
setZoomLevel( 'auto-scaled' );
setZoomValue( 0.45 );
}
};

const handleZoomChange = ( value ) => {
setZoomValue( value );
setZoomLevel( value );
};

return (
<Button
accessibleWhenDisabled
disabled={ disabled }
onClick={ handleZoomOut }
icon={ zoomOutIcon }
label={ __( 'Zoom Out' ) }
isPressed={ isZoomOut }
size="compact"
showTooltip={ ! showIconLabels }
className="editor-zoom-out-toggle"
/>
<>
<Button
accessibleWhenDisabled
disabled={ disabled }
onClick={ handleZoomOut }
icon={ zoomOutIcon }
label={ __( 'Zoom Out' ) }
isPressed={ isZoomOut }
size="compact"
showTooltip={ ! showIconLabels }
className="editor-zoom-out-toggle"
/>
{ isZoomOut && (
<div className="editor-zoom-control-wrapper">
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
className="editor-zoom-control"
value={ zoomValue }
onChange={ handleZoomChange }
min={ 0.45 }
max={ 0.95 }
step={ 0.05 }
disabled={ disabled }
withInputField={ false }
/>
</div>
) }
</>
);
};

Expand Down
Loading