-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. - The title and ID of each Meta Box is stored in the `core/edit-post` Redux store. - The `MetaBoxTitles` HOC provides an easy way to list all of the registered Meta Boxes within Gutenberg. - The `MetaBoxesVisibility` and `MetaBoxVisibility` components respond to the existing `isEditorPanelEnabled` selector and show/hide Meta Boxes using `el.style.display = 'none'`;
- Loading branch information
1 parent
df71243
commit f864dc0
Showing
9 changed files
with
113 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
packages/edit-post/src/components/meta-box-titles/index.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,20 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
function MetaBoxTitles( { titles, titleWrapper } ) { | ||
return map( titles, ( title, id ) => ( | ||
<Fragment key={ id }>{ titleWrapper( title, id ) }</Fragment> | ||
) ); | ||
} | ||
|
||
export default withSelect( ( select ) => ( { | ||
titles: select( 'core/edit-post' ).getMetaBoxTitles(), | ||
} ) )( MetaBoxTitles ); |
17 changes: 17 additions & 0 deletions
17
packages/edit-post/src/components/meta-boxes-visibility/index.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,17 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import MetaBoxTitles from '../meta-box-titles'; | ||
import MetaBoxVisibility from './meta-box-visibility'; | ||
|
||
function MetaBoxesVisibility() { | ||
return ( | ||
<MetaBoxTitles | ||
titleWrapper={ ( title, id ) => ( | ||
<MetaBoxVisibility id={ id } /> | ||
) } | ||
/> | ||
); | ||
} | ||
|
||
export default MetaBoxesVisibility; |
30 changes: 30 additions & 0 deletions
30
packages/edit-post/src/components/meta-boxes-visibility/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,30 @@ | ||
/** | ||
* 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; | ||
document.getElementById( id ).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
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