Skip to content

Commit

Permalink
Extensibility: Add possibility to disable document settings panels re…
Browse files Browse the repository at this point in the history
…gistered by plugins
  • Loading branch information
gziolo committed Aug 8, 2019
1 parent 8a052be commit 7d2ef43
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/edit-post/src/components/options-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
*/
import Section from './section';
import {
EnablePluginDocumentSettingPanelOption,
EnablePublishSidebarOption,
EnableTipsOption,
EnablePanelOption,
Expand All @@ -48,6 +49,7 @@ export function OptionsModal( { isModalActive, isViewable, closeModal } ) {
<EnableTipsOption label={ __( 'Enable Tips' ) } />
</Section>
<Section title={ __( 'Document Panels' ) }>
<EnablePluginDocumentSettingPanelOption.Slot />
{ isViewable && (
<EnablePanelOption label={ __( 'Permalink' ) } panelName="post-link" />
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import { EnablePanelOption } from './index';

const { Fill, Slot } = createSlotFill( 'EnablePluginDocumentSettingPanelOption' );

const EnablePluginDocumentSettingPanelOption = ( { label, panelName } ) => (
<Fill>
<EnablePanelOption
label={ label }
panelName={ panelName }
/>
</Fill>
);

EnablePluginDocumentSettingPanelOption.Slot = Slot;

export default EnablePluginDocumentSettingPanelOption;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as EnableCustomFieldsOption } from './enable-custom-fields';
export { default as EnablePanelOption } from './enable-panel';
export { default as EnablePluginDocumentSettingPanelOption } from './enable-plugin-document-setting-panel';
export { default as EnablePublishSidebarOption } from './enable-publish-sidebar';
export { default as EnableTipsOption } from './enable-tips';
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`OptionsModal should match snapshot when the modal is active 1`] = `
<Section
title="Document Panels"
>
<EnablePluginDocumentSettingPanelOptionSlot />
<WithSelect(PostTaxonomies)
taxonomyWrapper={[Function]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { withDispatch, withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { EnablePluginDocumentSettingPanelOption } from '../../options-modal/options';

export const { Fill, Slot } = createSlotFill( 'PluginDocumentSettingPanel' );

const PluginDocumentSettingFill = ( { isEnabled, opened, onToggle, className, title, icon, children } ) => {
if ( ! isEnabled ) {
return null;
}
const PluginDocumentSettingFill = ( { isEnabled, panelName, opened, onToggle, className, title, icon, children } ) => {
return (
<Fill>
<PanelBody
className={ className }
title={ title }
icon={ icon }
opened={ opened }
onToggle={ onToggle }
>
{ children }
</PanelBody>
</Fill>
<>
<EnablePluginDocumentSettingPanelOption
label={ title }
panelName={ panelName }
/>
<Fill>
{ isEnabled && (
<PanelBody
className={ className }
title={ title }
icon={ icon }
opened={ opened }
onToggle={ onToggle }
>
{ children }
</PanelBody>
) }
</Fill>
</>
);
};

Expand Down Expand Up @@ -104,4 +114,5 @@ const PluginDocumentSettingPanel = compose(
)( PluginDocumentSettingFill );

PluginDocumentSettingPanel.Slot = Slot;

export default PluginDocumentSettingPanel;

0 comments on commit 7d2ef43

Please sign in to comment.