-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
slot.js
77 lines (69 loc) · 1.71 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* WordPress dependencies
*/
import {
__experimentalUseSlotFills as useSlotFills,
__unstableMotionContext as MotionContext,
} from '@wordpress/components';
import { useContext, useMemo } from '@wordpress/element';
import warning from '@wordpress/warning';
import deprecated from '@wordpress/deprecated';
/**
* Internal dependencies
*/
import BlockSupportToolsPanel from './block-support-tools-panel';
import BlockSupportSlotContainer from './block-support-slot-container';
import groups from './groups';
export default function InspectorControlsSlot( {
__experimentalGroup,
group = 'default',
label,
fillProps,
...props
} ) {
if ( __experimentalGroup ) {
deprecated(
'`__experimentalGroup` property in `InspectorControlsSlot`',
{
since: '6.2',
version: '6.4',
alternative: '`group`',
}
);
group = __experimentalGroup;
}
const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
const motionContextValue = useContext( MotionContext );
const computedFillProps = useMemo(
() => ( {
...( fillProps ?? {} ),
forwardedContext: [
...( fillProps?.forwardedContext ?? [] ),
[ MotionContext.Provider, { value: motionContextValue } ],
],
} ),
[ motionContextValue, fillProps ]
);
if ( ! Slot ) {
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
if ( ! fills?.length ) {
return null;
}
if ( label ) {
return (
<BlockSupportToolsPanel group={ group } label={ label }>
<BlockSupportSlotContainer
{ ...props }
fillProps={ computedFillProps }
Slot={ Slot }
/>
</BlockSupportToolsPanel>
);
}
return (
<Slot { ...props } fillProps={ computedFillProps } bubblesVirtually />
);
}