-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor: Bring back Inspector Advanced Controls #5952
Changes from all commits
0a8474b
ea06108
65e0e4d
36ca30c
0d9961d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
export default createSlotFill( 'InspectorAdvancedControls' ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fill } from '@wordpress/components'; | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
export default function InspectorControls( { children } ) { | ||
return ( | ||
<Fill name="Inspector.Controls"> | ||
{ children } | ||
</Fill> | ||
); | ||
} | ||
export default createSlotFill( 'InspectorControls' ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,32 +45,34 @@ class Slot extends Component { | |
} | ||
|
||
render() { | ||
const { name, bubblesVirtually = false, fillProps = {} } = this.props; | ||
const { children, name, bubblesVirtually = false, fillProps = {} } = this.props; | ||
const { getFills = noop } = this.context; | ||
|
||
if ( bubblesVirtually ) { | ||
return <div ref={ this.bindNode } />; | ||
} | ||
|
||
const fills = map( getFills( name ), ( fill ) => { | ||
const fillKey = fill.occurrence; | ||
|
||
// If a function is passed as a child, render it with the fillProps. | ||
if ( isFunction( fill.props.children ) ) { | ||
return cloneElement( fill.props.children( fillProps ), { key: fillKey } ); | ||
} | ||
|
||
return Children.map( fill.props.children, ( child, childIndex ) => { | ||
if ( ! child || isString( child ) ) { | ||
return child; | ||
} | ||
|
||
const childKey = `${ fillKey }---${ child.key || childIndex }`; | ||
return cloneElement( child, { key: childKey } ); | ||
} ); | ||
} ); | ||
|
||
return ( | ||
<div ref={ this.bindNode }> | ||
{ map( getFills( name ), ( fill ) => { | ||
const fillKey = fill.occurrence; | ||
|
||
// If a function is passed as a child, render it with the fillProps. | ||
if ( isFunction( fill.props.children ) ) { | ||
return cloneElement( fill.props.children( fillProps ), { key: fillKey } ); | ||
} | ||
|
||
return Children.map( fill.props.children, ( child, childIndex ) => { | ||
if ( ! child || isString( child ) ) { | ||
return child; | ||
} | ||
|
||
const childKey = `${ fillKey }---${ child.key || childIndex }`; | ||
return cloneElement( child, { key: childKey } ); | ||
} ); | ||
} ) } | ||
{ isFunction( children ) ? children( fills.filter( Boolean ) ) : fills } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we filter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To get rid of empty elements. Some fills render nothing based on Redux state. If you want to prevent rendering a slot wrapper it it has no fill which render something this is the way to go. In retrospective, I think this could be also done outside. Should we move it out or improve here and add some comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments would be good. It was also strange to me that we filter only if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I will open PR with all your comments addressed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done #9371. |
||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External dependecies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createSlotFill, Fill, Slot } from '../'; | ||
|
||
describe( 'createSlotFill', () => { | ||
const SLOT_NAME = 'MyFill'; | ||
const MyFill = createSlotFill( SLOT_NAME ); | ||
|
||
test( 'should match snapshot for Fill', () => { | ||
const wrapper = shallow( <MyFill /> ); | ||
|
||
expect( wrapper.type() ).toBe( Fill ); | ||
expect( wrapper ).toHaveProp( 'name', SLOT_NAME ); | ||
} ); | ||
|
||
test( 'should match snapshot for Slot', () => { | ||
const wrapper = shallow( <MyFill.Slot /> ); | ||
|
||
expect( wrapper.type() ).toBe( Slot ); | ||
expect( wrapper ).toHaveProp( 'name', SLOT_NAME ); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice helper method 👍 It simplifies a lot the slot fill creation.