forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Custom Fields and Advanced Panels to Options modal (WordPress#10676)
* First pass at adding 'Advanced Panels' to Options modal Allows the user to enable or disable 'Advanced Panels' (AKA Meta Boxes) via the Options modal.
- Loading branch information
1 parent
218075e
commit bdfcb30
Showing
12 changed files
with
288 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { Fragment } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import MetaBoxesArea from './meta-boxes-area'; | ||
import MetaBoxVisibility from './meta-box-visibility'; | ||
|
||
function MetaBoxes( { location, isActive } ) { | ||
if ( ! isActive ) { | ||
return null; | ||
} | ||
|
||
return <MetaBoxesArea location={ location } />; | ||
function MetaBoxes( { location, isVisible, metaBoxes } ) { | ||
return ( | ||
<Fragment> | ||
{ map( metaBoxes, ( { id } ) => ( | ||
<MetaBoxVisibility key={ id } id={ id } /> | ||
) ) } | ||
{ isVisible && <MetaBoxesArea location={ location } /> } | ||
</Fragment> | ||
); | ||
} | ||
|
||
export default withSelect( ( select, ownProps ) => { | ||
const { isMetaBoxLocationActive } = select( 'core/edit-post' ); | ||
export default withSelect( ( select, { location } ) => { | ||
const { isMetaBoxLocationVisible, getMetaBoxesPerLocation } = select( 'core/edit-post' ); | ||
|
||
return { | ||
isActive: isMetaBoxLocationActive( ownProps.location ), | ||
metaBoxes: getMetaBoxesPerLocation( location ), | ||
isVisible: isMetaBoxLocationVisible( location ), | ||
}; | ||
} )( MetaBoxes ); |
33 changes: 33 additions & 0 deletions
33
packages/edit-post/src/components/meta-boxes/meta-box-visibility.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
class MetaBoxVisibility extends Component { | ||
componentDidMount() { | ||
this.updateDOM(); | ||
} | ||
|
||
componentDidUpdate( prevProps ) { | ||
if ( this.props.isVisible !== prevProps.isVisible ) { | ||
this.updateDOM(); | ||
} | ||
} | ||
|
||
updateDOM() { | ||
const { id, isVisible } = this.props; | ||
const element = document.getElementById( id ); | ||
if ( element ) { | ||
element.style.display = isVisible ? '' : 'none'; | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
export default withSelect( ( select, { id } ) => ( { | ||
isVisible: select( 'core/edit-post' ).isEditorPanelEnabled( `meta-box-${ id }` ), | ||
} ) )( MetaBoxVisibility ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.