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

Bootstrap the sections exploded view #40314

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/edit-site/src/components/block-list-exploded/index.js
@@ -1,14 +1,21 @@
/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as blockEditorStore, Inserter } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { pure } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockListExplodedItem from './item';

const InserterBeforeBlock = pure( ( { clientId } ) => (
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know we had this HoC. Should I prefer using this over React.memo?

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 be honest at this point, I don't know. What's certain is that we need to make a decision :P. This HoC was here before React introduced React.memo and if I'm not wrong also works for Class component contrary to React.memo which I think is only suited for function components.

Copy link
Member

Choose a reason for hiding this comment

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

Right, React.memo works only with functional components.

What's certain is that we need to make a decision

Got it. Use React.memo with function components use pure with Class components 😄

<div className="edit-site-block-list-exploded__inserter" key={ clientId }>
<Inserter clientId={ clientId } __experimentalIsQuick isPrimary />
</div>
) );

function BlockListExploded() {
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
Expand All @@ -17,8 +24,12 @@ function BlockListExploded() {
return (
<div className="edit-site-block-list-exploded">
{ blockOrder.map( ( clientId ) => (
<BlockListExplodedItem key={ clientId } clientId={ clientId } />
<div key={ clientId }>
<InserterBeforeBlock clientId={ clientId } />
<BlockListExplodedItem clientId={ clientId } />
</div>
) ) }
<InserterBeforeBlock />
</div>
);
}
Expand Down
59 changes: 23 additions & 36 deletions packages/edit-site/src/components/block-list-exploded/item.js
Expand Up @@ -9,7 +9,6 @@ import classnames from 'classnames';
import {
store as blockEditorStore,
BlockPreview,
Inserter,
useBlockDisplayInformation,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -52,43 +51,31 @@ function BlockListExplodedItem( { clientId } ) {
}, [ isSelected ] );

return (
<div>
<div
className={ classnames(
'edit-site-block-list-exploded__item-container',
{ 'is-selected': isSelected }
) }
>
{ isSelected && (
<BlockListExplodedTopToolbar clientId={ clientId } />
) }
<div
className="edit-site-block-list-exploded__inserter"
key={ block.clientId }
ref={ blockWrapper }
role="button"
onClick={ ( event ) => {
if ( event.detail === 1 ) {
selectBlock( clientId );
} else if ( event.detail === 2 ) {
switchEditorMode( 'visual' );
}
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
} }
onKeyPress={ () => selectBlock( clientId ) }
onFocus={ () => selectBlock( clientId ) }
aria-label={ blockLabel }
tabIndex={ 0 }
>
<Inserter
clientId={ block.clientId }
__experimentalIsQuick
isPrimary
/>
</div>
<div
className={ classnames(
'edit-site-block-list-exploded__item-container',
{ 'is-selected': isSelected }
) }
>
{ isSelected && (
<BlockListExplodedTopToolbar clientId={ clientId } />
) }
<div
ref={ blockWrapper }
role="button"
onClick={ ( event ) => {
if ( event.detail === 1 ) {
selectBlock( clientId );
} else if ( event.detail === 2 ) {
switchEditorMode( 'visual' );
}
} }
onKeyPress={ () => selectBlock( clientId ) }
onFocus={ () => selectBlock( clientId ) }
aria-label={ blockLabel }
tabIndex={ 0 }
>
<BlockPreview blocks={ blocksToPreview } />
</div>
<BlockPreview blocks={ blocksToPreview } />
</div>
</div>
);
Expand Down
Expand Up @@ -3,7 +3,6 @@
flex-direction: column;
width: $content-width;
margin: auto;
padding-bottom: 30px;
}

.edit-site-block-list-exploded__inserter > div {
Expand Down