From cb1e99367857b6eeca4bace4a6873334810bfd78 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Wed, 2 Jun 2021 12:18:59 -0700 Subject: [PATCH 1/2] Make sticky top of block toolbars configurable --- packages/block-editor/README.md | 1 + .../block-tools/block-contextual-toolbar.js | 13 ++++++++++- .../components/block-tools/block-popover.js | 4 ++++ .../src/components/block-tools/index.js | 23 ++++++++++++++----- packages/components/src/popover/index.js | 6 +++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index a8a19f6f830211..c75e7875442477 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -244,6 +244,7 @@ _Parameters_ - _$0_ `Object`: Props. - _$0.children_ `Object`: The block content and style container. - _$0.\_\_unstableContentRef_ `Object`: Ref holding the content scroll container. +- _$0.\_\_experimentalStickyTop_ `Object`: Offset for the top position of toolbars. # **BlockVerticalAlignmentControl** diff --git a/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js b/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js index a8e55abe6f408b..460d6fc5ded5cb 100644 --- a/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js +++ b/packages/block-editor/src/components/block-tools/block-contextual-toolbar.js @@ -17,7 +17,13 @@ import NavigableToolbar from '../navigable-toolbar'; import BlockToolbar from '../block-toolbar'; import { store as blockEditorStore } from '../../store'; -function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) { +function BlockContextualToolbar( { + focusOnMount, + isFixed, + __experimentalStickyTop, + style = {}, + ...props +} ) { const { blockType, hasParents, showParentSelector } = useSelect( ( select ) => { const { @@ -59,12 +65,17 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) { 'is-fixed': isFixed, } ); + if ( __experimentalStickyTop ) { + style.top = __experimentalStickyTop; + } + return ( diff --git a/packages/block-editor/src/components/block-tools/block-popover.js b/packages/block-editor/src/components/block-tools/block-popover.js index 8371cfff9bbba8..de6094a6989f2e 100644 --- a/packages/block-editor/src/components/block-tools/block-popover.js +++ b/packages/block-editor/src/components/block-tools/block-popover.js @@ -54,6 +54,7 @@ function BlockPopover( { capturingClientId, __unstablePopoverSlot, __unstableContentRef, + __experimentalStickyTop, } ) { const { isNavigationMode, @@ -213,6 +214,7 @@ function BlockPopover( { // Observe movement for block animations (especially horizontal). __unstableObserveElement={ node } shouldAnchorIncludePadding + __experimentalStickyTop={ __experimentalStickyTop } > { ( shouldShowContextualToolbar || isToolbarForced ) && (
); } diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index 04302c68e173f6..16b2b2b1a89116 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -19,11 +19,16 @@ import { usePopoverScroll } from './use-popover-scroll'; * insertion point and a slot for the inline rich text toolbar). Must be wrapped * around the block content and editor styles wrapper or iframe. * - * @param {Object} $0 Props. - * @param {Object} $0.children The block content and style container. - * @param {Object} $0.__unstableContentRef Ref holding the content scroll container. + * @param {Object} $0 Props. + * @param {Object} $0.children The block content and style container. + * @param {Object} $0.__unstableContentRef Ref holding the content scroll container. + * @param {Object} $0.__experimentalStickyTop Offset for the top position of toolbars. */ -export default function BlockTools( { children, __unstableContentRef } ) { +export default function BlockTools( { + children, + __unstableContentRef, + __experimentalStickyTop, +} ) { const isLargeViewport = useViewportMatch( 'medium' ); const hasFixedToolbar = useSelect( ( select ) => select( blockEditorStore ).getSettings().hasFixedToolbar, @@ -33,11 +38,17 @@ export default function BlockTools( { children, __unstableContentRef } ) { return ( { ( hasFixedToolbar || ! isLargeViewport ) && ( - + ) } { /* Even if the toolbar is fixed, the block popover is still needed for navigation mode. */ } - + { /* Used for the inline rich text toolbar. */ } Date: Sat, 5 Jun 2021 16:52:20 -0700 Subject: [PATCH 2/2] Make the editor header sticky and have it offset the block toolbar. --- packages/base-styles/_z-index.scss | 4 ++-- packages/customize-widgets/src/components/header/style.scss | 3 +++ .../src/components/sidebar-block-editor/index.js | 5 ++++- packages/customize-widgets/src/controls/style.scss | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/base-styles/_z-index.scss b/packages/base-styles/_z-index.scss index 80794990713ff3..9e8cc1161fe599 100644 --- a/packages/base-styles/_z-index.scss +++ b/packages/base-styles/_z-index.scss @@ -179,8 +179,8 @@ $z-layers: ( // Appear under the customizer heading UI, but over anything else. ".customize-widgets__topbar": 8, - // Appear under the topbar. - ".customize-widgets__block-toolbar": 7, + // Appear over the topbar of both editor and customizer. + ".customize-widgets__block-toolbar": 10, ); @function z-index( $key ) { diff --git a/packages/customize-widgets/src/components/header/style.scss b/packages/customize-widgets/src/components/header/style.scss index 1faf5fbe5ae46f..259f779930f415 100644 --- a/packages/customize-widgets/src/components/header/style.scss +++ b/packages/customize-widgets/src/components/header/style.scss @@ -1,4 +1,7 @@ .customize-widgets-header { + position: sticky; + top: 0; + @include break-medium() { // Make space for the floating toolbar. margin-bottom: $grid-unit-60 + $default-block-margin; diff --git a/packages/customize-widgets/src/components/sidebar-block-editor/index.js b/packages/customize-widgets/src/components/sidebar-block-editor/index.js index 40592021000aff..46b7e533503b60 100644 --- a/packages/customize-widgets/src/components/sidebar-block-editor/index.js +++ b/packages/customize-widgets/src/components/sidebar-block-editor/index.js @@ -33,6 +33,9 @@ import { store as customizeWidgetsStore } from '../../store'; import WelcomeGuide from '../welcome-guide'; import KeyboardShortcuts from '../keyboard-shortcuts'; +// Used to offset the block toolbar’s sticky top +const headerHeight = 49; + export default function SidebarBlockEditor( { blockEditorSettings, sidebar, @@ -113,7 +116,7 @@ export default function SidebarBlockEditor( { isFixedToolbarActive={ isFixedToolbarActive } /> - + diff --git a/packages/customize-widgets/src/controls/style.scss b/packages/customize-widgets/src/controls/style.scss index 57bc56d9fcbbf3..de905da202a153 100644 --- a/packages/customize-widgets/src/controls/style.scss +++ b/packages/customize-widgets/src/controls/style.scss @@ -12,13 +12,13 @@ // Override the inline styles added via JS that make the section title // sticky feature work. The customize widget block-editor disables this // sticky title. - padding-top: 10px !important; + padding-top: 12px !important; .customize-section-title { // Disable the sticky title. `!important` as this overrides inline // styles added via JavaScript. position: static !important; - top: 0 !important; width: unset !important; + margin-top: -12px !important; } }