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 a vertical toolbar for zoom out mode #60123

Merged
merged 28 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ee71d29
position toolbar popover to the left and change colors on zoomed-out …
MaggieCabrera Mar 22, 2024
9d5b2d6
Make zoom out toolbar component
jeryj May 9, 2024
21746ac
Create zoom out toolbar
jeryj May 9, 2024
500f8f4
Cleanup linting errors
jeryj May 10, 2024
97be83c
Add orientation to toolbar component
jeryj May 10, 2024
b89809e
css for vertical toolbars
MaggieCabrera May 10, 2024
6bea67c
Add similar classes to existing toolbar
jeryj May 10, 2024
e414fdd
Use correct placement for zoom out toolbar popover
jeryj May 10, 2024
f0a052a
remove cs that shouldn't be needed
MaggieCabrera May 10, 2024
f9b9d0a
Remove icon and block toolbar vertical css and apply just to base com…
jeryj May 10, 2024
476c5c2
made toolbar unstyled and fixed stray background
MaggieCabrera May 10, 2024
954c198
Update Changelog
MaggieCabrera Jun 4, 2024
767439e
removed transparent background from component css
MaggieCabrera Jun 4, 2024
236fc80
Update packages/components/src/toolbar/toolbar/types.ts
MaggieCabrera Jun 4, 2024
71bbd98
document new prop for the toolbar component
MaggieCabrera Jun 4, 2024
5dd9390
remove white background
scruffian Jun 18, 2024
3393172
increase margin width
scruffian Jun 18, 2024
ff87379
Also include the non-accessible toolbar in the vertical CSS rules
scruffian Jun 18, 2024
9b702ba
Move styles to the zoom out toolbar CSS
scruffian Jun 19, 2024
29a86ef
revert
scruffian Jun 19, 2024
6f2ef40
avoid shifting of the toolbar to the right side
MaggieCabrera Jun 25, 2024
d88ce34
fix focus outline
MaggieCabrera Jun 26, 2024
a0eb9bd
moved vertical styles to toolbar component
MaggieCabrera Jun 26, 2024
442110b
missing display flex
MaggieCabrera Jun 26, 2024
5592b7b
removed orientation from NavigableToolbar props
MaggieCabrera Jun 27, 2024
9fa1446
Revert "removed orientation from NavigableToolbar props"
MaggieCabrera Jun 27, 2024
056beb2
Use ToolbarButton instead of Button for Shuffle
jeryj Jul 2, 2024
e1f50a0
added classes to avoid using component selectors
MaggieCabrera Jul 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function Shuffle( { clientId, as = Container } ) {
<ComponentToUse
label={ __( 'Shuffle' ) }
icon={ shuffle }
className="block-editor-block-toolbar-shuffle"
onClick={ () => {
const nextPattern = getNextPattern();
nextPattern.blocks[ 0 ].attributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { dragHandle, trash } from '@wordpress/icons';
import { Button, Flex, FlexItem, ToolbarButton } from '@wordpress/components';
import { dragHandle } from '@wordpress/icons';
import { Button, Flex, FlexItem } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { forwardRef, useEffect } from '@wordpress/element';
import {
Expand Down Expand Up @@ -38,8 +38,6 @@ import BlockIcon from '../block-icon';
import { store as blockEditorStore } from '../../store';
import BlockDraggable from '../block-draggable';
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
import BlockMover from '../block-mover';
import Shuffle from '../block-toolbar/shuffle';

/**
* Block selection button component, displaying the label of the block. If the block
Expand All @@ -63,7 +61,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
__unstableGetEditorMode,
getNextBlockClientId,
getPreviousBlockClientId,
canRemoveBlock,
canMoveBlock,
} = select( blockEditorStore );
const { getActiveBlockVariation, getBlockType } =
Expand All @@ -74,26 +71,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
const orientation =
getBlockListSettings( rootClientId )?.orientation;
const match = getActiveBlockVariation( name, attributes );
const isBlockTemplatePart =
blockType?.name === 'core/template-part';

let isNextBlockTemplatePart = false;
const nextClientId = getNextBlockClientId();
if ( nextClientId ) {
const { name: nextName } = getBlock( nextClientId );
const nextBlockType = getBlockType( nextName );
isNextBlockTemplatePart =
nextBlockType?.name === 'core/template-part';
}

let isPrevBlockTemplatePart = false;
const prevClientId = getPreviousBlockClientId();
if ( prevClientId ) {
const { name: prevName } = getBlock( prevClientId );
const prevBlockType = getBlockType( prevName );
isPrevBlockTemplatePart =
prevBlockType?.name === 'core/template-part';
}

return {
blockMovingMode: hasBlockMovingClientId(),
Expand All @@ -105,26 +82,14 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
index + 1,
orientation
),
isBlockTemplatePart,
isNextBlockTemplatePart,
isPrevBlockTemplatePart,
canRemove: canRemoveBlock( clientId ),
canMove: canMoveBlock( clientId ),
canMove: canMoveBlock( clientId, rootClientId ),
getNextBlockClientId,
getPreviousBlockClientId,
};
},
[ clientId, rootClientId ]
);
const {
label,
icon,
blockMovingMode,
editorMode,
isBlockTemplatePart,
isNextBlockTemplatePart,
isPrevBlockTemplatePart,
canRemove,
canMove,
} = selected;
const { label, icon, blockMovingMode, editorMode, canMove } = selected;
const { setNavigationMode, removeBlock } = useDispatch( blockEditorStore );

// Focus the breadcrumb in navigation mode.
Expand Down Expand Up @@ -276,9 +241,7 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
);

const dragHandleLabel = __( 'Drag' );
const showBlockDraggable =
( canMove && editorMode === 'navigation' ) ||
( editorMode === 'zoom-out' && canMove && ! isBlockTemplatePart );
const showBlockDraggable = canMove && editorMode === 'navigation';

return (
<div className={ classNames }>
Expand Down Expand Up @@ -307,36 +270,6 @@ function BlockSelectionButton( { clientId, rootClientId }, ref ) {
</BlockDraggable>
</FlexItem>
) }
{ editorMode === 'zoom-out' && ! isBlockTemplatePart && (
<FlexItem>
<BlockMover
clientIds={ [ clientId ] }
hideDragHandle
isBlockMoverUpButtonDisabled={
isPrevBlockTemplatePart
}
isBlockMoverDownButtonDisabled={
isNextBlockTemplatePart
}
/>
</FlexItem>
) }
{ canMove && canRemove && editorMode === 'zoom-out' && (
<Shuffle clientId={ clientId } as={ Button } />
) }
{ canRemove &&
editorMode === 'zoom-out' &&
! isBlockTemplatePart && (
<FlexItem>
<ToolbarButton
icon={ trash }
label="Delete"
onClick={ () => {
removeBlock( clientId );
} }
/>
</FlexItem>
) }
{ editorMode === 'navigation' && (
<FlexItem>
<Button
Expand Down
9 changes: 9 additions & 0 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from './insertion-point';
import BlockToolbarPopover from './block-toolbar-popover';
import BlockToolbarBreadcrumb from './block-toolbar-breadcrumb';
import ZoomOutPopover from './zoom-out-popover';
import { store as blockEditorStore } from '../../store';
import usePopoverScroll from '../block-popover/use-popover-scroll';
import ZoomOutModeInserters from './zoom-out-mode-inserters';
Expand Down Expand Up @@ -79,6 +80,7 @@ export default function BlockTools( {
showEmptyBlockSideInserter,
showBreadcrumb,
showBlockToolbarPopover,
showZoomOutToolbar,
} = useShowBlockTools();

const {
Expand Down Expand Up @@ -229,6 +231,13 @@ export default function BlockTools( {
/>
) }

{ showZoomOutToolbar && (
<ZoomOutPopover
__unstableContentRef={ __unstableContentRef }
clientId={ clientId }
/>
) }

{ /* Used for the inline rich text toolbar. Until this toolbar is combined into BlockToolbar, someone implementing their own BlockToolbar will also need to use this to see the image caption toolbar. */ }
{ ! isZoomOutMode && ! hasFixedToolbar && (
<Popover.Slot
Expand Down
15 changes: 15 additions & 0 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,18 @@
top: 50%;
left: 50%;
}

.zoom-out-toolbar {

.block-editor-block-mover-button.block-editor-block-mover-button:focus-visible::before,
.zoom-out-toolbar-button:focus::before,
.block-editor-block-toolbar-shuffle:focus::before,
.block-selection-button_drag-handle:focus::before {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}

.block-editor-block-mover {
background: none;
border: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ export function useShowBlockTools() {
const maybeShowBreadcrumb =
hasSelectedBlock &&
! hasMultiSelection() &&
( editorMode === 'navigation' || editorMode === 'zoom-out' );
editorMode === 'navigation';

const _showBlockToolbarPopover =
editorMode !== 'zoom-out' &&
! getSettings().hasFixedToolbar &&
! _showEmptyBlockSideInserter &&
hasSelectedBlock &&
! isEmptyDefaultBlock &&
! maybeShowBreadcrumb;

return {
showEmptyBlockSideInserter: _showEmptyBlockSideInserter,
showBreadcrumb:
! _showEmptyBlockSideInserter && maybeShowBreadcrumb,
showBlockToolbarPopover:
! getSettings().hasFixedToolbar &&
showBlockToolbarPopover: _showBlockToolbarPopover,
showZoomOutToolbar:
editorMode === 'zoom-out' &&
! _showEmptyBlockSideInserter &&
hasSelectedBlock &&
! isEmptyDefaultBlock &&
! maybeShowBreadcrumb,
! maybeShowBreadcrumb &&
! _showBlockToolbarPopover,
};
}, [] );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* Internal dependencies
*/
import BlockPopover from '../block-popover';
import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';
import useSelectedBlockToolProps from './use-selected-block-tool-props';
import ZoomOutToolbar from './zoom-out-toolbar';

export default function ZoomOutPopover( { clientId, __unstableContentRef } ) {
const {
capturingClientId,
isInsertionPointVisible,
lastClientId,
rootClientId,
} = useSelectedBlockToolProps( clientId );

const popoverProps = useBlockToolbarPopoverProps( {
contentElement: __unstableContentRef?.current,
clientId,
} );

// Override some of the popover props for the zoom-out toolbar.
const props = {
...popoverProps,
placement: 'left-start',
flip: false,
};

return (
<BlockPopover
clientId={ capturingClientId || clientId }
bottomClientId={ lastClientId }
className={ clsx( 'zoom-out-toolbar-popover', {
'is-insertion-point-visible': isInsertionPointVisible,
} ) }
resize={ false }
{ ...props }
>
<ZoomOutToolbar
clientId={ clientId }
rootClientId={ rootClientId }
/>
</BlockPopover>
);
}
Loading
Loading