-
Notifications
You must be signed in to change notification settings - Fork 4k
/
fill.js
53 lines (49 loc) · 1.27 KB
/
fill.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
42
43
44
45
46
47
48
49
50
51
52
53
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import {
__experimentalStyleProvider as StyleProvider,
__experimentalToolsPanelContext as ToolsPanelContext,
} from '@wordpress/components';
import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import useDisplayBlockControls from '../use-display-block-controls';
import groups from './groups';
export default function InspectorControlsFill( {
__experimentalGroup: group = 'default',
children,
} ) {
const isDisplayed = useDisplayBlockControls();
const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
return null;
}
if ( ! isDisplayed ) {
return null;
}
return (
<StyleProvider document={ document }>
<Fill>
{ ( fillProps ) => {
// Children passed to InspectorControlsFill will not have
// access to any React Context whose Provider is part of
// the InspectorControlsSlot tree. So we re-create the
// Provider in this subtree.
const value = ! isEmpty( fillProps ) ? fillProps : null;
return (
<ToolsPanelContext.Provider value={ value }>
{ children }
</ToolsPanelContext.Provider>
);
} }
</Fill>
</StyleProvider>
);
}