-
Notifications
You must be signed in to change notification settings - Fork 4k
/
slot.js
41 lines (35 loc) · 1.02 KB
/
slot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* WordPress dependencies
*/
import { __experimentalUseSlot as useSlot } from '@wordpress/components';
import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import BlockSupportToolsPanel from './block-support-tools-panel';
import groups from './groups';
const blockSupportGroups = [ 'border', 'color', 'dimensions', 'typography' ];
export default function InspectorControlsSlot( {
group = 'default',
bubblesVirtually = true,
...props
} ) {
const Slot = groups[ group ]?.Slot;
const slot = useSlot( Slot?.__unstableName );
if ( ! Slot || ! slot ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
return null;
}
const hasFills = Boolean( slot.fills && slot.fills.length );
if ( ! hasFills ) {
return null;
}
if ( blockSupportGroups.includes( group ) ) {
return (
<BlockSupportToolsPanel group={ group }>
<Slot { ...props } bubblesVirtually={ bubblesVirtually } />
</BlockSupportToolsPanel>
);
}
return <Slot { ...props } bubblesVirtually={ bubblesVirtually } />;
}