Skip to content

Commit

Permalink
Add framer motion context to the forwarded contexts in inspector cont…
Browse files Browse the repository at this point in the history
…rols slot/fill
  • Loading branch information
ciampo committed Jun 8, 2023
1 parent 44d8a56 commit 829e4e0
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions packages/block-editor/src/components/inspector-controls/slot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
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';

Expand All @@ -16,6 +20,7 @@ export default function InspectorControlsSlot( {
__experimentalGroup,
group = 'default',
label,
fillProps,
...props
} ) {
if ( __experimentalGroup ) {
Expand All @@ -31,6 +36,20 @@ export default function InspectorControlsSlot( {
}
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;
Expand All @@ -43,10 +62,16 @@ export default function InspectorControlsSlot( {
if ( label ) {
return (
<BlockSupportToolsPanel group={ group } label={ label }>
<BlockSupportSlotContainer { ...props } Slot={ Slot } />
<BlockSupportSlotContainer
{ ...props }
fillProps={ computedFillProps }
Slot={ Slot }
/>
</BlockSupportToolsPanel>
);
}

return <Slot { ...props } bubblesVirtually />;
return (
<Slot { ...props } fillProps={ computedFillProps } bubblesVirtually />
);
}

0 comments on commit 829e4e0

Please sign in to comment.