Skip to content

Commit

Permalink
BlockControls, InspectorControls: remove useSlot, unify behavior on b…
Browse files Browse the repository at this point in the history
…ad group (#50198)
  • Loading branch information
jsnajdr authored May 2, 2023
1 parent 949ca32 commit 016651b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
12 changes: 8 additions & 4 deletions packages/block-editor/src/components/block-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ToolbarGroup,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand All @@ -15,11 +16,14 @@ import groups from './groups';

export default function BlockControlsSlot( { group = 'default', ...props } ) {
const accessibleToolbarState = useContext( ToolbarContext );
const Slot = groups[ group ].Slot;
const fills = useSlotFills( Slot.__unstableName );
const hasFills = Boolean( fills && fills.length );
const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}

if ( ! hasFills ) {
if ( ! fills?.length ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
__experimentalToolbarContext as ToolbarContext,
ToolbarGroup,
} from '@wordpress/components';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand All @@ -14,7 +15,11 @@ import groups from './groups';

export default function BlockControlsSlot( { group = 'default', ...props } ) {
const accessibleToolbarState = useContext( ToolbarContext );
const Slot = groups[ group ].Slot;
const Slot = groups[ group ]?.Slot;
if ( ! Slot ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}

if ( group === 'default' ) {
return <Slot { ...props } fillProps={ accessibleToolbarState } />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function InspectorControlsFill( {
const isDisplayed = useDisplayBlockControls();
const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
if ( ! isDisplayed ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function InspectorControlsFill( {

const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
if ( ! isDisplayed ) {
Expand Down
13 changes: 4 additions & 9 deletions packages/block-editor/src/components/inspector-controls/slot.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* WordPress dependencies
*/
import {
__experimentalUseSlot as useSlot,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
import warning from '@wordpress/warning';
import deprecated from '@wordpress/deprecated';

Expand Down Expand Up @@ -33,15 +30,13 @@ export default function InspectorControlsSlot( {
group = __experimentalGroup;
}
const Slot = groups[ group ]?.Slot;
const slot = useSlot( Slot?.__unstableName );
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot || ! slot ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
if ( ! Slot ) {
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}

const hasFills = Boolean( fills && fills.length );
if ( ! hasFills ) {
if ( ! fills?.length ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function InspectorControlsSlot( {
}
const Slot = groups[ group ]?.Slot;
if ( ! Slot ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}

Expand Down

0 comments on commit 016651b

Please sign in to comment.