-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alternative: add inserter to Nav block offcanvas experiment (#45947)
* Include offcanvas specific styles * Use standard Inserter only * Avoid using underscore naming convention * Use standard UI components for keyboard navigation * Extract appender to file * Apply TreeGridRow props * Remove clientId prop drilling * Remove need to pass clientID to offcanvas component
- Loading branch information
Showing
3 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/off-canvas-editor/appender.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { forwardRef } from '@wordpress/element'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import Inserter from '../inserter'; | ||
|
||
export const Appender = forwardRef( ( props, ref ) => { | ||
const { hideInserter, clientId } = useSelect( ( select ) => { | ||
const { | ||
getTemplateLock, | ||
__unstableGetEditorMode, | ||
getSelectedBlockClientId, | ||
} = select( blockEditorStore ); | ||
|
||
const _clientId = getSelectedBlockClientId(); | ||
|
||
return { | ||
clientId: getSelectedBlockClientId(), | ||
hideInserter: | ||
!! getTemplateLock( _clientId ) || | ||
__unstableGetEditorMode() === 'zoom-out', | ||
}; | ||
}, [] ); | ||
|
||
if ( hideInserter ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="offcanvas-editor__appender"> | ||
<Inserter | ||
ref={ ref } | ||
rootClientId={ clientId } | ||
position="bottom right" | ||
isAppender | ||
__experimentalIsQuick | ||
{ ...props } | ||
/> | ||
</div> | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
packages/block-editor/src/components/off-canvas-editor/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
//Styles for off-canvas editor, remove this line when you add some css to this file! | ||
.offcanvas-editor__appender .block-editor-inserter__toggle { | ||
background-color: #1e1e1e; | ||
color: #fff; | ||
margin: $grid-unit-10 0 0 28px; | ||
border-radius: 2px; | ||
height: 24px; | ||
min-width: 24px; | ||
padding: 0; | ||
|
||
&:hover, | ||
&:focus { | ||
background: var(--wp-admin-theme-color); | ||
color: #fff; | ||
} | ||
} |