-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental: PoC for placeholder insert, we should drop this commit
- Loading branch information
Showing
14 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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
95 changes: 95 additions & 0 deletions
95
packages/block-editor/src/components/placeholder-block-appender/index.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,95 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Button, Tooltip, VisuallyHidden } from '@wordpress/components'; | ||
import { forwardRef } from '@wordpress/element'; | ||
import { _x, sprintf } from '@wordpress/i18n'; | ||
import { Icon, plus } from '@wordpress/icons'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Inserter from '../inserter'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
function PlaceholderBlockAppender( | ||
{ replaceClientId, className, onFocus, tabIndex }, | ||
ref | ||
) { | ||
const rootClientId = useSelect( | ||
( select ) => { | ||
const { getBlockRootClientId } = select( blockEditorStore ); | ||
return getBlockRootClientId( replaceClientId ); | ||
}, | ||
[ replaceClientId ] | ||
); | ||
return ( | ||
<Inserter | ||
position="bottom center" | ||
rootClientId={ rootClientId } | ||
__experimentalIsQuick | ||
replaceClientId={ replaceClientId } | ||
renderToggle={ ( { | ||
onToggle, | ||
disabled, | ||
isOpen, | ||
blockTitle, | ||
hasSingleBlockType, | ||
} ) => { | ||
let label; | ||
if ( hasSingleBlockType ) { | ||
label = sprintf( | ||
// translators: %s: the name of the block when there is only one | ||
_x( 'Add %s', 'directly add the only allowed block' ), | ||
blockTitle | ||
); | ||
} else { | ||
label = _x( | ||
'Add block', | ||
'Generic label for block inserter button' | ||
); | ||
} | ||
const isToggleButton = ! hasSingleBlockType; | ||
|
||
//TODO: allow a pass through | ||
let inserterButton = ( | ||
<Button | ||
ref={ ref } | ||
onFocus={ onFocus } | ||
tabIndex={ tabIndex } | ||
className={ classnames( | ||
className, | ||
'block-editor-placeholder-block-appender' | ||
) } | ||
onClick={ onToggle } | ||
aria-haspopup={ isToggleButton ? 'true' : undefined } | ||
aria-expanded={ isToggleButton ? isOpen : undefined } | ||
disabled={ disabled } | ||
label={ label } | ||
> | ||
{ ! hasSingleBlockType && ( | ||
<VisuallyHidden as="span">{ label }</VisuallyHidden> | ||
) } | ||
<Icon icon={ plus } /> | ||
</Button> | ||
); | ||
|
||
if ( isToggleButton || hasSingleBlockType ) { | ||
inserterButton = ( | ||
<Tooltip text={ label }>{ inserterButton }</Tooltip> | ||
); | ||
} | ||
return inserterButton; | ||
} } | ||
isAppender | ||
/> | ||
); | ||
} | ||
|
||
export default forwardRef( PlaceholderBlockAppender ); |
16 changes: 16 additions & 0 deletions
16
packages/block-editor/src/components/placeholder-block-appender/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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//throwaway styling for basic PoC | ||
.wp-block.block-list-appender.block-editor-placeholder-appender { | ||
height: 36px; | ||
width: 36px; | ||
border: $border-width solid $gray-900; | ||
margin-left: 0; | ||
margin-right: 8px; | ||
|
||
.block-editor-inserter { | ||
margin-top: 6px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
padding: 6px; | ||
} | ||
} | ||
|
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
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
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,11 @@ | ||
{ | ||
"apiVersion": 2, | ||
"name": "core/placeholder", | ||
"category": "design", | ||
"attributes": {}, | ||
"supports": { | ||
"html": false | ||
}, | ||
"editorStyle": "wp-block-placeholder-editor", | ||
"style": "wp-block-placeholder" | ||
} |
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,5 @@ | ||
const Placeholder = () => { | ||
return ''; | ||
}; | ||
|
||
export default Placeholder; |
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,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { create as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
|
||
const { name } = metadata; | ||
export { metadata, name }; | ||
|
||
export const settings = { | ||
title: _x( 'Block Placeholder', 'block placeholder' ), | ||
description: __( | ||
'A block placeholder to quickly add blocks. Click on it to replace it with a specific block.' | ||
), | ||
icon, | ||
edit, | ||
}; |
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