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

Update fixed block toolbar #52123

Merged
merged 8 commits into from
Jul 5, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
import { levelUp } from '@wordpress/icons';
import { next, previous } from '@wordpress/icons';
import { useViewportMatch } from '@wordpress/compose';

/**
Expand All @@ -24,7 +24,6 @@ import { useViewportMatch } from '@wordpress/compose';
import NavigableToolbar from '../navigable-toolbar';
import BlockToolbar from '../block-toolbar';
import { store as blockEditorStore } from '../../store';
import BlockIcon from '../block-icon';
import { unlock } from '../../lock-unlock';

function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
Expand Down Expand Up @@ -94,6 +93,7 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
aria-label={ __( 'Block tools' ) }
{ ...props }
>
{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }
{ isFixed && isLargeViewport && blockType && (
<ToolbarGroup
className={
Expand All @@ -105,26 +105,19 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
<ToolbarItem
as={ ToolbarButton }
ref={ toolbarButtonRef }
icon={
isCollapsed ? (
<BlockIcon icon={ blockType.icon } />
) : (
levelUp
)
}
icon={ isCollapsed ? next : previous }
onClick={ () => {
setIsCollapsed( ( collapsed ) => ! collapsed );
toolbarButtonRef.current.focus();
} }
label={
isCollapsed
? __( 'Show block tools' )
: __( 'Show document tools' )
: __( 'Hide block tools' )
}
/>
</ToolbarGroup>
) }
{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }
</NavigableToolbar>
);
}
Expand Down
95 changes: 69 additions & 26 deletions packages/block-editor/src/components/block-tools/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@
@include break-medium() {
&.is-fixed {

// leave room for block inserter
margin-left: $grid-unit-80;
// leave room for block inserter, undo and redo, list view
margin-left: $grid-unit-80 * 3 - 2 * $grid-unit + $grid-unit-05;
// position on top of interface header
position: fixed;
top: $admin-bar-height + $grid-unit;
top: $admin-bar-height + $grid-unit - $border-width;
// Don't fill up when empty
min-height: initial;
// remove the border
Expand All @@ -145,39 +145,85 @@

&.is-collapsed {
width: initial;
margin-left: $grid-unit-80 * 3 + $grid-unit-30;
}

.is-fullscreen-mode & {
// leave room for block inserter
margin-left: $grid-unit-80 + $grid-unit-70;
top: $grid-unit;
// leave room for block inserter, undo and redo, list view
// and some margin left
margin-left: $grid-unit-80 * 4 - 2 * $grid-unit;
top: $grid-unit - $border-width;
&.is-collapsed {
width: initial;
margin-left: $grid-unit-80 * 4 + $grid-unit-30;
}
}

& > .block-editor-block-toolbar.is-showing-movers {
flex-grow: initial;
width: initial;

// Add a border as separator in the block toolbar.
&::before {
content: "";
width: $border-width;
height: 3 * $grid-unit;
margin-top: $grid-unit + $grid-unit-05;
margin-right: 0;
background-color: $gray-300;
position: relative;
left: math.div(-$grid-unit-05, 2);
top: -1px;
}
}

& > .block-editor-block-toolbar__group-collapse-fixed-toolbar {
border: none;

.show-icon-labels & {
.components-button.has-icon {
// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
font-size: $helptext-font-size;
}
}
}

// Add a border as separator in the block toolbar.
&::after {
&::before {
content: "";
width: $border-width;
height: 24px;
height: 3 * $grid-unit;
margin-top: $grid-unit + $grid-unit-05;
margin-bottom: $grid-unit + $grid-unit-05;
margin-right: $grid-unit-10;
background-color: $gray-300;
position: absolute;
left: 44px;
position: relative;
left: 0;
top: -1px;
}
}

& > .block-editor-block-toolbar__group-expand-fixed-toolbar {
border: none;

.show-icon-labels & {
width: $grid-unit-80 * 4;
.components-button.has-icon {
// Hide the button icons when labels are set to display...
svg {
display: none;
}
// ... and display labels.
&::after {
content: attr(aria-label);
font-size: $helptext-font-size;
}
}
}

// Add a border as separator in the block toolbar.
&::before {
content: "";
Expand All @@ -186,27 +232,20 @@
margin-bottom: $grid-unit + $grid-unit-05;
background-color: $gray-300;
position: relative;
left: -12px; //the padding of buttons
height: 24px;
left: -8px;
height: 3 * $grid-unit;
top: -1px;
}
}

.show-icon-labels & {

margin-left: $grid-unit-80;

&.is-collapsed {
margin-left: $grid-unit-80 * 6;
}
margin-left: $grid-unit-80 + 2 * $grid-unit; // inserter and margin ;

.is-fullscreen-mode & {
margin-left: $grid-unit-80 + $grid-unit-80;
&.is-collapsed {
margin-left: $grid-unit-80 * 7;
}
margin-left: $grid-unit * 18; // site hub, inserter and margin
}


.block-editor-block-parent-selector .block-editor-block-parent-selector__button::after {
left: 0;
}
Expand Down Expand Up @@ -234,12 +273,14 @@
}

&.is-fixed .block-editor-block-parent-selector {

.block-editor-block-parent-selector__button {
position: relative;
top: -1px;
border: 0;
padding-right: 6px;
padding-left: 6px;

&::after {
content: "\00B7";
font-size: 16px;
Expand Down Expand Up @@ -281,7 +322,9 @@
// for the block inserter the publish button
@include break-large() {
&.is-fixed {
width: initial;
// the combined with of the tools at the right of the header and the margin left
// of the toolbar which includes four buttons
width: calc(100% - 240px - #{4 * $grid-unit-80});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Button, ToolbarItem } from '@wordpress/components';
import { listView, plus } from '@wordpress/icons';
import { useRef, useCallback } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand All @@ -36,6 +37,8 @@ function HeaderToolbar() {
const inserterButton = useRef();
const { setIsInserterOpened, setIsListViewOpened } =
useDispatch( editPostStore );
const { get: getPreference } = useSelect( preferencesStore );
const hasFixedToolbar = getPreference( 'core/edit-post', 'fixedToolbar' );
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a good way to use selectors when value is used during the render. When the fixedToolbar preference value changes, this won't rerender the component.

Let's make it part of the useSelect below.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made a PR for this: #52332

Copy link
Member

Choose a reason for hiding this comment

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

There's another one in packages/edit-site/src/components/header-edit-mode/index.js, let fix both in one go :)

Copy link
Contributor

Choose a reason for hiding this comment

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

done

const {
isInserterEnabled,
isInserterOpened,
Expand Down Expand Up @@ -147,7 +150,7 @@ function HeaderToolbar() {
/>
{ ( isWideViewport || ! showIconLabels ) && (
<>
{ isLargeViewport && (
{ isLargeViewport && ! hasFixedToolbar && (
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
color: currentColor;
background: $gray-200;
}

@include break-medium() {
width: 50%;
}

@include break-large() {
width: min(100%, 450px);
}
}

.edit-site-document-actions__command {
Expand Down
26 changes: 17 additions & 9 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export default function HeaderEditMode() {
};
}, [] );

const { get: getPreference } = useSelect( preferencesStore );
const hasFixedToolbar = getPreference( editSiteStore.name, 'fixedToolbar' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this a hook so we can share the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me a two liner is not worth a hok. I would be if the two liner would be some arcane expression or something but this is really basic.

Copy link
Member

Choose a reason for hiding this comment

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


const {
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
setIsInserterOpened,
Expand Down Expand Up @@ -213,14 +216,18 @@ export default function HeaderEditMode() {
) }
{ isLargeViewport && (
<>
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
variant={
showIconLabels ? 'tertiary' : undefined
}
disabled={ ! isVisualMode }
/>
{ ! hasFixedToolbar && (
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
variant={
showIconLabels
? 'tertiary'
: undefined
}
disabled={ ! isVisualMode }
/>
) }
<ToolbarItem
as={ UndoButton }
showTooltip={ ! showIconLabels }
Expand Down Expand Up @@ -257,7 +264,8 @@ export default function HeaderEditMode() {
/>
) }
{ isZoomedOutViewExperimentEnabled &&
! isDistractionFree && (
! isDistractionFree &&
! hasFixedToolbar && (
<ToolbarItem
as={ Button }
className="edit-site-header-edit-mode__zoom-out-view-toggle"
Expand Down
11 changes: 0 additions & 11 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
color: $gray-400;
display: flex;
flex-direction: column;

// Expand the fixed block toolbar to cover the document title control.
.block-editor-block-contextual-toolbar {
@include break-medium() {
&.is-fixed {
// the combined with of the tools at the right of the header and the margin left
width: calc(100% - 240px - #{$grid-unit-80} - #{$grid-unit-70});
}
}
}

}

.edit-site-layout__hub {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class ToolbarUtils {
exact: true,
} );
this.blockToolbarShowDocumentButton = this.page.getByRole( 'button', {
name: 'Show document tools',
name: 'Hide block tools',
exact: true,
} );
}
Expand Down