-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
67 lines (59 loc) · 1.94 KB
/
index.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
// @ts-nocheck
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import BaseFill from './fill';
import BaseSlot from './slot';
import BubblesVirtuallyFill from './bubbles-virtually/fill';
import BubblesVirtuallySlot from './bubbles-virtually/slot';
import BubblesVirtuallySlotFillProvider from './bubbles-virtually/slot-fill-provider';
import SlotFillProvider from './provider';
export { default as useSlot } from './bubbles-virtually/use-slot';
export { default as useSlotFills } from './bubbles-virtually/use-slot-fills';
export function Fill( props ) {
// We're adding both Fills here so they can register themselves before
// their respective slot has been registered. Only the Fill that has a slot
// will render. The other one will return null.
return (
<>
<BaseFill { ...props } />
<BubblesVirtuallyFill { ...props } />
</>
);
}
export const Slot = forwardRef( ( { bubblesVirtually, ...props }, ref ) => {
if ( bubblesVirtually ) {
return <BubblesVirtuallySlot { ...props } ref={ ref } />;
}
return <BaseSlot { ...props } />;
} );
export function Provider( { children, ...props } ) {
return (
<SlotFillProvider { ...props }>
<BubblesVirtuallySlotFillProvider>
{ children }
</BubblesVirtuallySlotFillProvider>
</SlotFillProvider>
);
}
export function createSlotFill( key ) {
const baseName = typeof key === 'symbol' ? key.description : key;
const FillComponent = ( props ) => <Fill name={ key } { ...props } />;
FillComponent.displayName = `${ baseName }Fill`;
const SlotComponent = ( props ) => <Slot name={ key } { ...props } />;
SlotComponent.displayName = `${ baseName }Slot`;
SlotComponent.__unstableName = key;
return {
Fill: FillComponent,
Slot: SlotComponent,
};
}
export const createPrivateSlotFill = ( name ) => {
const privateKey = Symbol( name );
const privateSlotFill = createSlotFill( privateKey );
return { privateKey, ...privateSlotFill };
};